Skip to content

Commit 7149b76

Browse files
committed
Add desired/correct generated code to golden-record
1 parent acdd3d1 commit 7149b76

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .a_discriminated_union_type_2 import ADiscriminatedUnionType2
55
from .a_form_data import AFormData
66
from .a_model import AModel
7+
from .a_model_with_optional_property_ref_and_default_value import AModelWithOptionalPropertyRefAndDefaultValue
78
from .a_model_with_properties_reference_that_are_not_object import AModelWithPropertiesReferenceThatAreNotObject
89
from .all_of_has_properties_but_no_type import AllOfHasPropertiesButNoType
910
from .all_of_has_properties_but_no_type_type_enum import AllOfHasPropertiesButNoTypeTypeEnum
@@ -98,6 +99,7 @@
9899
"AllOfSubModel",
99100
"AllOfSubModelTypeEnum",
100101
"AModel",
102+
"AModelWithOptionalPropertyRefAndDefaultValue",
101103
"AModelWithPropertiesReferenceThatAreNotObject",
102104
"AnAllOfEnum",
103105
"AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from typing import Any, TypeVar, Union
2+
3+
from attrs import define as _attrs_define
4+
from attrs import field as _attrs_field
5+
6+
from ..models.an_enum import AnEnum
7+
from ..types import UNSET, Unset
8+
9+
T = TypeVar("T", bound="AModelWithOptionalPropertyRefAndDefaultValue")
10+
11+
12+
@_attrs_define
13+
class AModelWithOptionalPropertyRefAndDefaultValue:
14+
"""
15+
Attributes:
16+
enum_property_ref (Union[Unset, AnEnum]): For testing Enums in all the ways they can be used Default:
17+
AnEnum.FIRST_VALUE.
18+
"""
19+
20+
enum_property_ref: Union[Unset, AnEnum] = AnEnum.FIRST_VALUE
21+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
22+
23+
def to_dict(self) -> dict[str, Any]:
24+
enum_property_ref: Union[Unset, str] = UNSET
25+
if not isinstance(self.enum_property_ref, Unset):
26+
enum_property_ref = self.enum_property_ref.value
27+
28+
field_dict: dict[str, Any] = {}
29+
field_dict.update(self.additional_properties)
30+
field_dict.update({})
31+
if enum_property_ref is not UNSET:
32+
field_dict["enum_property_ref"] = enum_property_ref
33+
34+
return field_dict
35+
36+
@classmethod
37+
def from_dict(cls: type[T], src_dict: dict[str, Any]) -> T:
38+
d = src_dict.copy()
39+
_enum_property_ref = d.pop("enum_property_ref", UNSET)
40+
enum_property_ref: Union[Unset, AnEnum]
41+
if isinstance(_enum_property_ref, Unset):
42+
enum_property_ref = UNSET
43+
else:
44+
enum_property_ref = AnEnum(_enum_property_ref)
45+
46+
a_model_with_optional_property_ref_and_default_value = cls(
47+
enum_property_ref=enum_property_ref,
48+
)
49+
50+
a_model_with_optional_property_ref_and_default_value.additional_properties = d
51+
return a_model_with_optional_property_ref_and_default_value
52+
53+
@property
54+
def additional_keys(self) -> list[str]:
55+
return list(self.additional_properties.keys())
56+
57+
def __getitem__(self, key: str) -> Any:
58+
return self.additional_properties[key]
59+
60+
def __setitem__(self, key: str, value: Any) -> None:
61+
self.additional_properties[key] = value
62+
63+
def __delitem__(self, key: str) -> None:
64+
del self.additional_properties[key]
65+
66+
def __contains__(self, key: str) -> bool:
67+
return key in self.additional_properties

0 commit comments

Comments
 (0)