From 444bfc8ea49fa46766e1632b7bf1a8f5ca4ed43b Mon Sep 17 00:00:00 2001 From: Alexandre Franke Date: Tue, 1 Feb 2022 16:16:00 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20successive=20reference=20h?= =?UTF-8?q?andling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #3689 Signed-off-by: Alexandre Franke --- data/api/server-server/transactions.yaml | 2 +- scripts/dump-swagger.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/data/api/server-server/transactions.yaml b/data/api/server-server/transactions.yaml index 46dd17afd..4bd2e59c2 100644 --- a/data/api/server-server/transactions.yaml +++ b/data/api/server-server/transactions.yaml @@ -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: diff --git a/scripts/dump-swagger.py b/scripts/dump-swagger.py index 31004f733..e536ea858 100755 --- a/scripts/dump-swagger.py +++ b/scripts/dump-swagger.py @@ -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 = {}