|
| 1 | +import datetime |
| 2 | +from typing import Any, Dict, List, Type, TypeVar, Union |
| 3 | + |
| 4 | +from attrs import define as _attrs_define |
| 5 | +from attrs import field as _attrs_field |
| 6 | +from dateutil.parser import isoparse |
| 7 | + |
| 8 | +from ..models.model_with_merged_properties_string_to_enum import ModelWithMergedPropertiesStringToEnum |
| 9 | +from ..types import UNSET, Unset |
| 10 | + |
| 11 | +T = TypeVar("T", bound="ModelWithMergedProperties") |
| 12 | + |
| 13 | + |
| 14 | +@_attrs_define |
| 15 | +class ModelWithMergedProperties: |
| 16 | + """ |
| 17 | + Attributes: |
| 18 | + simple_string (Union[Unset, str]): extended simpleString description Default: 'new default'. |
| 19 | + string_to_enum (Union[Unset, ModelWithMergedPropertiesStringToEnum]): Default: |
| 20 | + ModelWithMergedPropertiesStringToEnum.A. |
| 21 | + string_to_date (Union[Unset, datetime.date]): |
| 22 | + number_to_int (Union[Unset, int]): |
| 23 | + any_to_string (Union[Unset, str]): Default: 'x'. |
| 24 | + """ |
| 25 | + |
| 26 | + simple_string: Union[Unset, str] = "new default" |
| 27 | + string_to_enum: Union[Unset, ModelWithMergedPropertiesStringToEnum] = ModelWithMergedPropertiesStringToEnum.A |
| 28 | + string_to_date: Union[Unset, datetime.date] = UNSET |
| 29 | + number_to_int: Union[Unset, int] = UNSET |
| 30 | + any_to_string: Union[Unset, str] = "x" |
| 31 | + additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) |
| 32 | + |
| 33 | + def to_dict(self) -> Dict[str, Any]: |
| 34 | + simple_string = self.simple_string |
| 35 | + |
| 36 | + string_to_enum: Union[Unset, str] = UNSET |
| 37 | + if not isinstance(self.string_to_enum, Unset): |
| 38 | + string_to_enum = self.string_to_enum.value |
| 39 | + |
| 40 | + string_to_date: Union[Unset, str] = UNSET |
| 41 | + if not isinstance(self.string_to_date, Unset): |
| 42 | + string_to_date = self.string_to_date.isoformat() |
| 43 | + |
| 44 | + number_to_int = self.number_to_int |
| 45 | + |
| 46 | + any_to_string = self.any_to_string |
| 47 | + |
| 48 | + field_dict: Dict[str, Any] = {} |
| 49 | + field_dict.update(self.additional_properties) |
| 50 | + field_dict.update({}) |
| 51 | + if simple_string is not UNSET: |
| 52 | + field_dict["simpleString"] = simple_string |
| 53 | + if string_to_enum is not UNSET: |
| 54 | + field_dict["stringToEnum"] = string_to_enum |
| 55 | + if string_to_date is not UNSET: |
| 56 | + field_dict["stringToDate"] = string_to_date |
| 57 | + if number_to_int is not UNSET: |
| 58 | + field_dict["numberToInt"] = number_to_int |
| 59 | + if any_to_string is not UNSET: |
| 60 | + field_dict["anyToString"] = any_to_string |
| 61 | + |
| 62 | + return field_dict |
| 63 | + |
| 64 | + @classmethod |
| 65 | + def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: |
| 66 | + d = src_dict.copy() |
| 67 | + simple_string = d.pop("simpleString", UNSET) |
| 68 | + |
| 69 | + _string_to_enum = d.pop("stringToEnum", UNSET) |
| 70 | + string_to_enum: Union[Unset, ModelWithMergedPropertiesStringToEnum] |
| 71 | + if isinstance(_string_to_enum, Unset): |
| 72 | + string_to_enum = UNSET |
| 73 | + else: |
| 74 | + string_to_enum = ModelWithMergedPropertiesStringToEnum(_string_to_enum) |
| 75 | + |
| 76 | + _string_to_date = d.pop("stringToDate", UNSET) |
| 77 | + string_to_date: Union[Unset, datetime.date] |
| 78 | + if isinstance(_string_to_date, Unset): |
| 79 | + string_to_date = UNSET |
| 80 | + else: |
| 81 | + string_to_date = isoparse(_string_to_date).date() |
| 82 | + |
| 83 | + number_to_int = d.pop("numberToInt", UNSET) |
| 84 | + |
| 85 | + any_to_string = d.pop("anyToString", UNSET) |
| 86 | + |
| 87 | + model_with_merged_properties = cls( |
| 88 | + simple_string=simple_string, |
| 89 | + string_to_enum=string_to_enum, |
| 90 | + string_to_date=string_to_date, |
| 91 | + number_to_int=number_to_int, |
| 92 | + any_to_string=any_to_string, |
| 93 | + ) |
| 94 | + |
| 95 | + model_with_merged_properties.additional_properties = d |
| 96 | + return model_with_merged_properties |
| 97 | + |
| 98 | + @property |
| 99 | + def additional_keys(self) -> List[str]: |
| 100 | + return list(self.additional_properties.keys()) |
| 101 | + |
| 102 | + def __getitem__(self, key: str) -> Any: |
| 103 | + return self.additional_properties[key] |
| 104 | + |
| 105 | + def __setitem__(self, key: str, value: Any) -> None: |
| 106 | + self.additional_properties[key] = value |
| 107 | + |
| 108 | + def __delitem__(self, key: str) -> None: |
| 109 | + del self.additional_properties[key] |
| 110 | + |
| 111 | + def __contains__(self, key: str) -> bool: |
| 112 | + return key in self.additional_properties |
0 commit comments