Skip to content
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
12 changes: 8 additions & 4 deletions modules/swagger-codegen/src/main/resources/python/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ from six import iteritems

from ..util import remove_none

from ..swagger import ApiClient

{{#operations}}
class {{classname}}(object):

Expand Down Expand Up @@ -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}}

accepts = [{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept([{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}])
if not header_params['Accept']:
del header_params['Accept']

content_types = [{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ApiClient(object):
def to_path_value(self, obj):
"""
Convert a string or object to a path-friendly value

:param obj: object or string value

:return string: quoted value
Expand Down Expand Up @@ -253,7 +253,32 @@ class ApiClient(object):

return params

@staticmethod
def select_header_accept(accepts):
"""
Return `Accept` based on an array of accepts provided
"""
if not accepts:
return

accepts = list(map(lambda x: x.lower(), accepts))

if 'application/json' 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'

content_types = list(map(lambda x: x.lower(), content_types))

if 'application/json' in content_types:
return 'application/json'
else:
return content_types[0]
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

from ..util import remove_none

from ..swagger import ApiClient

class PetApi(object):

def __init__(self, api_client):
Expand Down Expand Up @@ -63,11 +65,13 @@ def update_pet(self, **kwargs):
files = remove_none(dict())
body_params = params.get('body')

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = ['application/json', 'application/xml']
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type(['application/json', 'application/xml'])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down Expand Up @@ -102,11 +106,13 @@ def add_pet(self, **kwargs):
files = remove_none(dict())
body_params = params.get('body')

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = ['application/json', 'application/xml']
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type(['application/json', 'application/xml'])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down Expand Up @@ -141,11 +147,13 @@ def find_pets_by_status(self, **kwargs):
files = remove_none(dict())
body_params = None

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = []
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down Expand Up @@ -182,11 +190,13 @@ def find_pets_by_tags(self, **kwargs):
files = remove_none(dict())
body_params = None

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = []
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down Expand Up @@ -227,11 +237,13 @@ def get_pet_by_id(self, pet_id, **kwargs):
files = remove_none(dict())
body_params = None

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = []
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down Expand Up @@ -274,11 +286,13 @@ def update_pet_with_form(self, pet_id, **kwargs):
files = remove_none(dict())
body_params = None

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = ['application/x-www-form-urlencoded']
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type(['application/x-www-form-urlencoded'])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down Expand Up @@ -318,11 +332,13 @@ def delete_pet(self, pet_id, **kwargs):
files = remove_none(dict())
body_params = None

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = []
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down Expand Up @@ -363,11 +379,13 @@ def upload_file(self, pet_id, **kwargs):
files = remove_none(dict(file=params.get('file')))
body_params = None

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = ['multipart/form-data']
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type(['multipart/form-data'])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

from ..util import remove_none

from ..swagger import ApiClient

class StoreApi(object):

def __init__(self, api_client):
Expand Down Expand Up @@ -62,11 +64,13 @@ def get_inventory(self, **kwargs):
files = remove_none(dict())
body_params = None

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = []
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down Expand Up @@ -103,11 +107,13 @@ def place_order(self, **kwargs):
files = remove_none(dict())
body_params = params.get('body')

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = []
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down Expand Up @@ -148,11 +154,13 @@ def get_order_by_id(self, order_id, **kwargs):
files = remove_none(dict())
body_params = None

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = []
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down Expand Up @@ -193,11 +201,13 @@ def delete_order(self, order_id, **kwargs):
files = remove_none(dict())
body_params = None

accepts = ['application/json', 'application/xml']
header_params['Accept'] = ', '.join(accepts)
# HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']:
del header_params['Accept']

content_types = []
header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'
# HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([])

response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files,
Expand Down
Loading