Skip to content

Commit 8b51e93

Browse files
committed
Avoid generating singleton Unions
1 parent 691fc5b commit 8b51e93

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

end_to_end_tests/multiple-media-types-golden-record/multiple_media_types_client/api/multiple_media_types/post.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def _parse_response(
3333
if response.headers.get("content-type") == "application/octet-stream":
3434
response_200 = cast(Any, response.content)
3535
return response_200
36+
if response.status_code == 404:
37+
response_404: Any
38+
if response.headers.get("content-type") == "text/plain":
39+
response_404 = cast(Any, response.text)
40+
return response_404
3641
if response.status_code == 503:
3742
response_503: Union[ErrorResponse, Any]
3843
if response.headers.get("content-type") == "application/json":

end_to_end_tests/multiple-media-types.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ paths:
1515
schema:
1616
const: "Why have a fixed response? I dunno"
1717
"application/octet-stream": {}
18+
"404":
19+
description: "Not Found"
20+
content:
21+
"text/plain": {}
1822
"503":
1923
description: "Server Not Available"
2024
content:

openapi_python_client/templates/endpoint_module.py.jinja

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ def _parse_response(*, client: Union[AuthenticatedClient, Client], response: htt
8282
return None
8383
{% endif %}
8484
{% else %}
85+
{% if response.content[1:] %}
8586
{{response.content[0].prop.python_name}}: Union[{{ response.content | map(attribute='prop') | map(attribute='type_string') | join(', ') }}]
87+
{% else %}
88+
{{response.content[0].prop.python_name}}: {{response.content[0].prop.type_string}}
89+
{% endif %}
8690
{% for media_type in response.content %}
8791
{% if media_type.content_type %}
8892
if response.headers.get("content-type") == "{{ media_type.content_type }}":

0 commit comments

Comments
 (0)