Skip to content

Commit d56f292

Browse files
committed
Update individual property templates
1 parent 43f2716 commit d56f292

File tree

8 files changed

+33
-7
lines changed

8 files changed

+33
-7
lines changed

openapi_python_client/templates/property_templates/date_property.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ if {{ source }} is not None:
1212
{% if property.required %}
1313
{{ destination }} = {{ source }}.isoformat()
1414
{% else %}
15-
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
15+
if {{ source }} is UNSET:
16+
{{ destination }} = UNSET
17+
else:
18+
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
1619
{% endif %}
1720
{% endmacro %}

openapi_python_client/templates/property_templates/datetime_property.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ if {{ source }} is not None:
1212
{% if property.required %}
1313
{{ destination }} = {{ source }}.isoformat()
1414
{% else %}
15-
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
15+
if {{ source }} is UNSET:
16+
{{ destination }} = UNSET
17+
else:
18+
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
1619
{% endif %}
1720
{% endmacro %}

openapi_python_client/templates/property_templates/dict_property.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ if {{ source }} is not None:
1212
{% if property.required %}
1313
{{ destination }} = {{ source }}
1414
{% else %}
15-
{{ destination }} = {{ source }} if {{ source }} else None
15+
if {{ source }} is UNSET:
16+
{{ destination }} = UNSET
17+
else:
18+
{{ destination }} = {{ source }} if {{ source }} else None
1619
{% endif %}
1720
{% endmacro %}

openapi_python_client/templates/property_templates/enum_property.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from openapi_python_client.templates.types import UNSET
2+
13
{% macro construct(property, source) %}
24
{% if property.required %}
35
{{ property.python_name }} = {{ property.reference.class_name }}({{ source }})
@@ -12,6 +14,9 @@ if {{ source }} is not None:
1214
{% if property.required %}
1315
{{ destination }} = {{ source }}.value
1416
{% else %}
15-
{{ destination }} = {{ source }}.value if {{ source }} else None
17+
if {{ source }} is UNSET:
18+
{{ destination }} = UNSET
19+
else:
20+
{{ destination }} = {{ source }}.value if {{ source }} else None
1621
{% endif %}
1722
{% endmacro %}

openapi_python_client/templates/property_templates/file_property.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
{% if property.required %}
88
{{ destination }} = {{ source }}.to_tuple()
99
{% else %}
10-
{{ destination }} = {{ source }}.to_tuple() if {{ source }} else None
10+
if {{ source }} is UNSET:
11+
{{ destination }} = UNSET
12+
else:
13+
{{ destination }} = {{ source }}.to_tuple() if {{ source }} else None
1114
{% endif %}
1215
{% endmacro %}

openapi_python_client/templates/property_templates/list_property.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from openapi_python_client.templates.types import UNSET
2+
13
{% macro construct(property, source) %}
24
{% set inner_property = property.inner_property %}
35
{% if inner_property.template %}
@@ -36,6 +38,8 @@ for {{ inner_source }} in {{ source }}:
3638
{% if not property.required %}
3739
if {{ source }} is None:
3840
{{ destination }} = None
41+
elif {{ source }} is UNSET:
42+
{{ destination }} = UNSET
3943
else:
4044
{{ _transform(property, source, destination) | indent(4) }}
4145
{% else %}

openapi_python_client/templates/property_templates/ref_property.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ if {{ source }} is not None:
1212
{% if property.required %}
1313
{{ destination }} = {{ source }}.to_dict()
1414
{% else %}
15-
{{ destination }} = {{ source }}.to_dict() if {{ source }} else None
15+
if {{ source }} is UNSET:
16+
{{ destination }} = UNSET
17+
else:
18+
{{ destination }} = {{ source }}.to_dict() if {{ source }} else None
1619
{% endif %}
1720
{% endmacro %}

openapi_python_client/templates/property_templates/union_property.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def _parse_{{ property.python_name }}(data: Dict[str, Any]) -> {{ property.get_t
2525
{% if not property.required %}
2626
if {{ source }} is None:
2727
{{ destination }}: {{ property.get_type_string() }} = None
28+
elif {{ source }} is UNSET:
29+
{{ destination }} = UNSET
2830
{% endif %}
2931
{% for inner_property in property.inner_properties %}
3032
{% if loop.first and property.required %}{# No if None statement before this #}
@@ -36,7 +38,7 @@ else:
3638
{% endif %}
3739
{% if inner_property.template %}
3840
{% from "property_templates/" + inner_property.template import transform %}
39-
{{ transform(inner_property, source, destination) | indent(8) }}
41+
{{ transform(inner_property, source, destination) | indent(4) }}
4042
{% else %}
4143
{{ destination }} = {{ source }}
4244
{% endif %}

0 commit comments

Comments
 (0)