Skip to content

Commit 2a4be0c

Browse files
author
ahuang11
committed
Add default to object
1 parent 47e576c commit 2a4be0c

File tree

5 files changed

+110
-1
lines changed

5 files changed

+110
-1
lines changed

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
@@ -3,6 +3,8 @@
33
from .a_form_data import AFormData
44
from .a_model import AModel
55
from .a_model_with_properties_reference_that_are_not_object import AModelWithPropertiesReferenceThatAreNotObject
6+
from .all_of_has_properties_but_no_type import AllOfHasPropertiesButNoType
7+
from .all_of_has_properties_but_no_type_type_enum import AllOfHasPropertiesButNoTypeTypeEnum
68
from .all_of_sub_model import AllOfSubModel
79
from .all_of_sub_model_type_enum import AllOfSubModelTypeEnum
810
from .an_all_of_enum import AnAllOfEnum
@@ -53,6 +55,8 @@
5355

5456
__all__ = (
5557
"AFormData",
58+
"AllOfHasPropertiesButNoType",
59+
"AllOfHasPropertiesButNoTypeTypeEnum",
5660
"AllOfSubModel",
5761
"AllOfSubModelTypeEnum",
5862
"AModel",
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
from typing import Any, Dict, List, Type, TypeVar, Union
2+
3+
import attr
4+
5+
from ..models.all_of_has_properties_but_no_type_type_enum import AllOfHasPropertiesButNoTypeTypeEnum
6+
from ..types import UNSET, Unset
7+
8+
T = TypeVar("T", bound="AllOfHasPropertiesButNoType")
9+
10+
11+
@attr.s(auto_attribs=True)
12+
class AllOfHasPropertiesButNoType:
13+
"""
14+
Attributes:
15+
a_sub_property (Union[Unset, str]):
16+
type (Union[Unset, str]):
17+
type_enum (Union[Unset, AllOfHasPropertiesButNoTypeTypeEnum]):
18+
"""
19+
20+
a_sub_property: Union[Unset, str] = UNSET
21+
type: Union[Unset, str] = UNSET
22+
type_enum: Union[Unset, AllOfHasPropertiesButNoTypeTypeEnum] = UNSET
23+
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)
24+
25+
def to_dict(self) -> Dict[str, Any]:
26+
a_sub_property = self.a_sub_property
27+
type = self.type
28+
type_enum: Union[Unset, int] = UNSET
29+
if not isinstance(self.type_enum, Unset):
30+
type_enum = self.type_enum.value
31+
32+
field_dict: Dict[str, Any] = {}
33+
field_dict.update(self.additional_properties)
34+
field_dict.update({})
35+
if a_sub_property is not UNSET:
36+
field_dict["a_sub_property"] = a_sub_property
37+
if type is not UNSET:
38+
field_dict["type"] = type
39+
if type_enum is not UNSET:
40+
field_dict["type_enum"] = type_enum
41+
42+
return field_dict
43+
44+
@classmethod
45+
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
46+
d = src_dict.copy()
47+
a_sub_property = d.pop("a_sub_property", UNSET)
48+
49+
type = d.pop("type", UNSET)
50+
51+
_type_enum = d.pop("type_enum", UNSET)
52+
type_enum: Union[Unset, AllOfHasPropertiesButNoTypeTypeEnum]
53+
if isinstance(_type_enum, Unset):
54+
type_enum = UNSET
55+
else:
56+
type_enum = AllOfHasPropertiesButNoTypeTypeEnum(_type_enum)
57+
58+
all_of_has_properties_but_no_type = cls(
59+
a_sub_property=a_sub_property,
60+
type=type,
61+
type_enum=type_enum,
62+
)
63+
64+
all_of_has_properties_but_no_type.additional_properties = d
65+
return all_of_has_properties_but_no_type
66+
67+
@property
68+
def additional_keys(self) -> List[str]:
69+
return list(self.additional_properties.keys())
70+
71+
def __getitem__(self, key: str) -> Any:
72+
return self.additional_properties[key]
73+
74+
def __setitem__(self, key: str, value: Any) -> None:
75+
self.additional_properties[key] = value
76+
77+
def __delitem__(self, key: str) -> None:
78+
del self.additional_properties[key]
79+
80+
def __contains__(self, key: str) -> bool:
81+
return key in self.additional_properties
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from enum import IntEnum
2+
3+
4+
class AllOfHasPropertiesButNoTypeTypeEnum(IntEnum):
5+
VALUE_0 = 0
6+
VALUE_1 = 1
7+
8+
def __str__(self) -> str:
9+
return str(self.value)

end_to_end_tests/openapi.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,21 @@
17761776
}
17771777
}
17781778
},
1779+
"AllOfHasPropertiesButNoType": {
1780+
"title": "AllOfHasPropertiesButNoType",
1781+
"properties": {
1782+
"a_sub_property": {
1783+
"type": "string"
1784+
},
1785+
"type": {
1786+
"type": "string"
1787+
},
1788+
"type_enum": {
1789+
"type": "integer",
1790+
"enum": [0, 1]
1791+
}
1792+
}
1793+
},
17791794
"model_reference_doesnt_match": {
17801795
"title": "ModelName",
17811796
"type": "object"

openapi_python_client/parser/properties/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ def _property_from_data(
646646
return build_list_property(
647647
data=data, name=name, required=required, schemas=schemas, parent_name=parent_name, config=config
648648
)
649-
if data.type == oai.DataType.OBJECT or data.allOf:
649+
if data.type == oai.DataType.OBJECT or data.allOf or (data.type is None and data.properties):
650650
return build_model_property(
651651
data=data, name=name, schemas=schemas, required=required, parent_name=parent_name, config=config
652652
)

0 commit comments

Comments
 (0)