Skip to content

Commit 2ad8d29

Browse files
Support optional model
1 parent 7391c9f commit 2ad8d29

15 files changed

+792
-4
lines changed

end_to_end_tests/golden-record-custom/custom_e2e/models/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
""" Contains all the data models used in inputs/outputs """
22

33
from .a_model import AModel
4+
from .a_model_model import AModelModel
5+
from .a_model_not_required_model import AModelNotRequiredModel
6+
from .a_model_not_required_nullable_model import AModelNotRequiredNullableModel
7+
from .a_model_nullable_model import AModelNullableModel
48
from .an_enum import AnEnum
59
from .an_int_enum import AnIntEnum
610
from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost

end_to_end_tests/golden-record-custom/custom_e2e/models/a_model.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import attr
55
from dateutil.parser import isoparse
66

7+
from ..models.a_model_model import AModelModel
8+
from ..models.a_model_not_required_model import AModelNotRequiredModel
9+
from ..models.a_model_not_required_nullable_model import AModelNotRequiredNullableModel
10+
from ..models.a_model_nullable_model import AModelNullableModel
711
from ..models.an_enum import AnEnum
812
from ..models.different_enum import DifferentEnum
913
from ..types import UNSET, Unset
@@ -17,12 +21,16 @@ class AModel:
1721
a_camel_date_time: Union[datetime.datetime, datetime.date]
1822
a_date: datetime.date
1923
required_not_nullable: str
24+
model: AModelModel
2025
a_nullable_date: Optional[datetime.date]
2126
required_nullable: Optional[str]
27+
nullable_model: Optional[AModelNullableModel]
2228
nested_list_of_enums: Union[Unset, List[List[DifferentEnum]]] = UNSET
2329
attr_1_leading_digit: Union[Unset, str] = UNSET
2430
not_required_nullable: Union[Unset, Optional[str]] = UNSET
2531
not_required_not_nullable: Union[Unset, str] = UNSET
32+
not_required_model: Union[AModelNotRequiredModel, Unset] = UNSET
33+
not_required_nullable_model: Union[Optional[AModelNotRequiredNullableModel], Unset] = UNSET
2634

2735
def to_dict(self) -> Dict[str, Any]:
2836
an_enum_value = self.an_enum_value.value
@@ -35,6 +43,8 @@ def to_dict(self) -> Dict[str, Any]:
3543

3644
a_date = self.a_date.isoformat()
3745
required_not_nullable = self.required_not_nullable
46+
model = self.model.to_dict()
47+
3848
nested_list_of_enums: Union[Unset, List[Any]] = UNSET
3949
if not isinstance(self.nested_list_of_enums, Unset):
4050
nested_list_of_enums = []
@@ -52,6 +62,17 @@ def to_dict(self) -> Dict[str, Any]:
5262
required_nullable = self.required_nullable
5363
not_required_nullable = self.not_required_nullable
5464
not_required_not_nullable = self.not_required_not_nullable
65+
nullable_model = self.nullable_model.to_dict() if self.nullable_model else None
66+
67+
not_required_model: Union[Unset, Dict[str, Any]] = UNSET
68+
if not isinstance(self.not_required_model, Unset):
69+
not_required_model = self.not_required_model.to_dict()
70+
71+
not_required_nullable_model: Union[None, Unset, Dict[str, Any]] = UNSET
72+
if not isinstance(self.not_required_nullable_model, Unset):
73+
not_required_nullable_model = (
74+
self.not_required_nullable_model.to_dict() if self.not_required_nullable_model else None
75+
)
5576

5677
field_dict: Dict[str, Any] = {}
5778
field_dict.update(
@@ -60,8 +81,10 @@ def to_dict(self) -> Dict[str, Any]:
6081
"aCamelDateTime": a_camel_date_time,
6182
"a_date": a_date,
6283
"required_not_nullable": required_not_nullable,
84+
"model": model,
6385
"a_nullable_date": a_nullable_date,
6486
"required_nullable": required_nullable,
87+
"nullable_model": nullable_model,
6588
}
6689
)
6790
if nested_list_of_enums is not UNSET:
@@ -72,6 +95,10 @@ def to_dict(self) -> Dict[str, Any]:
7295
field_dict["not_required_nullable"] = not_required_nullable
7396
if not_required_not_nullable is not UNSET:
7497
field_dict["not_required_not_nullable"] = not_required_not_nullable
98+
if not_required_model is not UNSET:
99+
field_dict["not_required_model"] = not_required_model
100+
if not_required_nullable_model is not UNSET:
101+
field_dict["not_required_nullable_model"] = not_required_nullable_model
75102

76103
return field_dict
77104

@@ -99,6 +126,8 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat
99126

100127
required_not_nullable = d.pop("required_not_nullable")
101128

129+
model = AModelModel.from_dict(d.pop("model"))
130+
102131
nested_list_of_enums = []
103132
_nested_list_of_enums = d.pop("nested_list_of_enums", UNSET)
104133
for nested_list_of_enums_item_data in _nested_list_of_enums or []:
@@ -124,17 +153,38 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat
124153

125154
not_required_not_nullable = d.pop("not_required_not_nullable", UNSET)
126155

156+
nullable_model = None
157+
_nullable_model = d.pop("nullable_model")
158+
if _nullable_model is not None:
159+
nullable_model = AModelNullableModel.from_dict(cast(Dict[str, Any], _nullable_model))
160+
161+
not_required_model: Union[AModelNotRequiredModel, Unset] = UNSET
162+
_not_required_model = d.pop("not_required_model", UNSET)
163+
if not isinstance(_not_required_model, Unset):
164+
not_required_model = AModelNotRequiredModel.from_dict(cast(Dict[str, Any], _not_required_model))
165+
166+
not_required_nullable_model = None
167+
_not_required_nullable_model = d.pop("not_required_nullable_model", UNSET)
168+
if _not_required_nullable_model is not None and not isinstance(_not_required_nullable_model, Unset):
169+
not_required_nullable_model = AModelNotRequiredNullableModel.from_dict(
170+
cast(Dict[str, Any], _not_required_nullable_model)
171+
)
172+
127173
a_model = AModel(
128174
an_enum_value=an_enum_value,
129175
a_camel_date_time=a_camel_date_time,
130176
a_date=a_date,
131177
required_not_nullable=required_not_nullable,
178+
model=model,
132179
nested_list_of_enums=nested_list_of_enums,
133180
a_nullable_date=a_nullable_date,
134181
attr_1_leading_digit=attr_1_leading_digit,
135182
required_nullable=required_nullable,
136183
not_required_nullable=not_required_nullable,
137184
not_required_not_nullable=not_required_not_nullable,
185+
nullable_model=nullable_model,
186+
not_required_model=not_required_model,
187+
not_required_nullable_model=not_required_nullable_model,
138188
)
139189

140190
return a_model
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from typing import Any, Dict, List, 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 AModelModel:
12+
""" """
13+
14+
a_property: Union[Unset, AnEnum, AnIntEnum] = UNSET
15+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
16+
17+
def to_dict(self) -> Dict[str, Any]:
18+
a_property: Union[Unset, AnEnum, AnIntEnum]
19+
if isinstance(self.a_property, Unset):
20+
a_property = UNSET
21+
elif isinstance(self.a_property, AnEnum):
22+
a_property = UNSET
23+
if not isinstance(self.a_property, Unset):
24+
a_property = self.a_property
25+
26+
else:
27+
a_property = UNSET
28+
if not isinstance(self.a_property, Unset):
29+
a_property = self.a_property
30+
31+
field_dict: Dict[str, Any] = {}
32+
field_dict.update(self.additional_properties)
33+
field_dict.update({})
34+
if a_property is not UNSET:
35+
field_dict["a_property"] = a_property
36+
37+
return field_dict
38+
39+
@staticmethod
40+
def from_dict(src_dict: Dict[str, Any]) -> "AModelModel":
41+
d = src_dict.copy()
42+
43+
def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
44+
data = None if isinstance(data, Unset) else data
45+
a_property: Union[Unset, AnEnum, AnIntEnum]
46+
try:
47+
a_property = UNSET
48+
_a_property = data
49+
if _a_property is not None:
50+
a_property = AnEnum(_a_property)
51+
52+
return a_property
53+
except: # noqa: E722
54+
pass
55+
a_property = UNSET
56+
_a_property = data
57+
if _a_property is not None:
58+
a_property = AnIntEnum(_a_property)
59+
60+
return a_property
61+
62+
a_property = _parse_a_property(d.pop("a_property", UNSET))
63+
64+
a_model_model = AModelModel(
65+
a_property=a_property,
66+
)
67+
68+
a_model_model.additional_properties = d
69+
return a_model_model
70+
71+
@property
72+
def additional_keys(self) -> List[str]:
73+
return list(self.additional_properties.keys())
74+
75+
def __getitem__(self, key: str) -> Any:
76+
return self.additional_properties[key]
77+
78+
def __setitem__(self, key: str, value: Any) -> None:
79+
self.additional_properties[key] = value
80+
81+
def __delitem__(self, key: str) -> None:
82+
del self.additional_properties[key]
83+
84+
def __contains__(self, key: str) -> bool:
85+
return key in self.additional_properties
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from typing import Any, Dict, List, 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 AModelNotRequiredModel:
12+
""" """
13+
14+
a_property: Union[Unset, AnEnum, AnIntEnum] = UNSET
15+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
16+
17+
def to_dict(self) -> Dict[str, Any]:
18+
a_property: Union[Unset, AnEnum, AnIntEnum]
19+
if isinstance(self.a_property, Unset):
20+
a_property = UNSET
21+
elif isinstance(self.a_property, AnEnum):
22+
a_property = UNSET
23+
if not isinstance(self.a_property, Unset):
24+
a_property = self.a_property
25+
26+
else:
27+
a_property = UNSET
28+
if not isinstance(self.a_property, Unset):
29+
a_property = self.a_property
30+
31+
field_dict: Dict[str, Any] = {}
32+
field_dict.update(self.additional_properties)
33+
field_dict.update({})
34+
if a_property is not UNSET:
35+
field_dict["a_property"] = a_property
36+
37+
return field_dict
38+
39+
@staticmethod
40+
def from_dict(src_dict: Dict[str, Any]) -> "AModelNotRequiredModel":
41+
d = src_dict.copy()
42+
43+
def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
44+
data = None if isinstance(data, Unset) else data
45+
a_property: Union[Unset, AnEnum, AnIntEnum]
46+
try:
47+
a_property = UNSET
48+
_a_property = data
49+
if _a_property is not None:
50+
a_property = AnEnum(_a_property)
51+
52+
return a_property
53+
except: # noqa: E722
54+
pass
55+
a_property = UNSET
56+
_a_property = data
57+
if _a_property is not None:
58+
a_property = AnIntEnum(_a_property)
59+
60+
return a_property
61+
62+
a_property = _parse_a_property(d.pop("a_property", UNSET))
63+
64+
a_model_not_required_model = AModelNotRequiredModel(
65+
a_property=a_property,
66+
)
67+
68+
a_model_not_required_model.additional_properties = d
69+
return a_model_not_required_model
70+
71+
@property
72+
def additional_keys(self) -> List[str]:
73+
return list(self.additional_properties.keys())
74+
75+
def __getitem__(self, key: str) -> Any:
76+
return self.additional_properties[key]
77+
78+
def __setitem__(self, key: str, value: Any) -> None:
79+
self.additional_properties[key] = value
80+
81+
def __delitem__(self, key: str) -> None:
82+
del self.additional_properties[key]
83+
84+
def __contains__(self, key: str) -> bool:
85+
return key in self.additional_properties
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from typing import Any, Dict, List, 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 AModelNotRequiredNullableModel:
12+
""" """
13+
14+
a_property: Union[Unset, AnEnum, AnIntEnum] = UNSET
15+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
16+
17+
def to_dict(self) -> Dict[str, Any]:
18+
a_property: Union[Unset, AnEnum, AnIntEnum]
19+
if isinstance(self.a_property, Unset):
20+
a_property = UNSET
21+
elif isinstance(self.a_property, AnEnum):
22+
a_property = UNSET
23+
if not isinstance(self.a_property, Unset):
24+
a_property = self.a_property
25+
26+
else:
27+
a_property = UNSET
28+
if not isinstance(self.a_property, Unset):
29+
a_property = self.a_property
30+
31+
field_dict: Dict[str, Any] = {}
32+
field_dict.update(self.additional_properties)
33+
field_dict.update({})
34+
if a_property is not UNSET:
35+
field_dict["a_property"] = a_property
36+
37+
return field_dict
38+
39+
@staticmethod
40+
def from_dict(src_dict: Dict[str, Any]) -> "AModelNotRequiredNullableModel":
41+
d = src_dict.copy()
42+
43+
def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
44+
data = None if isinstance(data, Unset) else data
45+
a_property: Union[Unset, AnEnum, AnIntEnum]
46+
try:
47+
a_property = UNSET
48+
_a_property = data
49+
if _a_property is not None:
50+
a_property = AnEnum(_a_property)
51+
52+
return a_property
53+
except: # noqa: E722
54+
pass
55+
a_property = UNSET
56+
_a_property = data
57+
if _a_property is not None:
58+
a_property = AnIntEnum(_a_property)
59+
60+
return a_property
61+
62+
a_property = _parse_a_property(d.pop("a_property", UNSET))
63+
64+
a_model_not_required_nullable_model = AModelNotRequiredNullableModel(
65+
a_property=a_property,
66+
)
67+
68+
a_model_not_required_nullable_model.additional_properties = d
69+
return a_model_not_required_nullable_model
70+
71+
@property
72+
def additional_keys(self) -> List[str]:
73+
return list(self.additional_properties.keys())
74+
75+
def __getitem__(self, key: str) -> Any:
76+
return self.additional_properties[key]
77+
78+
def __setitem__(self, key: str, value: Any) -> None:
79+
self.additional_properties[key] = value
80+
81+
def __delitem__(self, key: str) -> None:
82+
del self.additional_properties[key]
83+
84+
def __contains__(self, key: str) -> bool:
85+
return key in self.additional_properties

0 commit comments

Comments
 (0)