updated ApiClient of python sdk.

Change staticmethod to instance method.
This commit is contained in:
geekerzp 2015-05-25 15:29:31 +08:00
parent 3beeb6125e
commit 2d545c7f0b
7 changed files with 72 additions and 88 deletions

View File

@ -29,8 +29,6 @@ from six import iteritems
from ..util import remove_none from ..util import remove_none
from ..swagger import ApiClient
from .. import config from .. import config
{{#operations}} {{#operations}}
@ -76,12 +74,12 @@ class {{classname}}(object):
body_params = {{#bodyParam}}params.get('{{paramName}}'){{/bodyParam}}{{^bodyParam}}None{{/bodyParam}} body_params = {{#bodyParam}}params.get('{{paramName}}'){{/bodyParam}}{{^bodyParam}}None{{/bodyParam}}
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept([{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]) header_params['Accept'] = self.api_client.select_header_accept([{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]) header_params['Content-Type'] = self.api_client.select_header_content_type([{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,

View File

@ -66,28 +66,28 @@ class ApiClient(object):
if self.cookie: if self.cookie:
headers['Cookie'] = self.cookie headers['Cookie'] = self.cookie
if headers: if headers:
headers = ApiClient.sanitize_for_serialization(headers) headers = self.sanitize_for_serialization(headers)
# path parameters # path parameters
if path_params: if path_params:
path_params = ApiClient.sanitize_for_serialization(path_params) path_params = self.sanitize_for_serialization(path_params)
for k, v in iteritems(path_params): for k, v in iteritems(path_params):
replacement = quote(str(self.to_path_value(v))) replacement = quote(str(self.to_path_value(v)))
resource_path = resource_path.replace('{' + k + '}', replacement) resource_path = resource_path.replace('{' + k + '}', replacement)
# query parameters # query parameters
if query_params: if query_params:
query_params = ApiClient.sanitize_for_serialization(query_params) query_params = self.sanitize_for_serialization(query_params)
query_params = {k: self.to_path_value(v) for k, v in iteritems(query_params)} query_params = {k: self.to_path_value(v) for k, v in iteritems(query_params)}
# post parameters # post parameters
if post_params: if post_params:
post_params = self.prepare_post_parameters(post_params, files) post_params = self.prepare_post_parameters(post_params, files)
post_params = ApiClient.sanitize_for_serialization(post_params) post_params = self.sanitize_for_serialization(post_params)
# body # body
if body: if body:
body = ApiClient.sanitize_for_serialization(body) body = self.sanitize_for_serialization(body)
# request url # request url
url = self.host + resource_path url = self.host + resource_path
@ -115,8 +115,7 @@ class ApiClient(object):
else: else:
return str(obj) return str(obj)
@staticmethod def sanitize_for_serialization(self, obj):
def sanitize_for_serialization(obj):
""" """
Sanitize an object for Request. Sanitize an object for Request.
@ -132,7 +131,7 @@ class ApiClient(object):
elif isinstance(obj, (str, int, float, bool, tuple)): elif isinstance(obj, (str, int, float, bool, tuple)):
return obj return obj
elif isinstance(obj, list): elif isinstance(obj, list):
return [ApiClient.sanitize_for_serialization(sub_obj) for sub_obj in obj] return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj]
elif isinstance(obj, (datetime.datetime, datetime.date)): elif isinstance(obj, (datetime.datetime, datetime.date)):
return obj.isoformat() return obj.isoformat()
else: else:
@ -145,7 +144,7 @@ class ApiClient(object):
obj_dict = {obj.attribute_map[key]: val obj_dict = {obj.attribute_map[key]: val
for key, val in iteritems(obj.__dict__) for key, val in iteritems(obj.__dict__)
if key != 'swagger_types' and key != 'attribute_map' and val is not None} if key != 'swagger_types' and key != 'attribute_map' and val is not None}
return {key: ApiClient.sanitize_for_serialization(val) return {key: self.sanitize_for_serialization(val)
for key, val in iteritems(obj_dict)} for key, val in iteritems(obj_dict)}
def deserialize(self, obj, obj_class): def deserialize(self, obj, obj_class):
@ -253,8 +252,7 @@ class ApiClient(object):
return params return params
@staticmethod def select_header_accept(self, accepts):
def select_header_accept(accepts):
""" """
Return `Accept` based on an array of accepts provided Return `Accept` based on an array of accepts provided
""" """
@ -268,8 +266,7 @@ class ApiClient(object):
else: else:
return ', '.join(accepts) return ', '.join(accepts)
@staticmethod def select_header_content_type(self, content_types):
def select_header_content_type(content_types):
""" """
Return `Content-Type` baseed on an array of content_types provided Return `Content-Type` baseed on an array of content_types provided
""" """

View File

@ -29,8 +29,6 @@ from six import iteritems
from ..util import remove_none from ..util import remove_none
from ..swagger import ApiClient
from .. import config from .. import config
class PetApi(object): class PetApi(object):
@ -71,12 +69,12 @@ class PetApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type(['application/json', 'application/xml']) header_params['Content-Type'] = self.api_client.select_header_content_type(['application/json', 'application/xml'])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -112,12 +110,12 @@ class PetApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type(['application/json', 'application/xml']) header_params['Content-Type'] = self.api_client.select_header_content_type(['application/json', 'application/xml'])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -153,12 +151,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -196,12 +194,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -243,12 +241,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -292,12 +290,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type(['application/x-www-form-urlencoded']) header_params['Content-Type'] = self.api_client.select_header_content_type(['application/x-www-form-urlencoded'])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -338,12 +336,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -385,12 +383,12 @@ class PetApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type(['multipart/form-data']) header_params['Content-Type'] = self.api_client.select_header_content_type(['multipart/form-data'])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,

View File

@ -29,8 +29,6 @@ from six import iteritems
from ..util import remove_none from ..util import remove_none
from ..swagger import ApiClient
from .. import config from .. import config
class StoreApi(object): class StoreApi(object):
@ -70,12 +68,12 @@ class StoreApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -113,12 +111,12 @@ class StoreApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -160,12 +158,12 @@ class StoreApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -207,12 +205,12 @@ class StoreApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,

View File

@ -29,8 +29,6 @@ from six import iteritems
from ..util import remove_none from ..util import remove_none
from ..swagger import ApiClient
from .. import config from .. import config
class UserApi(object): class UserApi(object):
@ -71,12 +69,12 @@ class UserApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -112,12 +110,12 @@ class UserApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -153,12 +151,12 @@ class UserApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -195,12 +193,12 @@ class UserApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -237,12 +235,12 @@ class UserApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -282,12 +280,12 @@ class UserApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -330,12 +328,12 @@ class UserApi(object):
body_params = params.get('body') body_params = params.get('body')
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,
@ -375,12 +373,12 @@ class UserApi(object):
body_params = None body_params = None
# HTTP header `Accept` # HTTP header `Accept`
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) header_params['Accept'] = self.api_client.select_header_accept(['application/json', 'application/xml'])
if not header_params['Accept']: if not header_params['Accept']:
del header_params['Accept'] del header_params['Accept']
# HTTP header `Content-Type` # HTTP header `Content-Type`
header_params['Content-Type'] = ApiClient.select_header_content_type([]) header_params['Content-Type'] = self.api_client.select_header_content_type([])
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
body=body_params, post_params=form_params, files=files, body=body_params, post_params=form_params, files=files,

View File

@ -66,28 +66,28 @@ class ApiClient(object):
if self.cookie: if self.cookie:
headers['Cookie'] = self.cookie headers['Cookie'] = self.cookie
if headers: if headers:
headers = ApiClient.sanitize_for_serialization(headers) headers = self.sanitize_for_serialization(headers)
# path parameters # path parameters
if path_params: if path_params:
path_params = ApiClient.sanitize_for_serialization(path_params) path_params = self.sanitize_for_serialization(path_params)
for k, v in iteritems(path_params): for k, v in iteritems(path_params):
replacement = quote(str(self.to_path_value(v))) replacement = quote(str(self.to_path_value(v)))
resource_path = resource_path.replace('{' + k + '}', replacement) resource_path = resource_path.replace('{' + k + '}', replacement)
# query parameters # query parameters
if query_params: if query_params:
query_params = ApiClient.sanitize_for_serialization(query_params) query_params = self.sanitize_for_serialization(query_params)
query_params = {k: self.to_path_value(v) for k, v in iteritems(query_params)} query_params = {k: self.to_path_value(v) for k, v in iteritems(query_params)}
# post parameters # post parameters
if post_params: if post_params:
post_params = self.prepare_post_parameters(post_params, files) post_params = self.prepare_post_parameters(post_params, files)
post_params = ApiClient.sanitize_for_serialization(post_params) post_params = self.sanitize_for_serialization(post_params)
# body # body
if body: if body:
body = ApiClient.sanitize_for_serialization(body) body = self.sanitize_for_serialization(body)
# request url # request url
url = self.host + resource_path url = self.host + resource_path
@ -115,8 +115,7 @@ class ApiClient(object):
else: else:
return str(obj) return str(obj)
@staticmethod def sanitize_for_serialization(self, obj):
def sanitize_for_serialization(obj):
""" """
Sanitize an object for Request. Sanitize an object for Request.
@ -132,7 +131,7 @@ class ApiClient(object):
elif isinstance(obj, (str, int, float, bool, tuple)): elif isinstance(obj, (str, int, float, bool, tuple)):
return obj return obj
elif isinstance(obj, list): elif isinstance(obj, list):
return [ApiClient.sanitize_for_serialization(sub_obj) for sub_obj in obj] return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj]
elif isinstance(obj, (datetime.datetime, datetime.date)): elif isinstance(obj, (datetime.datetime, datetime.date)):
return obj.isoformat() return obj.isoformat()
else: else:
@ -145,7 +144,7 @@ class ApiClient(object):
obj_dict = {obj.attribute_map[key]: val obj_dict = {obj.attribute_map[key]: val
for key, val in iteritems(obj.__dict__) for key, val in iteritems(obj.__dict__)
if key != 'swagger_types' and key != 'attribute_map' and val is not None} if key != 'swagger_types' and key != 'attribute_map' and val is not None}
return {key: ApiClient.sanitize_for_serialization(val) return {key: self.sanitize_for_serialization(val)
for key, val in iteritems(obj_dict)} for key, val in iteritems(obj_dict)}
def deserialize(self, obj, obj_class): def deserialize(self, obj, obj_class):
@ -253,8 +252,7 @@ class ApiClient(object):
return params return params
@staticmethod def select_header_accept(self, accepts):
def select_header_accept(accepts):
""" """
Return `Accept` based on an array of accepts provided Return `Accept` based on an array of accepts provided
""" """
@ -268,8 +266,7 @@ class ApiClient(object):
else: else:
return ', '.join(accepts) return ', '.join(accepts)
@staticmethod def select_header_content_type(self, content_types):
def select_header_content_type(content_types):
""" """
Return `Content-Type` baseed on an array of content_types provided Return `Content-Type` baseed on an array of content_types provided
""" """

View File

@ -23,44 +23,42 @@ class ApiClientTests(unittest.TestCase):
def test_select_header_accept(self): def test_select_header_accept(self):
accepts = ['APPLICATION/JSON', 'APPLICATION/XML'] accepts = ['APPLICATION/JSON', 'APPLICATION/XML']
accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) accept = self.api_client.select_header_accept(accepts)
self.assertEqual(accept, 'application/json') self.assertEqual(accept, 'application/json')
accepts = ['application/json', 'application/xml'] accepts = ['application/json', 'application/xml']
accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) accept = self.api_client.select_header_accept(accepts)
self.assertEqual(accept, 'application/json') self.assertEqual(accept, 'application/json')
accepts = ['application/xml', 'application/json'] accepts = ['application/xml', 'application/json']
accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) accept = self.api_client.select_header_accept(accepts)
self.assertEqual(accept, 'application/json') self.assertEqual(accept, 'application/json')
accepts = ['text/plain', 'application/xml'] accepts = ['text/plain', 'application/xml']
accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) accept = self.api_client.select_header_accept(accepts)
self.assertEqual(accept, 'text/plain, application/xml') self.assertEqual(accept, 'text/plain, application/xml')
accepts = [] accepts = []
accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) accept = self.api_client.select_header_accept(accepts)
self.assertEqual(accept, None) self.assertEqual(accept, None)
def test_select_header_content_type(self): def test_select_header_content_type(self):
content_types = ['APPLICATION/JSON', 'APPLICATION/XML'] content_types = ['APPLICATION/JSON', 'APPLICATION/XML']
content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json') self.assertEqual(content_type, 'application/json')
content_types = ['application/json', 'application/xml'] content_types = ['application/json', 'application/xml']
content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json') self.assertEqual(content_type, 'application/json')
content_types = ['application/xml', 'application/json'] content_types = ['application/xml', 'application/json']
content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json') self.assertEqual(content_type, 'application/json')
content_types = ['text/plain', 'application/xml'] content_types = ['text/plain', 'application/xml']
content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'text/plain') self.assertEqual(content_type, 'text/plain')
content_types = [] content_types = []
content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json') self.assertEqual(content_type, 'application/json')