schemadiff.changes.enum API documentation

# Module `schemadiff.changes.enum`

Expand source code

    from schemadiff.changes import Change, Criticality

    class EnumValueAdded(Change):
        def __init__(self, enum, value):
            self.criticality = Criticality.dangerous(
                "Adding an enum value may break existing clients that were not "
                "programming defensively against an added case when querying an enum."
            )
            self.enum = enum
            self.value = value
            self.description = enum.values[value].description

        @property
        def message(self):
            return f"Enum value `{self.value}` was added to `{self.enum.name}` enum"

        @property
        def path(self):
            return f"{self.enum.name}.{self.value}"

    class EnumValueRemoved(Change):
        def __init__(self, enum, value):
            self.criticality = Criticality.breaking(
                "Removing an enum value will break existing queries that use this enum value"
            )
            self.enum = enum
            self.value = value

        @property
        def message(self):
            return f"Enum value `{self.value}` was removed from `{self.enum.name}` enum"

        @property
        def path(self):
            return f"{self.enum.name}"

    class EnumValueDescriptionChanged(Change):

        criticality = Criticality.safe()

        def __init__(self, enum, name, old_value, new_value):
            self.enum = enum
            self.name = name
            self.old_value = old_value
            self.new_value = new_value

        @property
        def message(self):
            if not self.old_value.description:
                msg = f"Description for enum value `{self.name}` set to `{self.new_value.description}`"
            else:
                msg = (
                    f"Description for enum value `{self.name}` changed"
                    f" from `{self.old_value.description}` to `{self.new_value.description}`"
                )
            return msg

        @property
        def path(self):
            return f"{self.enum.name}.{self.name}"

    class EnumValueDeprecationReasonChanged(Change):

        criticality = Criticality.safe(
            "A deprecated field can still be used by clients and will give them time to adapt their queries"
        )

        def __init__(self, enum, name, old_value, new_value):
            self.enum = enum
            self.name = name
            self.old_value = old_value
            self.new_value = new_value

        @property
        def message(self):
            if not self.old_value.deprecation_reason:
                msg = (
                    f"Enum value `{self.name}` was deprecated "
                    f"with reason `{self.new_value.deprecation_reason}`"
                )
            else:
                msg = (
                    f"Deprecation reason for enum value `{self.name}` changed "
                    f"from `{self.old_value.deprecation_reason}` to `{self.new_value.deprecation_reason}`"
                )
            return msg

        @property
        def path(self):
            return f"{self.enum.name}.{self.name}"

## Classes

`class EnumValueAdded (enum, value)`

  Common interface of all schema changes

  This class offers the common operations and properties of all schema changes. You may use it as a type hint to get better suggestions in your editor of choice.

  Expand source code

      class EnumValueAdded(Change):
          def __init__(self, enum, value):
              self.criticality = Criticality.dangerous(
                  "Adding an enum value may break existing clients that were not "
                  "programming defensively against an added case when querying an enum."
              )
              self.enum = enum
              self.value = value
              self.description = enum.values[value].description

          @property
          def message(self):
              return f"Enum value `{self.value}` was added to `{self.enum.name}` enum"

          @property
          def path(self):
              return f"{self.enum.name}.{self.value}"

  ### Ancestors

  - Change
  - abc.ABC

  ### Inherited members

  - `Change`:
    - `breaking`
    - `checksum`
    - `dangerous`
    - `message`
    - `path`
    - `restricted`
    - `safe`
    - `to_dict`
    - `to_json`
`class EnumValueDeprecationReasonChanged (enum, name, old_value, new_value)`

  Common interface of all schema changes

  This class offers the common operations and properties of all schema changes. You may use it as a type hint to get better suggestions in your editor of choice.

  Expand source code

      class EnumValueDeprecationReasonChanged(Change):

          criticality = Criticality.safe(
              "A deprecated field can still be used by clients and will give them time to adapt their queries"
          )

          def __init__(self, enum, name, old_value, new_value):
              self.enum = enum
              self.name = name
              self.old_value = old_value
              self.new_value = new_value

          @property
          def message(self):
              if not self.old_value.deprecation_reason:
                  msg = (
                      f"Enum value `{self.name}` was deprecated "
                      f"with reason `{self.new_value.deprecation_reason}`"
                  )
              else:
                  msg = (
                      f"Deprecation reason for enum value `{self.name}` changed "
                      f"from `{self.old_value.deprecation_reason}` to `{self.new_value.deprecation_reason}`"
                  )
              return msg

          @property
          def path(self):
              return f"{self.enum.name}.{self.name}"

  ### Ancestors

  - Change
  - abc.ABC

  ### Class variables

  `var criticality : Criticality`

  ### Inherited members

  - `Change`:
    - `breaking`
    - `checksum`
    - `dangerous`
    - `message`
    - `path`
    - `restricted`
    - `safe`
    - `to_dict`
    - `to_json`
`class EnumValueDescriptionChanged (enum, name, old_value, new_value)`

  Common interface of all schema changes

  This class offers the common operations and properties of all schema changes. You may use it as a type hint to get better suggestions in your editor of choice.

  Expand source code

      class EnumValueDescriptionChanged(Change):

          criticality = Criticality.safe()

          def __init__(self, enum, name, old_value, new_value):
              self.enum = enum
              self.name = name
              self.old_value = old_value
              self.new_value = new_value

          @property
          def message(self):
              if not self.old_value.description:
                  msg = f"Description for enum value `{self.name}` set to `{self.new_value.description}`"
              else:
                  msg = (
                      f"Description for enum value `{self.name}` changed"
                      f" from `{self.old_value.description}` to `{self.new_value.description}`"
                  )
              return msg

          @property
          def path(self):
              return f"{self.enum.name}.{self.name}"

  ### Ancestors

  - Change
  - abc.ABC

  ### Class variables

  `var criticality : Criticality`

  ### Inherited members

  - `Change`:
    - `breaking`
    - `checksum`
    - `dangerous`
    - `message`
    - `path`
    - `restricted`
    - `safe`
    - `to_dict`
    - `to_json`
`class EnumValueRemoved (enum, value)`

  Common interface of all schema changes

  This class offers the common operations and properties of all schema changes. You may use it as a type hint to get better suggestions in your editor of choice.

  Expand source code

      class EnumValueRemoved(Change):
          def __init__(self, enum, value):
              self.criticality = Criticality.breaking(
                  "Removing an enum value will break existing queries that use this enum value"
              )
              self.enum = enum
              self.value = value

          @property
          def message(self):
              return f"Enum value `{self.value}` was removed from `{self.enum.name}` enum"

          @property
          def path(self):
              return f"{self.enum.name}"

  ### Ancestors

  - Change
  - abc.ABC

  ### Inherited members

  - `Change`:
    - `breaking`
    - `checksum`
    - `dangerous`
    - `message`
    - `path`
    - `restricted`
    - `safe`
    - `to_dict`
    - `to_json`