File tree 2 files changed +19
-6
lines changed
openapi_spec_validator/handlers
2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change 3
3
from yaml import load
4
4
5
5
from openapi_spec_validator .handlers .base import BaseHandler
6
+ from openapi_spec_validator .handlers .utils import uri_to_path
6
7
from openapi_spec_validator .loaders import ExtendedSafeLoader
7
8
8
9
@@ -19,12 +20,12 @@ def __call__(self, f):
19
20
class FileHandler (FileObjectHandler ):
20
21
"""OpenAPI spec validator file path handler."""
21
22
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 )
25
26
26
- assert f .startswith ("file" )
27
+ assert uri .startswith ("file" )
27
28
28
- filename = f [ 7 :]
29
- with open (filename ) as fh :
29
+ filepath = uri_to_path ( uri )
30
+ with open (filepath ) as fh :
30
31
return super (FileHandler , self ).__call__ (fh )
Original file line number Diff line number Diff line change
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
+ )
You can’t perform that action at this time.
0 commit comments