Skip to content

Commit 19b82a6

Browse files
committed
Don't blow up for boolean additionalProperties on draft 4.
1 parent be02558 commit 19b82a6

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

referencing/jsonschema.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,50 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
224224
return subresources_of
225225

226226

227+
def _subresources_of_with_crazy_aP_items_dependencies(
228+
in_value: Set[str] = frozenset(),
229+
in_subvalues: Set[str] = frozenset(),
230+
in_subarray: Set[str] = frozenset(),
231+
):
232+
"""
233+
Specifically handle even older drafts where there are some funky keywords.
234+
"""
235+
236+
def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
237+
if isinstance(contents, bool):
238+
return
239+
for each in in_value:
240+
if each in contents:
241+
yield contents[each]
242+
for each in in_subarray:
243+
if each in contents:
244+
yield from contents[each]
245+
for each in in_subvalues:
246+
if each in contents:
247+
yield from contents[each].values()
248+
249+
items = contents.get("items")
250+
if items is not None:
251+
if isinstance(items, Sequence):
252+
yield from items
253+
else:
254+
yield items
255+
dependencies = contents.get("dependencies")
256+
if dependencies is not None:
257+
values = iter(dependencies.values())
258+
value = next(values, None)
259+
if isinstance(value, Mapping):
260+
yield value
261+
yield from values
262+
263+
for each in "additionalItems", "additionalProperties":
264+
value = contents.get(each)
265+
if isinstance(value, Mapping):
266+
yield value
267+
268+
return subresources_of
269+
270+
227271
def _maybe_in_subresource(
228272
in_value: Set[str] = frozenset(),
229273
in_subvalues: Set[str] = frozenset(),
@@ -468,8 +512,8 @@ def maybe_in_subresource(
468512
DRAFT4 = Specification(
469513
name="draft-04",
470514
id_of=_legacy_id,
471-
subresources_of=_subresources_of_with_crazy_items_dependencies(
472-
in_value={"additionalItems", "additionalProperties", "not"},
515+
subresources_of=_subresources_of_with_crazy_aP_items_dependencies(
516+
in_value={"not"},
473517
in_subarray={"allOf", "anyOf", "oneOf"},
474518
in_subvalues={"definitions", "patternProperties", "properties"},
475519
),
@@ -484,8 +528,7 @@ def maybe_in_subresource(
484528
DRAFT3 = Specification(
485529
name="draft-03",
486530
id_of=_legacy_id,
487-
subresources_of=_subresources_of_with_crazy_items_dependencies(
488-
in_value={"additionalItems", "additionalProperties"},
531+
subresources_of=_subresources_of_with_crazy_aP_items_dependencies(
489532
in_subarray={"extends"},
490533
in_subvalues={"definitions", "patternProperties", "properties"},
491534
),

0 commit comments

Comments
 (0)