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.
Using
openapi-python-generator2.1.2 with OpenAPI 3.1, a required property declared like this:is generated as
strrather thanOptional[str]/str | None.Current behavior:
This is a bug because
requiredonly means the field must be present in the payload. It does not mean the value cannot benull. For a required nullable schema, the generated Python type should still acceptNone; otherwise the generated Pydantic models reject valid API responses containingnull.