Skip to content

Commit 99d5a7b

Browse files
committed
Fill in the rest of drafts 7, 6, 4 and 3 keywords.
1 parent 885b37f commit 99d5a7b

File tree

2 files changed

+99
-22
lines changed

2 files changed

+99
-22
lines changed

referencing/jsonschema.py

Lines changed: 98 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ def _subresources_of(
126126
in_value: Set[str] = frozenset(),
127127
in_subvalues: Set[str] = frozenset(),
128128
in_subarray: Set[str] = frozenset(),
129-
in_value_or_subarray: Set[str] = frozenset(),
130129
):
131130
"""
132131
Create a callable returning JSON Schema specification-style subschemas.
@@ -147,13 +146,77 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
147146
for each in in_subvalues:
148147
if each in contents:
149148
yield from contents[each].values()
150-
for each in in_value_or_subarray:
149+
150+
return subresources_of
151+
152+
153+
def _subresources_of_with_crazy_items(
154+
in_value: Set[str] = frozenset(),
155+
in_subvalues: Set[str] = frozenset(),
156+
in_subarray: Set[str] = frozenset(),
157+
):
158+
"""
159+
Specifically handle older drafts where there are some funky keywords.
160+
"""
161+
162+
def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
163+
if isinstance(contents, bool):
164+
return
165+
for each in in_value:
166+
if each in contents:
167+
yield contents[each]
168+
for each in in_subarray:
151169
if each in contents:
152-
value = contents[each]
153-
if isinstance(value, Mapping):
154-
yield value
155-
else:
156-
yield from value
170+
yield from contents[each]
171+
for each in in_subvalues:
172+
if each in contents:
173+
yield from contents[each].values()
174+
175+
items = contents.get("items")
176+
if items is not None:
177+
if isinstance(items, Mapping):
178+
yield items
179+
else:
180+
yield from items
181+
182+
return subresources_of
183+
184+
185+
def _subresources_of_with_crazy_items_dependencies(
186+
in_value: Set[str] = frozenset(),
187+
in_subvalues: Set[str] = frozenset(),
188+
in_subarray: Set[str] = frozenset(),
189+
):
190+
"""
191+
Specifically handle older drafts where there are some funky keywords.
192+
"""
193+
194+
def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
195+
if isinstance(contents, bool):
196+
return
197+
for each in in_value:
198+
if each in contents:
199+
yield contents[each]
200+
for each in in_subarray:
201+
if each in contents:
202+
yield from contents[each]
203+
for each in in_subvalues:
204+
if each in contents:
205+
yield from contents[each].values()
206+
207+
items = contents.get("items")
208+
if items is not None:
209+
if isinstance(items, Mapping):
210+
yield items
211+
else:
212+
yield from items
213+
dependencies = contents.get("dependencies")
214+
if dependencies is not None:
215+
values = iter(dependencies.values())
216+
value = next(values, None)
217+
if isinstance(value, Mapping):
218+
yield value
219+
yield from values
157220

158221
return subresources_of
159222

@@ -188,7 +251,7 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
188251
DRAFT201909 = Specification(
189252
name="draft2019-09",
190253
id_of=_dollar_id,
191-
subresources_of=_subresources_of(
254+
subresources_of=_subresources_of_with_crazy_items(
192255
in_value={
193256
"additionalItems",
194257
"additionalProperties",
@@ -209,47 +272,61 @@ def subresources_of(contents: Schema) -> Iterable[ObjectSchema]:
209272
"patternProperties",
210273
"properties",
211274
},
212-
in_value_or_subarray={"items"},
213275
),
214276
anchors_in=_anchor_2019,
215277
)
216278
DRAFT7 = Specification(
217279
name="draft-07",
218280
id_of=_legacy_dollar_id,
219-
subresources_of=_subresources_of(
220-
in_value={"additionalProperties", "if", "then", "else", "not"},
281+
subresources_of=_subresources_of_with_crazy_items_dependencies(
282+
in_value={
283+
"additionalItems",
284+
"additionalProperties",
285+
"contains",
286+
"else",
287+
"if",
288+
"not",
289+
"propertyNames",
290+
"then",
291+
},
221292
in_subarray={"allOf", "anyOf", "oneOf"},
222-
in_subvalues={"definitions", "properties"},
293+
in_subvalues={"definitions", "patternProperties", "properties"},
223294
),
224295
anchors_in=_legacy_anchor_in_dollar_id,
225296
)
226297
DRAFT6 = Specification(
227298
name="draft-06",
228299
id_of=_legacy_dollar_id,
229-
subresources_of=_subresources_of(
230-
in_value={"additionalProperties", "not"},
300+
subresources_of=_subresources_of_with_crazy_items_dependencies(
301+
in_value={
302+
"additionalItems",
303+
"additionalProperties",
304+
"contains",
305+
"not",
306+
"propertyNames",
307+
},
231308
in_subarray={"allOf", "anyOf", "oneOf"},
232-
in_subvalues={"definitions", "properties"},
309+
in_subvalues={"definitions", "patternProperties", "properties"},
233310
),
234311
anchors_in=_legacy_anchor_in_dollar_id,
235312
)
236313
DRAFT4 = Specification(
237314
name="draft-04",
238315
id_of=_legacy_id,
239-
subresources_of=_subresources_of(
240-
in_value={"additionalProperties", "not"},
316+
subresources_of=_subresources_of_with_crazy_items_dependencies(
317+
in_value={"additionalItems", "additionalProperties", "not"},
241318
in_subarray={"allOf", "anyOf", "oneOf"},
242-
in_subvalues={"definitions", "properties"},
319+
in_subvalues={"definitions", "patternProperties", "properties"},
243320
),
244321
anchors_in=_legacy_anchor_in_id,
245322
)
246323
DRAFT3 = Specification(
247324
name="draft-03",
248325
id_of=_legacy_id,
249-
subresources_of=_subresources_of(
250-
in_value={"additionalProperties"},
326+
subresources_of=_subresources_of_with_crazy_items_dependencies(
327+
in_value={"additionalItems", "additionalProperties"},
251328
in_subarray={"extends"},
252-
in_subvalues={"definitions", "properties"},
329+
in_subvalues={"definitions", "patternProperties", "properties"},
253330
),
254331
anchors_in=_legacy_anchor_in_id,
255332
)

suite

Submodule suite updated 45 files

0 commit comments

Comments
 (0)