@@ -123,3 +123,79 @@ def test_resolve_references(mocker):
123
123
assert all (p .required for p in model .required_properties )
124
124
assert sorted (p .name for p in model .optional_properties ) == ["Enum" , "Int" ]
125
125
assert all (not p .required for p in model .optional_properties )
126
+
127
+
128
+ def test_resolve_references_nested_allof (mocker ):
129
+ import openapi_python_client .schema as oai
130
+ from openapi_python_client .parser .properties import build_model_property
131
+
132
+ schemas = {
133
+ "RefA" : oai .Schema .construct (
134
+ title = mocker .MagicMock (),
135
+ description = mocker .MagicMock (),
136
+ required = ["String" ],
137
+ properties = {
138
+ "String" : oai .Schema .construct (type = "string" ),
139
+ "Enum" : oai .Schema .construct (type = "string" , enum = ["aValue" ]),
140
+ "DateTime" : oai .Schema .construct (type = "string" , format = "date-time" ),
141
+ },
142
+ ),
143
+ "RefB" : oai .Schema .construct (
144
+ title = mocker .MagicMock (),
145
+ description = mocker .MagicMock (),
146
+ required = ["DateTime" ],
147
+ properties = {
148
+ "Int" : oai .Schema .construct (type = "integer" ),
149
+ "DateTime" : oai .Schema .construct (type = "string" , format = "date-time" ),
150
+ "Float" : oai .Schema .construct (type = "number" , format = "float" ),
151
+ },
152
+ ),
153
+ # Intentionally no properties defined
154
+ "RefC" : oai .Schema .construct (
155
+ title = mocker .MagicMock (),
156
+ description = mocker .MagicMock (),
157
+ ),
158
+ }
159
+
160
+ model_schema = oai .Schema .construct (
161
+ type = "object" ,
162
+ properties = {
163
+ "Key" : oai .Schema .construct (
164
+ allOf = [
165
+ oai .Reference .construct (ref = "#/components/schemas/RefA" ),
166
+ oai .Reference .construct (ref = "#/components/schemas/RefB" ),
167
+ oai .Reference .construct (ref = "#/components/schemas/RefC" ),
168
+ oai .Schema .construct (
169
+ title = mocker .MagicMock (),
170
+ description = mocker .MagicMock (),
171
+ required = ["Float" ],
172
+ properties = {
173
+ "String" : oai .Schema .construct (type = "string" ),
174
+ "Float" : oai .Schema .construct (type = "number" , format = "float" ),
175
+ },
176
+ ),
177
+ ]
178
+ ),
179
+ }
180
+ )
181
+
182
+ components = {** schemas , "Model" : model_schema }
183
+
184
+ from openapi_python_client .parser .properties import ModelProperty , Schemas
185
+
186
+ schemas_holder = Schemas ()
187
+ model , schemas_holder = build_model_property (
188
+ data = model_schema , name = "Model" , required = True , schemas = schemas_holder , parent_name = None
189
+ )
190
+ model .resolve_references (components , schemas_holder )
191
+ assert sorted (p .name for p in model .required_properties ) == []
192
+ assert sorted (p .name for p in model .optional_properties ) == ["Key" ]
193
+ assert all (not p .required for p in model .optional_properties )
194
+
195
+ key_property = model .optional_properties [0 ]
196
+ assert isinstance (key_property , ModelProperty )
197
+ key_property .resolve_references (components , schemas_holder )
198
+ assert sorted (p .name for p in key_property .required_properties ) == ["DateTime" , "Float" , "String" ]
199
+ assert all (p .required for p in key_property .required_properties )
200
+ assert sorted (p .name for p in key_property .optional_properties ) == ["Enum" , "Int" ]
201
+ assert all (not p .required for p in key_property .optional_properties )
0 commit comments