forked from loafle/openapi-generator-original
Bugfix/issue 3723 (#3726)
* Extended request generation logic with support for serialized body content types other than Json * Updated the Petstore Python client tests * Fixed body content type identification for strings
This commit is contained in:
@@ -122,12 +122,12 @@ class RESTClientObject(object):
|
||||
r = self.pool_manager.request(method, url,
|
||||
body=request_body,
|
||||
headers=headers)
|
||||
if headers['Content-Type'] == 'application/x-www-form-urlencoded':
|
||||
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
|
||||
r = self.pool_manager.request(method, url,
|
||||
fields=post_params,
|
||||
encode_multipart=False,
|
||||
headers=headers)
|
||||
if headers['Content-Type'] == 'multipart/form-data':
|
||||
elif headers['Content-Type'] == 'multipart/form-data':
|
||||
# must del headers['Content-Type'], or the correct Content-Type
|
||||
# which generated by urllib3 will be overwritten.
|
||||
del headers['Content-Type']
|
||||
@@ -135,6 +135,19 @@ class RESTClientObject(object):
|
||||
fields=post_params,
|
||||
encode_multipart=True,
|
||||
headers=headers)
|
||||
# Pass a `string` parameter directly in the body to support
|
||||
# other content types than Json when `body` argument is provided
|
||||
# in serialized form
|
||||
elif isinstance(body, str):
|
||||
request_body = body
|
||||
r = self.pool_manager.request(method, url,
|
||||
body=request_body,
|
||||
headers=headers)
|
||||
else:
|
||||
# Cannot generate the request from given parameters
|
||||
msg = """Cannot prepare a request message for provided arguments.
|
||||
Please check that your arguments match declared content type."""
|
||||
raise ApiException(status=0, reason=msg)
|
||||
# For `GET`, `HEAD`
|
||||
else:
|
||||
r = self.pool_manager.request(method, url,
|
||||
|
||||
Reference in New Issue
Block a user