@@ -224,6 +224,29 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
224224 return subresources_of
225225
226226
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+
227250DRAFT202012 = Specification (
228251 name = "draft2020-12" ,
229252 id_of = _dollar_id ,
@@ -250,6 +273,28 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
250273 },
251274 ),
252275 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+ ),
253298)
254299DRAFT201909 = Specification (
255300 name = "draft2019-09" ,
@@ -277,6 +322,28 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
277322 },
278323 ),
279324 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+ ),
280347)
281348DRAFT7 = Specification (
282349 name = "draft-07" ,
@@ -296,6 +363,20 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
296363 in_subvalues = {"definitions" , "patternProperties" , "properties" },
297364 ),
298365 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+ ),
299380)
300381DRAFT6 = Specification (
301382 name = "draft-06" ,
@@ -312,6 +393,17 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
312393 in_subvalues = {"definitions" , "patternProperties" , "properties" },
313394 ),
314395 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+ ),
315407)
316408DRAFT4 = Specification (
317409 name = "draft-04" ,
@@ -322,6 +414,11 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
322414 in_subvalues = {"definitions" , "patternProperties" , "properties" },
323415 ),
324416 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+ ),
325422)
326423DRAFT3 = Specification (
327424 name = "draft-03" ,
@@ -332,6 +429,11 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
332429 in_subvalues = {"definitions" , "patternProperties" , "properties" },
333430 ),
334431 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+ ),
335437)
336438
337439
0 commit comments