Skip to content

Commit d4e14f9

Browse files
ahuang11dbanty
andauthored
fix: If data.type is None but has data.properties, assume type is object [openapi-generators#691, openapi-generators#674]. Thanks @ahuang11!
Co-authored-by: Dylan Anthony <[email protected]>
1 parent 9b983a0 commit d4e14f9

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

+4
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
@@ -71,6 +73,8 @@
7173

7274
__all__ = (
7375
"AFormData",
76+
"AllOfHasPropertiesButNoType",
77+
"AllOfHasPropertiesButNoTypeTypeEnum",
7478
"AllOfSubModel",
7579
"AllOfSubModelTypeEnum",
7680
"AModel",
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

+15
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ def _property_from_data(
696696
process_properties=process_properties,
697697
roots=roots,
698698
)
699-
if data.type == oai.DataType.OBJECT or data.allOf:
699+
if data.type == oai.DataType.OBJECT or data.allOf or (data.type is None and data.properties):
700700
return build_model_property(
701701
data=data,
702702
name=name,

0 commit comments

Comments
 (0)