Skip to content

Commit e1c6578

Browse files
fix(client): Nullable and optional properties which are models (#315)
1 parent 718acfd commit e1c6578

16 files changed

+501
-5
lines changed

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

+4
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

+50
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
@@ -19,12 +23,16 @@ class AModel:
1923
a_camel_date_time: Union[datetime.datetime, datetime.date]
2024
a_date: datetime.date
2125
required_not_nullable: str
26+
model: AModelModel
2227
a_nullable_date: Optional[datetime.date]
2328
required_nullable: Optional[str]
29+
nullable_model: Optional[AModelNullableModel]
2430
nested_list_of_enums: Union[Unset, List[List[DifferentEnum]]] = UNSET
2531
attr_1_leading_digit: Union[Unset, str] = UNSET
2632
not_required_nullable: Union[Unset, Optional[str]] = UNSET
2733
not_required_not_nullable: Union[Unset, str] = UNSET
34+
not_required_model: Union[AModelNotRequiredModel, Unset] = UNSET
35+
not_required_nullable_model: Union[Optional[AModelNotRequiredNullableModel], Unset] = UNSET
2836

2937
def to_dict(self) -> Dict[str, Any]:
3038
an_enum_value = self.an_enum_value.value
@@ -37,6 +45,8 @@ def to_dict(self) -> Dict[str, Any]:
3745

3846
a_date = self.a_date.isoformat()
3947
required_not_nullable = self.required_not_nullable
48+
model = self.model.to_dict()
49+
4050
nested_list_of_enums: Union[Unset, List[Any]] = UNSET
4151
if not isinstance(self.nested_list_of_enums, Unset):
4252
nested_list_of_enums = []
@@ -54,6 +64,17 @@ def to_dict(self) -> Dict[str, Any]:
5464
required_nullable = self.required_nullable
5565
not_required_nullable = self.not_required_nullable
5666
not_required_not_nullable = self.not_required_not_nullable
67+
nullable_model = self.nullable_model.to_dict() if self.nullable_model else None
68+
69+
not_required_model: Union[Unset, Dict[str, Any]] = UNSET
70+
if not isinstance(self.not_required_model, Unset):
71+
not_required_model = self.not_required_model.to_dict()
72+
73+
not_required_nullable_model: Union[None, Unset, Dict[str, Any]] = UNSET
74+
if not isinstance(self.not_required_nullable_model, Unset):
75+
not_required_nullable_model = (
76+
self.not_required_nullable_model.to_dict() if self.not_required_nullable_model else None
77+
)
5778

5879
field_dict: Dict[str, Any] = {}
5980
field_dict.update(
@@ -62,8 +83,10 @@ def to_dict(self) -> Dict[str, Any]:
6283
"aCamelDateTime": a_camel_date_time,
6384
"a_date": a_date,
6485
"required_not_nullable": required_not_nullable,
86+
"model": model,
6587
"a_nullable_date": a_nullable_date,
6688
"required_nullable": required_nullable,
89+
"nullable_model": nullable_model,
6790
}
6891
)
6992
if nested_list_of_enums is not UNSET:
@@ -74,6 +97,10 @@ def to_dict(self) -> Dict[str, Any]:
7497
field_dict["not_required_nullable"] = not_required_nullable
7598
if not_required_not_nullable is not UNSET:
7699
field_dict["not_required_not_nullable"] = not_required_not_nullable
100+
if not_required_model is not UNSET:
101+
field_dict["not_required_model"] = not_required_model
102+
if not_required_nullable_model is not UNSET:
103+
field_dict["not_required_nullable_model"] = not_required_nullable_model
77104

78105
return field_dict
79106

@@ -101,6 +128,8 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat
101128

102129
required_not_nullable = d.pop("required_not_nullable")
103130

131+
model = AModelModel.from_dict(d.pop("model"))
132+
104133
nested_list_of_enums = []
105134
_nested_list_of_enums = d.pop("nested_list_of_enums", UNSET)
106135
for nested_list_of_enums_item_data in _nested_list_of_enums or []:
@@ -126,17 +155,38 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat
126155

127156
not_required_not_nullable = d.pop("not_required_not_nullable", UNSET)
128157

158+
nullable_model = None
159+
_nullable_model = d.pop("nullable_model")
160+
if _nullable_model is not None:
161+
nullable_model = AModelNullableModel.from_dict(cast(Dict[str, Any], _nullable_model))
162+
163+
not_required_model: Union[AModelNotRequiredModel, Unset] = UNSET
164+
_not_required_model = d.pop("not_required_model", UNSET)
165+
if not isinstance(_not_required_model, Unset):
166+
not_required_model = AModelNotRequiredModel.from_dict(cast(Dict[str, Any], _not_required_model))
167+
168+
not_required_nullable_model = None
169+
_not_required_nullable_model = d.pop("not_required_nullable_model", UNSET)
170+
if _not_required_nullable_model is not None and not isinstance(_not_required_nullable_model, Unset):
171+
not_required_nullable_model = AModelNotRequiredNullableModel.from_dict(
172+
cast(Dict[str, Any], _not_required_nullable_model)
173+
)
174+
129175
a_model = cls(
130176
an_enum_value=an_enum_value,
131177
a_camel_date_time=a_camel_date_time,
132178
a_date=a_date,
133179
required_not_nullable=required_not_nullable,
180+
model=model,
134181
nested_list_of_enums=nested_list_of_enums,
135182
a_nullable_date=a_nullable_date,
136183
attr_1_leading_digit=attr_1_leading_digit,
137184
required_nullable=required_nullable,
138185
not_required_nullable=not_required_nullable,
139186
not_required_not_nullable=not_required_not_nullable,
187+
nullable_model=nullable_model,
188+
not_required_model=not_required_model,
189+
not_required_nullable_model=not_required_nullable_model,
140190
)
141191

142192
return a_model
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import Any, Dict, List, Type, TypeVar
2+
3+
import attr
4+
5+
T = TypeVar("T", bound="AModelModel")
6+
7+
8+
@attr.s(auto_attribs=True)
9+
class AModelModel:
10+
""" """
11+
12+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
13+
14+
def to_dict(self) -> Dict[str, Any]:
15+
16+
field_dict: Dict[str, Any] = {}
17+
field_dict.update(self.additional_properties)
18+
field_dict.update({})
19+
20+
return field_dict
21+
22+
@classmethod
23+
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
24+
d = src_dict.copy()
25+
a_model_model = cls()
26+
27+
a_model_model.additional_properties = d
28+
return a_model_model
29+
30+
@property
31+
def additional_keys(self) -> List[str]:
32+
return list(self.additional_properties.keys())
33+
34+
def __getitem__(self, key: str) -> Any:
35+
return self.additional_properties[key]
36+
37+
def __setitem__(self, key: str, value: Any) -> None:
38+
self.additional_properties[key] = value
39+
40+
def __delitem__(self, key: str) -> None:
41+
del self.additional_properties[key]
42+
43+
def __contains__(self, key: str) -> bool:
44+
return key in self.additional_properties
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import Any, Dict, List, Type, TypeVar
2+
3+
import attr
4+
5+
T = TypeVar("T", bound="AModelNotRequiredModel")
6+
7+
8+
@attr.s(auto_attribs=True)
9+
class AModelNotRequiredModel:
10+
""" """
11+
12+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
13+
14+
def to_dict(self) -> Dict[str, Any]:
15+
16+
field_dict: Dict[str, Any] = {}
17+
field_dict.update(self.additional_properties)
18+
field_dict.update({})
19+
20+
return field_dict
21+
22+
@classmethod
23+
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
24+
d = src_dict.copy()
25+
a_model_not_required_model = cls()
26+
27+
a_model_not_required_model.additional_properties = d
28+
return a_model_not_required_model
29+
30+
@property
31+
def additional_keys(self) -> List[str]:
32+
return list(self.additional_properties.keys())
33+
34+
def __getitem__(self, key: str) -> Any:
35+
return self.additional_properties[key]
36+
37+
def __setitem__(self, key: str, value: Any) -> None:
38+
self.additional_properties[key] = value
39+
40+
def __delitem__(self, key: str) -> None:
41+
del self.additional_properties[key]
42+
43+
def __contains__(self, key: str) -> bool:
44+
return key in self.additional_properties
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import Any, Dict, List, Type, TypeVar
2+
3+
import attr
4+
5+
T = TypeVar("T", bound="AModelNotRequiredNullableModel")
6+
7+
8+
@attr.s(auto_attribs=True)
9+
class AModelNotRequiredNullableModel:
10+
""" """
11+
12+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
13+
14+
def to_dict(self) -> Dict[str, Any]:
15+
16+
field_dict: Dict[str, Any] = {}
17+
field_dict.update(self.additional_properties)
18+
field_dict.update({})
19+
20+
return field_dict
21+
22+
@classmethod
23+
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
24+
d = src_dict.copy()
25+
a_model_not_required_nullable_model = cls()
26+
27+
a_model_not_required_nullable_model.additional_properties = d
28+
return a_model_not_required_nullable_model
29+
30+
@property
31+
def additional_keys(self) -> List[str]:
32+
return list(self.additional_properties.keys())
33+
34+
def __getitem__(self, key: str) -> Any:
35+
return self.additional_properties[key]
36+
37+
def __setitem__(self, key: str, value: Any) -> None:
38+
self.additional_properties[key] = value
39+
40+
def __delitem__(self, key: str) -> None:
41+
del self.additional_properties[key]
42+
43+
def __contains__(self, key: str) -> bool:
44+
return key in self.additional_properties
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import Any, Dict, List, Type, TypeVar
2+
3+
import attr
4+
5+
T = TypeVar("T", bound="AModelNullableModel")
6+
7+
8+
@attr.s(auto_attribs=True)
9+
class AModelNullableModel:
10+
""" """
11+
12+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
13+
14+
def to_dict(self) -> Dict[str, Any]:
15+
16+
field_dict: Dict[str, Any] = {}
17+
field_dict.update(self.additional_properties)
18+
field_dict.update({})
19+
20+
return field_dict
21+
22+
@classmethod
23+
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
24+
d = src_dict.copy()
25+
a_model_nullable_model = cls()
26+
27+
a_model_nullable_model.additional_properties = d
28+
return a_model_nullable_model
29+
30+
@property
31+
def additional_keys(self) -> List[str]:
32+
return list(self.additional_properties.keys())
33+
34+
def __getitem__(self, key: str) -> Any:
35+
return self.additional_properties[key]
36+
37+
def __setitem__(self, key: str, value: Any) -> None:
38+
self.additional_properties[key] = value
39+
40+
def __delitem__(self, key: str) -> None:
41+
del self.additional_properties[key]
42+
43+
def __contains__(self, key: str) -> bool:
44+
return key in self.additional_properties

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
3535
d = src_dict.copy()
3636
a_date_holder: Union[ModelWithPrimitiveAdditionalPropertiesADateHolder, Unset] = UNSET
3737
_a_date_holder = d.pop("a_date_holder", UNSET)
38-
if _a_date_holder is not None and not isinstance(_a_date_holder, Unset):
38+
if not isinstance(_a_date_holder, Unset):
3939
a_date_holder = ModelWithPrimitiveAdditionalPropertiesADateHolder.from_dict(
4040
cast(Dict[str, Any], _a_date_holder)
4141
)

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

+4
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

0 commit comments

Comments
 (0)