diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py index ec2216810..2ed83e388 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py @@ -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 diff --git a/end_to_end_tests/openapi.json b/end_to_end_tests/openapi.json index 359419473..ed0de8918 100644 --- a/end_to_end_tests/openapi.json +++ b/end_to_end_tests/openapi.json @@ -70,6 +70,16 @@ } } } + }, + "423": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } } } } diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index 705985aab..0f721f714 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -71,6 +71,12 @@ 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 @@ -78,8 +84,9 @@ None {{ 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 %}