Skip to content

Commit dc62987

Browse files
committed
Ignore $ref suitably when calculating $ids.
1 parent 24e9575 commit dc62987

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

referencing/jsonschema.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ def _dollar_id(contents: Schema) -> URI | None:
3535
return contents.get("$id")
3636

3737

38+
def _dollar_id_pre2019(contents: Schema) -> URI | None:
39+
if isinstance(contents, bool) or "$ref" in contents:
40+
return
41+
return contents.get("$id")
42+
43+
3844
def _legacy_id(contents: ObjectSchema) -> URI | None:
3945
return contents.get("id")
4046

4147

4248
def _subresources_of(
4349
in_value: Set[str] = frozenset(),
4450
in_subvalues: Set[str] = frozenset(),
51+
in_subarray: Set[str] = frozenset(),
4552
):
4653
"""
4754
Create a callable returning JSON Schema specification-style subschemas.
@@ -54,6 +61,9 @@ def subresources_of(resource: ObjectSchema) -> Iterable[ObjectSchema]:
5461
for each in in_value:
5562
if each in resource:
5663
yield resource[each]
64+
for each in in_subarray:
65+
if each in resource:
66+
yield from resource[each]
5767
for each in in_subvalues:
5868
if each in resource:
5969
yield from resource[each].values()
@@ -73,9 +83,10 @@ def subresources_of(resource: ObjectSchema) -> Iterable[ObjectSchema]:
7383
)
7484
DRAFT7 = Specification(
7585
name="draft-07",
76-
id_of=_dollar_id,
86+
id_of=_dollar_id_pre2019,
7787
subresources_of=_subresources_of(
7888
in_value={"if", "then", "else"},
89+
in_subarray={"allOf", "anyOf", "oneOf"},
7990
in_subvalues={"definitions"},
8091
),
8192
)

0 commit comments

Comments
 (0)