forked from loafle/openapi-generator-original
[Python] Make the code look Pythonic (#4352)
This commit is contained in:
parent
c3571b28a5
commit
4d2a13018b
@ -1,13 +1,7 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
{{>partial_header}}
|
{{>partial_header}}
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from . import models
|
|
||||||
from .rest import RESTClientObject
|
|
||||||
from .rest import ApiException
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
@ -15,14 +9,15 @@ import mimetypes
|
|||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import date, datetime
|
||||||
from datetime import date
|
|
||||||
|
|
||||||
# python 2 and python 3 compatibility library
|
# python 2 and python 3 compatibility library
|
||||||
from six import PY3, integer_types, iteritems, text_type
|
from six import PY3, integer_types, iteritems, text_type
|
||||||
from six.moves.urllib.parse import quote
|
from six.moves.urllib.parse import quote
|
||||||
|
|
||||||
|
from . import models
|
||||||
from .configuration import Configuration
|
from .configuration import Configuration
|
||||||
|
from .rest import ApiException, RESTClientObject
|
||||||
|
|
||||||
|
|
||||||
class ApiClient(object):
|
class ApiClient(object):
|
||||||
@ -42,8 +37,20 @@ class ApiClient(object):
|
|||||||
:param header_name: a header to pass when making calls to the API.
|
:param header_name: a header to pass when making calls to the API.
|
||||||
:param header_value: a header value to pass when making calls to the API.
|
:param header_value: a header value to pass when making calls to the API.
|
||||||
"""
|
"""
|
||||||
def __init__(self, host=None, header_name=None, header_value=None, cookie=None):
|
|
||||||
|
|
||||||
|
PRIMITIVE_TYPES = (float, bool, bytes, text_type) + integer_types
|
||||||
|
NATIVE_TYPES_MAPPING = {
|
||||||
|
'int': int,
|
||||||
|
'long': int if PY3 else long,
|
||||||
|
'float': float,
|
||||||
|
'str': str,
|
||||||
|
'bool': bool,
|
||||||
|
'date': date,
|
||||||
|
'datetime': datetime,
|
||||||
|
'object': object,
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, host=None, header_name=None, header_value=None, cookie=None):
|
||||||
"""
|
"""
|
||||||
Constructor of the class.
|
Constructor of the class.
|
||||||
"""
|
"""
|
||||||
@ -144,7 +151,10 @@ class ApiClient(object):
|
|||||||
return_data = None
|
return_data = None
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
callback(return_data) if _return_http_data_only else callback((return_data, response_data.status, response_data.getheaders()))
|
if _return_http_data_only:
|
||||||
|
callback(return_data)
|
||||||
|
else:
|
||||||
|
callback((return_data, response_data.status, response_data.getheaders()))
|
||||||
elif _return_http_data_only:
|
elif _return_http_data_only:
|
||||||
return (return_data)
|
return (return_data)
|
||||||
else:
|
else:
|
||||||
@ -165,10 +175,9 @@ class ApiClient(object):
|
|||||||
:param obj: The data to serialize.
|
:param obj: The data to serialize.
|
||||||
:return: The serialized form of data.
|
:return: The serialized form of data.
|
||||||
"""
|
"""
|
||||||
types = (str, float, bool, bytes) + tuple(integer_types) + (text_type,)
|
if obj is None:
|
||||||
if isinstance(obj, type(None)):
|
|
||||||
return None
|
return None
|
||||||
elif isinstance(obj, types):
|
elif isinstance(obj, self.PRIMITIVE_TYPES):
|
||||||
return obj
|
return obj
|
||||||
elif isinstance(obj, list):
|
elif isinstance(obj, list):
|
||||||
return [self.sanitize_for_serialization(sub_obj)
|
return [self.sanitize_for_serialization(sub_obj)
|
||||||
@ -178,21 +187,21 @@ class ApiClient(object):
|
|||||||
for sub_obj in obj)
|
for sub_obj in obj)
|
||||||
elif isinstance(obj, (datetime, date)):
|
elif isinstance(obj, (datetime, date)):
|
||||||
return obj.isoformat()
|
return obj.isoformat()
|
||||||
else:
|
|
||||||
if isinstance(obj, dict):
|
|
||||||
obj_dict = obj
|
|
||||||
else:
|
|
||||||
# Convert model obj to dict except
|
|
||||||
# attributes `swagger_types`, `attribute_map`
|
|
||||||
# and attributes which value is not None.
|
|
||||||
# Convert attribute name to json key in
|
|
||||||
# model definition for request.
|
|
||||||
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
|
|
||||||
for attr, _ in iteritems(obj.swagger_types)
|
|
||||||
if getattr(obj, attr) is not None}
|
|
||||||
|
|
||||||
return {key: self.sanitize_for_serialization(val)
|
if isinstance(obj, dict):
|
||||||
for key, val in iteritems(obj_dict)}
|
obj_dict = obj
|
||||||
|
else:
|
||||||
|
# Convert model obj to dict except
|
||||||
|
# attributes `swagger_types`, `attribute_map`
|
||||||
|
# and attributes which value is not None.
|
||||||
|
# Convert attribute name to json key in
|
||||||
|
# model definition for request.
|
||||||
|
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
|
||||||
|
for attr, _ in iteritems(obj.swagger_types)
|
||||||
|
if getattr(obj, attr) is not None}
|
||||||
|
|
||||||
|
return {key: self.sanitize_for_serialization(val)
|
||||||
|
for key, val in iteritems(obj_dict)}
|
||||||
|
|
||||||
def deserialize(self, response, response_type):
|
def deserialize(self, response, response_type):
|
||||||
"""
|
"""
|
||||||
@ -206,7 +215,7 @@ class ApiClient(object):
|
|||||||
"""
|
"""
|
||||||
# handle file downloading
|
# handle file downloading
|
||||||
# save response body into a tmp file and return the instance
|
# save response body into a tmp file and return the instance
|
||||||
if "file" == response_type:
|
if response_type == "file":
|
||||||
return self.__deserialize_file(response)
|
return self.__deserialize_file(response)
|
||||||
|
|
||||||
# fetch data from response object
|
# fetch data from response object
|
||||||
@ -241,17 +250,12 @@ class ApiClient(object):
|
|||||||
for k, v in iteritems(data)}
|
for k, v in iteritems(data)}
|
||||||
|
|
||||||
# convert str to class
|
# convert str to class
|
||||||
# for native types
|
if klass in self.NATIVE_TYPES_MAPPING:
|
||||||
if klass in ['int', 'float', 'str', 'bool',
|
klass = self.NATIVE_TYPES_MAPPING[klass]
|
||||||
"date", 'datetime', "object"]:
|
|
||||||
klass = eval(klass)
|
|
||||||
elif klass == 'long':
|
|
||||||
klass = int if PY3 else long
|
|
||||||
# for model types
|
|
||||||
else:
|
else:
|
||||||
klass = eval('models.' + klass)
|
klass = getattr(models, klass)
|
||||||
|
|
||||||
if klass in integer_types or klass in (float, str, bool):
|
if klass in self.PRIMITIVE_TYPES:
|
||||||
return self.__deserialize_primitive(data, klass)
|
return self.__deserialize_primitive(data, klass)
|
||||||
elif klass == object:
|
elif klass == object:
|
||||||
return self.__deserialize_object(data)
|
return self.__deserialize_object(data)
|
||||||
@ -451,7 +455,7 @@ class ApiClient(object):
|
|||||||
if not accepts:
|
if not accepts:
|
||||||
return
|
return
|
||||||
|
|
||||||
accepts = list(map(lambda x: x.lower(), accepts))
|
accepts = [x.lower() for x in accepts]
|
||||||
|
|
||||||
if 'application/json' in accepts:
|
if 'application/json' in accepts:
|
||||||
return 'application/json'
|
return 'application/json'
|
||||||
@ -468,7 +472,7 @@ class ApiClient(object):
|
|||||||
if not content_types:
|
if not content_types:
|
||||||
return 'application/json'
|
return 'application/json'
|
||||||
|
|
||||||
content_types = list(map(lambda x: x.lower(), content_types))
|
content_types = [x.lower() for x in content_types]
|
||||||
|
|
||||||
if 'application/json' in content_types or '*/*' in content_types:
|
if 'application/json' in content_types or '*/*' in content_types:
|
||||||
return 'application/json'
|
return 'application/json'
|
||||||
@ -538,12 +542,11 @@ class ApiClient(object):
|
|||||||
:return: int, long, float, str, bool.
|
:return: int, long, float, str, bool.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
value = klass(data)
|
return klass(data)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
value = unicode(data)
|
return unicode(data)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
value = data
|
return data
|
||||||
return value
|
|
||||||
|
|
||||||
def __deserialize_object(self, value):
|
def __deserialize_object(self, value):
|
||||||
"""
|
"""
|
||||||
@ -568,8 +571,7 @@ class ApiClient(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise ApiException(
|
raise ApiException(
|
||||||
status=0,
|
status=0,
|
||||||
reason="Failed to parse `{0}` into a date object"
|
reason="Failed to parse `{0}` into a date object".format(string)
|
||||||
.format(string)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def __deserialize_datatime(self, string):
|
def __deserialize_datatime(self, string):
|
||||||
@ -589,8 +591,10 @@ class ApiClient(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise ApiException(
|
raise ApiException(
|
||||||
status=0,
|
status=0,
|
||||||
reason="Failed to parse `{0}` into a datetime object".
|
reason=(
|
||||||
format(string)
|
"Failed to parse `{0}` into a datetime object"
|
||||||
|
.format(string)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def __deserialize_model(self, data, klass):
|
def __deserialize_model(self, data, klass):
|
||||||
@ -608,7 +612,7 @@ class ApiClient(object):
|
|||||||
|
|
||||||
for attr, attr_type in iteritems(instance.swagger_types):
|
for attr, attr_type in iteritems(instance.swagger_types):
|
||||||
if data is not None \
|
if data is not None \
|
||||||
and instance.attribute_map[attr] in data\
|
and instance.attribute_map[attr] in data \
|
||||||
and isinstance(data, (list, dict)):
|
and isinstance(data, (list, dict)):
|
||||||
value = data[instance.attribute_map[attr]]
|
value = data[instance.attribute_map[attr]]
|
||||||
setattr(instance, attr, self.__deserialize(value, attr_type))
|
setattr(instance, attr, self.__deserialize(value, attr_type))
|
||||||
|
@ -8,20 +8,9 @@
|
|||||||
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
# import models into sdk package
|
# import models into sdk package
|
||||||
|
@ -1,29 +1,16 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Copyright 2016 SmartBear Software
|
Swagger Petstore */ ' \" =end -- \\r\\n \\n \\r
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end --
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
||||||
|
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
|
|
||||||
ref: https://github.com/swagger-api/swagger-codegen
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from . import models
|
|
||||||
from .rest import RESTClientObject
|
|
||||||
from .rest import ApiException
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
@ -31,14 +18,15 @@ import mimetypes
|
|||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import date, datetime
|
||||||
from datetime import date
|
|
||||||
|
|
||||||
# python 2 and python 3 compatibility library
|
# python 2 and python 3 compatibility library
|
||||||
from six import PY3, integer_types, iteritems, text_type
|
from six import PY3, integer_types, iteritems, text_type
|
||||||
from six.moves.urllib.parse import quote
|
from six.moves.urllib.parse import quote
|
||||||
|
|
||||||
|
from . import models
|
||||||
from .configuration import Configuration
|
from .configuration import Configuration
|
||||||
|
from .rest import ApiException, RESTClientObject
|
||||||
|
|
||||||
|
|
||||||
class ApiClient(object):
|
class ApiClient(object):
|
||||||
@ -58,8 +46,20 @@ class ApiClient(object):
|
|||||||
:param header_name: a header to pass when making calls to the API.
|
:param header_name: a header to pass when making calls to the API.
|
||||||
:param header_value: a header value to pass when making calls to the API.
|
:param header_value: a header value to pass when making calls to the API.
|
||||||
"""
|
"""
|
||||||
def __init__(self, host=None, header_name=None, header_value=None, cookie=None):
|
|
||||||
|
|
||||||
|
PRIMITIVE_TYPES = (float, bool, bytes, text_type) + integer_types
|
||||||
|
NATIVE_TYPES_MAPPING = {
|
||||||
|
'int': int,
|
||||||
|
'long': int if PY3 else long,
|
||||||
|
'float': float,
|
||||||
|
'str': str,
|
||||||
|
'bool': bool,
|
||||||
|
'date': date,
|
||||||
|
'datetime': datetime,
|
||||||
|
'object': object,
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, host=None, header_name=None, header_value=None, cookie=None):
|
||||||
"""
|
"""
|
||||||
Constructor of the class.
|
Constructor of the class.
|
||||||
"""
|
"""
|
||||||
@ -96,7 +96,8 @@ class ApiClient(object):
|
|||||||
path_params=None, query_params=None, header_params=None,
|
path_params=None, query_params=None, header_params=None,
|
||||||
body=None, post_params=None, files=None,
|
body=None, post_params=None, files=None,
|
||||||
response_type=None, auth_settings=None, callback=None,
|
response_type=None, auth_settings=None, callback=None,
|
||||||
_return_http_data_only=None, collection_formats=None):
|
_return_http_data_only=None, collection_formats=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
|
|
||||||
# header parameters
|
# header parameters
|
||||||
header_params = header_params or {}
|
header_params = header_params or {}
|
||||||
@ -144,22 +145,29 @@ class ApiClient(object):
|
|||||||
response_data = self.request(method, url,
|
response_data = self.request(method, url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
headers=header_params,
|
headers=header_params,
|
||||||
post_params=post_params, body=body)
|
post_params=post_params, body=body,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout)
|
||||||
|
|
||||||
self.last_response = response_data
|
self.last_response = response_data
|
||||||
|
|
||||||
# deserialize response data
|
return_data = response_data
|
||||||
if response_type:
|
if _preload_content:
|
||||||
deserialized_data = self.deserialize(response_data, response_type)
|
# deserialize response data
|
||||||
else:
|
if response_type:
|
||||||
deserialized_data = None
|
return_data = self.deserialize(response_data, response_type)
|
||||||
|
else:
|
||||||
|
return_data = None
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
callback(deserialized_data) if _return_http_data_only else callback((deserialized_data, response_data.status, response_data.getheaders()))
|
if _return_http_data_only:
|
||||||
|
callback(return_data)
|
||||||
|
else:
|
||||||
|
callback((return_data, response_data.status, response_data.getheaders()))
|
||||||
elif _return_http_data_only:
|
elif _return_http_data_only:
|
||||||
return (deserialized_data)
|
return (return_data)
|
||||||
else:
|
else:
|
||||||
return (deserialized_data, response_data.status, response_data.getheaders())
|
return (return_data, response_data.status, response_data.getheaders())
|
||||||
|
|
||||||
def sanitize_for_serialization(self, obj):
|
def sanitize_for_serialization(self, obj):
|
||||||
"""
|
"""
|
||||||
@ -176,34 +184,33 @@ class ApiClient(object):
|
|||||||
:param obj: The data to serialize.
|
:param obj: The data to serialize.
|
||||||
:return: The serialized form of data.
|
:return: The serialized form of data.
|
||||||
"""
|
"""
|
||||||
types = (str, float, bool, bytes) + tuple(integer_types) + (text_type,)
|
if obj is None:
|
||||||
if isinstance(obj, type(None)):
|
|
||||||
return None
|
return None
|
||||||
elif isinstance(obj, types):
|
elif isinstance(obj, self.PRIMITIVE_TYPES):
|
||||||
return obj
|
return obj
|
||||||
elif isinstance(obj, list):
|
elif isinstance(obj, list):
|
||||||
return [self.sanitize_for_serialization(sub_obj)
|
return [self.sanitize_for_serialization(sub_obj)
|
||||||
for sub_obj in obj]
|
for sub_obj in obj]
|
||||||
elif isinstance(obj, tuple):
|
elif isinstance(obj, tuple):
|
||||||
return tuple(self.sanitize_for_serialization(sub_obj)
|
return tuple(self.sanitize_for_serialization(sub_obj)
|
||||||
for sub_obj in obj)
|
for sub_obj in obj)
|
||||||
elif isinstance(obj, (datetime, date)):
|
elif isinstance(obj, (datetime, date)):
|
||||||
return obj.isoformat()
|
return obj.isoformat()
|
||||||
else:
|
|
||||||
if isinstance(obj, dict):
|
|
||||||
obj_dict = obj
|
|
||||||
else:
|
|
||||||
# Convert model obj to dict except
|
|
||||||
# attributes `swagger_types`, `attribute_map`
|
|
||||||
# and attributes which value is not None.
|
|
||||||
# Convert attribute name to json key in
|
|
||||||
# model definition for request.
|
|
||||||
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
|
|
||||||
for attr, _ in iteritems(obj.swagger_types)
|
|
||||||
if getattr(obj, attr) is not None}
|
|
||||||
|
|
||||||
return {key: self.sanitize_for_serialization(val)
|
if isinstance(obj, dict):
|
||||||
for key, val in iteritems(obj_dict)}
|
obj_dict = obj
|
||||||
|
else:
|
||||||
|
# Convert model obj to dict except
|
||||||
|
# attributes `swagger_types`, `attribute_map`
|
||||||
|
# and attributes which value is not None.
|
||||||
|
# Convert attribute name to json key in
|
||||||
|
# model definition for request.
|
||||||
|
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
|
||||||
|
for attr, _ in iteritems(obj.swagger_types)
|
||||||
|
if getattr(obj, attr) is not None}
|
||||||
|
|
||||||
|
return {key: self.sanitize_for_serialization(val)
|
||||||
|
for key, val in iteritems(obj_dict)}
|
||||||
|
|
||||||
def deserialize(self, response, response_type):
|
def deserialize(self, response, response_type):
|
||||||
"""
|
"""
|
||||||
@ -217,7 +224,7 @@ class ApiClient(object):
|
|||||||
"""
|
"""
|
||||||
# handle file downloading
|
# handle file downloading
|
||||||
# save response body into a tmp file and return the instance
|
# save response body into a tmp file and return the instance
|
||||||
if "file" == response_type:
|
if response_type == "file":
|
||||||
return self.__deserialize_file(response)
|
return self.__deserialize_file(response)
|
||||||
|
|
||||||
# fetch data from response object
|
# fetch data from response object
|
||||||
@ -252,17 +259,12 @@ class ApiClient(object):
|
|||||||
for k, v in iteritems(data)}
|
for k, v in iteritems(data)}
|
||||||
|
|
||||||
# convert str to class
|
# convert str to class
|
||||||
# for native types
|
if klass in self.NATIVE_TYPES_MAPPING:
|
||||||
if klass in ['int', 'float', 'str', 'bool',
|
klass = self.NATIVE_TYPES_MAPPING[klass]
|
||||||
"date", 'datetime', "object"]:
|
|
||||||
klass = eval(klass)
|
|
||||||
elif klass == 'long':
|
|
||||||
klass = int if PY3 else long
|
|
||||||
# for model types
|
|
||||||
else:
|
else:
|
||||||
klass = eval('models.' + klass)
|
klass = getattr(models, klass)
|
||||||
|
|
||||||
if klass in integer_types or klass in (float, str, bool):
|
if klass in self.PRIMITIVE_TYPES:
|
||||||
return self.__deserialize_primitive(data, klass)
|
return self.__deserialize_primitive(data, klass)
|
||||||
elif klass == object:
|
elif klass == object:
|
||||||
return self.__deserialize_object(data)
|
return self.__deserialize_object(data)
|
||||||
@ -277,7 +279,8 @@ class ApiClient(object):
|
|||||||
path_params=None, query_params=None, header_params=None,
|
path_params=None, query_params=None, header_params=None,
|
||||||
body=None, post_params=None, files=None,
|
body=None, post_params=None, files=None,
|
||||||
response_type=None, auth_settings=None, callback=None,
|
response_type=None, auth_settings=None, callback=None,
|
||||||
_return_http_data_only=None, collection_formats=None):
|
_return_http_data_only=None, collection_formats=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
"""
|
"""
|
||||||
Makes the HTTP request (synchronous) and return the deserialized data.
|
Makes the HTTP request (synchronous) and return the deserialized data.
|
||||||
To make an async request, define a function for callback.
|
To make an async request, define a function for callback.
|
||||||
@ -301,6 +304,10 @@ class ApiClient(object):
|
|||||||
:param _return_http_data_only: response data without head status code and headers
|
:param _return_http_data_only: response data without head status code and headers
|
||||||
:param collection_formats: dict of collection formats for path, query,
|
:param collection_formats: dict of collection formats for path, query,
|
||||||
header, and post parameters.
|
header, and post parameters.
|
||||||
|
:param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
|
||||||
|
reading/decoding response data. Default is True.
|
||||||
|
:param _request_timeout: timeout setting for this request. If one number provided, it will be total request
|
||||||
|
timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
||||||
:return:
|
:return:
|
||||||
If provide parameter callback,
|
If provide parameter callback,
|
||||||
the request will be called asynchronously.
|
the request will be called asynchronously.
|
||||||
@ -313,7 +320,7 @@ class ApiClient(object):
|
|||||||
path_params, query_params, header_params,
|
path_params, query_params, header_params,
|
||||||
body, post_params, files,
|
body, post_params, files,
|
||||||
response_type, auth_settings, callback,
|
response_type, auth_settings, callback,
|
||||||
_return_http_data_only, collection_formats)
|
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
|
||||||
else:
|
else:
|
||||||
thread = threading.Thread(target=self.__call_api,
|
thread = threading.Thread(target=self.__call_api,
|
||||||
args=(resource_path, method,
|
args=(resource_path, method,
|
||||||
@ -322,51 +329,65 @@ class ApiClient(object):
|
|||||||
post_params, files,
|
post_params, files,
|
||||||
response_type, auth_settings,
|
response_type, auth_settings,
|
||||||
callback, _return_http_data_only,
|
callback, _return_http_data_only,
|
||||||
collection_formats))
|
collection_formats, _preload_content, _request_timeout))
|
||||||
thread.start()
|
thread.start()
|
||||||
return thread
|
return thread
|
||||||
|
|
||||||
def request(self, method, url, query_params=None, headers=None,
|
def request(self, method, url, query_params=None, headers=None,
|
||||||
post_params=None, body=None):
|
post_params=None, body=None, _preload_content=True, _request_timeout=None):
|
||||||
"""
|
"""
|
||||||
Makes the HTTP request using RESTClient.
|
Makes the HTTP request using RESTClient.
|
||||||
"""
|
"""
|
||||||
if method == "GET":
|
if method == "GET":
|
||||||
return self.rest_client.GET(url,
|
return self.rest_client.GET(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif method == "HEAD":
|
elif method == "HEAD":
|
||||||
return self.rest_client.HEAD(url,
|
return self.rest_client.HEAD(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif method == "OPTIONS":
|
elif method == "OPTIONS":
|
||||||
return self.rest_client.OPTIONS(url,
|
return self.rest_client.OPTIONS(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "POST":
|
elif method == "POST":
|
||||||
return self.rest_client.POST(url,
|
return self.rest_client.POST(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "PUT":
|
elif method == "PUT":
|
||||||
return self.rest_client.PUT(url,
|
return self.rest_client.PUT(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "PATCH":
|
elif method == "PATCH":
|
||||||
return self.rest_client.PATCH(url,
|
return self.rest_client.PATCH(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
elif method == "DELETE":
|
elif method == "DELETE":
|
||||||
return self.rest_client.DELETE(url,
|
return self.rest_client.DELETE(url,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
else:
|
else:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
@ -443,7 +464,7 @@ class ApiClient(object):
|
|||||||
if not accepts:
|
if not accepts:
|
||||||
return
|
return
|
||||||
|
|
||||||
accepts = list(map(lambda x: x.lower(), accepts))
|
accepts = [x.lower() for x in accepts]
|
||||||
|
|
||||||
if 'application/json' in accepts:
|
if 'application/json' in accepts:
|
||||||
return 'application/json'
|
return 'application/json'
|
||||||
@ -460,9 +481,9 @@ class ApiClient(object):
|
|||||||
if not content_types:
|
if not content_types:
|
||||||
return 'application/json'
|
return 'application/json'
|
||||||
|
|
||||||
content_types = list(map(lambda x: x.lower(), content_types))
|
content_types = [x.lower() for x in content_types]
|
||||||
|
|
||||||
if 'application/json' in content_types:
|
if 'application/json' in content_types or '*/*' in content_types:
|
||||||
return 'application/json'
|
return 'application/json'
|
||||||
else:
|
else:
|
||||||
return content_types[0]
|
return content_types[0]
|
||||||
@ -530,12 +551,11 @@ class ApiClient(object):
|
|||||||
:return: int, long, float, str, bool.
|
:return: int, long, float, str, bool.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
value = klass(data)
|
return klass(data)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
value = unicode(data)
|
return unicode(data)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
value = data
|
return data
|
||||||
return value
|
|
||||||
|
|
||||||
def __deserialize_object(self, value):
|
def __deserialize_object(self, value):
|
||||||
"""
|
"""
|
||||||
@ -560,8 +580,7 @@ class ApiClient(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise ApiException(
|
raise ApiException(
|
||||||
status=0,
|
status=0,
|
||||||
reason="Failed to parse `{0}` into a date object"
|
reason="Failed to parse `{0}` into a date object".format(string)
|
||||||
.format(string)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def __deserialize_datatime(self, string):
|
def __deserialize_datatime(self, string):
|
||||||
@ -581,8 +600,10 @@ class ApiClient(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise ApiException(
|
raise ApiException(
|
||||||
status=0,
|
status=0,
|
||||||
reason="Failed to parse `{0}` into a datetime object".
|
reason=(
|
||||||
format(string)
|
"Failed to parse `{0}` into a datetime object"
|
||||||
|
.format(string)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def __deserialize_model(self, data, klass):
|
def __deserialize_model(self, data, klass):
|
||||||
@ -600,7 +621,7 @@ class ApiClient(object):
|
|||||||
|
|
||||||
for attr, attr_type in iteritems(instance.swagger_types):
|
for attr, attr_type in iteritems(instance.swagger_types):
|
||||||
if data is not None \
|
if data is not None \
|
||||||
and instance.attribute_map[attr] in data\
|
and instance.attribute_map[attr] in data \
|
||||||
and isinstance(data, (list, dict)):
|
and isinstance(data, (list, dict)):
|
||||||
value = data[instance.attribute_map[attr]]
|
value = data[instance.attribute_map[attr]]
|
||||||
setattr(instance, attr, self.__deserialize(value, attr_type))
|
setattr(instance, attr, self.__deserialize(value, attr_type))
|
||||||
|
@ -8,20 +8,9 @@
|
|||||||
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@ -54,8 +43,6 @@ class FakeApi(object):
|
|||||||
def test_code_inject____end__rn_n_r(self, **kwargs):
|
def test_code_inject____end__rn_n_r(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
To test code injection */ ' \" =end -- \\r\\n \\n \\r
|
To test code injection */ ' \" =end -- \\r\\n \\n \\r
|
||||||
|
|
||||||
|
|
||||||
This method makes a synchronous HTTP request by default. To make an
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
asynchronous HTTP request, please define a `callback` function
|
asynchronous HTTP request, please define a `callback` function
|
||||||
to be invoked when receiving the response.
|
to be invoked when receiving the response.
|
||||||
@ -81,8 +68,6 @@ class FakeApi(object):
|
|||||||
def test_code_inject____end__rn_n_r_with_http_info(self, **kwargs):
|
def test_code_inject____end__rn_n_r_with_http_info(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
To test code injection */ ' \" =end -- \\r\\n \\n \\r
|
To test code injection */ ' \" =end -- \\r\\n \\n \\r
|
||||||
|
|
||||||
|
|
||||||
This method makes a synchronous HTTP request by default. To make an
|
This method makes a synchronous HTTP request by default. To make an
|
||||||
asynchronous HTTP request, please define a `callback` function
|
asynchronous HTTP request, please define a `callback` function
|
||||||
to be invoked when receiving the response.
|
to be invoked when receiving the response.
|
||||||
@ -102,6 +87,8 @@ class FakeApi(object):
|
|||||||
all_params = ['test_code_inject____end____rn_n_r']
|
all_params = ['test_code_inject____end____rn_n_r']
|
||||||
all_params.append('callback')
|
all_params.append('callback')
|
||||||
all_params.append('_return_http_data_only')
|
all_params.append('_return_http_data_only')
|
||||||
|
all_params.append('_preload_content')
|
||||||
|
all_params.append('_request_timeout')
|
||||||
|
|
||||||
params = locals()
|
params = locals()
|
||||||
for key, val in iteritems(params['kwargs']):
|
for key, val in iteritems(params['kwargs']):
|
||||||
@ -144,14 +131,16 @@ class FakeApi(object):
|
|||||||
auth_settings = []
|
auth_settings = []
|
||||||
|
|
||||||
return self.api_client.call_api(resource_path, 'PUT',
|
return self.api_client.call_api(resource_path, 'PUT',
|
||||||
path_params,
|
path_params,
|
||||||
query_params,
|
query_params,
|
||||||
header_params,
|
header_params,
|
||||||
body=body_params,
|
body=body_params,
|
||||||
post_params=form_params,
|
post_params=form_params,
|
||||||
files=local_var_files,
|
files=local_var_files,
|
||||||
response_type=None,
|
response_type=None,
|
||||||
auth_settings=auth_settings,
|
auth_settings=auth_settings,
|
||||||
callback=params.get('callback'),
|
callback=params.get('callback'),
|
||||||
_return_http_data_only=params.get('_return_http_data_only'),
|
_return_http_data_only=params.get('_return_http_data_only'),
|
||||||
collection_formats=collection_formats)
|
_preload_content=params.get('_preload_content', True),
|
||||||
|
_request_timeout=params.get('_request_timeout'),
|
||||||
|
collection_formats=collection_formats)
|
||||||
|
@ -8,20 +8,9 @@
|
|||||||
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import urllib3
|
import urllib3
|
||||||
|
@ -8,20 +8,9 @@
|
|||||||
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
# import models into model package
|
# import models into model package
|
||||||
|
@ -8,20 +8,9 @@
|
|||||||
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from six import iteritems
|
from six import iteritems
|
||||||
import re
|
import re
|
||||||
@ -51,7 +40,6 @@ class ModelReturn(object):
|
|||||||
|
|
||||||
self.__return = _return
|
self.__return = _return
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _return(self):
|
def _return(self):
|
||||||
"""
|
"""
|
||||||
|
@ -8,20 +8,9 @@
|
|||||||
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import io
|
import io
|
||||||
@ -69,10 +58,11 @@ class RESTResponse(io.IOBase):
|
|||||||
|
|
||||||
class RESTClientObject(object):
|
class RESTClientObject(object):
|
||||||
|
|
||||||
def __init__(self, pools_size=4):
|
def __init__(self, pools_size=4, maxsize=4):
|
||||||
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
# urllib3.PoolManager will pass all kw parameters to connectionpool
|
||||||
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75
|
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75
|
||||||
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680
|
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680
|
||||||
|
# maxsize is the number of requests to host that are allowed in parallel
|
||||||
# ca_certs vs cert_file vs key_file
|
# ca_certs vs cert_file vs key_file
|
||||||
# http://stackoverflow.com/a/23957365/2985775
|
# http://stackoverflow.com/a/23957365/2985775
|
||||||
|
|
||||||
@ -98,6 +88,7 @@ class RESTClientObject(object):
|
|||||||
# https pool manager
|
# https pool manager
|
||||||
self.pool_manager = urllib3.PoolManager(
|
self.pool_manager = urllib3.PoolManager(
|
||||||
num_pools=pools_size,
|
num_pools=pools_size,
|
||||||
|
maxsize=maxsize,
|
||||||
cert_reqs=cert_reqs,
|
cert_reqs=cert_reqs,
|
||||||
ca_certs=ca_certs,
|
ca_certs=ca_certs,
|
||||||
cert_file=cert_file,
|
cert_file=cert_file,
|
||||||
@ -105,7 +96,7 @@ class RESTClientObject(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def request(self, method, url, query_params=None, headers=None,
|
def request(self, method, url, query_params=None, headers=None,
|
||||||
body=None, post_params=None):
|
body=None, post_params=None, _preload_content=True, _request_timeout=None):
|
||||||
"""
|
"""
|
||||||
:param method: http request method
|
:param method: http request method
|
||||||
:param url: http request url
|
:param url: http request url
|
||||||
@ -115,6 +106,10 @@ class RESTClientObject(object):
|
|||||||
:param post_params: request post parameters,
|
:param post_params: request post parameters,
|
||||||
`application/x-www-form-urlencoded`
|
`application/x-www-form-urlencoded`
|
||||||
and `multipart/form-data`
|
and `multipart/form-data`
|
||||||
|
:param _preload_content: if False, the urllib3.HTTPResponse object will be returned without
|
||||||
|
reading/decoding response data. Default is True.
|
||||||
|
:param _request_timeout: timeout setting for this request. If one number provided, it will be total request
|
||||||
|
timeout. It can also be a pair (tuple) of (connection, read) timeouts.
|
||||||
"""
|
"""
|
||||||
method = method.upper()
|
method = method.upper()
|
||||||
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS']
|
assert method in ['GET', 'HEAD', 'DELETE', 'POST', 'PUT', 'PATCH', 'OPTIONS']
|
||||||
@ -127,6 +122,13 @@ class RESTClientObject(object):
|
|||||||
post_params = post_params or {}
|
post_params = post_params or {}
|
||||||
headers = headers or {}
|
headers = headers or {}
|
||||||
|
|
||||||
|
timeout = None
|
||||||
|
if _request_timeout:
|
||||||
|
if isinstance(_request_timeout, (int, ) if PY3 else (int, long)):
|
||||||
|
timeout = urllib3.Timeout(total=_request_timeout)
|
||||||
|
elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2:
|
||||||
|
timeout = urllib3.Timeout(connect=_request_timeout[0], read=_request_timeout[1])
|
||||||
|
|
||||||
if 'Content-Type' not in headers:
|
if 'Content-Type' not in headers:
|
||||||
headers['Content-Type'] = 'application/json'
|
headers['Content-Type'] = 'application/json'
|
||||||
|
|
||||||
@ -141,11 +143,15 @@ class RESTClientObject(object):
|
|||||||
request_body = json.dumps(body)
|
request_body = json.dumps(body)
|
||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
body=request_body,
|
body=request_body,
|
||||||
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
|
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
|
||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
fields=post_params,
|
fields=post_params,
|
||||||
encode_multipart=False,
|
encode_multipart=False,
|
||||||
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
elif headers['Content-Type'] == 'multipart/form-data':
|
elif headers['Content-Type'] == 'multipart/form-data':
|
||||||
# must del headers['Content-Type'], or the correct Content-Type
|
# must del headers['Content-Type'], or the correct Content-Type
|
||||||
@ -154,6 +160,8 @@ class RESTClientObject(object):
|
|||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
fields=post_params,
|
fields=post_params,
|
||||||
encode_multipart=True,
|
encode_multipart=True,
|
||||||
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
# Pass a `string` parameter directly in the body to support
|
# Pass a `string` parameter directly in the body to support
|
||||||
# other content types than Json when `body` argument is provided
|
# other content types than Json when `body` argument is provided
|
||||||
@ -162,6 +170,8 @@ class RESTClientObject(object):
|
|||||||
request_body = body
|
request_body = body
|
||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
body=request_body,
|
body=request_body,
|
||||||
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
else:
|
else:
|
||||||
# Cannot generate the request from given parameters
|
# Cannot generate the request from given parameters
|
||||||
@ -172,68 +182,89 @@ class RESTClientObject(object):
|
|||||||
else:
|
else:
|
||||||
r = self.pool_manager.request(method, url,
|
r = self.pool_manager.request(method, url,
|
||||||
fields=query_params,
|
fields=query_params,
|
||||||
|
preload_content=_preload_content,
|
||||||
|
timeout=timeout,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
except urllib3.exceptions.SSLError as e:
|
except urllib3.exceptions.SSLError as e:
|
||||||
msg = "{0}\n{1}".format(type(e).__name__, str(e))
|
msg = "{0}\n{1}".format(type(e).__name__, str(e))
|
||||||
raise ApiException(status=0, reason=msg)
|
raise ApiException(status=0, reason=msg)
|
||||||
|
|
||||||
r = RESTResponse(r)
|
if _preload_content:
|
||||||
|
r = RESTResponse(r)
|
||||||
|
|
||||||
# In the python 3, the response.data is bytes.
|
# In the python 3, the response.data is bytes.
|
||||||
# we need to decode it to string.
|
# we need to decode it to string.
|
||||||
if PY3:
|
if PY3:
|
||||||
r.data = r.data.decode('utf8')
|
r.data = r.data.decode('utf8')
|
||||||
|
|
||||||
# log response body
|
# log response body
|
||||||
logger.debug("response body: %s", r.data)
|
logger.debug("response body: %s", r.data)
|
||||||
|
|
||||||
if r.status not in range(200, 206):
|
if r.status not in range(200, 206):
|
||||||
raise ApiException(http_resp=r)
|
raise ApiException(http_resp=r)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def GET(self, url, headers=None, query_params=None):
|
def GET(self, url, headers=None, query_params=None, _preload_content=True, _request_timeout=None):
|
||||||
return self.request("GET", url,
|
return self.request("GET", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
query_params=query_params)
|
query_params=query_params)
|
||||||
|
|
||||||
def HEAD(self, url, headers=None, query_params=None):
|
def HEAD(self, url, headers=None, query_params=None, _preload_content=True, _request_timeout=None):
|
||||||
return self.request("HEAD", url,
|
return self.request("HEAD", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
query_params=query_params)
|
query_params=query_params)
|
||||||
|
|
||||||
def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None):
|
def OPTIONS(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("OPTIONS", url,
|
return self.request("OPTIONS", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def DELETE(self, url, headers=None, query_params=None, body=None):
|
def DELETE(self, url, headers=None, query_params=None, body=None, _preload_content=True, _request_timeout=None):
|
||||||
return self.request("DELETE", url,
|
return self.request("DELETE", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def POST(self, url, headers=None, query_params=None, post_params=None, body=None):
|
def POST(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("POST", url,
|
return self.request("POST", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def PUT(self, url, headers=None, query_params=None, post_params=None, body=None):
|
def PUT(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("PUT", url,
|
return self.request("PUT", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def PATCH(self, url, headers=None, query_params=None, post_params=None, body=None):
|
def PATCH(self, url, headers=None, query_params=None, post_params=None, body=None, _preload_content=True,
|
||||||
|
_request_timeout=None):
|
||||||
return self.request("PATCH", url,
|
return self.request("PATCH", url,
|
||||||
headers=headers,
|
headers=headers,
|
||||||
query_params=query_params,
|
query_params=query_params,
|
||||||
post_params=post_params,
|
post_params=post_params,
|
||||||
|
_preload_content=_preload_content,
|
||||||
|
_request_timeout=_request_timeout,
|
||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,26 +8,14 @@
|
|||||||
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
OpenAPI spec version: 1.0.0 */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
Contact: apiteam@swagger.io */ ' \" =end -- \\r\\n \\n \\r
|
||||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
NAME = "petstore_api"
|
NAME = "petstore_api"
|
||||||
VERSION = "1.0.0"
|
VERSION = "1.0.0"
|
||||||
|
|
||||||
# To install the library, run the following
|
# To install the library, run the following
|
||||||
#
|
#
|
||||||
# python setup.py install
|
# python setup.py install
|
||||||
@ -51,4 +39,3 @@ setup(
|
|||||||
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end --
|
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ */ ' \" =end --
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -105,6 +105,7 @@ Class | Method | HTTP request | Description
|
|||||||
- [ArrayTest](docs/ArrayTest.md)
|
- [ArrayTest](docs/ArrayTest.md)
|
||||||
- [Cat](docs/Cat.md)
|
- [Cat](docs/Cat.md)
|
||||||
- [Category](docs/Category.md)
|
- [Category](docs/Category.md)
|
||||||
|
- [ClassModel](docs/ClassModel.md)
|
||||||
- [Client](docs/Client.md)
|
- [Client](docs/Client.md)
|
||||||
- [Dog](docs/Dog.md)
|
- [Dog](docs/Dog.md)
|
||||||
- [EnumArrays](docs/EnumArrays.md)
|
- [EnumArrays](docs/EnumArrays.md)
|
||||||
|
10
samples/client/petstore/python/docs/ClassModel.md
Normal file
10
samples/client/petstore/python/docs/ClassModel.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# ClassModel
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
Name | Type | Description | Notes
|
||||||
|
------------ | ------------- | ------------- | -------------
|
||||||
|
**_class** | **str** | | [optional]
|
||||||
|
|
||||||
|
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||||
|
|
||||||
|
|
@ -153,7 +153,7 @@ enum_header_string_array = ['enum_header_string_array_example'] # list[str] | He
|
|||||||
enum_header_string = '-efg' # str | Header parameter enum test (string) (optional) (default to -efg)
|
enum_header_string = '-efg' # str | Header parameter enum test (string) (optional) (default to -efg)
|
||||||
enum_query_string_array = ['enum_query_string_array_example'] # list[str] | Query parameter enum test (string array) (optional)
|
enum_query_string_array = ['enum_query_string_array_example'] # list[str] | Query parameter enum test (string array) (optional)
|
||||||
enum_query_string = '-efg' # str | Query parameter enum test (string) (optional) (default to -efg)
|
enum_query_string = '-efg' # str | Query parameter enum test (string) (optional) (default to -efg)
|
||||||
enum_query_integer = 3.4 # float | Query parameter enum test (double) (optional)
|
enum_query_integer = 56 # int | Query parameter enum test (double) (optional)
|
||||||
enum_query_double = 1.2 # float | Query parameter enum test (double) (optional)
|
enum_query_double = 1.2 # float | Query parameter enum test (double) (optional)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -173,7 +173,7 @@ Name | Type | Description | Notes
|
|||||||
**enum_header_string** | **str**| Header parameter enum test (string) | [optional] [default to -efg]
|
**enum_header_string** | **str**| Header parameter enum test (string) | [optional] [default to -efg]
|
||||||
**enum_query_string_array** | [**list[str]**](str.md)| Query parameter enum test (string array) | [optional]
|
**enum_query_string_array** | [**list[str]**](str.md)| Query parameter enum test (string array) | [optional]
|
||||||
**enum_query_string** | **str**| Query parameter enum test (string) | [optional] [default to -efg]
|
**enum_query_string** | **str**| Query parameter enum test (string) | [optional] [default to -efg]
|
||||||
**enum_query_integer** | **float**| Query parameter enum test (double) | [optional]
|
**enum_query_integer** | **int**| Query parameter enum test (double) | [optional]
|
||||||
**enum_query_double** | **float**| Query parameter enum test (double) | [optional]
|
**enum_query_double** | **float**| Query parameter enum test (double) | [optional]
|
||||||
|
|
||||||
### Return type
|
### Return type
|
||||||
|
@ -23,6 +23,7 @@ from .models.array_of_number_only import ArrayOfNumberOnly
|
|||||||
from .models.array_test import ArrayTest
|
from .models.array_test import ArrayTest
|
||||||
from .models.cat import Cat
|
from .models.cat import Cat
|
||||||
from .models.category import Category
|
from .models.category import Category
|
||||||
|
from .models.class_model import ClassModel
|
||||||
from .models.client import Client
|
from .models.client import Client
|
||||||
from .models.dog import Dog
|
from .models.dog import Dog
|
||||||
from .models.enum_arrays import EnumArrays
|
from .models.enum_arrays import EnumArrays
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Swagger Petstore
|
Swagger Petstore
|
||||||
|
|
||||||
@ -10,13 +9,8 @@
|
|||||||
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from . import models
|
|
||||||
from .rest import RESTClientObject
|
|
||||||
from .rest import ApiException
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
@ -24,14 +18,15 @@ import mimetypes
|
|||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import date, datetime
|
||||||
from datetime import date
|
|
||||||
|
|
||||||
# python 2 and python 3 compatibility library
|
# python 2 and python 3 compatibility library
|
||||||
from six import PY3, integer_types, iteritems, text_type
|
from six import PY3, integer_types, iteritems, text_type
|
||||||
from six.moves.urllib.parse import quote
|
from six.moves.urllib.parse import quote
|
||||||
|
|
||||||
|
from . import models
|
||||||
from .configuration import Configuration
|
from .configuration import Configuration
|
||||||
|
from .rest import ApiException, RESTClientObject
|
||||||
|
|
||||||
|
|
||||||
class ApiClient(object):
|
class ApiClient(object):
|
||||||
@ -51,8 +46,20 @@ class ApiClient(object):
|
|||||||
:param header_name: a header to pass when making calls to the API.
|
:param header_name: a header to pass when making calls to the API.
|
||||||
:param header_value: a header value to pass when making calls to the API.
|
:param header_value: a header value to pass when making calls to the API.
|
||||||
"""
|
"""
|
||||||
def __init__(self, host=None, header_name=None, header_value=None, cookie=None):
|
|
||||||
|
|
||||||
|
PRIMITIVE_TYPES = (float, bool, bytes, text_type) + integer_types
|
||||||
|
NATIVE_TYPES_MAPPING = {
|
||||||
|
'int': int,
|
||||||
|
'long': int if PY3 else long,
|
||||||
|
'float': float,
|
||||||
|
'str': str,
|
||||||
|
'bool': bool,
|
||||||
|
'date': date,
|
||||||
|
'datetime': datetime,
|
||||||
|
'object': object,
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, host=None, header_name=None, header_value=None, cookie=None):
|
||||||
"""
|
"""
|
||||||
Constructor of the class.
|
Constructor of the class.
|
||||||
"""
|
"""
|
||||||
@ -153,7 +160,10 @@ class ApiClient(object):
|
|||||||
return_data = None
|
return_data = None
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
callback(return_data) if _return_http_data_only else callback((return_data, response_data.status, response_data.getheaders()))
|
if _return_http_data_only:
|
||||||
|
callback(return_data)
|
||||||
|
else:
|
||||||
|
callback((return_data, response_data.status, response_data.getheaders()))
|
||||||
elif _return_http_data_only:
|
elif _return_http_data_only:
|
||||||
return (return_data)
|
return (return_data)
|
||||||
else:
|
else:
|
||||||
@ -174,10 +184,9 @@ class ApiClient(object):
|
|||||||
:param obj: The data to serialize.
|
:param obj: The data to serialize.
|
||||||
:return: The serialized form of data.
|
:return: The serialized form of data.
|
||||||
"""
|
"""
|
||||||
types = (str, float, bool, bytes) + tuple(integer_types) + (text_type,)
|
if obj is None:
|
||||||
if isinstance(obj, type(None)):
|
|
||||||
return None
|
return None
|
||||||
elif isinstance(obj, types):
|
elif isinstance(obj, self.PRIMITIVE_TYPES):
|
||||||
return obj
|
return obj
|
||||||
elif isinstance(obj, list):
|
elif isinstance(obj, list):
|
||||||
return [self.sanitize_for_serialization(sub_obj)
|
return [self.sanitize_for_serialization(sub_obj)
|
||||||
@ -187,21 +196,21 @@ class ApiClient(object):
|
|||||||
for sub_obj in obj)
|
for sub_obj in obj)
|
||||||
elif isinstance(obj, (datetime, date)):
|
elif isinstance(obj, (datetime, date)):
|
||||||
return obj.isoformat()
|
return obj.isoformat()
|
||||||
else:
|
|
||||||
if isinstance(obj, dict):
|
|
||||||
obj_dict = obj
|
|
||||||
else:
|
|
||||||
# Convert model obj to dict except
|
|
||||||
# attributes `swagger_types`, `attribute_map`
|
|
||||||
# and attributes which value is not None.
|
|
||||||
# Convert attribute name to json key in
|
|
||||||
# model definition for request.
|
|
||||||
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
|
|
||||||
for attr, _ in iteritems(obj.swagger_types)
|
|
||||||
if getattr(obj, attr) is not None}
|
|
||||||
|
|
||||||
return {key: self.sanitize_for_serialization(val)
|
if isinstance(obj, dict):
|
||||||
for key, val in iteritems(obj_dict)}
|
obj_dict = obj
|
||||||
|
else:
|
||||||
|
# Convert model obj to dict except
|
||||||
|
# attributes `swagger_types`, `attribute_map`
|
||||||
|
# and attributes which value is not None.
|
||||||
|
# Convert attribute name to json key in
|
||||||
|
# model definition for request.
|
||||||
|
obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
|
||||||
|
for attr, _ in iteritems(obj.swagger_types)
|
||||||
|
if getattr(obj, attr) is not None}
|
||||||
|
|
||||||
|
return {key: self.sanitize_for_serialization(val)
|
||||||
|
for key, val in iteritems(obj_dict)}
|
||||||
|
|
||||||
def deserialize(self, response, response_type):
|
def deserialize(self, response, response_type):
|
||||||
"""
|
"""
|
||||||
@ -215,7 +224,7 @@ class ApiClient(object):
|
|||||||
"""
|
"""
|
||||||
# handle file downloading
|
# handle file downloading
|
||||||
# save response body into a tmp file and return the instance
|
# save response body into a tmp file and return the instance
|
||||||
if "file" == response_type:
|
if response_type == "file":
|
||||||
return self.__deserialize_file(response)
|
return self.__deserialize_file(response)
|
||||||
|
|
||||||
# fetch data from response object
|
# fetch data from response object
|
||||||
@ -250,17 +259,12 @@ class ApiClient(object):
|
|||||||
for k, v in iteritems(data)}
|
for k, v in iteritems(data)}
|
||||||
|
|
||||||
# convert str to class
|
# convert str to class
|
||||||
# for native types
|
if klass in self.NATIVE_TYPES_MAPPING:
|
||||||
if klass in ['int', 'float', 'str', 'bool',
|
klass = self.NATIVE_TYPES_MAPPING[klass]
|
||||||
"date", 'datetime', "object"]:
|
|
||||||
klass = eval(klass)
|
|
||||||
elif klass == 'long':
|
|
||||||
klass = int if PY3 else long
|
|
||||||
# for model types
|
|
||||||
else:
|
else:
|
||||||
klass = eval('models.' + klass)
|
klass = getattr(models, klass)
|
||||||
|
|
||||||
if klass in integer_types or klass in (float, str, bool):
|
if klass in self.PRIMITIVE_TYPES:
|
||||||
return self.__deserialize_primitive(data, klass)
|
return self.__deserialize_primitive(data, klass)
|
||||||
elif klass == object:
|
elif klass == object:
|
||||||
return self.__deserialize_object(data)
|
return self.__deserialize_object(data)
|
||||||
@ -460,7 +464,7 @@ class ApiClient(object):
|
|||||||
if not accepts:
|
if not accepts:
|
||||||
return
|
return
|
||||||
|
|
||||||
accepts = list(map(lambda x: x.lower(), accepts))
|
accepts = [x.lower() for x in accepts]
|
||||||
|
|
||||||
if 'application/json' in accepts:
|
if 'application/json' in accepts:
|
||||||
return 'application/json'
|
return 'application/json'
|
||||||
@ -477,7 +481,7 @@ class ApiClient(object):
|
|||||||
if not content_types:
|
if not content_types:
|
||||||
return 'application/json'
|
return 'application/json'
|
||||||
|
|
||||||
content_types = list(map(lambda x: x.lower(), content_types))
|
content_types = [x.lower() for x in content_types]
|
||||||
|
|
||||||
if 'application/json' in content_types or '*/*' in content_types:
|
if 'application/json' in content_types or '*/*' in content_types:
|
||||||
return 'application/json'
|
return 'application/json'
|
||||||
@ -547,12 +551,11 @@ class ApiClient(object):
|
|||||||
:return: int, long, float, str, bool.
|
:return: int, long, float, str, bool.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
value = klass(data)
|
return klass(data)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
value = unicode(data)
|
return unicode(data)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
value = data
|
return data
|
||||||
return value
|
|
||||||
|
|
||||||
def __deserialize_object(self, value):
|
def __deserialize_object(self, value):
|
||||||
"""
|
"""
|
||||||
@ -577,8 +580,7 @@ class ApiClient(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise ApiException(
|
raise ApiException(
|
||||||
status=0,
|
status=0,
|
||||||
reason="Failed to parse `{0}` into a date object"
|
reason="Failed to parse `{0}` into a date object".format(string)
|
||||||
.format(string)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def __deserialize_datatime(self, string):
|
def __deserialize_datatime(self, string):
|
||||||
@ -598,8 +600,10 @@ class ApiClient(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
raise ApiException(
|
raise ApiException(
|
||||||
status=0,
|
status=0,
|
||||||
reason="Failed to parse `{0}` into a datetime object".
|
reason=(
|
||||||
format(string)
|
"Failed to parse `{0}` into a datetime object"
|
||||||
|
.format(string)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def __deserialize_model(self, data, klass):
|
def __deserialize_model(self, data, klass):
|
||||||
@ -617,7 +621,7 @@ class ApiClient(object):
|
|||||||
|
|
||||||
for attr, attr_type in iteritems(instance.swagger_types):
|
for attr, attr_type in iteritems(instance.swagger_types):
|
||||||
if data is not None \
|
if data is not None \
|
||||||
and instance.attribute_map[attr] in data\
|
and instance.attribute_map[attr] in data \
|
||||||
and isinstance(data, (list, dict)):
|
and isinstance(data, (list, dict)):
|
||||||
value = data[instance.attribute_map[attr]]
|
value = data[instance.attribute_map[attr]]
|
||||||
setattr(instance, attr, self.__deserialize(value, attr_type))
|
setattr(instance, attr, self.__deserialize(value, attr_type))
|
||||||
|
@ -258,14 +258,14 @@ class FakeApi(object):
|
|||||||
raise ValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value greater than or equal to `67.8`")
|
raise ValueError("Invalid value for parameter `double` when calling `test_endpoint_parameters`, must be a value greater than or equal to `67.8`")
|
||||||
if 'pattern_without_delimiter' in params and not re.search('^[A-Z].*', params['pattern_without_delimiter']):
|
if 'pattern_without_delimiter' in params and not re.search('^[A-Z].*', params['pattern_without_delimiter']):
|
||||||
raise ValueError("Invalid value for parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`, must conform to the pattern `/^[A-Z].*/`")
|
raise ValueError("Invalid value for parameter `pattern_without_delimiter` when calling `test_endpoint_parameters`, must conform to the pattern `/^[A-Z].*/`")
|
||||||
if 'integer' in params and params['integer'] > 100.0:
|
if 'integer' in params and params['integer'] > 100:
|
||||||
raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value less than or equal to `100.0`")
|
raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value less than or equal to `100`")
|
||||||
if 'integer' in params and params['integer'] < 10.0:
|
if 'integer' in params and params['integer'] < 10:
|
||||||
raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value greater than or equal to `10.0`")
|
raise ValueError("Invalid value for parameter `integer` when calling `test_endpoint_parameters`, must be a value greater than or equal to `10`")
|
||||||
if 'int32' in params and params['int32'] > 200.0:
|
if 'int32' in params and params['int32'] > 200:
|
||||||
raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value less than or equal to `200.0`")
|
raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value less than or equal to `200`")
|
||||||
if 'int32' in params and params['int32'] < 20.0:
|
if 'int32' in params and params['int32'] < 20:
|
||||||
raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value greater than or equal to `20.0`")
|
raise ValueError("Invalid value for parameter `int32` when calling `test_endpoint_parameters`, must be a value greater than or equal to `20`")
|
||||||
if 'float' in params and params['float'] > 987.6:
|
if 'float' in params and params['float'] > 987.6:
|
||||||
raise ValueError("Invalid value for parameter `float` when calling `test_endpoint_parameters`, must be a value less than or equal to `987.6`")
|
raise ValueError("Invalid value for parameter `float` when calling `test_endpoint_parameters`, must be a value less than or equal to `987.6`")
|
||||||
if 'string' in params and not re.search('[a-z]', params['string'], flags=re.IGNORECASE):
|
if 'string' in params and not re.search('[a-z]', params['string'], flags=re.IGNORECASE):
|
||||||
@ -364,7 +364,7 @@ class FakeApi(object):
|
|||||||
:param str enum_header_string: Header parameter enum test (string)
|
:param str enum_header_string: Header parameter enum test (string)
|
||||||
:param list[str] enum_query_string_array: Query parameter enum test (string array)
|
:param list[str] enum_query_string_array: Query parameter enum test (string array)
|
||||||
:param str enum_query_string: Query parameter enum test (string)
|
:param str enum_query_string: Query parameter enum test (string)
|
||||||
:param float enum_query_integer: Query parameter enum test (double)
|
:param int enum_query_integer: Query parameter enum test (double)
|
||||||
:param float enum_query_double: Query parameter enum test (double)
|
:param float enum_query_double: Query parameter enum test (double)
|
||||||
:return: None
|
:return: None
|
||||||
If the method is called asynchronously,
|
If the method is called asynchronously,
|
||||||
@ -396,7 +396,7 @@ class FakeApi(object):
|
|||||||
:param str enum_header_string: Header parameter enum test (string)
|
:param str enum_header_string: Header parameter enum test (string)
|
||||||
:param list[str] enum_query_string_array: Query parameter enum test (string array)
|
:param list[str] enum_query_string_array: Query parameter enum test (string array)
|
||||||
:param str enum_query_string: Query parameter enum test (string)
|
:param str enum_query_string: Query parameter enum test (string)
|
||||||
:param float enum_query_integer: Query parameter enum test (double)
|
:param int enum_query_integer: Query parameter enum test (double)
|
||||||
:param float enum_query_double: Query parameter enum test (double)
|
:param float enum_query_double: Query parameter enum test (double)
|
||||||
:return: None
|
:return: None
|
||||||
If the method is called asynchronously,
|
If the method is called asynchronously,
|
||||||
|
@ -319,10 +319,10 @@ class StoreApi(object):
|
|||||||
if ('order_id' not in params) or (params['order_id'] is None):
|
if ('order_id' not in params) or (params['order_id'] is None):
|
||||||
raise ValueError("Missing the required parameter `order_id` when calling `get_order_by_id`")
|
raise ValueError("Missing the required parameter `order_id` when calling `get_order_by_id`")
|
||||||
|
|
||||||
if 'order_id' in params and params['order_id'] > 5.0:
|
if 'order_id' in params and params['order_id'] > 5:
|
||||||
raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value less than or equal to `5.0`")
|
raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value less than or equal to `5`")
|
||||||
if 'order_id' in params and params['order_id'] < 1.0:
|
if 'order_id' in params and params['order_id'] < 1:
|
||||||
raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value greater than or equal to `1.0`")
|
raise ValueError("Invalid value for parameter `order_id` when calling `get_order_by_id`, must be a value greater than or equal to `1`")
|
||||||
|
|
||||||
collection_formats = {}
|
collection_formats = {}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ from .array_of_number_only import ArrayOfNumberOnly
|
|||||||
from .array_test import ArrayTest
|
from .array_test import ArrayTest
|
||||||
from .cat import Cat
|
from .cat import Cat
|
||||||
from .category import Category
|
from .category import Category
|
||||||
|
from .class_model import ClassModel
|
||||||
from .client import Client
|
from .client import Client
|
||||||
from .dog import Dog
|
from .dog import Dog
|
||||||
from .enum_arrays import EnumArrays
|
from .enum_arrays import EnumArrays
|
||||||
|
@ -0,0 +1,112 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Swagger Petstore
|
||||||
|
|
||||||
|
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||||
|
|
||||||
|
OpenAPI spec version: 1.0.0
|
||||||
|
Contact: apiteam@swagger.io
|
||||||
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from pprint import pformat
|
||||||
|
from six import iteritems
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class ClassModel(object):
|
||||||
|
"""
|
||||||
|
NOTE: This class is auto generated by the swagger code generator program.
|
||||||
|
Do not edit the class manually.
|
||||||
|
"""
|
||||||
|
def __init__(self, _class=None):
|
||||||
|
"""
|
||||||
|
ClassModel - a model defined in Swagger
|
||||||
|
|
||||||
|
:param dict swaggerTypes: The key is attribute name
|
||||||
|
and the value is attribute type.
|
||||||
|
:param dict attributeMap: The key is attribute name
|
||||||
|
and the value is json key in definition.
|
||||||
|
"""
|
||||||
|
self.swagger_types = {
|
||||||
|
'_class': 'str'
|
||||||
|
}
|
||||||
|
|
||||||
|
self.attribute_map = {
|
||||||
|
'_class': '_class'
|
||||||
|
}
|
||||||
|
|
||||||
|
self.__class = _class
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _class(self):
|
||||||
|
"""
|
||||||
|
Gets the _class of this ClassModel.
|
||||||
|
|
||||||
|
:return: The _class of this ClassModel.
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
|
return self.__class
|
||||||
|
|
||||||
|
@_class.setter
|
||||||
|
def _class(self, _class):
|
||||||
|
"""
|
||||||
|
Sets the _class of this ClassModel.
|
||||||
|
|
||||||
|
:param _class: The _class of this ClassModel.
|
||||||
|
:type: str
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.__class = _class
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
"""
|
||||||
|
Returns the model properties as a dict
|
||||||
|
"""
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
for attr, _ in iteritems(self.swagger_types):
|
||||||
|
value = getattr(self, attr)
|
||||||
|
if isinstance(value, list):
|
||||||
|
result[attr] = list(map(
|
||||||
|
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
|
||||||
|
value
|
||||||
|
))
|
||||||
|
elif hasattr(value, "to_dict"):
|
||||||
|
result[attr] = value.to_dict()
|
||||||
|
elif isinstance(value, dict):
|
||||||
|
result[attr] = dict(map(
|
||||||
|
lambda item: (item[0], item[1].to_dict())
|
||||||
|
if hasattr(item[1], "to_dict") else item,
|
||||||
|
value.items()
|
||||||
|
))
|
||||||
|
else:
|
||||||
|
result[attr] = value
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def to_str(self):
|
||||||
|
"""
|
||||||
|
Returns the string representation of the model
|
||||||
|
"""
|
||||||
|
return pformat(self.to_dict())
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
"""
|
||||||
|
For `print` and `pprint`
|
||||||
|
"""
|
||||||
|
return self.to_str()
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
"""
|
||||||
|
Returns true if both objects are equal
|
||||||
|
"""
|
||||||
|
return self.__dict__ == other.__dict__
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
"""
|
||||||
|
Returns true if both objects are not equal
|
||||||
|
"""
|
||||||
|
return not self == other
|
@ -94,10 +94,10 @@ class FormatTest(object):
|
|||||||
:param integer: The integer of this FormatTest.
|
:param integer: The integer of this FormatTest.
|
||||||
:type: int
|
:type: int
|
||||||
"""
|
"""
|
||||||
if integer is not None and integer > 100.0:
|
if integer is not None and integer > 100:
|
||||||
raise ValueError("Invalid value for `integer`, must be a value less than or equal to `100.0`")
|
raise ValueError("Invalid value for `integer`, must be a value less than or equal to `100`")
|
||||||
if integer is not None and integer < 10.0:
|
if integer is not None and integer < 10:
|
||||||
raise ValueError("Invalid value for `integer`, must be a value greater than or equal to `10.0`")
|
raise ValueError("Invalid value for `integer`, must be a value greater than or equal to `10`")
|
||||||
|
|
||||||
self._integer = integer
|
self._integer = integer
|
||||||
|
|
||||||
@ -119,10 +119,10 @@ class FormatTest(object):
|
|||||||
:param int32: The int32 of this FormatTest.
|
:param int32: The int32 of this FormatTest.
|
||||||
:type: int
|
:type: int
|
||||||
"""
|
"""
|
||||||
if int32 is not None and int32 > 200.0:
|
if int32 is not None and int32 > 200:
|
||||||
raise ValueError("Invalid value for `int32`, must be a value less than or equal to `200.0`")
|
raise ValueError("Invalid value for `int32`, must be a value less than or equal to `200`")
|
||||||
if int32 is not None and int32 < 20.0:
|
if int32 is not None and int32 < 20:
|
||||||
raise ValueError("Invalid value for `int32`, must be a value greater than or equal to `20.0`")
|
raise ValueError("Invalid value for `int32`, must be a value greater than or equal to `20`")
|
||||||
|
|
||||||
self._int32 = int32
|
self._int32 = int32
|
||||||
|
|
||||||
|
42
samples/client/petstore/python/test/test_class_model.py
Normal file
42
samples/client/petstore/python/test/test_class_model.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Swagger Petstore
|
||||||
|
|
||||||
|
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
|
||||||
|
|
||||||
|
OpenAPI spec version: 1.0.0
|
||||||
|
Contact: apiteam@swagger.io
|
||||||
|
Generated by: https://github.com/swagger-api/swagger-codegen.git
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import petstore_api
|
||||||
|
from petstore_api.rest import ApiException
|
||||||
|
from petstore_api.models.class_model import ClassModel
|
||||||
|
|
||||||
|
|
||||||
|
class TestClassModel(unittest.TestCase):
|
||||||
|
""" ClassModel unit test stubs """
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def testClassModel(self):
|
||||||
|
"""
|
||||||
|
Test ClassModel
|
||||||
|
"""
|
||||||
|
model = petstore_api.models.class_model.ClassModel()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user