Skip to content

Commit

Permalink
Don't blow up for boolean additionalProperties on draft 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Mar 8, 2023
1 parent be02558 commit 19b82a6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
51 changes: 47 additions & 4 deletions referencing/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,50 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
return subresources_of


def _subresources_of_with_crazy_aP_items_dependencies(
in_value: Set[str] = frozenset(),
in_subvalues: Set[str] = frozenset(),
in_subarray: Set[str] = frozenset(),
):
"""
Specifically handle even older drafts where there are some funky keywords.
"""

def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
if isinstance(contents, bool):
return
for each in in_value:
if each in contents:
yield contents[each]
for each in in_subarray:
if each in contents:
yield from contents[each]
for each in in_subvalues:
if each in contents:
yield from contents[each].values()

items = contents.get("items")
if items is not None:
if isinstance(items, Sequence):
yield from items
else:
yield items
dependencies = contents.get("dependencies")
if dependencies is not None:
values = iter(dependencies.values())
value = next(values, None)
if isinstance(value, Mapping):
yield value
yield from values

for each in "additionalItems", "additionalProperties":
value = contents.get(each)
if isinstance(value, Mapping):
yield value

return subresources_of


def _maybe_in_subresource(
in_value: Set[str] = frozenset(),
in_subvalues: Set[str] = frozenset(),
Expand Down Expand Up @@ -468,8 +512,8 @@ def maybe_in_subresource(
DRAFT4 = Specification(
name="draft-04",
id_of=_legacy_id,
subresources_of=_subresources_of_with_crazy_items_dependencies(
in_value={"additionalItems", "additionalProperties", "not"},
subresources_of=_subresources_of_with_crazy_aP_items_dependencies(
in_value={"not"},
in_subarray={"allOf", "anyOf", "oneOf"},
in_subvalues={"definitions", "patternProperties", "properties"},
),
Expand All @@ -484,8 +528,7 @@ def maybe_in_subresource(
DRAFT3 = Specification(
name="draft-03",
id_of=_legacy_id,
subresources_of=_subresources_of_with_crazy_items_dependencies(
in_value={"additionalItems", "additionalProperties"},
subresources_of=_subresources_of_with_crazy_aP_items_dependencies(
in_subarray={"extends"},
in_subvalues={"definitions", "patternProperties", "properties"},
),
Expand Down

0 comments on commit 19b82a6

Please sign in to comment.