diff --git a/LCS/PyCommon/json_utils.py b/LCS/PyCommon/json_utils.py index 4b84ad903e6e0510240743901ba4b9ec7397fb49..0ff868fe1f18f5a6066fe7057531139d920b8d19 100644 --- a/LCS/PyCommon/json_utils.py +++ b/LCS/PyCommon/json_utils.py @@ -175,6 +175,24 @@ def resolved_refs(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): '''validate the give json object against its own schema (the URI/URL that its propery $schema points to)''' schema_url = json_object['$schema']