🐛 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"
example: {
"$ref": "examples/transaction.json",
"edus": [{"$ref": "edu.json"}] # Relative to the examples directory
"edus": [{"$ref": "examples/edu.json"}] # Relative to the examples directory
}
responses:
200:

@ -37,11 +37,18 @@ def resolve_references(path, schema):
# do $ref first
if '$ref' in schema:
value = schema['$ref']
previous_path = path
path = os.path.join(os.path.dirname(path), value)
with open(path, encoding="utf-8") as f:
ref = yaml.safe_load(f)
result = resolve_references(path, ref)
del schema['$ref']
try:
with open(path, encoding="utf-8") as f:
ref = yaml.safe_load(f)
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:
result = {}

Loading…
Cancel
Save