forked from loafle/openapi-generator-original
fix for issue 567, added reserved words, rebuilt client
This commit is contained in:
parent
92621f2f2d
commit
492ab20c00
@ -15,12 +15,17 @@ Copyright 2015 Reverb Technologies, Inc.
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Category:
|
class Category(object):
|
||||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||||
Do not edit the class manually."""
|
Do not edit the class manually."""
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
swaggerTypes (dict): The key is attribute name and the value is attribute type.
|
||||||
|
attributeMap (dict): The key is attribute name and the value is json key in definition.
|
||||||
|
"""
|
||||||
self.swaggerTypes = {
|
self.swaggerTypes = {
|
||||||
|
|
||||||
'id': 'long',
|
'id': 'long',
|
||||||
@ -30,6 +35,13 @@ class Category:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.attributeMap = {
|
||||||
|
|
||||||
|
'id': 'id',
|
||||||
|
|
||||||
|
'name': 'name'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,12 +15,17 @@ Copyright 2015 Reverb Technologies, Inc.
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Order:
|
class Order(object):
|
||||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||||
Do not edit the class manually."""
|
Do not edit the class manually."""
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
swaggerTypes (dict): The key is attribute name and the value is attribute type.
|
||||||
|
attributeMap (dict): The key is attribute name and the value is json key in definition.
|
||||||
|
"""
|
||||||
self.swaggerTypes = {
|
self.swaggerTypes = {
|
||||||
|
|
||||||
'id': 'long',
|
'id': 'long',
|
||||||
@ -42,6 +47,21 @@ class Order:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.attributeMap = {
|
||||||
|
|
||||||
|
'id': 'id',
|
||||||
|
|
||||||
|
'petId': 'petId',
|
||||||
|
|
||||||
|
'quantity': 'quantity',
|
||||||
|
|
||||||
|
'shipDate': 'shipDate',
|
||||||
|
|
||||||
|
'status': 'status',
|
||||||
|
|
||||||
|
'complete': 'complete'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,12 +15,17 @@ Copyright 2015 Reverb Technologies, Inc.
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Pet:
|
class Pet(object):
|
||||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||||
Do not edit the class manually."""
|
Do not edit the class manually."""
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
swaggerTypes (dict): The key is attribute name and the value is attribute type.
|
||||||
|
attributeMap (dict): The key is attribute name and the value is json key in definition.
|
||||||
|
"""
|
||||||
self.swaggerTypes = {
|
self.swaggerTypes = {
|
||||||
|
|
||||||
'id': 'long',
|
'id': 'long',
|
||||||
@ -42,6 +47,21 @@ class Pet:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.attributeMap = {
|
||||||
|
|
||||||
|
'id': 'id',
|
||||||
|
|
||||||
|
'category': 'category',
|
||||||
|
|
||||||
|
'name': 'name',
|
||||||
|
|
||||||
|
'photoUrls': 'photoUrls',
|
||||||
|
|
||||||
|
'tags': 'tags',
|
||||||
|
|
||||||
|
'status': 'status'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,12 +15,17 @@ Copyright 2015 Reverb Technologies, Inc.
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Tag:
|
class Tag(object):
|
||||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||||
Do not edit the class manually."""
|
Do not edit the class manually."""
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
swaggerTypes (dict): The key is attribute name and the value is attribute type.
|
||||||
|
attributeMap (dict): The key is attribute name and the value is json key in definition.
|
||||||
|
"""
|
||||||
self.swaggerTypes = {
|
self.swaggerTypes = {
|
||||||
|
|
||||||
'id': 'long',
|
'id': 'long',
|
||||||
@ -30,6 +35,13 @@ class Tag:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.attributeMap = {
|
||||||
|
|
||||||
|
'id': 'id',
|
||||||
|
|
||||||
|
'name': 'name'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,12 +15,17 @@ Copyright 2015 Reverb Technologies, Inc.
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class User:
|
class User(object):
|
||||||
"""NOTE: This class is auto generated by the swagger code generator program.
|
"""NOTE: This class is auto generated by the swagger code generator program.
|
||||||
Do not edit the class manually."""
|
Do not edit the class manually."""
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Attributes:
|
||||||
|
swaggerTypes (dict): The key is attribute name and the value is attribute type.
|
||||||
|
attributeMap (dict): The key is attribute name and the value is json key in definition.
|
||||||
|
"""
|
||||||
self.swaggerTypes = {
|
self.swaggerTypes = {
|
||||||
|
|
||||||
'id': 'long',
|
'id': 'long',
|
||||||
@ -48,6 +53,25 @@ class User:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.attributeMap = {
|
||||||
|
|
||||||
|
'id': 'id',
|
||||||
|
|
||||||
|
'username': 'username',
|
||||||
|
|
||||||
|
'firstName': 'firstName',
|
||||||
|
|
||||||
|
'lastName': 'lastName',
|
||||||
|
|
||||||
|
'email': 'email',
|
||||||
|
|
||||||
|
'password': 'password',
|
||||||
|
|
||||||
|
'phone': 'phone',
|
||||||
|
|
||||||
|
'userStatus': 'userStatus'
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import string
|
|||||||
from models import *
|
from models import *
|
||||||
|
|
||||||
|
|
||||||
class ApiClient:
|
class ApiClient(object):
|
||||||
"""Generic API client for Swagger client library builds
|
"""Generic API client for Swagger client library builds
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
@ -41,13 +41,13 @@ class ApiClient:
|
|||||||
headers = {}
|
headers = {}
|
||||||
if headerParams:
|
if headerParams:
|
||||||
for param, value in headerParams.iteritems():
|
for param, value in headerParams.iteritems():
|
||||||
headers[param] = value
|
headers[param] = ApiClient.sanitizeForSerialization(value)
|
||||||
|
|
||||||
if self.headerName:
|
if self.headerName:
|
||||||
headers[self.headerName] = self.headerValue
|
headers[self.headerName] = ApiClient.sanitizeForSerialization(self.headerValue)
|
||||||
|
|
||||||
if self.cookie:
|
if self.cookie:
|
||||||
headers['Cookie'] = self.cookie
|
headers['Cookie'] = ApiClient.sanitizeForSerialization(self.cookie)
|
||||||
|
|
||||||
data = None
|
data = None
|
||||||
|
|
||||||
@ -55,8 +55,8 @@ class ApiClient:
|
|||||||
# Need to remove None values, these should not be sent
|
# Need to remove None values, these should not be sent
|
||||||
sentQueryParams = {}
|
sentQueryParams = {}
|
||||||
for param, value in queryParams.items():
|
for param, value in queryParams.items():
|
||||||
if value != None:
|
if value is not None:
|
||||||
sentQueryParams[param] = value
|
sentQueryParams[param] = ApiClient.sanitizeForSerialization(value)
|
||||||
url = url + '?' + urllib.urlencode(sentQueryParams)
|
url = url + '?' + urllib.urlencode(sentQueryParams)
|
||||||
|
|
||||||
if method in ['GET']:
|
if method in ['GET']:
|
||||||
@ -65,7 +65,7 @@ class ApiClient:
|
|||||||
|
|
||||||
elif method in ['POST', 'PUT', 'DELETE']:
|
elif method in ['POST', 'PUT', 'DELETE']:
|
||||||
if postData:
|
if postData:
|
||||||
postData = self.sanitizeForSerialization(postData)
|
postData = ApiClient.sanitizeForSerialization(postData)
|
||||||
if 'Content-type' not in headers:
|
if 'Content-type' not in headers:
|
||||||
headers['Content-type'] = 'application/json'
|
headers['Content-type'] = 'application/json'
|
||||||
data = json.dumps(postData)
|
data = json.dumps(postData)
|
||||||
@ -107,34 +107,38 @@ class ApiClient:
|
|||||||
else:
|
else:
|
||||||
return urllib.quote(str(obj))
|
return urllib.quote(str(obj))
|
||||||
|
|
||||||
def sanitizeForSerialization(self, obj):
|
@staticmethod
|
||||||
"""Dump an object into JSON for POSTing."""
|
def sanitizeForSerialization(obj):
|
||||||
|
"""
|
||||||
|
Sanitize an object for Request.
|
||||||
|
|
||||||
if type(obj) == type(None):
|
If obj is None, return None.
|
||||||
|
If obj is str, int, long, float, bool, return directly.
|
||||||
|
If obj is datetime.datetime, datetime.date convert to string in iso8601 format.
|
||||||
|
If obj is list, santize each element in the list.
|
||||||
|
If obj is dict, return the dict.
|
||||||
|
If obj is swagger model, return the properties dict.
|
||||||
|
"""
|
||||||
|
if isinstance(obj, type(None)):
|
||||||
return None
|
return None
|
||||||
elif type(obj) in [str, int, long, float, bool]:
|
elif isinstance(obj, (str, int, long, float, bool, file)):
|
||||||
return obj
|
return obj
|
||||||
elif type(obj) == list:
|
elif isinstance(obj, list):
|
||||||
return [self.sanitizeForSerialization(subObj) for subObj in obj]
|
return [ApiClient.sanitizeForSerialization(subObj) for subObj in obj]
|
||||||
elif type(obj) == datetime.datetime:
|
elif isinstance(obj, (datetime.datetime, datetime.date)):
|
||||||
return obj.isoformat()
|
return obj.isoformat()
|
||||||
else:
|
else:
|
||||||
if type(obj) == dict:
|
if isinstance(obj, dict):
|
||||||
objDict = obj
|
objDict = obj
|
||||||
else:
|
else:
|
||||||
objDict = obj.__dict__
|
# Convert model obj to dict except attributes `swaggerTypes`, `attributeMap`
|
||||||
return {key: self.sanitizeForSerialization(val)
|
# and attributes which value is not None.
|
||||||
for (key, val) in objDict.iteritems()
|
# Convert attribute name to json key in model definition for request.
|
||||||
if key != 'swaggerTypes'}
|
objDict = {obj.attributeMap[key]: val
|
||||||
|
for key, val in obj.__dict__.iteritems()
|
||||||
if type(postData) == list:
|
if key != 'swaggerTypes' and key != 'attributeMap' and val is not None}
|
||||||
# Could be a list of objects
|
return {key: ApiClient.sanitizeForSerialization(val)
|
||||||
if type(postData[0]) in safeToDump:
|
for (key, val) in objDict.iteritems()}
|
||||||
data = json.dumps(postData)
|
|
||||||
else:
|
|
||||||
data = json.dumps([datum.__dict__ for datum in postData])
|
|
||||||
elif type(postData) not in safeToDump:
|
|
||||||
data = json.dumps(postData.__dict__)
|
|
||||||
|
|
||||||
def buildMultipartFormData(self, postData, files):
|
def buildMultipartFormData(self, postData, files):
|
||||||
def escape_quotes(s):
|
def escape_quotes(s):
|
||||||
@ -194,16 +198,13 @@ class ApiClient:
|
|||||||
if objClass in [int, long, float, dict, list, str, bool]:
|
if objClass in [int, long, float, dict, list, str, bool]:
|
||||||
return objClass(obj)
|
return objClass(obj)
|
||||||
elif objClass == datetime:
|
elif objClass == datetime:
|
||||||
# Server will always return a time stamp in UTC, but with
|
return self.__parse_string_to_datetime(obj)
|
||||||
# trailing +0000 indicating no offset from UTC. So don't process
|
|
||||||
# last 5 characters.
|
|
||||||
return datetime.datetime.strptime(obj[:-5], "%Y-%m-%dT%H:%M:%S.%f")
|
|
||||||
|
|
||||||
instance = objClass()
|
instance = objClass()
|
||||||
|
|
||||||
for attr, attrType in instance.swaggerTypes.iteritems():
|
for attr, attrType in instance.swaggerTypes.iteritems():
|
||||||
if obj is not None and attr in obj and type(obj) in [list, dict]:
|
if obj is not None and instance.attributeMap[attr] in obj and type(obj) in [list, dict]:
|
||||||
value = obj[attr]
|
value = obj[instance.attributeMap[attr]]
|
||||||
if attrType in ['str', 'int', 'long', 'float', 'bool']:
|
if attrType in ['str', 'int', 'long', 'float', 'bool']:
|
||||||
attrType = eval(attrType)
|
attrType = eval(attrType)
|
||||||
try:
|
try:
|
||||||
@ -214,7 +215,7 @@ class ApiClient:
|
|||||||
value = value
|
value = value
|
||||||
setattr(instance, attr, value)
|
setattr(instance, attr, value)
|
||||||
elif (attrType == 'datetime'):
|
elif (attrType == 'datetime'):
|
||||||
setattr(instance, attr, datetime.datetime.strptime(value[:-5], "%Y-%m-%dT%H:%M:%S.%f"))
|
setattr(instance, attr, self.__parse_string_to_datetime(value))
|
||||||
elif 'list[' in attrType:
|
elif 'list[' in attrType:
|
||||||
match = re.match('list\[(.*)\]', attrType)
|
match = re.match('list\[(.*)\]', attrType)
|
||||||
subClass = match.group(1)
|
subClass = match.group(1)
|
||||||
@ -226,10 +227,21 @@ class ApiClient:
|
|||||||
subValues.append(self.deserialize(subValue, subClass))
|
subValues.append(self.deserialize(subValue, subClass))
|
||||||
setattr(instance, attr, subValues)
|
setattr(instance, attr, subValues)
|
||||||
else:
|
else:
|
||||||
setattr(instance, attr, self.deserialize(value, objClass))
|
setattr(instance, attr, self.deserialize(value, attrType))
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
def __parse_string_to_datetime(self, string):
|
||||||
|
"""
|
||||||
|
Parse datetime in string to datetime.
|
||||||
|
|
||||||
|
The string should be in iso8601 datetime format.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
from dateutil.parser import parse
|
||||||
|
return parse(string)
|
||||||
|
except ImportError:
|
||||||
|
return string
|
||||||
|
|
||||||
class MethodRequest(urllib2.Request):
|
class MethodRequest(urllib2.Request):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -243,4 +255,4 @@ class MethodRequest(urllib2.Request):
|
|||||||
return urllib2.Request.__init__(self, *args, **kwargs)
|
return urllib2.Request.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
def get_method(self):
|
def get_method(self):
|
||||||
return getattr(self, 'method', urllib2.Request.get_method(self))
|
return getattr(self, 'method', urllib2.Request.get_method(self))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user