mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 11:23:58 +00:00
better escaping for path parameters
This commit is contained in:
parent
93c0134da9
commit
29cec989b2
@ -81,16 +81,16 @@ class ApiClient:
|
||||
return data
|
||||
|
||||
def toPathValue(self, obj):
|
||||
"""Serialize a list to a CSV string, if necessary.
|
||||
"""Convert a string or object to a path-friendly value
|
||||
Args:
|
||||
obj -- data object to be serialized
|
||||
obj -- object or string value
|
||||
Returns:
|
||||
string -- json serialization of object
|
||||
string -- quoted value
|
||||
"""
|
||||
if type(obj) == list:
|
||||
return ','.join(obj)
|
||||
return urllib.quote(','.join(obj))
|
||||
else:
|
||||
return obj
|
||||
return urllib.quote(str(obj))
|
||||
|
||||
def sanitizeForSerialization(self, obj):
|
||||
"""Dump an object into JSON for POSTing."""
|
||||
@ -139,12 +139,12 @@ class ApiClient:
|
||||
subClass = match.group(1)
|
||||
return [self.deserialize(subObj, subClass) for subObj in obj]
|
||||
|
||||
if (objClass in ['int', 'float', 'long', 'dict', 'list', 'str']):
|
||||
if (objClass in ['int', 'float', 'long', 'dict', 'list', 'str', 'bool', 'datetime']):
|
||||
objClass = eval(objClass)
|
||||
else: # not a native type, must be model class
|
||||
objClass = eval(objClass + '.' + objClass)
|
||||
|
||||
if objClass in [str, int, long, float, bool]:
|
||||
if objClass in [int, long, float, dict, list, str, bool]:
|
||||
return objClass(obj)
|
||||
elif objClass == datetime:
|
||||
# Server will always return a time stamp in UTC, but with
|
||||
@ -165,6 +165,9 @@ class ApiClient:
|
||||
except UnicodeEncodeError:
|
||||
value = unicode(value)
|
||||
setattr(instance, attr, value)
|
||||
elif (attrType == 'datetime'):
|
||||
setattr(instance, attr, datetime.datetime.strptime(value[:-5],
|
||||
"%Y-%m-%dT%H:%M:%S.%f"))
|
||||
elif 'list[' in attrType:
|
||||
match = re.match('list\[(.*)\]', attrType)
|
||||
subClass = match.group(1)
|
||||
@ -197,3 +200,4 @@ class MethodRequest(urllib2.Request):
|
||||
|
||||
def get_method(self):
|
||||
return getattr(self, 'method', urllib2.Request.get_method(self))
|
||||
|
||||
|
@ -84,16 +84,16 @@ class ApiClient:
|
||||
return data
|
||||
|
||||
def toPathValue(self, obj):
|
||||
"""Serialize a list to a CSV string, if necessary.
|
||||
"""Convert a string or object to a path-friendly value
|
||||
Args:
|
||||
obj -- data object to be serialized
|
||||
obj -- object or string value
|
||||
Returns:
|
||||
string -- json serialization of object
|
||||
string -- quoted value
|
||||
"""
|
||||
if type(obj) == list:
|
||||
return ','.join(obj)
|
||||
return urllib.parse.quote(','.join(obj))
|
||||
else:
|
||||
return obj
|
||||
return urllib.parse.quote(str(obj))
|
||||
|
||||
def sanitizeForSerialization(self, obj):
|
||||
"""Dump an object into JSON for POSTing."""
|
||||
@ -133,12 +133,12 @@ class ApiClient:
|
||||
subClass = match.group(1)
|
||||
return [self.deserialize(subObj, subClass) for subObj in obj]
|
||||
|
||||
if (objClass in ['int', 'float', 'dict', 'list', 'str']):
|
||||
if (objClass in ['int', 'float', 'dict', 'list', 'str', 'bool', 'datetime']):
|
||||
objClass = eval(objClass)
|
||||
else: # not a native type, must be model class
|
||||
objClass = eval(objClass + '.' + objClass)
|
||||
|
||||
if objClass in [str, int, float, bool]:
|
||||
if objClass in [int, float, dict, list, str, bool]:
|
||||
return objClass(obj)
|
||||
elif objClass == datetime:
|
||||
# Server will always return a time stamp in UTC, but with
|
||||
@ -160,6 +160,9 @@ class ApiClient:
|
||||
except UnicodeEncodeError:
|
||||
value = unicode(value)
|
||||
setattr(instance, attr, value)
|
||||
elif (attrType == 'datetime'):
|
||||
setattr(instance, attr, datetime.datetime.strptime(value[:-5],
|
||||
"%Y-%m-%dT%H:%M:%S.%f"))
|
||||
elif 'list[' in attrType:
|
||||
match = re.match('list\[(.*)\]', attrType)
|
||||
subClass = match.group(1)
|
||||
|
Loading…
Reference in New Issue
Block a user