Closed
Description
Describe the bug
When a list occurs inside a union, this call causes the list template to initialize the value with UNSET
instead of []
. The list template then tries to call append
on UNSET
, which of course does not work.
OpenAPI Spec File
A link to your openapi.json which produces this issue.
Desktop (please complete the following information):
- OS: Ubuntu 22.04.2
- Python Version: 2.10.8
- openapi-python-client version 0.14.0
Additional context
The above OpneAPI spec file generates the following code, for reference:
def _parse_response(
*, client: Client, response: httpx.Response
) -> Optional[Union["GetExampleResponse200Type0", List["GetExampleResponse200Type1Item"]]]:
if response.status_code == HTTPStatus.OK:
def _parse_response_200(
data: object,
) -> Union["GetExampleResponse200Type0", List["GetExampleResponse200Type1Item"]]:
try:
if not isinstance(data, dict):
raise TypeError()
response_200_type_0 = GetExampleResponse200Type0.from_dict(data)
return response_200_type_0
except: # noqa: E722
pass
if not isinstance(data, list):
raise TypeError()
response_200_type_1 = UNSET # PROBLEM IS HERE
_response_200_type_1 = data
for response_200_type_1_item_data in _response_200_type_1:
response_200_type_1_item = GetExampleResponse200Type1Item.from_dict(response_200_type_1_item_data)
response_200_type_1.append(response_200_type_1_item)
return response_200_type_1
response_200 = _parse_response_200(response.json())
return response_200
if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None