pyopenapi / pyswagger

An OpenAPI (fka Swagger) client & converter in python, which is type-safe, dynamic, spec-compliant.
MIT License
384 stars 88 forks source link

url_scheme does not respect selected scheme when loading from local file. #178

Open mitchellkingsley opened 5 years ago

mitchellkingsley commented 5 years ago

When using a URI to specify a local swagger file on windows, client.request() throws a ValueError.

Code Run:

app = App.create('file:///C:/Users/.../api.json')
client = Client()
params = dict(param1="example_string", param2 = "example_string2")

opt = dict(url_netloc='localhost:8500', url_scheme='https')

op = app.op['ExampleTag', 'ExampleID']
req_and_resp = op(param1=params)
response = client.request(req_and_resp, opt=opt)

The reported error:

Traceback (most recent call last):
  File ".\swagger_api.py", line 12, in <module>
    response = client.request(req_and_resp)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyswagger\contrib\client\requests.py", line 39, in request
    req.prepare(scheme=self.prepare_schemes(req), handle_files=False)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\pyswagger\core.py", line 568, in prepare_schemes
    raise ValueError('No schemes available: {0}'.format(req.schemes))
ValueError: No schemes available: ['file']

In the swagger provided there is no scheme specified, so it seems like the standard is followed:

If the schemes is not included, the default scheme to be used is the one used to access the Swagger definition itself.

From looking around it seems like I should be able to specify a scheme to use via 'url_scheme' in opt. It seems like that selection isn't being honored.

If I am doing something wrong, any help would be greatly appreciated.