Skip to content

Commit

Permalink
[Python] remove default content-type in the request (#10782)
Browse files Browse the repository at this point in the history
* remove default content-type in the request

* add remove default content-type test

* fix duplicate content type

* update sample

* add missing params

* update sample

* only assign content type if exist

* update sample

* update sample

* format code

* update sample
  • Loading branch information
kevchentw authored Feb 24, 2022
1 parent 7bda473 commit ab63786
Show file tree
Hide file tree
Showing 33 changed files with 248 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,12 @@ class {{classname}}(object):
{{/hasProduces}}
{{#hasConsumes}}
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
[{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}],
'{{httpMethod}}', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

{{/hasConsumes}}
# Authentication setting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ class ApiClient(object):
:return: Content-Type (e.g. application/json).
"""
if not content_types:
return 'application/json'
return None

content_types = [x.lower() for x in content_types]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ class ApiClient(object):
:return: Content-Type (e.g. application/json).
"""
if not content_types:
return 'application/json'
return None

content_types = [x.lower() for x in content_types]

Expand Down Expand Up @@ -863,10 +863,11 @@ class Endpoint(object):
content_type_headers_list = self.headers_map['content_type']
if content_type_headers_list:
if params['body'] != "":
header_list = self.api_client.select_header_content_type(
content_types_list = self.api_client.select_header_content_type(
content_type_headers_list, self.settings['http_method'],
params['body'])
params['header']['Content-Type'] = header_list
if content_types_list:
params['header']['Content-Type'] = content_types_list

return self.api_client.call_api(
self.settings['endpoint_path'], self.settings['http_method'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5
['application/json']) # noqa: E501

# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'PATCH', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501
if 'xml_item' in local_var_params:
body_params = local_var_params['xml_item']
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/xml', 'application/xml; charset=utf-8', 'application/xml; charset=utf-16', 'text/xml', 'text/xml; charset=utf-8', 'text/xml; charset=utf-16'],
'POST', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -821,10 +823,12 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5
if 'body' in local_var_params:
body_params = local_var_params['body']
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'PUT', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -968,10 +972,12 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): #
if 'body' in local_var_params:
body_params = local_var_params['body']
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'PUT', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -1110,10 +1116,12 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501
['application/json']) # noqa: E501

# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'PATCH', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -1381,10 +1389,12 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou

body_params = None
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/x-www-form-urlencoded'],
'POST', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = ['http_basic_test'] # noqa: E501
Expand Down Expand Up @@ -1567,10 +1577,12 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501

body_params = None
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/x-www-form-urlencoded'],
'GET', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -1878,10 +1890,12 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): #
if 'param' in local_var_params:
body_params = local_var_params['param']
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'POST', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -2025,10 +2039,12 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa:

body_params = None
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/x-www-form-urlencoded'],
'GET', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ def test_classname_with_http_info(self, body, **kwargs): # noqa: E501
['application/json']) # noqa: E501

# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'PATCH', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = ['api_key_query'] # noqa: E501
Expand Down
20 changes: 15 additions & 5 deletions samples/client/petstore/python-asyncio/petstore_api/api/pet_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ def add_pet_with_http_info(self, body, **kwargs): # noqa: E501
if 'body' in local_var_params:
body_params = local_var_params['body']
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json', 'application/xml'],
'POST', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = ['petstore_auth'] # noqa: E501
Expand Down Expand Up @@ -838,10 +840,12 @@ def update_pet_with_http_info(self, body, **kwargs): # noqa: E501
if 'body' in local_var_params:
body_params = local_var_params['body']
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json', 'application/xml'],
'PUT', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = ['petstore_auth'] # noqa: E501
Expand Down Expand Up @@ -988,10 +992,12 @@ def update_pet_with_form_with_http_info(self, pet_id, **kwargs): # noqa: E501

body_params = None
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/x-www-form-urlencoded'],
'POST', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = ['petstore_auth'] # noqa: E501
Expand Down Expand Up @@ -1142,10 +1148,12 @@ def upload_file_with_http_info(self, pet_id, **kwargs): # noqa: E501
['application/json']) # noqa: E501

# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['multipart/form-data'],
'POST', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = ['petstore_auth'] # noqa: E501
Expand Down Expand Up @@ -1302,10 +1310,12 @@ def upload_file_with_required_file_with_http_info(self, pet_id, required_file, *
['application/json']) # noqa: E501

# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['multipart/form-data'],
'POST', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = ['petstore_auth'] # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def select_header_content_type(self, content_types, method=None, body=None):
:return: Content-Type (e.g. application/json).
"""
if not content_types:
return 'application/json'
return None

content_types = [x.lower() for x in content_types]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ def call_123_test_special_tags_with_http_info(self, body, **kwargs): # noqa: E5
['application/json']) # noqa: E501

# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'PATCH', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down
32 changes: 24 additions & 8 deletions samples/client/petstore/python-legacy/petstore_api/api/fake_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ def create_xml_item_with_http_info(self, xml_item, **kwargs): # noqa: E501
if 'xml_item' in local_var_params:
body_params = local_var_params['xml_item']
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/xml', 'application/xml; charset=utf-8', 'application/xml; charset=utf-16', 'text/xml', 'text/xml; charset=utf-8', 'text/xml; charset=utf-16'],
'POST', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -821,10 +823,12 @@ def test_body_with_file_schema_with_http_info(self, body, **kwargs): # noqa: E5
if 'body' in local_var_params:
body_params = local_var_params['body']
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'PUT', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -968,10 +972,12 @@ def test_body_with_query_params_with_http_info(self, query, body, **kwargs): #
if 'body' in local_var_params:
body_params = local_var_params['body']
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'PUT', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -1110,10 +1116,12 @@ def test_client_model_with_http_info(self, body, **kwargs): # noqa: E501
['application/json']) # noqa: E501

# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'PATCH', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -1381,10 +1389,12 @@ def test_endpoint_parameters_with_http_info(self, number, double, pattern_withou

body_params = None
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/x-www-form-urlencoded'],
'POST', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = ['http_basic_test'] # noqa: E501
Expand Down Expand Up @@ -1567,10 +1577,12 @@ def test_enum_parameters_with_http_info(self, **kwargs): # noqa: E501

body_params = None
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/x-www-form-urlencoded'],
'GET', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -1878,10 +1890,12 @@ def test_inline_additional_properties_with_http_info(self, param, **kwargs): #
if 'param' in local_var_params:
body_params = local_var_params['param']
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/json'],
'POST', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down Expand Up @@ -2025,10 +2039,12 @@ def test_json_form_data_with_http_info(self, param, param2, **kwargs): # noqa:

body_params = None
# HTTP header `Content-Type`
header_params['Content-Type'] = local_var_params.get('_content_type',
content_types_list = local_var_params.get('_content_type',
self.api_client.select_header_content_type(
['application/x-www-form-urlencoded'],
'GET', body_params)) # noqa: E501
if content_types_list:
header_params['Content-Type'] = content_types_list

# Authentication setting
auth_settings = [] # noqa: E501
Expand Down
Loading

0 comments on commit ab63786

Please sign in to comment.