Support pure object response for python client.

This commit is contained in:
geekerzp 2015-06-13 18:58:27 +08:00
parent e2d441e862
commit ff9623fb5c
4 changed files with 14 additions and 2 deletions

View File

@ -50,6 +50,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
typeMapping.put("boolean", "bool");
typeMapping.put("string", "str");
typeMapping.put("date", "datetime");
typeMapping.put("object", "object");
// from https://docs.python.org/release/2.5.4/ref/keywords.html
reservedWords = new HashSet<String>(

View File

@ -173,13 +173,15 @@ class ApiClient(object):
sub_class = match.group(2)
return {k: self.deserialize(v, sub_class) for k, v in iteritems(obj)}
if obj_class in ['int', 'float', 'dict', 'list', 'str', 'bool', 'datetime']:
if obj_class in ['int', 'float', 'dict', 'list', 'str', 'bool', 'datetime', "object"]:
obj_class = eval(obj_class)
else: # not a native type, must be model class
obj_class = eval('models.' + obj_class)
if obj_class in [int, float, dict, list, str, bool]:
return obj_class(obj)
elif obj_class == object:
return object()
elif obj_class == datetime:
return self.__parse_string_to_datetime(obj)

View File

@ -173,13 +173,15 @@ class ApiClient(object):
sub_class = match.group(2)
return {k: self.deserialize(v, sub_class) for k, v in iteritems(obj)}
if obj_class in ['int', 'float', 'dict', 'list', 'str', 'bool', 'datetime']:
if obj_class in ['int', 'float', 'dict', 'list', 'str', 'bool', 'datetime', "object"]:
obj_class = eval(obj_class)
else: # not a native type, must be model class
obj_class = eval('models.' + obj_class)
if obj_class in [int, float, dict, list, str, bool]:
return obj_class(obj)
elif obj_class == object:
return object()
elif obj_class == datetime:
return self.__parse_string_to_datetime(obj)

View File

@ -124,3 +124,10 @@ class ApiClientTests(unittest.TestCase):
data = self.api_client.deserialize(json, 'dict(str, int)')
self.assertTrue(isinstance(data, dict))
self.assertTrue(isinstance(data['integer'], int))
def test_deserialize_to_object(self):
data = self.api_client.deserialize("", "object")
self.assertTrue(isinstance(data, object))