Skip to content

Handle Unset Enums when deserializing #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
project info.
- `none` will not create a project folder at all, only the inner package folder (which won't be inner anymore)
- Attempt to detect and alert users if they are using an unsupported version of OpenAPI (#281).
- Fixes `Enum` deserialization when the value is `UNSET`.

### Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
try:
a_property = UNSET
_a_property = data
if _a_property is not None:
if _a_property is not None and _a_property is not UNSET:
a_property = AnEnum(_a_property)

return a_property
except: # noqa: E722
pass
a_property = UNSET
_a_property = data
if _a_property is not None:
if _a_property is not None and _a_property is not UNSET:
a_property = AnIntEnum(_a_property)

return a_property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
try:
a_property = UNSET
_a_property = data
if _a_property is not None:
if _a_property is not None and _a_property is not UNSET:
a_property = AnEnum(_a_property)

return a_property
except: # noqa: E722
pass
a_property = UNSET
_a_property = data
if _a_property is not None:
if _a_property is not None and _a_property is not UNSET:
a_property = AnIntEnum(_a_property)

return a_property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% else %}
{{ property.python_name }} = {{ initial_value }}
_{{ property.python_name }} = {{ source }}
if _{{ property.python_name }} is not None:
if _{{ property.python_name }} is not None and _{{ property.python_name }} is not UNSET:
{{ property.python_name }} = {{ property.reference.class_name }}(_{{ property.python_name }})
{% endif %}
{% endmacro %}
Expand Down