Skip to content

Commit f167664

Browse files
forest-benchlingbowenwr
authored andcommitted
fix: Fix optional model properties BNCH-20284 (#35)
1 parent 3b12217 commit f167664

14 files changed

+729
-5
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
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
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 AModelNullableModel:
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]) -> "AModelNullableModel":
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_nullable_model = AModelNullableModel(
65+
a_property=a_property,
66+
)
67+
68+
a_model_nullable_model.additional_properties = d
69+
return a_model_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

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

Lines changed: 1 addition & 1 deletion
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[Unset, ModelWithPrimitiveAdditionalPropertiesADateHolder] = 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

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

0 commit comments

Comments
 (0)