🐛 Fix successive reference handling

Fixes #3689

Signed-off-by: Alexandre Franke <alexandre.franke@matrix.org>
pull/3684/head
Alexandre Franke 4 years ago
parent fdd95b2e6b
commit 444bfc8ea4

@ -69,7 +69,7 @@ paths:
$ref: "definitions/edu.yaml" $ref: "definitions/edu.yaml"
example: { example: {
"$ref": "examples/transaction.json", "$ref": "examples/transaction.json",
"edus": [{"$ref": "edu.json"}] # Relative to the examples directory "edus": [{"$ref": "examples/edu.json"}] # Relative to the examples directory
} }
responses: responses:
200: 200:

@ -37,11 +37,18 @@ def resolve_references(path, schema):
# do $ref first # do $ref first
if '$ref' in schema: if '$ref' in schema:
value = schema['$ref'] value = schema['$ref']
previous_path = path
path = os.path.join(os.path.dirname(path), value) path = os.path.join(os.path.dirname(path), value)
with open(path, encoding="utf-8") as f: try:
ref = yaml.safe_load(f) with open(path, encoding="utf-8") as f:
result = resolve_references(path, ref) ref = yaml.safe_load(f)
del schema['$ref'] result = resolve_references(path, ref)
del schema['$ref']
path = previous_path
except FileNotFoundError:
print("Resolving {}".format(schema))
print("File not found: {}".format(path))
result = {}
else: else:
result = {} result = {}

Loading…
Cancel
Save