You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, if I use the client generated by swagger-codegen, the abort message would be missing. I can only get something like HTTP Error 400: BAD REQUEST
Investigated further, I see that ApiClient issues a urllib2.urlopen(request)
class ApiClient:
"""Generic API client for Swagger client library builds"""
def __init__(self, apiKey=None, apiServer=None):
if apiKey == None:
raise Exception('You must pass an apiKey when instantiating the '
'APIClient')
self.apiKey = apiKey
self.apiServer = apiServer
self.cookie = None
def callAPI(self, resourcePath, method, queryParams, postData,
headerParams=None):
url = self.apiServer + resourcePath
headers = {}
if headerParams:
for param, value in headerParams.iteritems():
headers[param] = value
headers['Content-type'] = 'application/json'
headers['api_key'] = self.apiKey
if self.cookie:
headers['Cookie'] = self.cookie
data = None
if method == 'GET':
...(omitted)
else:
raise Exception('Method ' + method + ' is not recognized.')
request = MethodRequest(method=method, url=url, headers=headers,
data=data)
# Make the request
response = urllib2.urlopen(request)
if 'Set-Cookie' in response.headers:
self.cookie = response.headers['Set-Cookie']
string = response.read()
try:
data = json.loads(string)
except ValueError: # PUT requests don't return anything
data = None
return data
and abort() would be caught in HTTPDefaultErrorHandler of urllib2.py, and the message we put could not be found there anymore.
My application is based on flask-restful-swagger, swagger-codegen, and python.
I universally use
abort()
in server side logic for unexpected situations, and it works fine on swagger UI (the abort reason is displayed fine).However, if I use the client generated by swagger-codegen, the abort message would be missing. I can only get something like HTTP Error 400: BAD REQUEST
Investigated further, I see that ApiClient issues a
urllib2.urlopen(request)
and
abort()
would be caught in HTTPDefaultErrorHandler of urllib2.py, and the message we put could not be found there anymore.Result (our message 'custom error messages here....' is lost):
I was wondering that if this is a limitation on API Client use case of swagger-codegen, and how could we get around of this issue. Thanks.
The text was updated successfully, but these errors were encountered: