diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 4595d8550777..7fee45b2d4e6 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -2493,6 +2493,14 @@ public CodegenOperation fromOperation(String path, if (methodResponse != null) { Schema responseSchema = ModelUtils.unaliasSchema(this.openAPI, ModelUtils.getSchemaFromResponse(methodResponse)); + for (CodegenResponse response : op.responses){ + Schema thisResponseSchema = (Schema) response.schema; + if (thisResponseSchema != null) { + CodegenProperty cm = fromProperty("response", thisResponseSchema); + response.dataType = cm.dataType; + } + } + if (responseSchema != null) { CodegenProperty cm = fromProperty("response", responseSchema); diff --git a/modules/openapi-generator/src/main/resources/python/api.mustache b/modules/openapi-generator/src/main/resources/python/api.mustache index 590299dc5f4b..e2c5546c9e2e 100644 --- a/modules/openapi-generator/src/main/resources/python/api.mustache +++ b/modules/openapi-generator/src/main/resources/python/api.mustache @@ -222,6 +222,13 @@ class {{classname}}(object): # Authentication setting auth_settings = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}] # noqa: E501 + # multiple potential response types + response_types = { + {{#responses}} + {{code}}: {{#dataType}}'{{dataType}}'{{/dataType}}{{^dataType}}None{{/dataType}}{{#hasMore}},{{/hasMore}} + {{/responses}} + } + return self.api_client.call_api( '{{{path}}}', '{{httpMethod}}', path_params, @@ -230,7 +237,7 @@ class {{classname}}(object): body=body_params, post_params=form_params, files=local_var_files, - response_type={{#returnType}}'{{returnType}}'{{/returnType}}{{^returnType}}None{{/returnType}}, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/modules/openapi-generator/src/main/resources/python/api_client.mustache b/modules/openapi-generator/src/main/resources/python/api_client.mustache index 768b8d973f8f..518a6e24740f 100644 --- a/modules/openapi-generator/src/main/resources/python/api_client.mustache +++ b/modules/openapi-generator/src/main/resources/python/api_client.mustache @@ -106,11 +106,13 @@ class ApiClient(object): {{#asyncio}}async {{/asyncio}}def __call_api( self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, - files=None, response_type=None, auth_settings=None, + files=None, response_types=None, auth_settings=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): config = self.configuration + if response_types is None: + response_types = {} # header parameters header_params = header_params or {} @@ -162,18 +164,22 @@ class ApiClient(object): # use server/host defined in path or operation instead url = _host + resource_path + _decode_utf8 = {k: v != 'file' for k, v in six.iteritems(response_types)} # noqa: E501 + # perform request and return response response_data = {{#asyncio}}await {{/asyncio}}{{#tornado}}yield {{/tornado}}self.request( method, url, query_params=query_params, headers=header_params, post_params=post_params, body=body, _preload_content=_preload_content, - _request_timeout=_request_timeout) + _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8) self.last_response = response_data return_data = response_data if _preload_content: # deserialize response data + response_type = response_types.get(response_data.status) if response_type: return_data = self.deserialize(response_data, response_type) else: @@ -300,7 +306,7 @@ class ApiClient(object): def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None, - response_type=None, auth_settings=None, async_req=None, + response_types=None, auth_settings=None, async_req=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): """Makes the HTTP request (synchronous) and returns deserialized data. @@ -343,15 +349,16 @@ class ApiClient(object): return self.__call_api(resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types, auth_settings, _return_http_data_only, collection_formats, - _preload_content, _request_timeout, _host) + _preload_content, _request_timeout, + _host) else: thread = self.pool.apply_async(self.__call_api, (resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types, auth_settings, _return_http_data_only, collection_formats, _preload_content, @@ -361,20 +368,22 @@ class ApiClient(object): def request(self, method, url, query_params=None, headers=None, post_params=None, body=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Makes the HTTP request using RESTClient.""" if method == "GET": return self.rest_client.GET(url, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - headers=headers) + headers=headers, + _decode_utf8=_decode_utf8) elif method == "HEAD": return self.rest_client.HEAD(url, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - headers=headers) + headers=headers, + _decode_utf8=_decode_utf8) elif method == "OPTIONS": return self.rest_client.OPTIONS(url, query_params=query_params, @@ -382,7 +391,8 @@ class ApiClient(object): post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "POST": return self.rest_client.POST(url, query_params=query_params, @@ -390,7 +400,8 @@ class ApiClient(object): post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "PUT": return self.rest_client.PUT(url, query_params=query_params, @@ -398,7 +409,8 @@ class ApiClient(object): post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "PATCH": return self.rest_client.PATCH(url, query_params=query_params, @@ -406,14 +418,16 @@ class ApiClient(object): post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "DELETE": return self.rest_client.DELETE(url, query_params=query_params, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) else: raise ApiValueError( "http method must be `GET`, `HEAD`, `OPTIONS`," @@ -485,10 +499,9 @@ class ApiClient(object): accepts = [x.lower() for x in accepts] - if 'application/json' in accepts: - return 'application/json' - else: - return ', '.join(accepts) + accepts = [x + (';q=1' if x == 'application/json' else ';q=0.9') for x in accepts] # noqa: E501 + + return ', '.join(accepts) def select_header_content_type(self, content_types): """Returns `Content-Type` based on an array of content_types provided. diff --git a/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache b/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache index 36b061f8f49c..3edfd4455205 100644 --- a/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache @@ -11,7 +11,6 @@ import ssl import aiohttp import certifi import asyncio -# python 2 and python 3 compatibility library from six.moves.urllib.parse import urlencode from {{packageName}}.exceptions import ApiException, ApiValueError @@ -79,7 +78,7 @@ class RESTClientObject(object): async def request(self, method, url, query_params=None, headers=None, body=None, post_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Execute request :param method: http request method @@ -101,6 +100,9 @@ class RESTClientObject(object): assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS'] + if _decode_utf8 is None: + _decode_utf8 = {} + if post_params and body: raise ApiValueError( "body parameter cannot be used with post_params parameter." @@ -174,69 +176,80 @@ class RESTClientObject(object): return r async def GET(self, url, headers=None, query_params=None, - _preload_content=True, _request_timeout=None): + _preload_content=True, _request_timeout=None, + _decode_utf8=True): return (await self.request("GET", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params)) async def HEAD(self, url, headers=None, query_params=None, - _preload_content=True, _request_timeout=None): + _preload_content=True, _request_timeout=None, + _decode_utf8=True): return (await self.request("HEAD", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params)) async def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return (await self.request("OPTIONS", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body)) async def DELETE(self, url, headers=None, query_params=None, body=None, - _preload_content=True, _request_timeout=None): + _preload_content=True, _request_timeout=None, + _decode_utf8=True): return (await self.request("DELETE", url, headers=headers, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body)) async def POST(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return (await self.request("POST", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body)) async def PUT(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, + _decode_utf8=True): return (await self.request("PUT", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body)) async def PATCH(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return (await self.request("PATCH", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body)) diff --git a/modules/openapi-generator/src/main/resources/python/rest.mustache b/modules/openapi-generator/src/main/resources/python/rest.mustache index 772efe91b39f..40590fb1fb19 100644 --- a/modules/openapi-generator/src/main/resources/python/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python/rest.mustache @@ -100,7 +100,7 @@ class RESTClientObject(object): def request(self, method, url, query_params=None, headers=None, body=None, post_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Perform requests. :param method: http request method @@ -123,6 +123,9 @@ class RESTClientObject(object): assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS'] + if _decode_utf8 is None: + _decode_utf8 = {} + if post_params and body: raise ApiValueError( "body parameter cannot be used with post_params parameter." @@ -209,13 +212,14 @@ class RESTClientObject(object): if _preload_content: r = RESTResponse(r) - # In the python 3, the response.data is bytes. - # we need to decode it to string. - if six.PY3: - r.data = r.data.decode('utf8') + if _decode_utf8.get(r.status, True): + # In the python 3, the response.data is bytes. + # we need to decode it to string. + if six.PY3: + r.data = r.data.decode('utf8') - # log response body - logger.debug("response body: %s", r.data) + # log response body + logger.debug("response body: %s", r.data) if not 200 <= r.status <= 299: raise ApiException(http_resp=r) @@ -223,66 +227,73 @@ class RESTClientObject(object): return r def GET(self, url, headers=None, query_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return self.request("GET", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params) def HEAD(self, url, headers=None, query_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return self.request("HEAD", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params) def OPTIONS(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("OPTIONS", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def DELETE(self, url, headers=None, query_params=None, body=None, - _preload_content=True, _request_timeout=None): + _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("DELETE", url, headers=headers, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def POST(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("POST", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def PUT(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("PUT", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def PATCH(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("PATCH", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) diff --git a/modules/openapi-generator/src/main/resources/python/tornado/rest.mustache b/modules/openapi-generator/src/main/resources/python/tornado/rest.mustache index e7a760f37060..6b3f42e6cda1 100644 --- a/modules/openapi-generator/src/main/resources/python/tornado/rest.mustache +++ b/modules/openapi-generator/src/main/resources/python/tornado/rest.mustache @@ -8,7 +8,6 @@ import logging import re # python 2 and python 3 compatibility library -import six from six.moves.urllib.parse import urlencode import tornado import tornado.gen @@ -28,11 +27,7 @@ class RESTResponse(io.IOBase): self.reason = resp.reason if resp.body: - # In Python 3, the response body is utf-8 encoded bytes. - if six.PY3: - self.data = resp.body.decode('utf-8') - else: - self.data = resp.body + self.data = resp.body else: self.data = None @@ -66,7 +61,7 @@ class RESTClientObject(object): @tornado.gen.coroutine def request(self, method, url, query_params=None, headers=None, body=None, post_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Execute Request :param method: http request method @@ -88,6 +83,9 @@ class RESTClientObject(object): assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS'] + if _decode_utf8 is None: + _decode_utf8 = {} + if post_params and body: raise ApiValueError( "body parameter cannot be used with post_params parameter." @@ -151,7 +149,7 @@ class RESTClientObject(object): @tornado.gen.coroutine def GET(self, url, headers=None, query_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): result = yield self.request("GET", url, headers=headers, _preload_content=_preload_content, @@ -161,69 +159,80 @@ class RESTClientObject(object): @tornado.gen.coroutine def HEAD(self, url, headers=None, query_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): result = yield self.request("HEAD", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params) raise tornado.gen.Return(result) @tornado.gen.coroutine def OPTIONS(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, + _decode_utf8=True): result = yield self.request("OPTIONS", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) raise tornado.gen.Return(result) @tornado.gen.coroutine def DELETE(self, url, headers=None, query_params=None, body=None, - _preload_content=True, _request_timeout=None): + _preload_content=True, _request_timeout=None, + _decode_utf8=True): result = yield self.request("DELETE", url, headers=headers, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) raise tornado.gen.Return(result) @tornado.gen.coroutine def POST(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, + _decode_utf8=True): result = yield self.request("POST", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) raise tornado.gen.Return(result) @tornado.gen.coroutine def PUT(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, + _decode_utf8=True): result = yield self.request("PUT", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) raise tornado.gen.Return(result) @tornado.gen.coroutine def PATCH(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, + _decode_utf8=True): result = yield self.request("PATCH", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) raise tornado.gen.Return(result) diff --git a/modules/openapi-generator/src/main/resources/scala-finch/sbt b/modules/openapi-generator/src/main/resources/scala-finch/sbt old mode 100644 new mode 100755 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/another_fake_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/another_fake_api.py index a47a8e3ea184..693409952af4 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/another_fake_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/another_fake_api.py @@ -132,6 +132,11 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/another-fake/dummy', 'PATCH', path_params, @@ -140,7 +145,7 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/fake_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/fake_api.py index 1847804c552b..c2cae07c59eb 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/fake_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/fake_api.py @@ -128,6 +128,11 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/create_xml_item', 'POST', path_params, @@ -136,7 +141,7 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -232,6 +237,11 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'bool' + } + return self.api_client.call_api( '/fake/outer/boolean', 'POST', path_params, @@ -240,7 +250,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='bool', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -336,6 +346,11 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'OuterComposite' + } + return self.api_client.call_api( '/fake/outer/composite', 'POST', path_params, @@ -344,7 +359,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='OuterComposite', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -440,6 +455,11 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'float' + } + return self.api_client.call_api( '/fake/outer/number', 'POST', path_params, @@ -448,7 +468,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='float', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -544,6 +564,11 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'str' + } + return self.api_client.call_api( '/fake/outer/string', 'POST', path_params, @@ -552,7 +577,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -652,6 +677,11 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/body-with-file-schema', 'PUT', path_params, @@ -660,7 +690,7 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -766,6 +796,11 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/body-with-query-params', 'PUT', path_params, @@ -774,7 +809,7 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -878,6 +913,11 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/fake', 'PATCH', path_params, @@ -886,7 +926,7 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1078,6 +1118,12 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou # Authentication setting auth_settings = ['http_basic_test'] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/fake', 'POST', path_params, @@ -1086,7 +1132,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1213,6 +1259,12 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/fake', 'GET', path_params, @@ -1221,7 +1273,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1345,6 +1397,11 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None + } + return self.api_client.call_api( '/fake', 'DELETE', path_params, @@ -1353,7 +1410,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1451,6 +1508,11 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/inline-additionalProperties', 'POST', path_params, @@ -1459,7 +1521,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1565,6 +1627,11 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/jsonFormData', 'GET', path_params, @@ -1573,7 +1640,7 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/fake_classname_tags_123_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/fake_classname_tags_123_api.py index 3e778e922686..68b09db1e61e 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/fake_classname_tags_123_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/fake_classname_tags_123_api.py @@ -132,6 +132,11 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key_query'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/fake_classname_test', 'PATCH', path_params, @@ -140,7 +145,7 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/pet_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/pet_api.py index 1deb664c43e5..e934d0ab01bb 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/pet_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/pet_api.py @@ -126,6 +126,12 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: None, + 405: None + } + return self.api_client.call_api( '/pet', 'POST', path_params, @@ -134,7 +140,7 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -232,6 +238,12 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: None, + 400: None + } + return self.api_client.call_api( '/pet/{petId}', 'DELETE', path_params, @@ -240,7 +252,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -341,6 +353,12 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'list[Pet]', + 400: None + } + return self.api_client.call_api( '/pet/findByStatus', 'GET', path_params, @@ -349,7 +367,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -450,6 +468,12 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'list[Pet]', + 400: None + } + return self.api_client.call_api( '/pet/findByTags', 'GET', path_params, @@ -458,7 +482,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -558,6 +582,13 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Pet', + 400: None, + 404: None + } + return self.api_client.call_api( '/pet/{petId}', 'GET', path_params, @@ -566,7 +597,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Pet', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -664,6 +695,14 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: None, + 400: None, + 404: None, + 405: None + } + return self.api_client.call_api( '/pet', 'PUT', path_params, @@ -672,7 +711,7 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -778,6 +817,11 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 405: None + } + return self.api_client.call_api( '/pet/{petId}', 'POST', path_params, @@ -786,7 +830,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -896,6 +940,11 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'ApiResponse' + } + return self.api_client.call_api( '/pet/{petId}/uploadImage', 'POST', path_params, @@ -904,7 +953,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1018,6 +1067,11 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'ApiResponse' + } + return self.api_client.call_api( '/fake/{petId}/uploadImageWithRequiredFile', 'POST', path_params, @@ -1026,7 +1080,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/store_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/store_api.py index c3aa1c4a3d59..906d8924fea2 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/store_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/store_api.py @@ -124,6 +124,12 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/store/order/{order_id}', 'DELETE', path_params, @@ -132,7 +138,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -224,6 +230,11 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'dict(str, int)' + } + return self.api_client.call_api( '/store/inventory', 'GET', path_params, @@ -232,7 +243,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='dict(str, int)', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -336,6 +347,13 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Order', + 400: None, + 404: None + } + return self.api_client.call_api( '/store/order/{order_id}', 'GET', path_params, @@ -344,7 +362,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -442,6 +460,12 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Order', + 400: None + } + return self.api_client.call_api( '/store/order', 'POST', path_params, @@ -450,7 +474,7 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api/user_api.py b/samples/client/petstore/python-asyncio/petstore_api/api/user_api.py index d3674f5ba5c6..199fcb571d78 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api/user_api.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api/user_api.py @@ -124,6 +124,11 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user', 'POST', path_params, @@ -132,7 +137,7 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -226,6 +231,11 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/createWithArray', 'POST', path_params, @@ -234,7 +244,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -328,6 +338,11 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/createWithList', 'POST', path_params, @@ -336,7 +351,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -432,6 +447,12 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'DELETE', path_params, @@ -440,7 +461,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -538,6 +559,13 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'User', + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'GET', path_params, @@ -546,7 +574,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='User', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -652,6 +680,12 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'str', + 400: None + } + return self.api_client.call_api( '/user/login', 'GET', path_params, @@ -660,7 +694,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -746,6 +780,11 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/logout', 'GET', path_params, @@ -754,7 +793,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -858,6 +897,12 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'PUT', path_params, @@ -866,7 +911,7 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-asyncio/petstore_api/api_client.py b/samples/client/petstore/python-asyncio/petstore_api/api_client.py index c6fc3a0609cd..65d20fe22a74 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/api_client.py +++ b/samples/client/petstore/python-asyncio/petstore_api/api_client.py @@ -108,11 +108,13 @@ def set_default_header(self, header_name, header_value): async def __call_api( self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, - files=None, response_type=None, auth_settings=None, + files=None, response_types=None, auth_settings=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): config = self.configuration + if response_types is None: + response_types = {} # header parameters header_params = header_params or {} @@ -164,18 +166,22 @@ async def __call_api( # use server/host defined in path or operation instead url = _host + resource_path + _decode_utf8 = {k: v != 'file' for k, v in six.iteritems(response_types)} # noqa: E501 + # perform request and return response response_data = await self.request( method, url, query_params=query_params, headers=header_params, post_params=post_params, body=body, _preload_content=_preload_content, - _request_timeout=_request_timeout) + _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8) self.last_response = response_data return_data = response_data if _preload_content: # deserialize response data + response_type = response_types.get(response_data.status) if response_type: return_data = self.deserialize(response_data, response_type) else: @@ -293,7 +299,7 @@ def __deserialize(self, data, klass): def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None, - response_type=None, auth_settings=None, async_req=None, + response_types=None, auth_settings=None, async_req=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): """Makes the HTTP request (synchronous) and returns deserialized data. @@ -336,15 +342,16 @@ def call_api(self, resource_path, method, return self.__call_api(resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types, auth_settings, _return_http_data_only, collection_formats, - _preload_content, _request_timeout, _host) + _preload_content, _request_timeout, + _host) else: thread = self.pool.apply_async(self.__call_api, (resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types, auth_settings, _return_http_data_only, collection_formats, _preload_content, @@ -354,20 +361,22 @@ def call_api(self, resource_path, method, def request(self, method, url, query_params=None, headers=None, post_params=None, body=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Makes the HTTP request using RESTClient.""" if method == "GET": return self.rest_client.GET(url, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - headers=headers) + headers=headers, + _decode_utf8=_decode_utf8) elif method == "HEAD": return self.rest_client.HEAD(url, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - headers=headers) + headers=headers, + _decode_utf8=_decode_utf8) elif method == "OPTIONS": return self.rest_client.OPTIONS(url, query_params=query_params, @@ -375,7 +384,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "POST": return self.rest_client.POST(url, query_params=query_params, @@ -383,7 +393,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "PUT": return self.rest_client.PUT(url, query_params=query_params, @@ -391,7 +402,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "PATCH": return self.rest_client.PATCH(url, query_params=query_params, @@ -399,14 +411,16 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "DELETE": return self.rest_client.DELETE(url, query_params=query_params, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) else: raise ApiValueError( "http method must be `GET`, `HEAD`, `OPTIONS`," @@ -478,10 +492,9 @@ def select_header_accept(self, accepts): accepts = [x.lower() for x in accepts] - if 'application/json' in accepts: - return 'application/json' - else: - return ', '.join(accepts) + accepts = [x + (';q=1' if x == 'application/json' else ';q=0.9') for x in accepts] # noqa: E501 + + return ', '.join(accepts) def select_header_content_type(self, content_types): """Returns `Content-Type` based on an array of content_types provided. diff --git a/samples/client/petstore/python-asyncio/petstore_api/rest.py b/samples/client/petstore/python-asyncio/petstore_api/rest.py index d06b8459fb8a..e16fb5e2e5b2 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/rest.py +++ b/samples/client/petstore/python-asyncio/petstore_api/rest.py @@ -19,7 +19,6 @@ import aiohttp import certifi import asyncio -# python 2 and python 3 compatibility library from six.moves.urllib.parse import urlencode from petstore_api.exceptions import ApiException, ApiValueError @@ -87,7 +86,7 @@ def __del__(self): async def request(self, method, url, query_params=None, headers=None, body=None, post_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Execute request :param method: http request method @@ -109,6 +108,9 @@ async def request(self, method, url, query_params=None, headers=None, assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS'] + if _decode_utf8 is None: + _decode_utf8 = {} + if post_params and body: raise ApiValueError( "body parameter cannot be used with post_params parameter." @@ -182,69 +184,80 @@ async def request(self, method, url, query_params=None, headers=None, return r async def GET(self, url, headers=None, query_params=None, - _preload_content=True, _request_timeout=None): + _preload_content=True, _request_timeout=None, + _decode_utf8=True): return (await self.request("GET", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params)) async def HEAD(self, url, headers=None, query_params=None, - _preload_content=True, _request_timeout=None): + _preload_content=True, _request_timeout=None, + _decode_utf8=True): return (await self.request("HEAD", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params)) async def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return (await self.request("OPTIONS", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body)) async def DELETE(self, url, headers=None, query_params=None, body=None, - _preload_content=True, _request_timeout=None): + _preload_content=True, _request_timeout=None, + _decode_utf8=True): return (await self.request("DELETE", url, headers=headers, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body)) async def POST(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return (await self.request("POST", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body)) async def PUT(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, + _decode_utf8=True): return (await self.request("PUT", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body)) async def PATCH(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return (await self.request("PATCH", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body)) diff --git a/samples/client/petstore/python-tornado/petstore_api/api/another_fake_api.py b/samples/client/petstore/python-tornado/petstore_api/api/another_fake_api.py index a47a8e3ea184..693409952af4 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/another_fake_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/another_fake_api.py @@ -132,6 +132,11 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/another-fake/dummy', 'PATCH', path_params, @@ -140,7 +145,7 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api/fake_api.py b/samples/client/petstore/python-tornado/petstore_api/api/fake_api.py index 1847804c552b..c2cae07c59eb 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/fake_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/fake_api.py @@ -128,6 +128,11 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/create_xml_item', 'POST', path_params, @@ -136,7 +141,7 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -232,6 +237,11 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'bool' + } + return self.api_client.call_api( '/fake/outer/boolean', 'POST', path_params, @@ -240,7 +250,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='bool', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -336,6 +346,11 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'OuterComposite' + } + return self.api_client.call_api( '/fake/outer/composite', 'POST', path_params, @@ -344,7 +359,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='OuterComposite', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -440,6 +455,11 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'float' + } + return self.api_client.call_api( '/fake/outer/number', 'POST', path_params, @@ -448,7 +468,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='float', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -544,6 +564,11 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'str' + } + return self.api_client.call_api( '/fake/outer/string', 'POST', path_params, @@ -552,7 +577,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -652,6 +677,11 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/body-with-file-schema', 'PUT', path_params, @@ -660,7 +690,7 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -766,6 +796,11 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/body-with-query-params', 'PUT', path_params, @@ -774,7 +809,7 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -878,6 +913,11 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/fake', 'PATCH', path_params, @@ -886,7 +926,7 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1078,6 +1118,12 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou # Authentication setting auth_settings = ['http_basic_test'] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/fake', 'POST', path_params, @@ -1086,7 +1132,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1213,6 +1259,12 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/fake', 'GET', path_params, @@ -1221,7 +1273,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1345,6 +1397,11 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None + } + return self.api_client.call_api( '/fake', 'DELETE', path_params, @@ -1353,7 +1410,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1451,6 +1508,11 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/inline-additionalProperties', 'POST', path_params, @@ -1459,7 +1521,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1565,6 +1627,11 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/jsonFormData', 'GET', path_params, @@ -1573,7 +1640,7 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api/fake_classname_tags_123_api.py b/samples/client/petstore/python-tornado/petstore_api/api/fake_classname_tags_123_api.py index 3e778e922686..68b09db1e61e 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/fake_classname_tags_123_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/fake_classname_tags_123_api.py @@ -132,6 +132,11 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key_query'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/fake_classname_test', 'PATCH', path_params, @@ -140,7 +145,7 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api/pet_api.py b/samples/client/petstore/python-tornado/petstore_api/api/pet_api.py index 1deb664c43e5..e934d0ab01bb 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/pet_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/pet_api.py @@ -126,6 +126,12 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: None, + 405: None + } + return self.api_client.call_api( '/pet', 'POST', path_params, @@ -134,7 +140,7 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -232,6 +238,12 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: None, + 400: None + } + return self.api_client.call_api( '/pet/{petId}', 'DELETE', path_params, @@ -240,7 +252,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -341,6 +353,12 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'list[Pet]', + 400: None + } + return self.api_client.call_api( '/pet/findByStatus', 'GET', path_params, @@ -349,7 +367,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -450,6 +468,12 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'list[Pet]', + 400: None + } + return self.api_client.call_api( '/pet/findByTags', 'GET', path_params, @@ -458,7 +482,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -558,6 +582,13 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Pet', + 400: None, + 404: None + } + return self.api_client.call_api( '/pet/{petId}', 'GET', path_params, @@ -566,7 +597,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Pet', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -664,6 +695,14 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: None, + 400: None, + 404: None, + 405: None + } + return self.api_client.call_api( '/pet', 'PUT', path_params, @@ -672,7 +711,7 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -778,6 +817,11 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 405: None + } + return self.api_client.call_api( '/pet/{petId}', 'POST', path_params, @@ -786,7 +830,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -896,6 +940,11 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'ApiResponse' + } + return self.api_client.call_api( '/pet/{petId}/uploadImage', 'POST', path_params, @@ -904,7 +953,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1018,6 +1067,11 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'ApiResponse' + } + return self.api_client.call_api( '/fake/{petId}/uploadImageWithRequiredFile', 'POST', path_params, @@ -1026,7 +1080,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api/store_api.py b/samples/client/petstore/python-tornado/petstore_api/api/store_api.py index c3aa1c4a3d59..906d8924fea2 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/store_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/store_api.py @@ -124,6 +124,12 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/store/order/{order_id}', 'DELETE', path_params, @@ -132,7 +138,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -224,6 +230,11 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'dict(str, int)' + } + return self.api_client.call_api( '/store/inventory', 'GET', path_params, @@ -232,7 +243,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='dict(str, int)', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -336,6 +347,13 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Order', + 400: None, + 404: None + } + return self.api_client.call_api( '/store/order/{order_id}', 'GET', path_params, @@ -344,7 +362,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -442,6 +460,12 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Order', + 400: None + } + return self.api_client.call_api( '/store/order', 'POST', path_params, @@ -450,7 +474,7 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api/user_api.py b/samples/client/petstore/python-tornado/petstore_api/api/user_api.py index d3674f5ba5c6..199fcb571d78 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api/user_api.py +++ b/samples/client/petstore/python-tornado/petstore_api/api/user_api.py @@ -124,6 +124,11 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user', 'POST', path_params, @@ -132,7 +137,7 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -226,6 +231,11 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/createWithArray', 'POST', path_params, @@ -234,7 +244,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -328,6 +338,11 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/createWithList', 'POST', path_params, @@ -336,7 +351,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -432,6 +447,12 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'DELETE', path_params, @@ -440,7 +461,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -538,6 +559,13 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'User', + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'GET', path_params, @@ -546,7 +574,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='User', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -652,6 +680,12 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'str', + 400: None + } + return self.api_client.call_api( '/user/login', 'GET', path_params, @@ -660,7 +694,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -746,6 +780,11 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/logout', 'GET', path_params, @@ -754,7 +793,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -858,6 +897,12 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'PUT', path_params, @@ -866,7 +911,7 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python-tornado/petstore_api/api_client.py b/samples/client/petstore/python-tornado/petstore_api/api_client.py index 59c17a32f28b..3999ffacc4a4 100644 --- a/samples/client/petstore/python-tornado/petstore_api/api_client.py +++ b/samples/client/petstore/python-tornado/petstore_api/api_client.py @@ -110,11 +110,13 @@ def set_default_header(self, header_name, header_value): def __call_api( self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, - files=None, response_type=None, auth_settings=None, + files=None, response_types=None, auth_settings=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): config = self.configuration + if response_types is None: + response_types = {} # header parameters header_params = header_params or {} @@ -166,18 +168,22 @@ def __call_api( # use server/host defined in path or operation instead url = _host + resource_path + _decode_utf8 = {k: v != 'file' for k, v in six.iteritems(response_types)} # noqa: E501 + # perform request and return response response_data = yield self.request( method, url, query_params=query_params, headers=header_params, post_params=post_params, body=body, _preload_content=_preload_content, - _request_timeout=_request_timeout) + _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8) self.last_response = response_data return_data = response_data if _preload_content: # deserialize response data + response_type = response_types.get(response_data.status) if response_type: return_data = self.deserialize(response_data, response_type) else: @@ -295,7 +301,7 @@ def __deserialize(self, data, klass): def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None, - response_type=None, auth_settings=None, async_req=None, + response_types=None, auth_settings=None, async_req=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): """Makes the HTTP request (synchronous) and returns deserialized data. @@ -338,15 +344,16 @@ def call_api(self, resource_path, method, return self.__call_api(resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types, auth_settings, _return_http_data_only, collection_formats, - _preload_content, _request_timeout, _host) + _preload_content, _request_timeout, + _host) else: thread = self.pool.apply_async(self.__call_api, (resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types, auth_settings, _return_http_data_only, collection_formats, _preload_content, @@ -356,20 +363,22 @@ def call_api(self, resource_path, method, def request(self, method, url, query_params=None, headers=None, post_params=None, body=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Makes the HTTP request using RESTClient.""" if method == "GET": return self.rest_client.GET(url, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - headers=headers) + headers=headers, + _decode_utf8=_decode_utf8) elif method == "HEAD": return self.rest_client.HEAD(url, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - headers=headers) + headers=headers, + _decode_utf8=_decode_utf8) elif method == "OPTIONS": return self.rest_client.OPTIONS(url, query_params=query_params, @@ -377,7 +386,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "POST": return self.rest_client.POST(url, query_params=query_params, @@ -385,7 +395,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "PUT": return self.rest_client.PUT(url, query_params=query_params, @@ -393,7 +404,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "PATCH": return self.rest_client.PATCH(url, query_params=query_params, @@ -401,14 +413,16 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "DELETE": return self.rest_client.DELETE(url, query_params=query_params, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) else: raise ApiValueError( "http method must be `GET`, `HEAD`, `OPTIONS`," @@ -480,10 +494,9 @@ def select_header_accept(self, accepts): accepts = [x.lower() for x in accepts] - if 'application/json' in accepts: - return 'application/json' - else: - return ', '.join(accepts) + accepts = [x + (';q=1' if x == 'application/json' else ';q=0.9') for x in accepts] # noqa: E501 + + return ', '.join(accepts) def select_header_content_type(self, content_types): """Returns `Content-Type` based on an array of content_types provided. diff --git a/samples/client/petstore/python-tornado/petstore_api/rest.py b/samples/client/petstore/python-tornado/petstore_api/rest.py index d5661febf4b5..3a6e696b2b45 100644 --- a/samples/client/petstore/python-tornado/petstore_api/rest.py +++ b/samples/client/petstore/python-tornado/petstore_api/rest.py @@ -16,7 +16,6 @@ import re # python 2 and python 3 compatibility library -import six from six.moves.urllib.parse import urlencode import tornado import tornado.gen @@ -36,11 +35,7 @@ def __init__(self, resp): self.reason = resp.reason if resp.body: - # In Python 3, the response body is utf-8 encoded bytes. - if six.PY3: - self.data = resp.body.decode('utf-8') - else: - self.data = resp.body + self.data = resp.body else: self.data = None @@ -74,7 +69,7 @@ def __init__(self, configuration, pools_size=4, maxsize=4): @tornado.gen.coroutine def request(self, method, url, query_params=None, headers=None, body=None, post_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Execute Request :param method: http request method @@ -96,6 +91,9 @@ def request(self, method, url, query_params=None, headers=None, body=None, assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS'] + if _decode_utf8 is None: + _decode_utf8 = {} + if post_params and body: raise ApiValueError( "body parameter cannot be used with post_params parameter." @@ -159,7 +157,7 @@ def request(self, method, url, query_params=None, headers=None, body=None, @tornado.gen.coroutine def GET(self, url, headers=None, query_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): result = yield self.request("GET", url, headers=headers, _preload_content=_preload_content, @@ -169,69 +167,80 @@ def GET(self, url, headers=None, query_params=None, _preload_content=True, @tornado.gen.coroutine def HEAD(self, url, headers=None, query_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): result = yield self.request("HEAD", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params) raise tornado.gen.Return(result) @tornado.gen.coroutine def OPTIONS(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, + _decode_utf8=True): result = yield self.request("OPTIONS", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) raise tornado.gen.Return(result) @tornado.gen.coroutine def DELETE(self, url, headers=None, query_params=None, body=None, - _preload_content=True, _request_timeout=None): + _preload_content=True, _request_timeout=None, + _decode_utf8=True): result = yield self.request("DELETE", url, headers=headers, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) raise tornado.gen.Return(result) @tornado.gen.coroutine def POST(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, + _decode_utf8=True): result = yield self.request("POST", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) raise tornado.gen.Return(result) @tornado.gen.coroutine def PUT(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, + _decode_utf8=True): result = yield self.request("PUT", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) raise tornado.gen.Return(result) @tornado.gen.coroutine def PATCH(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, + _decode_utf8=True): result = yield self.request("PATCH", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) raise tornado.gen.Return(result) diff --git a/samples/client/petstore/python/petstore_api/api/another_fake_api.py b/samples/client/petstore/python/petstore_api/api/another_fake_api.py index a47a8e3ea184..693409952af4 100644 --- a/samples/client/petstore/python/petstore_api/api/another_fake_api.py +++ b/samples/client/petstore/python/petstore_api/api/another_fake_api.py @@ -132,6 +132,11 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/another-fake/dummy', 'PATCH', path_params, @@ -140,7 +145,7 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api/fake_api.py b/samples/client/petstore/python/petstore_api/api/fake_api.py index 1847804c552b..c2cae07c59eb 100644 --- a/samples/client/petstore/python/petstore_api/api/fake_api.py +++ b/samples/client/petstore/python/petstore_api/api/fake_api.py @@ -128,6 +128,11 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/create_xml_item', 'POST', path_params, @@ -136,7 +141,7 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -232,6 +237,11 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'bool' + } + return self.api_client.call_api( '/fake/outer/boolean', 'POST', path_params, @@ -240,7 +250,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='bool', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -336,6 +346,11 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'OuterComposite' + } + return self.api_client.call_api( '/fake/outer/composite', 'POST', path_params, @@ -344,7 +359,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='OuterComposite', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -440,6 +455,11 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'float' + } + return self.api_client.call_api( '/fake/outer/number', 'POST', path_params, @@ -448,7 +468,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='float', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -544,6 +564,11 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'str' + } + return self.api_client.call_api( '/fake/outer/string', 'POST', path_params, @@ -552,7 +577,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -652,6 +677,11 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/body-with-file-schema', 'PUT', path_params, @@ -660,7 +690,7 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -766,6 +796,11 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/body-with-query-params', 'PUT', path_params, @@ -774,7 +809,7 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -878,6 +913,11 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/fake', 'PATCH', path_params, @@ -886,7 +926,7 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1078,6 +1118,12 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou # Authentication setting auth_settings = ['http_basic_test'] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/fake', 'POST', path_params, @@ -1086,7 +1132,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1213,6 +1259,12 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/fake', 'GET', path_params, @@ -1221,7 +1273,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1345,6 +1397,11 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None + } + return self.api_client.call_api( '/fake', 'DELETE', path_params, @@ -1353,7 +1410,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1451,6 +1508,11 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/inline-additionalProperties', 'POST', path_params, @@ -1459,7 +1521,7 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1565,6 +1627,11 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/jsonFormData', 'GET', path_params, @@ -1573,7 +1640,7 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py b/samples/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py index 3e778e922686..68b09db1e61e 100644 --- a/samples/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py +++ b/samples/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py @@ -132,6 +132,11 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key_query'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/fake_classname_test', 'PATCH', path_params, @@ -140,7 +145,7 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api/pet_api.py b/samples/client/petstore/python/petstore_api/api/pet_api.py index 1deb664c43e5..e934d0ab01bb 100644 --- a/samples/client/petstore/python/petstore_api/api/pet_api.py +++ b/samples/client/petstore/python/petstore_api/api/pet_api.py @@ -126,6 +126,12 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: None, + 405: None + } + return self.api_client.call_api( '/pet', 'POST', path_params, @@ -134,7 +140,7 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -232,6 +238,12 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: None, + 400: None + } + return self.api_client.call_api( '/pet/{petId}', 'DELETE', path_params, @@ -240,7 +252,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -341,6 +353,12 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'list[Pet]', + 400: None + } + return self.api_client.call_api( '/pet/findByStatus', 'GET', path_params, @@ -349,7 +367,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -450,6 +468,12 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'list[Pet]', + 400: None + } + return self.api_client.call_api( '/pet/findByTags', 'GET', path_params, @@ -458,7 +482,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -558,6 +582,13 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Pet', + 400: None, + 404: None + } + return self.api_client.call_api( '/pet/{petId}', 'GET', path_params, @@ -566,7 +597,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Pet', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -664,6 +695,14 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: None, + 400: None, + 404: None, + 405: None + } + return self.api_client.call_api( '/pet', 'PUT', path_params, @@ -672,7 +711,7 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -778,6 +817,11 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 405: None + } + return self.api_client.call_api( '/pet/{petId}', 'POST', path_params, @@ -786,7 +830,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -896,6 +940,11 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'ApiResponse' + } + return self.api_client.call_api( '/pet/{petId}/uploadImage', 'POST', path_params, @@ -904,7 +953,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1018,6 +1067,11 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'ApiResponse' + } + return self.api_client.call_api( '/fake/{petId}/uploadImageWithRequiredFile', 'POST', path_params, @@ -1026,7 +1080,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api/store_api.py b/samples/client/petstore/python/petstore_api/api/store_api.py index c3aa1c4a3d59..906d8924fea2 100644 --- a/samples/client/petstore/python/petstore_api/api/store_api.py +++ b/samples/client/petstore/python/petstore_api/api/store_api.py @@ -124,6 +124,12 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/store/order/{order_id}', 'DELETE', path_params, @@ -132,7 +138,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -224,6 +230,11 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'dict(str, int)' + } + return self.api_client.call_api( '/store/inventory', 'GET', path_params, @@ -232,7 +243,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='dict(str, int)', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -336,6 +347,13 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Order', + 400: None, + 404: None + } + return self.api_client.call_api( '/store/order/{order_id}', 'GET', path_params, @@ -344,7 +362,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -442,6 +460,12 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Order', + 400: None + } + return self.api_client.call_api( '/store/order', 'POST', path_params, @@ -450,7 +474,7 @@ def place_order_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api/user_api.py b/samples/client/petstore/python/petstore_api/api/user_api.py index d3674f5ba5c6..199fcb571d78 100644 --- a/samples/client/petstore/python/petstore_api/api/user_api.py +++ b/samples/client/petstore/python/petstore_api/api/user_api.py @@ -124,6 +124,11 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user', 'POST', path_params, @@ -132,7 +137,7 @@ def create_user_with_http_info(self, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -226,6 +231,11 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/createWithArray', 'POST', path_params, @@ -234,7 +244,7 @@ def create_users_with_array_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -328,6 +338,11 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/createWithList', 'POST', path_params, @@ -336,7 +351,7 @@ def create_users_with_list_input_with_http_info(self, body, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -432,6 +447,12 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'DELETE', path_params, @@ -440,7 +461,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -538,6 +559,13 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'User', + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'GET', path_params, @@ -546,7 +574,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='User', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -652,6 +680,12 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'str', + 400: None + } + return self.api_client.call_api( '/user/login', 'GET', path_params, @@ -660,7 +694,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -746,6 +780,11 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/logout', 'GET', path_params, @@ -754,7 +793,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -858,6 +897,12 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'PUT', path_params, @@ -866,7 +911,7 @@ def update_user_with_http_info(self, username, body, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/client/petstore/python/petstore_api/api_client.py b/samples/client/petstore/python/petstore_api/api_client.py index df3a9815aa04..dcacba987e91 100644 --- a/samples/client/petstore/python/petstore_api/api_client.py +++ b/samples/client/petstore/python/petstore_api/api_client.py @@ -108,11 +108,13 @@ def set_default_header(self, header_name, header_value): def __call_api( self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, - files=None, response_type=None, auth_settings=None, + files=None, response_types=None, auth_settings=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): config = self.configuration + if response_types is None: + response_types = {} # header parameters header_params = header_params or {} @@ -164,18 +166,22 @@ def __call_api( # use server/host defined in path or operation instead url = _host + resource_path + _decode_utf8 = {k: v != 'file' for k, v in six.iteritems(response_types)} # noqa: E501 + # perform request and return response response_data = self.request( method, url, query_params=query_params, headers=header_params, post_params=post_params, body=body, _preload_content=_preload_content, - _request_timeout=_request_timeout) + _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8) self.last_response = response_data return_data = response_data if _preload_content: # deserialize response data + response_type = response_types.get(response_data.status) if response_type: return_data = self.deserialize(response_data, response_type) else: @@ -293,7 +299,7 @@ def __deserialize(self, data, klass): def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None, - response_type=None, auth_settings=None, async_req=None, + response_types=None, auth_settings=None, async_req=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): """Makes the HTTP request (synchronous) and returns deserialized data. @@ -336,15 +342,16 @@ def call_api(self, resource_path, method, return self.__call_api(resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types, auth_settings, _return_http_data_only, collection_formats, - _preload_content, _request_timeout, _host) + _preload_content, _request_timeout, + _host) else: thread = self.pool.apply_async(self.__call_api, (resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types, auth_settings, _return_http_data_only, collection_formats, _preload_content, @@ -354,20 +361,22 @@ def call_api(self, resource_path, method, def request(self, method, url, query_params=None, headers=None, post_params=None, body=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Makes the HTTP request using RESTClient.""" if method == "GET": return self.rest_client.GET(url, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - headers=headers) + headers=headers, + _decode_utf8=_decode_utf8) elif method == "HEAD": return self.rest_client.HEAD(url, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - headers=headers) + headers=headers, + _decode_utf8=_decode_utf8) elif method == "OPTIONS": return self.rest_client.OPTIONS(url, query_params=query_params, @@ -375,7 +384,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "POST": return self.rest_client.POST(url, query_params=query_params, @@ -383,7 +393,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "PUT": return self.rest_client.PUT(url, query_params=query_params, @@ -391,7 +402,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "PATCH": return self.rest_client.PATCH(url, query_params=query_params, @@ -399,14 +411,16 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "DELETE": return self.rest_client.DELETE(url, query_params=query_params, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) else: raise ApiValueError( "http method must be `GET`, `HEAD`, `OPTIONS`," @@ -478,10 +492,9 @@ def select_header_accept(self, accepts): accepts = [x.lower() for x in accepts] - if 'application/json' in accepts: - return 'application/json' - else: - return ', '.join(accepts) + accepts = [x + (';q=1' if x == 'application/json' else ';q=0.9') for x in accepts] # noqa: E501 + + return ', '.join(accepts) def select_header_content_type(self, content_types): """Returns `Content-Type` based on an array of content_types provided. diff --git a/samples/client/petstore/python/petstore_api/rest.py b/samples/client/petstore/python/petstore_api/rest.py index 7ed815b8a187..d2c8b820a584 100644 --- a/samples/client/petstore/python/petstore_api/rest.py +++ b/samples/client/petstore/python/petstore_api/rest.py @@ -108,7 +108,7 @@ def __init__(self, configuration, pools_size=4, maxsize=None): def request(self, method, url, query_params=None, headers=None, body=None, post_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Perform requests. :param method: http request method @@ -131,6 +131,9 @@ def request(self, method, url, query_params=None, headers=None, assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS'] + if _decode_utf8 is None: + _decode_utf8 = {} + if post_params and body: raise ApiValueError( "body parameter cannot be used with post_params parameter." @@ -217,13 +220,14 @@ def request(self, method, url, query_params=None, headers=None, if _preload_content: r = RESTResponse(r) - # In the python 3, the response.data is bytes. - # we need to decode it to string. - if six.PY3: - r.data = r.data.decode('utf8') + if _decode_utf8.get(r.status, True): + # In the python 3, the response.data is bytes. + # we need to decode it to string. + if six.PY3: + r.data = r.data.decode('utf8') - # log response body - logger.debug("response body: %s", r.data) + # log response body + logger.debug("response body: %s", r.data) if not 200 <= r.status <= 299: raise ApiException(http_resp=r) @@ -231,66 +235,73 @@ def request(self, method, url, query_params=None, headers=None, return r def GET(self, url, headers=None, query_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return self.request("GET", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params) def HEAD(self, url, headers=None, query_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return self.request("HEAD", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params) def OPTIONS(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("OPTIONS", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def DELETE(self, url, headers=None, query_params=None, body=None, - _preload_content=True, _request_timeout=None): + _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("DELETE", url, headers=headers, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def POST(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("POST", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def PUT(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("PUT", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def PATCH(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("PATCH", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) diff --git a/samples/client/petstore/python/tests/test_api_client.py b/samples/client/petstore/python/tests/test_api_client.py index a41dbaba9c9f..5e5b7f62ad22 100644 --- a/samples/client/petstore/python/tests/test_api_client.py +++ b/samples/client/petstore/python/tests/test_api_client.py @@ -58,23 +58,23 @@ def test_configuration(self): def test_select_header_accept(self): accepts = ['APPLICATION/JSON', 'APPLICATION/XML'] accept = self.api_client.select_header_accept(accepts) - self.assertEqual(accept, 'application/json') + self.assertEqual('application/json;q=1, application/xml;q=0.9', accept) accepts = ['application/json', 'application/xml'] accept = self.api_client.select_header_accept(accepts) - self.assertEqual(accept, 'application/json') + self.assertEqual('application/json;q=1, application/xml;q=0.9', accept) accepts = ['application/xml', 'application/json'] accept = self.api_client.select_header_accept(accepts) - self.assertEqual(accept, 'application/json') + self.assertEqual('application/xml;q=0.9, application/json;q=1', accept) accepts = ['text/plain', 'application/xml'] accept = self.api_client.select_header_accept(accepts) - self.assertEqual(accept, 'text/plain, application/xml') + self.assertEqual('text/plain;q=0.9, application/xml;q=0.9', accept) accepts = [] accept = self.api_client.select_header_accept(accepts) - self.assertEqual(accept, None) + self.assertEqual(None, accept) def test_select_header_content_type(self): content_types = ['APPLICATION/JSON', 'APPLICATION/XML'] diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py index 07cf6defd827..c67093329414 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/another_fake_api.py @@ -132,6 +132,11 @@ def call_123_test_special_tags_with_http_info(self, client, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/another-fake/dummy', 'PATCH', path_params, @@ -140,7 +145,7 @@ def call_123_test_special_tags_with_http_info(self, client, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py index 8add874824b9..b0e88b603621 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/default_api.py @@ -118,6 +118,11 @@ def foo_get_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: 'InlineResponseDefault' + } + return self.api_client.call_api( '/foo', 'GET', path_params, @@ -126,7 +131,7 @@ def foo_get_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='InlineResponseDefault', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py index 3f95f76d3453..127321551047 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/fake_api.py @@ -118,6 +118,11 @@ def fake_health_get_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'HealthCheckResult' + } + return self.api_client.call_api( '/fake/health', 'GET', path_params, @@ -126,7 +131,7 @@ def fake_health_get_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='HealthCheckResult', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -226,6 +231,11 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'bool' + } + return self.api_client.call_api( '/fake/outer/boolean', 'POST', path_params, @@ -234,7 +244,7 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='bool', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -334,6 +344,11 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'OuterComposite' + } + return self.api_client.call_api( '/fake/outer/composite', 'POST', path_params, @@ -342,7 +357,7 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='OuterComposite', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -442,6 +457,11 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'float' + } + return self.api_client.call_api( '/fake/outer/number', 'POST', path_params, @@ -450,7 +470,7 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='float', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -550,6 +570,11 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'str' + } + return self.api_client.call_api( '/fake/outer/string', 'POST', path_params, @@ -558,7 +583,7 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -658,6 +683,11 @@ def test_body_with_file_schema_with_http_info(self, file_schema_test_class, **kw # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/body-with-file-schema', 'PUT', path_params, @@ -666,7 +696,7 @@ def test_body_with_file_schema_with_http_info(self, file_schema_test_class, **kw body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -772,6 +802,11 @@ def test_body_with_query_params_with_http_info(self, query, user, **kwargs): # # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/body-with-query-params', 'PUT', path_params, @@ -780,7 +815,7 @@ def test_body_with_query_params_with_http_info(self, query, user, **kwargs): # body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -884,6 +919,11 @@ def test_client_model_with_http_info(self, client, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/fake', 'PATCH', path_params, @@ -892,7 +932,7 @@ def test_client_model_with_http_info(self, client, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1084,6 +1124,12 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou # Authentication setting auth_settings = ['http_basic_test'] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/fake', 'POST', path_params, @@ -1092,7 +1138,7 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1219,6 +1265,12 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/fake', 'GET', path_params, @@ -1227,7 +1279,7 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1351,6 +1403,11 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b # Authentication setting auth_settings = ['bearer_test'] # noqa: E501 + # multiple potential response types + response_types = { + 400: None + } + return self.api_client.call_api( '/fake', 'DELETE', path_params, @@ -1359,7 +1416,7 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1457,6 +1514,11 @@ def test_inline_additional_properties_with_http_info(self, request_body, **kwarg # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/inline-additionalProperties', 'POST', path_params, @@ -1465,7 +1527,7 @@ def test_inline_additional_properties_with_http_info(self, request_body, **kwarg body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1571,6 +1633,11 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: None + } + return self.api_client.call_api( '/fake/jsonFormData', 'GET', path_params, @@ -1579,7 +1646,7 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py index 8446a6d39973..2dcecc34ccb8 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/fake_classname_tags_123_api.py @@ -132,6 +132,11 @@ def test_classname_with_http_info(self, client, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key_query'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Client' + } + return self.api_client.call_api( '/fake_classname_test', 'PATCH', path_params, @@ -140,7 +145,7 @@ def test_classname_with_http_info(self, client, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Client', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py index 60987d9715b6..01f35979e3cf 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/pet_api.py @@ -132,6 +132,11 @@ def add_pet_with_http_info(self, pet, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 405: None + } + return self.api_client.call_api( '/pet', 'POST', path_params, @@ -140,7 +145,7 @@ def add_pet_with_http_info(self, pet, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -239,6 +244,11 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 400: None + } + return self.api_client.call_api( '/pet/{petId}', 'DELETE', path_params, @@ -247,7 +257,7 @@ def delete_pet_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -348,6 +358,12 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'list[Pet]', + 400: None + } + return self.api_client.call_api( '/pet/findByStatus', 'GET', path_params, @@ -356,7 +372,7 @@ def find_pets_by_status_with_http_info(self, status, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -457,6 +473,12 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'list[Pet]', + 400: None + } + return self.api_client.call_api( '/pet/findByTags', 'GET', path_params, @@ -465,7 +487,7 @@ def find_pets_by_tags_with_http_info(self, tags, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='list[Pet]', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -565,6 +587,13 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Pet', + 400: None, + 404: None + } + return self.api_client.call_api( '/pet/{petId}', 'GET', path_params, @@ -573,7 +602,7 @@ def get_pet_by_id_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Pet', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -677,6 +706,13 @@ def update_pet_with_http_info(self, pet, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None, + 405: None + } + return self.api_client.call_api( '/pet', 'PUT', path_params, @@ -685,7 +721,7 @@ def update_pet_with_http_info(self, pet, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -792,6 +828,11 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 405: None + } + return self.api_client.call_api( '/pet/{petId}', 'POST', path_params, @@ -800,7 +841,7 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -910,6 +951,11 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'ApiResponse' + } + return self.api_client.call_api( '/pet/{petId}/uploadImage', 'POST', path_params, @@ -918,7 +964,7 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -1032,6 +1078,11 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * # Authentication setting auth_settings = ['petstore_auth'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'ApiResponse' + } + return self.api_client.call_api( '/fake/{petId}/uploadImageWithRequiredFile', 'POST', path_params, @@ -1040,7 +1091,7 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, * body=body_params, post_params=form_params, files=local_var_files, - response_type='ApiResponse', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py index 944ea66190c7..e56992036b97 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/store_api.py @@ -124,6 +124,12 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/store/order/{order_id}', 'DELETE', path_params, @@ -132,7 +138,7 @@ def delete_order_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -224,6 +230,11 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = ['api_key'] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'dict(str, int)' + } + return self.api_client.call_api( '/store/inventory', 'GET', path_params, @@ -232,7 +243,7 @@ def get_inventory_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='dict(str, int)', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -336,6 +347,13 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Order', + 400: None, + 404: None + } + return self.api_client.call_api( '/store/order/{order_id}', 'GET', path_params, @@ -344,7 +362,7 @@ def get_order_by_id_with_http_info(self, order_id, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -446,6 +464,12 @@ def place_order_with_http_info(self, order, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'Order', + 400: None + } + return self.api_client.call_api( '/store/order', 'POST', path_params, @@ -454,7 +478,7 @@ def place_order_with_http_info(self, order, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='Order', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py b/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py index 5e8125477fb2..e6324f8a34d1 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api/user_api.py @@ -128,6 +128,11 @@ def create_user_with_http_info(self, user, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user', 'POST', path_params, @@ -136,7 +141,7 @@ def create_user_with_http_info(self, user, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -234,6 +239,11 @@ def create_users_with_array_input_with_http_info(self, user, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/createWithArray', 'POST', path_params, @@ -242,7 +252,7 @@ def create_users_with_array_input_with_http_info(self, user, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -340,6 +350,11 @@ def create_users_with_list_input_with_http_info(self, user, **kwargs): # noqa: # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/createWithList', 'POST', path_params, @@ -348,7 +363,7 @@ def create_users_with_list_input_with_http_info(self, user, **kwargs): # noqa: body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -444,6 +459,12 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'DELETE', path_params, @@ -452,7 +473,7 @@ def delete_user_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -550,6 +571,13 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'User', + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'GET', path_params, @@ -558,7 +586,7 @@ def get_user_by_name_with_http_info(self, username, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='User', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -664,6 +692,12 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 200: 'str', + 400: None + } + return self.api_client.call_api( '/user/login', 'GET', path_params, @@ -672,7 +706,7 @@ def login_user_with_http_info(self, username, password, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type='str', # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -758,6 +792,11 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 0: None + } + return self.api_client.call_api( '/user/logout', 'GET', path_params, @@ -766,7 +805,7 @@ def logout_user_with_http_info(self, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 @@ -874,6 +913,12 @@ def update_user_with_http_info(self, username, user, **kwargs): # noqa: E501 # Authentication setting auth_settings = [] # noqa: E501 + # multiple potential response types + response_types = { + 400: None, + 404: None + } + return self.api_client.call_api( '/user/{username}', 'PUT', path_params, @@ -882,7 +927,7 @@ def update_user_with_http_info(self, username, user, **kwargs): # noqa: E501 body=body_params, post_params=form_params, files=local_var_files, - response_type=None, # noqa: E501 + response_types=response_types, auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 diff --git a/samples/openapi3/client/petstore/python/petstore_api/api_client.py b/samples/openapi3/client/petstore/python/petstore_api/api_client.py index df3a9815aa04..dcacba987e91 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/api_client.py +++ b/samples/openapi3/client/petstore/python/petstore_api/api_client.py @@ -108,11 +108,13 @@ def set_default_header(self, header_name, header_value): def __call_api( self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, - files=None, response_type=None, auth_settings=None, + files=None, response_types=None, auth_settings=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): config = self.configuration + if response_types is None: + response_types = {} # header parameters header_params = header_params or {} @@ -164,18 +166,22 @@ def __call_api( # use server/host defined in path or operation instead url = _host + resource_path + _decode_utf8 = {k: v != 'file' for k, v in six.iteritems(response_types)} # noqa: E501 + # perform request and return response response_data = self.request( method, url, query_params=query_params, headers=header_params, post_params=post_params, body=body, _preload_content=_preload_content, - _request_timeout=_request_timeout) + _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8) self.last_response = response_data return_data = response_data if _preload_content: # deserialize response data + response_type = response_types.get(response_data.status) if response_type: return_data = self.deserialize(response_data, response_type) else: @@ -293,7 +299,7 @@ def __deserialize(self, data, klass): def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None, - response_type=None, auth_settings=None, async_req=None, + response_types=None, auth_settings=None, async_req=None, _return_http_data_only=None, collection_formats=None, _preload_content=True, _request_timeout=None, _host=None): """Makes the HTTP request (synchronous) and returns deserialized data. @@ -336,15 +342,16 @@ def call_api(self, resource_path, method, return self.__call_api(resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types, auth_settings, _return_http_data_only, collection_formats, - _preload_content, _request_timeout, _host) + _preload_content, _request_timeout, + _host) else: thread = self.pool.apply_async(self.__call_api, (resource_path, method, path_params, query_params, header_params, body, post_params, files, - response_type, auth_settings, + response_types, auth_settings, _return_http_data_only, collection_formats, _preload_content, @@ -354,20 +361,22 @@ def call_api(self, resource_path, method, def request(self, method, url, query_params=None, headers=None, post_params=None, body=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Makes the HTTP request using RESTClient.""" if method == "GET": return self.rest_client.GET(url, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - headers=headers) + headers=headers, + _decode_utf8=_decode_utf8) elif method == "HEAD": return self.rest_client.HEAD(url, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - headers=headers) + headers=headers, + _decode_utf8=_decode_utf8) elif method == "OPTIONS": return self.rest_client.OPTIONS(url, query_params=query_params, @@ -375,7 +384,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "POST": return self.rest_client.POST(url, query_params=query_params, @@ -383,7 +393,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "PUT": return self.rest_client.PUT(url, query_params=query_params, @@ -391,7 +402,8 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "PATCH": return self.rest_client.PATCH(url, query_params=query_params, @@ -399,14 +411,16 @@ def request(self, method, url, query_params=None, headers=None, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) elif method == "DELETE": return self.rest_client.DELETE(url, query_params=query_params, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, - body=body) + body=body, + _decode_utf8=_decode_utf8) else: raise ApiValueError( "http method must be `GET`, `HEAD`, `OPTIONS`," @@ -478,10 +492,9 @@ def select_header_accept(self, accepts): accepts = [x.lower() for x in accepts] - if 'application/json' in accepts: - return 'application/json' - else: - return ', '.join(accepts) + accepts = [x + (';q=1' if x == 'application/json' else ';q=0.9') for x in accepts] # noqa: E501 + + return ', '.join(accepts) def select_header_content_type(self, content_types): """Returns `Content-Type` based on an array of content_types provided. diff --git a/samples/openapi3/client/petstore/python/petstore_api/rest.py b/samples/openapi3/client/petstore/python/petstore_api/rest.py index 7ed815b8a187..d2c8b820a584 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/rest.py +++ b/samples/openapi3/client/petstore/python/petstore_api/rest.py @@ -108,7 +108,7 @@ def __init__(self, configuration, pools_size=4, maxsize=None): def request(self, method, url, query_params=None, headers=None, body=None, post_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=None): """Perform requests. :param method: http request method @@ -131,6 +131,9 @@ def request(self, method, url, query_params=None, headers=None, assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS'] + if _decode_utf8 is None: + _decode_utf8 = {} + if post_params and body: raise ApiValueError( "body parameter cannot be used with post_params parameter." @@ -217,13 +220,14 @@ def request(self, method, url, query_params=None, headers=None, if _preload_content: r = RESTResponse(r) - # In the python 3, the response.data is bytes. - # we need to decode it to string. - if six.PY3: - r.data = r.data.decode('utf8') + if _decode_utf8.get(r.status, True): + # In the python 3, the response.data is bytes. + # we need to decode it to string. + if six.PY3: + r.data = r.data.decode('utf8') - # log response body - logger.debug("response body: %s", r.data) + # log response body + logger.debug("response body: %s", r.data) if not 200 <= r.status <= 299: raise ApiException(http_resp=r) @@ -231,66 +235,73 @@ def request(self, method, url, query_params=None, headers=None, return r def GET(self, url, headers=None, query_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return self.request("GET", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params) def HEAD(self, url, headers=None, query_params=None, _preload_content=True, - _request_timeout=None): + _request_timeout=None, _decode_utf8=True): return self.request("HEAD", url, headers=headers, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, query_params=query_params) def OPTIONS(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("OPTIONS", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def DELETE(self, url, headers=None, query_params=None, body=None, - _preload_content=True, _request_timeout=None): + _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("DELETE", url, headers=headers, query_params=query_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def POST(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("POST", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def PUT(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("PUT", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body) def PATCH(self, url, headers=None, query_params=None, post_params=None, - body=None, _preload_content=True, _request_timeout=None): + body=None, _preload_content=True, _request_timeout=None, _decode_utf8=True): return self.request("PATCH", url, headers=headers, query_params=query_params, post_params=post_params, _preload_content=_preload_content, _request_timeout=_request_timeout, + _decode_utf8=_decode_utf8, body=body)