Skip to content

Commit aa6972c

Browse files
authored
fix: Handle Unset Enums when deserializing (#306)
1 parent abf906d commit aa6972c

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
project info.
1616
- `none` will not create a project folder at all, only the inner package folder (which won't be inner anymore)
1717
- Attempt to detect and alert users if they are using an unsupported version of OpenAPI (#281).
18+
- Fixes `Enum` deserialization when the value is `UNSET`.
1819

1920
### Changes
2021

end_to_end_tests/golden-record-custom/custom_e2e/models/model_with_union_property.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
4646
try:
4747
a_property = UNSET
4848
_a_property = data
49-
if _a_property is not None:
49+
if _a_property is not None and _a_property is not UNSET:
5050
a_property = AnEnum(_a_property)
5151

5252
return a_property
5353
except: # noqa: E722
5454
pass
5555
a_property = UNSET
5656
_a_property = data
57-
if _a_property is not None:
57+
if _a_property is not None and _a_property is not UNSET:
5858
a_property = AnIntEnum(_a_property)
5959

6060
return a_property

end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
4646
try:
4747
a_property = UNSET
4848
_a_property = data
49-
if _a_property is not None:
49+
if _a_property is not None and _a_property is not UNSET:
5050
a_property = AnEnum(_a_property)
5151

5252
return a_property
5353
except: # noqa: E722
5454
pass
5555
a_property = UNSET
5656
_a_property = data
57-
if _a_property is not None:
57+
if _a_property is not None and _a_property is not UNSET:
5858
a_property = AnIntEnum(_a_property)
5959

6060
return a_property

openapi_python_client/templates/property_templates/enum_property.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{% else %}
55
{{ property.python_name }} = {{ initial_value }}
66
_{{ property.python_name }} = {{ source }}
7-
if _{{ property.python_name }} is not None:
7+
if _{{ property.python_name }} is not None and _{{ property.python_name }} is not UNSET:
88
{{ property.python_name }} = {{ property.reference.class_name }}(_{{ property.python_name }})
99
{% endif %}
1010
{% endmacro %}

0 commit comments

Comments
 (0)