Skip to content

Commit 44cf7ef

Browse files
committed
File handler uri to os path convert fix
1 parent 3979ff6 commit 44cf7ef

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

openapi_spec_validator/handlers/file.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from yaml import load
44

55
from openapi_spec_validator.handlers.base import BaseHandler
6+
from openapi_spec_validator.handlers.utils import uri_to_path
67
from openapi_spec_validator.loaders import ExtendedSafeLoader
78

89

@@ -19,12 +20,12 @@ def __call__(self, f):
1920
class FileHandler(FileObjectHandler):
2021
"""OpenAPI spec validator file path handler."""
2122

22-
def __call__(self, f):
23-
if isinstance(f, StringIO):
24-
return super(FileHandler, self).__call__(f)
23+
def __call__(self, uri):
24+
if isinstance(uri, StringIO):
25+
return super(FileHandler, self).__call__(uri)
2526

26-
assert f.startswith("file")
27+
assert uri.startswith("file")
2728

28-
filename = f[7:]
29-
with open(filename) as fh:
29+
filepath = uri_to_path(uri)
30+
with open(filepath) as fh:
3031
return super(FileHandler, self).__call__(fh)
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os.path
2+
3+
from six.moves.urllib.parse import urlparse, unquote
4+
from six.moves.urllib.request import url2pathname
5+
6+
7+
def uri_to_path(uri):
8+
parsed = urlparse(uri)
9+
host = "{0}{0}{mnt}{0}".format(os.path.sep, mnt=parsed.netloc)
10+
return os.path.normpath(
11+
os.path.join(host, url2pathname(unquote(parsed.path)))
12+
)

0 commit comments

Comments
 (0)