Skip to content

Commit ff24140

Browse files
p1-raNementon
authored andcommitted
template / macro: return_type / correct duplicate
1 parent 95a29a8 commit ff24140

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

openapi_python_client/templates/endpoint_macros.py.jinja

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,22 @@ params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
7171
{% endif %}
7272
{% endmacro %}
7373

74+
{% macro reponses_type_csv(responses) %}
75+
{% for response in responses %}
76+
{{ response.prop.get_type_string() }}{{"," if not loop.last }}
77+
{% endfor %}
78+
{% endmacro %}
79+
7480
{% macro return_type(endpoint) %}
7581
{% if endpoint.responses | length == 0 %}
7682
None
7783
{%- elif endpoint.responses | length == 1 %}
7884
{{ endpoint.responses[0].prop.get_type_string() }}
7985
{%- else %}
8086
Union[
81-
{% for response in endpoint.responses %}
82-
{{ response.prop.get_type_string() }}{{ "," if not loop.last }}
87+
{% set response_types = reponses_type_csv(endpoint.responses) | trim %}
88+
{% for type_string in (response_types.split(',') | unique | list) %}
89+
{{ type_string }}{{ "," if not loop.last }}
8390
{% endfor %}
8491
]
8592
{%- endif %}

0 commit comments

Comments
 (0)