@@ -241,41 +241,47 @@ def test_oneof_required(self):
241241
242242
243243 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" ]
257252 },
258- "required" : ["discipline" , "length" ]
253+ "length" : {
254+ "type" : "integer" ,
255+ }
259256 },
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" ,
270268 },
271- "required" : ["discipline" , "height" ]
272269 },
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
279285 }
280286 }
281287
@@ -290,11 +296,11 @@ def test_oneof_discriminator(self):
290296 discriminator = {
291297 "propertyName" : "discipline" ,
292298 "mapping" : {
293- "mountain_hiking" : "#/$defs /MountainHiking" ,
294- "alpine_climbing" : "#/$defs /AlpineClimbing" ,
299+ "mountain_hiking" : "#/components/schemas /MountainHiking" ,
300+ "alpine_climbing" : "#/components/schemas /AlpineClimbing" ,
295301 }
296302 }
297- schema ['$defs ' ]['Route' ]['discriminator' ] = discriminator
303+ schema ['components' ][ 'schemas ' ]['Route' ]['discriminator' ] = discriminator
298304 validator = OAS30Validator (schema , format_checker = oas30_format_checker )
299305 with pytest .raises (ValidationError , match = "does not contain discriminating property" ):
300306 validator .validate ({
0 commit comments