Skip to content

Required nullable fields generate non-nullable types #135

Description

@skylarmb

Using openapi-python-generator 2.1.2 with OpenAPI 3.1, a required property declared like this:

description:
  type:
    - string
    - 'null'

is generated as str rather than Optional[str] / str | None.

Current behavior:

  • required + nullable field -> non-nullable Python type
  • non-required + nullable field -> nullable Python type

This is a bug because required only means the field must be present in the payload. It does not mean the value cannot be null. For a required nullable schema, the generated Python type should still accept None; otherwise the generated Pydantic models reject valid API responses containing null.

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