Skip to content

Commit 10588f1

Browse files
fix: explicitly track first if-branch usage in union template
1 parent 82a9ad6 commit 10588f1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

openapi_python_client/templates/property_templates/union_property.py.jinja

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ elif {{ source }} is None:
6666
{% else %}
6767
{% set ns.contains_modified_properties = true %}
6868
{% endif %}
69+
{% set has_first_clause = false %}
6970
{% if loop.first and property.required and not property.nullable %}{# No if UNSET or if None statement before this #}
71+
{% set has_first_clause = true %}
7072
if isinstance({{ source }}, {{ inner_property.get_instance_type_string() }}):
7173
{% elif not loop.last or ns.contains_properties_without_transform %}
72-
elif isinstance({{ source }}, {{ inner_property.get_instance_type_string() }}):
74+
{% if not has_first_clause %}if{% else %}elif{% endif %} isinstance({{ source }}, {{ inner_property.get_instance_type_string() }}):
75+
{% set has_first_clause = true %}
7376
{% else %}
7477
else:
7578
{% endif %}

0 commit comments

Comments
 (0)