@@ -102,7 +102,6 @@ def resolver(schema):
102
102
103
103
@pytest .mark .parametrize ("schema" , [AnalysisSchema , AnalysisSchema ()])
104
104
def test_resolve_schema_dict_auto_reference_return_none (self , schema ):
105
- # this resolver return None
106
105
def resolver (schema ):
107
106
return None
108
107
@@ -162,6 +161,27 @@ class NameClashSchema(Schema):
162
161
assert "Pet" in definitions
163
162
assert "Pet1" in definitions
164
163
164
+ def test_resolve_nested_schema_many_true_resolver_return_none (self ):
165
+ def resolver (schema ):
166
+ return None
167
+
168
+ class PetFamilySchema (Schema ):
169
+ pets_1 = Nested (PetSchema , many = True )
170
+ pets_2 = List (Nested (PetSchema ))
171
+
172
+ spec = APISpec (
173
+ title = "Test auto-reference" ,
174
+ version = "0.1" ,
175
+ openapi_version = "2.0" ,
176
+ plugins = (MarshmallowPlugin (schema_name_resolver = resolver ),),
177
+ )
178
+
179
+ spec .components .schema ("PetFamily" , schema = PetFamilySchema )
180
+ props = get_schemas (spec )["PetFamily" ]["properties" ]
181
+ pets_1 = props ["pets_1" ]
182
+ pets_2 = props ["pets_2" ]
183
+ assert pets_1 ["type" ] == pets_2 ["type" ] == "array"
184
+
165
185
166
186
class TestComponentParameterHelper :
167
187
@pytest .mark .parametrize ("schema" , [PetSchema , PetSchema ()])
@@ -250,7 +270,8 @@ class CustomPetBSchema(PetSchema):
250
270
251
271
class TestOperationHelper :
252
272
@pytest .mark .parametrize (
253
- "pet_schema" , (PetSchema , PetSchema (), "tests.schemas.PetSchema" )
273
+ "pet_schema" ,
274
+ (PetSchema , PetSchema (), PetSchema (many = True ), "tests.schemas.PetSchema" ),
254
275
)
255
276
@pytest .mark .parametrize ("spec_fixture" , ("2.0" ,), indirect = True )
256
277
def test_schema_v2 (self , spec_fixture , pet_schema ):
@@ -268,15 +289,20 @@ def test_schema_v2(self, spec_fixture, pet_schema):
268
289
},
269
290
)
270
291
get = get_paths (spec_fixture .spec )["/pet" ]["get" ]
271
- reference = get ["responses" ][200 ]["schema" ]
292
+ if isinstance (pet_schema , Schema ) and pet_schema .many is True :
293
+ assert get ["responses" ][200 ]["schema" ]["type" ] == "array"
294
+ reference = get ["responses" ][200 ]["schema" ]["items" ]
295
+ else :
296
+ reference = get ["responses" ][200 ]["schema" ]
272
297
assert reference == {"$ref" : ref_path (spec_fixture .spec ) + "Pet" }
273
298
assert len (spec_fixture .spec .components ._schemas ) == 1
274
299
resolved_schema = spec_fixture .spec .components ._schemas ["Pet" ]
275
300
assert resolved_schema == spec_fixture .openapi .schema2jsonschema (PetSchema )
276
301
assert get ["responses" ][200 ]["description" ] == "successful operation"
277
302
278
303
@pytest .mark .parametrize (
279
- "pet_schema" , (PetSchema , PetSchema (), "tests.schemas.PetSchema" )
304
+ "pet_schema" ,
305
+ (PetSchema , PetSchema (), PetSchema (many = True ), "tests.schemas.PetSchema" ),
280
306
)
281
307
@pytest .mark .parametrize ("spec_fixture" , ("3.0.0" ,), indirect = True )
282
308
def test_schema_v3 (self , spec_fixture , pet_schema ):
@@ -294,7 +320,16 @@ def test_schema_v3(self, spec_fixture, pet_schema):
294
320
},
295
321
)
296
322
get = get_paths (spec_fixture .spec )["/pet" ]["get" ]
297
- reference = get ["responses" ][200 ]["content" ]["application/json" ]["schema" ]
323
+ if isinstance (pet_schema , Schema ) and pet_schema .many is True :
324
+ assert (
325
+ get ["responses" ][200 ]["content" ]["application/json" ]["schema" ]["type" ]
326
+ == "array"
327
+ )
328
+ reference = get ["responses" ][200 ]["content" ]["application/json" ]["schema" ][
329
+ "items"
330
+ ]
331
+ else :
332
+ reference = get ["responses" ][200 ]["content" ]["application/json" ]["schema" ]
298
333
299
334
assert reference == {"$ref" : ref_path (spec_fixture .spec ) + "Pet" }
300
335
assert len (spec_fixture .spec .components ._schemas ) == 1
0 commit comments