|
1 | | -from typing import Any, Dict, List, Type, TypeVar |
| 1 | +from typing import Any, Dict, List, Type, TypeVar, Union |
2 | 2 |
|
3 | 3 | import attr |
4 | 4 |
|
| 5 | +from ..models.an_enum import AnEnum |
| 6 | +from ..models.an_int_enum import AnIntEnum |
| 7 | +from ..types import UNSET, Unset |
| 8 | + |
5 | 9 | T = TypeVar("T", bound="AModelNotRequiredNullableModel") |
6 | 10 |
|
7 | 11 |
|
8 | 12 | @attr.s(auto_attribs=True) |
9 | 13 | class AModelNotRequiredNullableModel: |
10 | 14 | """ """ |
11 | 15 |
|
| 16 | + a_property: Union[Unset, AnEnum, AnIntEnum] = UNSET |
12 | 17 | additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) |
13 | 18 |
|
14 | 19 | def to_dict(self) -> Dict[str, Any]: |
| 20 | + a_property: Union[Unset, AnEnum, AnIntEnum] |
| 21 | + if isinstance(self.a_property, Unset): |
| 22 | + a_property = UNSET |
| 23 | + elif isinstance(self.a_property, AnEnum): |
| 24 | + a_property = UNSET |
| 25 | + if not isinstance(self.a_property, Unset): |
| 26 | + a_property = self.a_property |
| 27 | + |
| 28 | + else: |
| 29 | + a_property = UNSET |
| 30 | + if not isinstance(self.a_property, Unset): |
| 31 | + a_property = self.a_property |
15 | 32 |
|
16 | 33 | field_dict: Dict[str, Any] = {} |
17 | 34 | field_dict.update(self.additional_properties) |
18 | 35 | field_dict.update({}) |
| 36 | + if a_property is not UNSET: |
| 37 | + field_dict["a_property"] = a_property |
19 | 38 |
|
20 | 39 | return field_dict |
21 | 40 |
|
22 | 41 | @classmethod |
23 | 42 | def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: |
24 | 43 | d = src_dict.copy() |
25 | | - a_model_not_required_nullable_model = cls() |
| 44 | + |
| 45 | + def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]: |
| 46 | + data = None if isinstance(data, Unset) else data |
| 47 | + a_property: Union[Unset, AnEnum, AnIntEnum] |
| 48 | + try: |
| 49 | + a_property = UNSET |
| 50 | + _a_property = data |
| 51 | + if _a_property is not None and _a_property is not UNSET: |
| 52 | + a_property = AnEnum(_a_property) |
| 53 | + |
| 54 | + return a_property |
| 55 | + except: # noqa: E722 |
| 56 | + pass |
| 57 | + a_property = UNSET |
| 58 | + _a_property = data |
| 59 | + if _a_property is not None and _a_property is not UNSET: |
| 60 | + a_property = AnIntEnum(_a_property) |
| 61 | + |
| 62 | + return a_property |
| 63 | + |
| 64 | + a_property = _parse_a_property(d.pop("a_property", UNSET)) |
| 65 | + |
| 66 | + a_model_not_required_nullable_model = cls( |
| 67 | + a_property=a_property, |
| 68 | + ) |
26 | 69 |
|
27 | 70 | a_model_not_required_nullable_model.additional_properties = d |
28 | 71 | return a_model_not_required_nullable_model |
|
0 commit comments