openapi-generators / openapi-generators/openapi-python-client
Incorrect parsing of null as nullable enum value serialized as strings
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2k
- Forks
- 293
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Description
Consider the following schema definition (which passes validation with the openapitools/openapi-generator-cli container image):
// [...]
"deviceEncryptionKeyScheme": {
"$ref": "#/components/schemas/DeviceEncryptionKeyScheme",
"nullable": true // <-- nullability declared
},
// [...]
"DeviceEncryptionKeyScheme": {
"enum": ["Default8"],
"type": "string"
},
It looks as if openapi-python-client version 0.23.1 supports deserialization with the deviceEncryptionKeyScheme property being unset, but not it being null:
_device_encryption_key_scheme = d.pop("deviceEncryptionKeyScheme", UNSET)
device_encryption_key_scheme: Union[Unset, DeviceEncryptionKeyScheme]
if isinstance(_device_encryption_key_scheme, Unset):
device_encryption_key_scheme = UNSET
else:
device_encryption_key_scheme = DeviceEncryptionKeyScheme(_device_encryption_key_scheme)
This looks like a bug to me.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the nullable enum case from the issue using the openapi-python-client 0.23.1 behavior and the shown generated deserialization code. Start at the handling of deviceEncryptionKeyScheme after d.pop; compare the UNSET path with the null path. Done means an explicitly null value deserializes successfully while an unset property remains represented as UNSET.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100