Skip to content

$ref overwrites nullable property #159

@bushkov

Description

@bushkov

If a property is defined via a $ref and it's nullable set to True, then this nullable will be ignored.

If you take an example from the TODO app, make a title nullable:

    Item:
      type: object
      required:
        - title
      properties:
        title:
          type: string
          maxLength: 40
          nullable: true

and modify ITEMS in app.py to contain an item with null property:

ITEMS = [
    Item(title="Buy milk"),
    Item(title="Buy eggs"),
    Item(title="Make pankaces!"),
    Item(title=None),
]

Then everything works fine.

However, if we define title via a $ref:

    Title:
      type: string
      maxLength: 40
      nullable: true

    Item:
      type: object
      required:
        - title
      properties:
        title:
          $ref: '#/components/schemas/Title'

Then we get the following error:

Value [{'title': 'Buy milk'}, {'title': 'Buy eggs'}, {'title': 'Make pankaces!'}, {'title': None}] not valid for schema of type SchemaType.ARRAY: (<ValidationError: 'None for not nullable'>,)

Note that we started observing this error only since yesterday, before it was working as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions