mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 14:40:53 +00:00
minor improvement to python client accept and content-type header
This commit is contained in:
parent
2b7bbd9513
commit
52807c0724
@ -29,6 +29,8 @@ from six import iteritems
|
||||
|
||||
from ..util import remove_none
|
||||
|
||||
from ..swagger import ApiClient
|
||||
|
||||
{{#operations}}
|
||||
class {{classname}}(object):
|
||||
|
||||
@ -68,11 +70,13 @@ class {{classname}}(object):
|
||||
files = remove_none(dict({{#formParams}}{{#isFile}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/isFile}}{{/formParams}}))
|
||||
body_params = {{#bodyParam}}params.get('{{paramName}}'){{/bodyParam}}{{^bodyParam}}None{{/bodyParam}}
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = [{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = [{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
|
@ -253,7 +253,28 @@ class ApiClient(object):
|
||||
|
||||
return params
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def select_header_accept(accepts):
|
||||
"""
|
||||
Return `Accept` based on an array of accepts provided
|
||||
"""
|
||||
if not accepts:
|
||||
return 'application/json'
|
||||
if 'application/json'.lower() in accepts:
|
||||
return 'application/json'
|
||||
else:
|
||||
return ', '.join(accepts)
|
||||
|
||||
@staticmethod
|
||||
def select_header_content_type(content_types):
|
||||
"""
|
||||
Return `Content-Type` baseed on an array of content_types provided
|
||||
"""
|
||||
if not content_types:
|
||||
return 'application/json'
|
||||
if 'application/json'.lower() in content_types:
|
||||
return 'application/json'
|
||||
else:
|
||||
return content_types[0]
|
||||
|
||||
|
||||
|
@ -29,6 +29,8 @@ from six import iteritems
|
||||
|
||||
from ..util import remove_none
|
||||
|
||||
from ..swagger import ApiClient
|
||||
|
||||
class PetApi(object):
|
||||
|
||||
def __init__(self, api_client):
|
||||
@ -63,11 +65,13 @@ class PetApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = params.get('body')
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = ['application/json', 'application/xml']
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -102,11 +106,13 @@ class PetApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = params.get('body')
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = ['application/json', 'application/xml']
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -141,11 +147,13 @@ class PetApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -182,11 +190,13 @@ class PetApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -227,11 +237,18 @@ class PetApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
# HTTP header `Accept`
|
||||
accepts = []
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
print('-----------------------------')
|
||||
print('header_params: ', header_params)
|
||||
print('-----------------------------')
|
||||
return
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -274,11 +291,13 @@ class PetApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = ['application/x-www-form-urlencoded']
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -318,11 +337,13 @@ class PetApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -363,11 +384,13 @@ class PetApi(object):
|
||||
files = remove_none(dict(file=params.get('file')))
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = ['multipart/form-data']
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
|
@ -29,6 +29,8 @@ from six import iteritems
|
||||
|
||||
from ..util import remove_none
|
||||
|
||||
from ..swagger import ApiClient
|
||||
|
||||
class StoreApi(object):
|
||||
|
||||
def __init__(self, api_client):
|
||||
@ -62,11 +64,13 @@ class StoreApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -103,11 +107,13 @@ class StoreApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = params.get('body')
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -148,11 +154,13 @@ class StoreApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -193,11 +201,13 @@ class StoreApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
|
@ -29,6 +29,8 @@ from six import iteritems
|
||||
|
||||
from ..util import remove_none
|
||||
|
||||
from ..swagger import ApiClient
|
||||
|
||||
class UserApi(object):
|
||||
|
||||
def __init__(self, api_client):
|
||||
@ -63,11 +65,13 @@ class UserApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = params.get('body')
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -102,11 +106,13 @@ class UserApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = params.get('body')
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -141,11 +147,13 @@ class UserApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = params.get('body')
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -181,11 +189,13 @@ class UserApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -221,11 +231,13 @@ class UserApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -264,11 +276,13 @@ class UserApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -310,11 +324,13 @@ class UserApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = params.get('body')
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
@ -353,11 +369,13 @@ class UserApi(object):
|
||||
files = remove_none(dict())
|
||||
body_params = None
|
||||
|
||||
# HTTP header `Accept`
|
||||
accepts = ['application/json', 'application/xml']
|
||||
header_params['Accept'] = ', '.join(accepts)
|
||||
header_params['Accept'] = ApiClient.select_header_accept(accepts)
|
||||
|
||||
# HTTP header `Content-Type`
|
||||
content_types = []
|
||||
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
|
||||
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
|
||||
|
||||
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
|
||||
body=body_params, post_params=form_params, files=files,
|
||||
|
@ -253,7 +253,28 @@ class ApiClient(object):
|
||||
|
||||
return params
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def select_header_accept(accepts):
|
||||
"""
|
||||
Return `Accept` based on an array of accepts provided
|
||||
"""
|
||||
if not accepts:
|
||||
return 'application/json'
|
||||
if 'application/json'.lower() in accepts:
|
||||
return 'application/json'
|
||||
else:
|
||||
return ', '.join(accepts)
|
||||
|
||||
@staticmethod
|
||||
def select_header_content_type(content_types):
|
||||
"""
|
||||
Return `Content-Type` baseed on an array of content_types provided
|
||||
"""
|
||||
if not content_types:
|
||||
return 'application/json'
|
||||
if 'application/json'.lower() in content_types:
|
||||
return 'application/json'
|
||||
else:
|
||||
return content_types[0]
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user