From 9f730a94f0aea7e9980c447f4117280efc1c4016 Mon Sep 17 00:00:00 2001 From: Henry Chladil Date: Thu, 4 Nov 2021 16:56:50 +1000 Subject: [PATCH 1/2] Window support for local files Previous impl did not support windows when using a local file e.g. > openapi2jsonschema C:\myfile.yaml --- openapi2jsonschema/command.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/openapi2jsonschema/command.py b/openapi2jsonschema/command.py index 9cd1bfc..22de046 100644 --- a/openapi2jsonschema/command.py +++ b/openapi2jsonschema/command.py @@ -58,7 +58,14 @@ def default(output, schema, prefix, stand_alone, expanded, kubernetes, strict): response = urllib.urlopen(schema) else: if os.path.isfile(schema): - schema = "file://" + os.path.realpath(schema) + if sys.version_info >= (3, 4): + import pathlib + schema = pathlib.Path(os.path.realpath(schema)).as_uri() + else: + schema = schema = 'file://' + os.path.realpath(schema) # does not support windows + req = urllib.request.Request(schema) + response = urllib.request.urlopen(req) + req = urllib.request.Request(schema) response = urllib.request.urlopen(req) From 146429cca4b104d778848d977858c61871ddce9e Mon Sep 17 00:00:00 2001 From: Henry Chladil Date: Thu, 4 Nov 2021 16:57:44 +1000 Subject: [PATCH 2/2] online code editor mistake --- openapi2jsonschema/command.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/openapi2jsonschema/command.py b/openapi2jsonschema/command.py index 22de046..fa38b7c 100644 --- a/openapi2jsonschema/command.py +++ b/openapi2jsonschema/command.py @@ -65,10 +65,6 @@ def default(output, schema, prefix, stand_alone, expanded, kubernetes, strict): schema = schema = 'file://' + os.path.realpath(schema) # does not support windows req = urllib.request.Request(schema) response = urllib.request.urlopen(req) - - req = urllib.request.Request(schema) - response = urllib.request.urlopen(req) - info("Parsing schema") # Note that JSON is valid YAML, so we can use the YAML parser whether # the schema is stored in JSON or YAML