Is there a way to specify the scheme to use on a request?
MartinDelVecchio opened this issue · 5 comments
The swagger I am testing specifies two schemes:
schemes:
- http
- https
But the system I am testing against only actually supports HTTPS. I recognize that this is a bug, or invalid swagger.
But I am hoping to work around it by specifying HTTPS for each request I make. I am executing a request with this call:
# Execute it
response = self.client.request (self.app.op[operation_id](**kwargs), opt=opt, headers=headers)
I would love to be able to specify the scheme either in the opt dictionary (where I cam currently specifying url_netloc. For example:
opt = {'url_netloc': self.netloc, 'url_scheme': 'https'}
Is there a way to do this now that I am not seeing?
Thanks!
The way you suggested is fine, I'll add it in next release. Before I add that capability. For now, you can still restrict the scheme used when making requests by inheriting the client class, ex:
from pyswagger.contrib.client.requests import Client
class YourCustomizedClient(Client):
__schemes__ = ['https']
# use your customized client for later request
Thanks, I will try that this weekend.
Thanks.
I created this class as you suggested:
# Subclass Client so that we can specify the scheme we want to use
class HTTPSOnlyClient (Client):
__schemes__ = ['https']
And then I use it:
self.client = HTTPSOnlyClient (self.auth, send_opt={'verify': False})
But I am getting an exception:
smoky/api.py:124: in execute_operation_by_id
response = self.client.request (self.app.opoperation_id, opt=opt, headers=headers)
/usr/lib/python2.7/site-packages/pyswagger/contrib/client/requests.py:39: in request
req.prepare(scheme=self.prepare_schemes(req), handle_files=False)
self = <smoky.api.HTTPSOnlyClient object at 0x6fffd0f7e10>, req = <pyswagger.io.Request object at 0x6fffd06b290>
def prepare_schemes(self, req):
""" make sure this client support schemes required by current request
:param pyswagger.io.Request req: current request object
"""
# fix test bug when in python3 scheme, more details in commint msg
ret = sorted(self.__schemes__ & set(req.schemes), reverse=True)
E TypeError: unsupported operand type(s) for &: 'list' and 'set'
/usr/lib/python2.7/site-packages/pyswagger/core.py:566: TypeError
I tried it as a set:
class HTTPSOnlyClient (Client):
__schemes__ = set(['https'])
And it worked.
Thanks.
This issue should be fixed in v0.8.35
, please feel free to open it if it's not working.
Verified. Thanks!