From 37f11fee12e7291bd05c878b0800c556a91bd24b Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Tue, 29 Dec 2020 16:24:09 +0100 Subject: [PATCH] TMSS-493: added method to get all the references from a schema --- LCS/PyCommon/json_utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/LCS/PyCommon/json_utils.py b/LCS/PyCommon/json_utils.py index 4b84ad903e6..0ff868fe1f1 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'] -- GitLab