Skip to content

[Python] correct return types if multiple responses are defined #7427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 3, 2020
Merged
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
19 changes: 18 additions & 1 deletion modules/openapi-generator/src/main/resources/python/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,23 @@ class {{classname}}(object):
{{/hasConsumes}}
# Authentication setting
auth_settings = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}] # noqa: E501

{{#returnType}}
{{#responses}}
{{#-first}}
response_types_map = {
{{/-first}}
{{^isWildcard}}
{{code}}: {{#dataType}}"{{dataType}}"{{/dataType}}{{^dataType}}None{{/dataType}},
{{/isWildcard}}
{{#-last}}
}
{{/-last}}
{{/responses}}
{{/returnType}}
{{^returnType}}
response_types_map = {}
{{/returnType}}

return self.api_client.call_api(
'{{{path}}}', '{{httpMethod}}',
Expand All @@ -262,7 +279,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_map=response_types_map,
Copy link
Contributor

@spacether spacether Sep 17, 2020

Choose a reason for hiding this comment

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

Rather than using two parameters for return type

  • return_type
  • response_types_map

how about using a single parameter like:

  • return_types which is a map of status code to data type

Please see this similar-to PR which was never finished

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@spacether
I ve just removed response_type
Could you check the pr one more time ?

Copy link
Contributor

@spacether spacether Sep 21, 2020

Choose a reason for hiding this comment

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

Thank you for using only one parameter. This pr has failing ci testa because the samples need to be regenerated. Can you please regenerate samples with these commands?

mvn clean install
bin/generate_samples

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@spacether
I ve just regenerated

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 @@ -130,7 +130,7 @@ 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_map=None, auth_settings=None,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_request_auth=None):
Expand Down Expand Up @@ -213,6 +213,8 @@ class ApiClient(object):
{{#tornado}}
raise tornado.gen.Return(return_data)
{{/tornado}}

response_type = response_types_map.get(response_data.status, None)

if six.PY3 and response_type not in ["file", "bytes"]:
match = None
Expand All @@ -222,6 +224,7 @@ class ApiClient(object):
response_data.data = response_data.data.decode(encoding)

# deserialize response data

if response_type:
return_data = self.deserialize(response_data, response_type)
else:
Expand Down Expand Up @@ -348,10 +351,10 @@ 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,
_return_http_data_only=None, collection_formats=None,
_preload_content=True, _request_timeout=None, _host=None,
_request_auth=None):
response_types_map=None, auth_settings=None,
async_req=None, _return_http_data_only=None,
collection_formats=None,_preload_content=True,
_request_timeout=None, _host=None, _request_auth=None):
"""Makes the HTTP request (synchronous) and returns deserialized data.

To make an async_req request, set the async_req parameter.
Expand Down Expand Up @@ -396,7 +399,7 @@ 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_map, auth_settings,
_return_http_data_only, collection_formats,
_preload_content, _request_timeout, _host,
_request_auth)
Expand All @@ -406,7 +409,7 @@ class ApiClient(object):
query_params,
header_params, body,
post_params, files,
response_type,
response_types_map,
auth_settings,
_return_http_data_only,
collection_formats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {
200: "Client",
}

return self.api_client.call_api(
'/another-fake/dummy', 'PATCH',
Expand All @@ -162,7 +166,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_map=response_types_map,
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
66 changes: 52 additions & 14 deletions samples/client/petstore/python-asyncio/petstore_api/api/fake_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {}

return self.api_client.call_api(
'/fake/create_xml_item', 'POST',
Expand All @@ -158,7 +160,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_map=response_types_map,
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 Expand Up @@ -276,6 +278,10 @@ def fake_outer_boolean_serialize_with_http_info(self, **kwargs): # noqa: E501

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {
200: "bool",
}

return self.api_client.call_api(
'/fake/outer/boolean', 'POST',
Expand All @@ -285,7 +291,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_map=response_types_map,
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 Expand Up @@ -403,6 +409,10 @@ def fake_outer_composite_serialize_with_http_info(self, **kwargs): # noqa: E501

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {
200: "OuterComposite",
}

return self.api_client.call_api(
'/fake/outer/composite', 'POST',
Expand All @@ -412,7 +422,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_map=response_types_map,
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 Expand Up @@ -530,6 +540,10 @@ def fake_outer_number_serialize_with_http_info(self, **kwargs): # noqa: E501

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {
200: "float",
}

return self.api_client.call_api(
'/fake/outer/number', 'POST',
Expand All @@ -539,7 +553,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_map=response_types_map,
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 Expand Up @@ -657,6 +671,10 @@ def fake_outer_string_serialize_with_http_info(self, **kwargs): # noqa: E501

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {
200: "str",
}

return self.api_client.call_api(
'/fake/outer/string', 'POST',
Expand All @@ -666,7 +684,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_map=response_types_map,
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 Expand Up @@ -788,6 +806,8 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {}

return self.api_client.call_api(
'/fake/body-with-file-schema', 'PUT',
Expand All @@ -797,7 +817,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_map=response_types_map,
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 Expand Up @@ -928,6 +948,8 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): #

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {}

return self.api_client.call_api(
'/fake/body-with-query-params', 'PUT',
Expand All @@ -937,7 +959,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_map=response_types_map,
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 Expand Up @@ -1063,6 +1085,10 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {
200: "Client",
}

return self.api_client.call_api(
'/fake', 'PATCH',
Expand All @@ -1072,7 +1098,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_map=response_types_map,
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 Expand Up @@ -1325,6 +1351,8 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou

# Authentication setting
auth_settings = ['http_basic_test'] # noqa: E501

response_types_map = {}

return self.api_client.call_api(
'/fake', 'POST',
Expand All @@ -1334,7 +1362,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_map=response_types_map,
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 Expand Up @@ -1504,6 +1532,8 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {}

return self.api_client.call_api(
'/fake', 'GET',
Expand All @@ -1513,7 +1543,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_map=response_types_map,
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 Expand Up @@ -1674,6 +1704,8 @@ def test_group_parameters_with_http_info(self, required_string_group, required_b
body_params = None
# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {}

return self.api_client.call_api(
'/fake', 'DELETE',
Expand All @@ -1683,7 +1715,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_map=response_types_map,
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 Expand Up @@ -1803,6 +1835,8 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): #

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {}

return self.api_client.call_api(
'/fake/inline-additionalProperties', 'POST',
Expand All @@ -1812,7 +1846,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_map=response_types_map,
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 Expand Up @@ -1943,6 +1977,8 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa:

# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {}

return self.api_client.call_api(
'/fake/jsonFormData', 'GET',
Expand All @@ -1952,7 +1988,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_map=response_types_map,
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 Expand Up @@ -2119,6 +2155,8 @@ def test_query_parameter_collection_format_with_http_info(self, pipe, ioutil, ht
body_params = None
# Authentication setting
auth_settings = [] # noqa: E501

response_types_map = {}

return self.api_client.call_api(
'/fake/test-query-paramters', 'PUT',
Expand All @@ -2128,7 +2166,7 @@ def test_query_parameter_collection_format_with_http_info(self, pipe, ioutil, ht
body=body_params,
post_params=form_params,
files=local_var_files,
response_type=None, # noqa: E501
response_types_map=response_types_map,
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 @@ -153,6 +153,10 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501

# Authentication setting
auth_settings = ['api_key_query'] # noqa: E501

response_types_map = {
200: "Client",
}

return self.api_client.call_api(
'/fake_classname_test', 'PATCH',
Expand All @@ -162,7 +166,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_map=response_types_map,
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
Loading