Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/algorithms/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
def _get_all_json_refs(item: Any) -> set[JsonRef]:
"""Get all the definitions references from a JSON schema."""
refs: set[JsonRef] = set()
if isinstance(item, dict):
for key, value in item.items():
if key == "$ref" and isinstance(value, str):
# the isinstance check ensures that '$ref' isn't the name of a property, etc.
refs.add(JsonRef(value))
elif isinstance(value, dict):
refs.update(_get_all_json_refs(value))
elif isinstance(value, list):
for item in value:
refs.update(_get_all_json_refs(item))
elif isinstance(item, list):
for item in item:
refs.update(_get_all_json_refs(item))
stack = [item]
while stack:
current = stack.pop()
if isinstance(current, dict):
for key, value in current.items():
if key == "$ref" and isinstance(value, str):
# the isinstance check ensures that '$ref' isn't the name of a property, etc.
refs.add(JsonRef(value))
elif isinstance(value, dict):
stack.append(value)
elif isinstance(value, list):
stack.extend(value)
elif isinstance(current, list):
stack.extend(current)
return refs


Expand Down