@@ -224,6 +224,29 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
224
224
return subresources_of
225
225
226
226
227
+ def _maybe_in_subresource (
228
+ in_value : Set [str ] = frozenset (),
229
+ in_subvalues : Set [str ] = frozenset (),
230
+ in_subarray : Set [str ] = frozenset (),
231
+ ):
232
+ def maybe_in_subresource (
233
+ segments : Sequence [int | str ],
234
+ resolver : _Resolver [Any ],
235
+ subresource : Resource [Any ],
236
+ ) -> _Resolver [Any ]:
237
+ _segments = iter (segments )
238
+ for segment in _segments :
239
+ if segment in in_value :
240
+ continue
241
+ elif segment in in_subarray or segment in in_subvalues :
242
+ if next (_segments , None ) is not None :
243
+ continue
244
+ return resolver
245
+ return resolver .in_subresource (subresource )
246
+
247
+ return maybe_in_subresource
248
+
249
+
227
250
DRAFT202012 = Specification (
228
251
name = "draft2020-12" ,
229
252
id_of = _dollar_id ,
@@ -250,6 +273,28 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
250
273
},
251
274
),
252
275
anchors_in = _anchor ,
276
+ maybe_in_subresource = _maybe_in_subresource (
277
+ in_value = {
278
+ "additionalProperties" ,
279
+ "contains" ,
280
+ "contentSchema" ,
281
+ "else" ,
282
+ "if" ,
283
+ "items" ,
284
+ "not" ,
285
+ "propertyNames" ,
286
+ "then" ,
287
+ "unevaluatedItems" ,
288
+ "unevaluatedProperties" ,
289
+ },
290
+ in_subarray = {"allOf" , "anyOf" , "oneOf" , "prefixItems" },
291
+ in_subvalues = {
292
+ "$defs" ,
293
+ "dependentSchemas" ,
294
+ "patternProperties" ,
295
+ "properties" ,
296
+ },
297
+ ),
253
298
)
254
299
DRAFT201909 = Specification (
255
300
name = "draft2019-09" ,
@@ -277,6 +322,28 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
277
322
},
278
323
),
279
324
anchors_in = _anchor_2019 ,
325
+ maybe_in_subresource = _maybe_in_subresource (
326
+ in_value = {
327
+ "additionalItems" ,
328
+ "additionalProperties" ,
329
+ "contains" ,
330
+ "contentSchema" ,
331
+ "else" ,
332
+ "if" ,
333
+ "not" ,
334
+ "propertyNames" ,
335
+ "then" ,
336
+ "unevaluatedItems" ,
337
+ "unevaluatedProperties" ,
338
+ },
339
+ in_subarray = {"allOf" , "anyOf" , "oneOf" },
340
+ in_subvalues = {
341
+ "$defs" ,
342
+ "dependentSchemas" ,
343
+ "patternProperties" ,
344
+ "properties" ,
345
+ },
346
+ ),
280
347
)
281
348
DRAFT7 = Specification (
282
349
name = "draft-07" ,
@@ -296,6 +363,20 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
296
363
in_subvalues = {"definitions" , "patternProperties" , "properties" },
297
364
),
298
365
anchors_in = _legacy_anchor_in_dollar_id ,
366
+ maybe_in_subresource = _maybe_in_subresource (
367
+ in_value = {
368
+ "additionalItems" ,
369
+ "additionalProperties" ,
370
+ "contains" ,
371
+ "else" ,
372
+ "if" ,
373
+ "not" ,
374
+ "propertyNames" ,
375
+ "then" ,
376
+ },
377
+ in_subarray = {"allOf" , "anyOf" , "oneOf" },
378
+ in_subvalues = {"definitions" , "patternProperties" , "properties" },
379
+ ),
299
380
)
300
381
DRAFT6 = Specification (
301
382
name = "draft-06" ,
@@ -312,6 +393,17 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
312
393
in_subvalues = {"definitions" , "patternProperties" , "properties" },
313
394
),
314
395
anchors_in = _legacy_anchor_in_dollar_id ,
396
+ maybe_in_subresource = _maybe_in_subresource (
397
+ in_value = {
398
+ "additionalItems" ,
399
+ "additionalProperties" ,
400
+ "contains" ,
401
+ "not" ,
402
+ "propertyNames" ,
403
+ },
404
+ in_subarray = {"allOf" , "anyOf" , "oneOf" },
405
+ in_subvalues = {"definitions" , "patternProperties" , "properties" },
406
+ ),
315
407
)
316
408
DRAFT4 = Specification (
317
409
name = "draft-04" ,
@@ -322,6 +414,11 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
322
414
in_subvalues = {"definitions" , "patternProperties" , "properties" },
323
415
),
324
416
anchors_in = _legacy_anchor_in_id ,
417
+ maybe_in_subresource = _maybe_in_subresource (
418
+ in_value = {"additionalItems" , "additionalProperties" , "not" },
419
+ in_subarray = {"allOf" , "anyOf" , "oneOf" },
420
+ in_subvalues = {"definitions" , "patternProperties" , "properties" },
421
+ ),
325
422
)
326
423
DRAFT3 = Specification (
327
424
name = "draft-03" ,
@@ -332,6 +429,11 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
332
429
in_subvalues = {"definitions" , "patternProperties" , "properties" },
333
430
),
334
431
anchors_in = _legacy_anchor_in_id ,
432
+ maybe_in_subresource = _maybe_in_subresource (
433
+ in_value = {"additionalItems" , "additionalProperties" },
434
+ in_subarray = {"extends" },
435
+ in_subvalues = {"definitions" , "patternProperties" , "properties" },
436
+ ),
335
437
)
336
438
337
439
0 commit comments