Skip to content

Commit 77e52ae

Browse files
test: Add end-to-end test for allOf required override
Add AllOfRequiredBase and AllOfRequiredDerived schemas to baseline specs to verify the generated code correctly handles required field overrides in allOf schemas. Update golden records accordingly.
1 parent be1b6d3 commit 77e52ae

File tree

5 files changed

+191
-0
lines changed

5 files changed

+191
-0
lines changed

end_to_end_tests/baseline_openapi_3.0.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,30 @@
19181918
}
19191919
]
19201920
},
1921+
"AllOfRequiredBase": {
1922+
"type": "object",
1923+
"properties": {
1924+
"bar": {
1925+
"type": "string",
1926+
"description": "The bar property"
1927+
},
1928+
"baz": {
1929+
"type": "string",
1930+
"description": "The baz property"
1931+
}
1932+
}
1933+
},
1934+
"AllOfRequiredDerived": {
1935+
"allOf": [
1936+
{
1937+
"$ref": "#/components/schemas/AllOfRequiredBase"
1938+
},
1939+
{
1940+
"type": "object",
1941+
"required": ["bar"]
1942+
}
1943+
]
1944+
},
19211945
"AModel": {
19221946
"title": "AModel",
19231947
"required": [

end_to_end_tests/baseline_openapi_3.1.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,27 @@ info:
18711871
}
18721872
]
18731873
},
1874+
"AllOfRequiredBase": {
1875+
"type": "object",
1876+
"properties": {
1877+
"bar": {
1878+
"type": "string",
1879+
"description": "The bar property"
1880+
},
1881+
"baz": {
1882+
"type": "string",
1883+
"description": "The baz property"
1884+
}
1885+
}
1886+
},
1887+
"AllOfRequiredDerived": {
1888+
"allOf": [
1889+
{ "$ref": "#/components/schemas/AllOfRequiredBase" },
1890+
{ "type": "object",
1891+
"required": ["bar"]
1892+
}
1893+
]
1894+
},
18741895
"AModel": {
18751896
"title": "AModel",
18761897
"required": [

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
@@ -7,6 +7,8 @@
77
from .a_model_with_properties_reference_that_are_not_object import AModelWithPropertiesReferenceThatAreNotObject
88
from .all_of_has_properties_but_no_type import AllOfHasPropertiesButNoType
99
from .all_of_has_properties_but_no_type_type_enum import AllOfHasPropertiesButNoTypeTypeEnum
10+
from .all_of_required_base import AllOfRequiredBase
11+
from .all_of_required_derived import AllOfRequiredDerived
1012
from .all_of_sub_model import AllOfSubModel
1113
from .all_of_sub_model_type_enum import AllOfSubModelTypeEnum
1214
from .an_all_of_enum import AnAllOfEnum
@@ -100,6 +102,8 @@
100102
"AFormData",
101103
"AllOfHasPropertiesButNoType",
102104
"AllOfHasPropertiesButNoTypeTypeEnum",
105+
"AllOfRequiredBase",
106+
"AllOfRequiredDerived",
103107
"AllOfSubModel",
104108
"AllOfSubModelTypeEnum",
105109
"AModel",
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from __future__ import annotations
2+
3+
from collections.abc import Mapping
4+
from typing import Any, TypeVar
5+
6+
from attrs import define as _attrs_define
7+
from attrs import field as _attrs_field
8+
9+
from ..types import UNSET, Unset
10+
11+
T = TypeVar("T", bound="AllOfRequiredBase")
12+
13+
14+
@_attrs_define
15+
class AllOfRequiredBase:
16+
"""
17+
Attributes:
18+
bar (str | Unset): The bar property
19+
baz (str | Unset): The baz property
20+
"""
21+
22+
bar: str | Unset = UNSET
23+
baz: str | Unset = UNSET
24+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
25+
26+
def to_dict(self) -> dict[str, Any]:
27+
bar = self.bar
28+
29+
baz = self.baz
30+
31+
field_dict: dict[str, Any] = {}
32+
field_dict.update(self.additional_properties)
33+
field_dict.update({})
34+
if bar is not UNSET:
35+
field_dict["bar"] = bar
36+
if baz is not UNSET:
37+
field_dict["baz"] = baz
38+
39+
return field_dict
40+
41+
@classmethod
42+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
43+
d = dict(src_dict)
44+
bar = d.pop("bar", UNSET)
45+
46+
baz = d.pop("baz", UNSET)
47+
48+
all_of_required_base = cls(
49+
bar=bar,
50+
baz=baz,
51+
)
52+
53+
all_of_required_base.additional_properties = d
54+
return all_of_required_base
55+
56+
@property
57+
def additional_keys(self) -> list[str]:
58+
return list(self.additional_properties.keys())
59+
60+
def __getitem__(self, key: str) -> Any:
61+
return self.additional_properties[key]
62+
63+
def __setitem__(self, key: str, value: Any) -> None:
64+
self.additional_properties[key] = value
65+
66+
def __delitem__(self, key: str) -> None:
67+
del self.additional_properties[key]
68+
69+
def __contains__(self, key: str) -> bool:
70+
return key in self.additional_properties
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
from __future__ import annotations
2+
3+
from collections.abc import Mapping
4+
from typing import Any, TypeVar
5+
6+
from attrs import define as _attrs_define
7+
from attrs import field as _attrs_field
8+
9+
from ..types import UNSET, Unset
10+
11+
T = TypeVar("T", bound="AllOfRequiredDerived")
12+
13+
14+
@_attrs_define
15+
class AllOfRequiredDerived:
16+
"""
17+
Attributes:
18+
bar (str): The bar property
19+
baz (str | Unset): The baz property
20+
"""
21+
22+
bar: str
23+
baz: str | Unset = UNSET
24+
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
25+
26+
def to_dict(self) -> dict[str, Any]:
27+
bar = self.bar
28+
29+
baz = self.baz
30+
31+
field_dict: dict[str, Any] = {}
32+
field_dict.update(self.additional_properties)
33+
field_dict.update(
34+
{
35+
"bar": bar,
36+
}
37+
)
38+
if baz is not UNSET:
39+
field_dict["baz"] = baz
40+
41+
return field_dict
42+
43+
@classmethod
44+
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
45+
d = dict(src_dict)
46+
bar = d.pop("bar")
47+
48+
baz = d.pop("baz", UNSET)
49+
50+
all_of_required_derived = cls(
51+
bar=bar,
52+
baz=baz,
53+
)
54+
55+
all_of_required_derived.additional_properties = d
56+
return all_of_required_derived
57+
58+
@property
59+
def additional_keys(self) -> list[str]:
60+
return list(self.additional_properties.keys())
61+
62+
def __getitem__(self, key: str) -> Any:
63+
return self.additional_properties[key]
64+
65+
def __setitem__(self, key: str, value: Any) -> None:
66+
self.additional_properties[key] = value
67+
68+
def __delitem__(self, key: str) -> None:
69+
del self.additional_properties[key]
70+
71+
def __contains__(self, key: str) -> bool:
72+
return key in self.additional_properties

0 commit comments

Comments
 (0)