Skip to content
Snippets Groups Projects
Commit 37f11fee authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-493: added method to get all the references from a schema

parent 1b67931b
Branches
Tags
1 merge request!324Resolve TMSS-493
...@@ -175,6 +175,24 @@ def resolved_refs(schema): ...@@ -175,6 +175,24 @@ def resolved_refs(schema):
return schema return schema
def get_refs(schema) -> set:
'''return a set of all $refs in the schema'''
refs = set()
if isinstance(schema, dict):
for key, value in schema.items():
if key == "$ref":
refs.add(value)
else:
refs.update(get_refs(value))
if isinstance(schema, list):
for item in schema:
refs.update(get_refs(item))
return refs
def validate_json_against_its_schema(json_object: dict): def validate_json_against_its_schema(json_object: dict):
'''validate the give json object against its own schema (the URI/URL that its propery $schema points to)''' '''validate the give json object against its own schema (the URI/URL that its propery $schema points to)'''
schema_url = json_object['$schema'] schema_url = json_object['$schema']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment