When an OpenAPI schema defines an enum property with nullable: true as a property attribute (rather than including null in the enum values), the generated Python code raises TypeError when deserializing null from the API.
conditionable_type: type: string enum: - AlertField nullable: true
Per OpenAPI v3.0.3 spec:
"If nullable is true, then null is allowed as a value regardless of any other constraints."
The generated code should accept None as a valid value.
The generated from_dict() method passes None directly to the enum check function, which raises:
TypeError: Unexpected value None. Expected one of {'AlertField'}
_conditionable_type = d.pop("conditionable_type", UNSET) conditionable_type: SomeEnumType | Unset # Missing `| None` if isinstance(_conditionable_type, Unset): conditionable_type = UNSET else: # Passes None directly to check function - FAILS conditionable_type = check_some_enum_type(_conditionable_type)
Should be similar to how nullable string properties are handled:
def _parse_conditionable_type(data: object) -> SomeEnumType | None | Unset: if data is None: return data if isinstance(data, Unset): return data return check_some_enum_type(data) conditionable_type = _parse_conditionable_type(d.pop("conditionable_type", UNSET))
The EnumProperty class only checks for null in the enum values list:
unchecked_value_list = [value for value in enum if value is not None]
It does not check for nullable: true as a separate property attribute on the schema.
Both are valid per OpenAPI spec, but only the first case is currently handled.
Minimal OpenAPI spec:
openapi: "3.0.3" info: title: Test version: "1.0" paths: {} components: schemas: TestModel: type: object properties: my_enum: type: string enum: - value1 nullable: true
Generate client, then:
from my_client.models import TestModel TestModel.from_dict({"my_enum": None}) # Raises TypeError
Release v1.1.1: Fix nullable enums, regenerate client
Release v1.2.0: Fix nullable enums, add new features from OpenAPI spec
Activity
Release v1.1.1: Fix nullable enums, regenerate client
Release v1.2.0: Fix nullable enums, add new features from OpenAPI spec