forked from loafle/openapi-generator-original
Support pure object response for python client.
This commit is contained in:
parent
e2d441e862
commit
ff9623fb5c
@ -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>(
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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))
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user