Skip to content

Fix/template-duplicate-return-type #364

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

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[List[AModel],
response_422 = HTTPValidationError.from_dict(response.json())

return response_422
if response.status_code == 423:
response_423 = HTTPValidationError.from_dict(response.json())

return response_423
return None


Expand Down
10 changes: 10 additions & 0 deletions end_to_end_tests/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
}
}
}
},
"423": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions openapi_python_client/templates/endpoint_macros.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,22 @@ params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
{% endif %}
{% endmacro %}

{% macro reponses_type_csv(responses) %}
{% for response in responses %}
{{ response.prop.get_type_string() }}{{"," if not loop.last }}
{% endfor %}
{% endmacro %}

{% macro return_type(endpoint) %}
{% if endpoint.responses | length == 0 %}
None
{%- elif endpoint.responses | length == 1 %}
{{ endpoint.responses[0].prop.get_type_string() }}
{%- else %}
Union[
{% for response in endpoint.responses %}
{{ response.prop.get_type_string() }}{{ "," if not loop.last }}
{% set response_types = reponses_type_csv(endpoint.responses) | trim %}
{% for type_string in (response_types.split(',') | unique | list) %}
{{ type_string }}{{ "," if not loop.last }}
{% endfor %}
]
{%- endif %}
Expand Down