Skip to content

0.30.0: duplicate "maxLength: 0" entry for EmailField with default #1517

Description

@glennmatthews

Describe the bug

In v0.30, but not v0.29, a serializer EmailField(default="") generates an incorrect schema entry with redundant maxLength: 0 entries. A similar field with no default generates a valid schema.

        # v0.29.0 schema
        email:
          oneOf:
          - type: string
            maxLength: 254
            format: email
          - type: string
            maxLength: 254
          default: ''
          title: E-mail
        # v0.30.0 schema
        email:
          oneOf:
          - oneOf:
            - type: string
              maxLength: 254
              format: email
            - type: string
              maxLength: 0
          - oneOf:
            - type: string
              format: email
              maxLength: 254
            - type: string
              maxLength: 0
          default: ''
          title: E-mail

The v0.30.0 schema fails validation by openapi_spec_validator:

openapi_spec_validator.validation.exceptions.OpenAPIValidationError: '' is valid under each of {'oneOf': [{'type': 'string', 'format': 'email', 'maxLength': 254}, {'type': 'string', 'maxLength': 0}]}, {'oneOf': [{'type': 'string', 'maxLength': 254, 'format': 'email'}, {'type': 'string', 'maxLength': 0}]}

To Reproduce

>>> ContactSerializer().fields["email"]
EmailField(allow_blank=True, default='', label='E-mail', max_length=254, required=False)

Expected behavior

A valid schema should be generated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions