Skip to content

Commit eb45e92

Browse files
committed
Fix for union property
Reduce indent of inner properties Don't declare type on call-out to subtemplate
1 parent 0e0525b commit eb45e92

File tree

9 files changed

+19
-18
lines changed

9 files changed

+19
-18
lines changed

openapi_python_client/templates/property_templates/date_property.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ if {{ source }} is not None:
88
{% endif %}
99
{% endmacro %}
1010

11-
{% macro transform(property, source, destination) %}
11+
{% macro transform(property, source, destination, declare_type=True) %}
1212
{% if property.required %}
1313
{% if property.nullable %}
1414
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
1515
{% else %}
1616
{{ destination }} = {{ source }}.isoformat()
1717
{% endif %}
1818
{% else %}
19-
{{ destination }}: Union[Unset, str] = UNSET
19+
{{ destination }}{% if declare_type %}: Union[Unset, str]{% endif %} = UNSET
2020
if not isinstance({{ source }}, Unset):
2121
{% if property.nullable %}
2222
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None

openapi_python_client/templates/property_templates/datetime_property.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ if {{ source }} is not None:
88
{% endif %}
99
{% endmacro %}
1010

11-
{% macro transform(property, source, destination) %}
11+
{% macro transform(property, source, destination, declare_type=True) %}
1212
{% if property.required %}
1313
{% if property.nullable %}
1414
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
1515
{% else %}
1616
{{ destination }} = {{ source }}.isoformat()
1717
{% endif %}
1818
{% else %}
19-
{{ destination }}: Union[Unset, str] = UNSET
19+
{{ destination }}{% if declare_type %}: Union[Unset, str]{% endif %} = UNSET
2020
if not isinstance({{ source }}, Unset):
2121
{% if property.nullable %}
2222
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None

openapi_python_client/templates/property_templates/dict_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if {{ source }} is not None:
88
{% endif %}
99
{% endmacro %}
1010

11-
{% macro transform(property, source, destination) %}
11+
{% macro transform(property, source, destination, declare_type=True) %}
1212
{% if property.nullable %}
1313
{{ destination }} = {{ source }} if {{ source }} else None
1414
{% else %}

openapi_python_client/templates/property_templates/enum_property.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ if {{ source }} is not None:
88
{% endif %}
99
{% endmacro %}
1010

11-
{% macro transform(property, source, destination) %}
11+
{% macro transform(property, source, destination, declare_type=True) %}
1212
{% if property.required %}
1313
{% if property.nullable %}
1414
{{ destination }} = {{ source }}.value if {{ source }} else None
1515
{% else %}
1616
{{ destination }} = {{ source }}.value
1717
{% endif %}
1818
{% else %}
19-
{{ destination }}: {{ property.get_type_string() }} = UNSET
19+
{{ destination }}{% if declare_type %}: {{ property.get_type_string() }}{% endif %} = UNSET
2020
if not isinstance({{ source }}, Unset):
2121
{% if property.nullable %}
2222
{{ destination }} = {{ source }}.value if {{ source }} else None

openapi_python_client/templates/property_templates/file_property.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
)
55
{% endmacro %}
66

7-
{% macro transform(property, source, destination) %}
7+
{% macro transform(property, source, destination, declare_type=True) %}
88
{% if property.required %}
99
{% if property.nullable %}
1010
{{ destination }} = {{ source }}.to_tuple() if {{ source }} else None
1111
{% else %}
1212
{{ destination }} = {{ source }}.to_tuple()
1313
{% endif %}
1414
{% else %}
15-
{{ destination }}: {{ property.get_type_string() }} = UNSET
15+
{{ destination }}{% if declare_type %}: {{ property.get_type_string() }}{% endif %} = UNSET
1616
if not isinstance({{ source }}, Unset):
1717
{% if property.nullable %}
1818
{{ destination }} = {{ source }}.to_tuple() if {{ source }} else None

openapi_python_client/templates/property_templates/list_property.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ for {{ inner_source }} in {{ source }}:
3131
{% endmacro %}
3232

3333

34-
{% macro transform(property, source, destination) %}
34+
{% macro transform(property, source, destination, declare_type=True) %}
3535
{% set inner_property = property.inner_property %}
3636
{% if property.required %}
3737
{% if property.nullable %}
@@ -43,7 +43,7 @@ else:
4343
{{ _transform(property, source, destination) }}
4444
{% endif %}
4545
{% else %}
46-
{{ destination }}: Union[Unset, List[Any]] = UNSET
46+
{{ destination }}{% if declare_type %}: Union[Unset, List[Any]]{% endif %} = UNSET
4747
if not isinstance({{ source }}, Unset):
4848
{% if property.nullable %}
4949
if {{ source }} is None:

openapi_python_client/templates/property_templates/model_property.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ if {{ source }} is not None:
88
{% endif %}
99
{% endmacro %}
1010

11-
{% macro transform(property, source, destination) %}
11+
{% macro transform(property, source, destination, declare_type=True) %}
1212
{% if property.required %}
1313
{% if property.nullable %}
1414
{{ destination }} = {{ source }}.to_dict() if {{ source }} else None
1515
{% else %}
1616
{{ destination }} = {{ source }}.to_dict()
1717
{% endif %}
1818
{% else %}
19-
{{ destination }}: {{ property.get_type_string() }} = UNSET
19+
{{ destination }}{% if declare_type %}: {{ property.get_type_string() }}{% endif %} = UNSET
2020
if not isinstance({{ source }}, Unset):
2121
{% if property.nullable %}
2222
{{ destination }} = {{ source }}.to_dict() if {{ source }} else None

openapi_python_client/templates/property_templates/none_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{{ property.python_name }} = None
33
{% endmacro %}
44

5-
{% macro transform(property, source, destination) %}
5+
{% macro transform(property, source, destination, declare_type=True) %}
66
{{ destination }} = None
77
{% endmacro %}

openapi_python_client/templates/property_templates/union_property.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ def _parse_{{ property.python_name }}(data: Dict[str, Any]) -> {{ property.get_t
2121
{{ property.python_name }} = _parse_{{ property.python_name }}({{ source }})
2222
{% endmacro %}
2323

24-
{% macro transform(property, source, destination) %}
24+
{% macro transform(property, source, destination, declare_type=True) %}
2525
{% if not property.required %}
26-
{{ destination }}: {{ property.get_type_string() }}
26+
{{ destination }}{% if declare_type %}: {{ property.get_type_string() }}{% endif %}
27+
2728
if isinstance({{ source }}, Unset):
2829
{{ destination }} = UNSET
2930
{% endif %}
@@ -33,7 +34,7 @@ if {{ source }} is None:
3334
{% else %}{# There's an if UNSET statement before this #}
3435
elif {{ source }} is None:
3536
{% endif %}
36-
{{ destination }}: {{ property.get_type_string() }} = None
37+
{{ destination }}{% if declare_type %}: {{ property.get_type_string() }}{% endif %} = None
3738
{% endif %}
3839
{% for inner_property in property.inner_properties %}
3940
{% if loop.first and property.required and not property.nullable %}{# No if UNSET or if None statement before this #}
@@ -45,7 +46,7 @@ else:
4546
{% endif %}
4647
{% if inner_property.template %}
4748
{% from "property_templates/" + inner_property.template import transform %}
48-
{{ transform(inner_property, source, destination) | indent(4) }}
49+
{{ transform(inner_property, source, destination, declare_type=False) | indent(4) }}
4950
{% else %}
5051
{{ destination }} = {{ source }}
5152
{% endif %}

0 commit comments

Comments
 (0)