Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor

@spacether spacether Apr 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rienafairefr why are you setting the response's dataType equal to the CodegenProperty dataType here? What is incorrect about how fromResponse is setting response.dataType higher up?

}
}

if (responseSchema != null) {
CodegenProperty cm = fromProperty("response", responseSchema);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use baseType here instead of dataType?
It looks like dataType is used for primitive types. It looks like baseType is used for model names per here:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L2678
Then the baseType is used to import the model name here:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L2382

{{/responses}}
}

return self.api_client.call_api(
'{{{path}}}', '{{httpMethod}}',
path_params,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -361,59 +368,66 @@ 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,
headers=headers,
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,
headers=headers,
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,
headers=headers,
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,
headers=headers,
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`,"
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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."
Expand Down Expand Up @@ -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))
Loading