@@ -241,41 +241,47 @@ def test_oneof_required(self):
241
241
242
242
243
243
def test_oneof_discriminator (self ):
244
- schema = {
245
- "$ref" : "#/$defs/Route" ,
246
- "$defs" : {
247
- "MountainHiking" : {
248
- "type" : "object" ,
249
- "properties" : {
250
- "discipline" : {
251
- "type" : "string" ,
252
- "enum" : ["mountain_hiking" ]
253
- },
254
- "length" : {
255
- "type" : "integer" ,
256
- }
244
+ # We define a few components schemas
245
+ components = {
246
+ "MountainHiking" : {
247
+ "type" : "object" ,
248
+ "properties" : {
249
+ "discipline" : {
250
+ "type" : "string" ,
251
+ "enum" : ["mountain_hiking" ]
257
252
},
258
- "required" : ["discipline" , "length" ]
253
+ "length" : {
254
+ "type" : "integer" ,
255
+ }
259
256
},
260
- "AlpineClimbing" : {
261
- "type" : "object" ,
262
- "properties" : {
263
- "discipline" : {
264
- "type" : "string" ,
265
- "enum" : ["alpine_climbing" ]
266
- },
267
- "height" : {
268
- "type" : "integer" ,
269
- },
257
+ "required" : ["discipline" , "length" ]
258
+ },
259
+ "AlpineClimbing" : {
260
+ "type" : "object" ,
261
+ "properties" : {
262
+ "discipline" : {
263
+ "type" : "string" ,
264
+ "enum" : ["alpine_climbing" ]
265
+ },
266
+ "height" : {
267
+ "type" : "integer" ,
270
268
},
271
- "required" : ["discipline" , "height" ]
272
269
},
273
- "Route" : {
274
- "oneOf" : [
275
- {"$ref" : "#/$defs/MountainHiking" },
276
- {"$ref" : "#/$defs/AlpineClimbing" },
277
- ]
278
- }
270
+ "required" : ["discipline" , "height" ]
271
+ },
272
+ "Route" : {
273
+ "oneOf" : [
274
+ {"$ref" : "#/components/schemas/MountainHiking" },
275
+ {"$ref" : "#/components/schemas/AlpineClimbing" },
276
+ ]
277
+ }
278
+ }
279
+
280
+ # Add the compoments in a minimalis schema
281
+ schema = {
282
+ "$ref" : "#/components/schemas/Route" ,
283
+ "components" : {
284
+ "schemas" : components
279
285
}
280
286
}
281
287
@@ -290,11 +296,11 @@ def test_oneof_discriminator(self):
290
296
discriminator = {
291
297
"propertyName" : "discipline" ,
292
298
"mapping" : {
293
- "mountain_hiking" : "#/$defs /MountainHiking" ,
294
- "alpine_climbing" : "#/$defs /AlpineClimbing" ,
299
+ "mountain_hiking" : "#/components/schemas /MountainHiking" ,
300
+ "alpine_climbing" : "#/components/schemas /AlpineClimbing" ,
295
301
}
296
302
}
297
- schema ['$defs ' ]['Route' ]['discriminator' ] = discriminator
303
+ schema ['components' ][ 'schemas ' ]['Route' ]['discriminator' ] = discriminator
298
304
validator = OAS30Validator (schema , format_checker = oas30_format_checker )
299
305
with pytest .raises (ValidationError , match = "does not contain discriminating property" ):
300
306
validator .validate ({
0 commit comments