diff --git a/LCS/PyCommon/json_utils.py b/LCS/PyCommon/json_utils.py index f1aee10a64206f6c4897c69868991fd724b92f72..956fd3b0a29c34bc25bc3e204ff877943e266ca1 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):