From d2c065d368b406acd79caa8b9225a04b69b7492a Mon Sep 17 00:00:00 2001 From: Jorrit Schaap <schaap@astron.nl> Date: Wed, 21 Oct 2020 08:06:53 +0200 Subject: [PATCH] TMSS-379: keep extra properties when ref_resolving schema --- LCS/PyCommon/json_utils.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/LCS/PyCommon/json_utils.py b/LCS/PyCommon/json_utils.py index f1aee10a642..956fd3b0a29 100644 --- a/LCS/PyCommon/json_utils.py +++ b/LCS/PyCommon/json_utils.py @@ -134,23 +134,13 @@ def resolved_refs(schema): '''return the given schema with all $ref fields replaced by the referred json (sub)schema that they point to.''' if isinstance(schema, dict): updated_schema = {} - for key, value in schema.items(): - if key in "$ref" and isinstance(value, str): - if value.startswith('#'): - # reference to local document, no need for http injection - updated_schema[key] = value - else: - try: - # by returning the referenced (sub)schema, the $ref-key and url-value are replaced from the caller's perspective. - # also, recursively resolve refs in referenced_subschema - referenced_subschema = get_referenced_subschema(value) - return resolved_refs(referenced_subschema) - except: - # can't get the referenced schema - # so, just accept the original value and assume that the user uploaded a proper schema - updated_schema[key] = value - else: - updated_schema[key] = resolved_refs(value) + keys = list(schema.keys()) + if "$ref" in keys and isinstance(schema['$ref'], str) and schema['$ref'].startswith('http'): + keys.remove("$ref") + updated_schema = resolved_refs(get_referenced_subschema(schema['$ref'])) + + for key in keys: + updated_schema[key] = resolved_refs(schema[key]) return updated_schema if isinstance(schema, list): -- GitLab