Skip to content

Commit 7223731

Browse files
committed
Update e2e tests, add model with union prop
1 parent 072f8da commit 7223731

File tree

5 files changed

+75
-4
lines changed

5 files changed

+75
-4
lines changed

end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _get_kwargs(
5353

5454
json_enum_prop: Union[Unset, AnEnum] = UNSET
5555
if not isinstance(enum_prop, Unset):
56-
json_enum_prop = enum_prop.value
56+
json_enum_prop = enum_prop
5757

5858
params: Dict[str, Any] = {}
5959
if string_prop is not UNSET:

end_to_end_tests/golden-record/my_test_api_client/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
77
from .different_enum import DifferentEnum
88
from .http_validation_error import HTTPValidationError
9+
from .model_with_union_property import ModelWithUnionProperty
910
from .test_inline_objectsjson_body import TestInlineObjectsjsonBody
1011
from .test_inline_objectsresponse_200 import TestInlineObjectsresponse_200
1112
from .validation_error import ValidationError

end_to_end_tests/golden-record/my_test_api_client/models/a_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ def to_dict(self) -> Dict[str, Any]:
7474
def from_dict(d: Dict[str, Any]) -> "AModel":
7575
an_enum_value = AnEnum(d["an_enum_value"])
7676

77-
def _parse_a_camel_date_time(data: Dict[str, Any]) -> Union[datetime.datetime, datetime.date]:
77+
def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.date]:
7878
a_camel_date_time: Union[datetime.datetime, datetime.date]
7979
try:
80-
a_camel_date_time = isoparse(d["aCamelDateTime"])
80+
a_camel_date_time = isoparse(data)
8181

8282
return a_camel_date_time
8383
except: # noqa: E722
8484
pass
85-
a_camel_date_time = isoparse(d["aCamelDateTime"]).date()
85+
a_camel_date_time = isoparse(data).date()
8686

8787
return a_camel_date_time
8888

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from typing import Any, Dict, Union
2+
3+
import attr
4+
5+
from ..models.an_enum import AnEnum
6+
from ..models.an_int_enum import AnIntEnum
7+
from ..types import UNSET, Unset
8+
9+
10+
@attr.s(auto_attribs=True)
11+
class ModelWithUnionProperty:
12+
""" """
13+
14+
a_property: Union[Unset, AnEnum, AnIntEnum] = UNSET
15+
16+
def to_dict(self) -> Dict[str, Any]:
17+
a_property: Union[Unset, AnEnum, AnIntEnum]
18+
if isinstance(self.a_property, Unset):
19+
a_property = UNSET
20+
elif isinstance(self.a_property, AnEnum):
21+
a_property = UNSET
22+
if not isinstance(self.a_property, Unset):
23+
a_property = self.a_property
24+
25+
else:
26+
a_property = UNSET
27+
if not isinstance(self.a_property, Unset):
28+
a_property = self.a_property
29+
30+
field_dict = {}
31+
if a_property is not UNSET:
32+
field_dict["a_property"] = a_property
33+
34+
return field_dict
35+
36+
@staticmethod
37+
def from_dict(d: Dict[str, Any]) -> "ModelWithUnionProperty":
38+
def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
39+
a_property: Union[Unset, AnEnum, AnIntEnum]
40+
try:
41+
a_property = UNSET
42+
if data is not None:
43+
a_property = AnEnum(data)
44+
45+
return a_property
46+
except: # noqa: E722
47+
pass
48+
a_property = UNSET
49+
if data is not None:
50+
a_property = AnIntEnum(data)
51+
52+
return a_property
53+
54+
a_property = _parse_a_property(d.get("a_property", UNSET))
55+
56+
return ModelWithUnionProperty(
57+
a_property=a_property,
58+
)

end_to_end_tests/openapi.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,18 @@
727727
"type": "string"
728728
}
729729
}
730+
},
731+
"ModelWithUnionProperty": {
732+
"title": "ModelWithUnionProperty",
733+
"type": "object",
734+
"properties": {
735+
"a_property": {
736+
"oneOf": [
737+
{"$ref": "#/components/schemas/AnEnum"},
738+
{"$ref": "#/components/schemas/AnIntEnum"}
739+
]
740+
}
741+
}
730742
}
731743
}
732744
}

0 commit comments

Comments
 (0)