forked from loafle/openapi-generator-original
Update deserialization of python client.
Return None if deserialize data is None.
This commit is contained in:
@@ -183,6 +183,9 @@ class ApiClient(object):
|
||||
|
||||
:return: object
|
||||
"""
|
||||
if data is None:
|
||||
return None
|
||||
|
||||
if type(klass) == str:
|
||||
if 'list[' in klass:
|
||||
sub_kls = re.match('list\[(.*)\]', klass).group(1)
|
||||
@@ -366,18 +369,6 @@ class ApiClient(object):
|
||||
and instance.attribute_map[attr] in data\
|
||||
and isinstance(data, (list, dict)):
|
||||
value = data[instance.attribute_map[attr]]
|
||||
if attr_type in ['str', 'int', 'float', 'bool']:
|
||||
attr_type = eval(attr_type)
|
||||
setattr(instance, attr, self.__deserialize_primitive(value, attr_type))
|
||||
elif attr_type == 'datetime':
|
||||
setattr(instance, attr, self.__deserialize_datatime(value))
|
||||
elif 'list[' in attr_type:
|
||||
if not value:
|
||||
setattr(instance, attr, None)
|
||||
else:
|
||||
sub_kls = re.match('list\[(.*)\]', attr_type).group(1)
|
||||
setattr(instance, attr, [self.__deserialize(v, sub_kls) for v in value])
|
||||
else:
|
||||
setattr(instance, attr, self.__deserialize(value, attr_type))
|
||||
|
||||
return instance
|
||||
|
||||
@@ -183,6 +183,9 @@ class ApiClient(object):
|
||||
|
||||
:return: object
|
||||
"""
|
||||
if data is None:
|
||||
return None
|
||||
|
||||
if type(klass) == str:
|
||||
if 'list[' in klass:
|
||||
sub_kls = re.match('list\[(.*)\]', klass).group(1)
|
||||
@@ -366,18 +369,6 @@ class ApiClient(object):
|
||||
and instance.attribute_map[attr] in data\
|
||||
and isinstance(data, (list, dict)):
|
||||
value = data[instance.attribute_map[attr]]
|
||||
if attr_type in ['str', 'int', 'float', 'bool']:
|
||||
attr_type = eval(attr_type)
|
||||
setattr(instance, attr, self.__deserialize_primitive(value, attr_type))
|
||||
elif attr_type == 'datetime':
|
||||
setattr(instance, attr, self.__deserialize_datatime(value))
|
||||
elif 'list[' in attr_type:
|
||||
if not value:
|
||||
setattr(instance, attr, None)
|
||||
else:
|
||||
sub_kls = re.match('list\[(.*)\]', attr_type).group(1)
|
||||
setattr(instance, attr, [self.__deserialize(v, sub_kls) for v in value])
|
||||
else:
|
||||
setattr(instance, attr, self.__deserialize(value, attr_type))
|
||||
|
||||
return instance
|
||||
|
||||
@@ -143,3 +143,8 @@ class DeserializationTests(unittest.TestCase):
|
||||
self.assertEqual(deserialized[1].id, 1)
|
||||
self.assertEqual(deserialized[0].name, "doggie0")
|
||||
self.assertEqual(deserialized[1].name, "doggie1")
|
||||
|
||||
def test_deserialize_none(self):
|
||||
""" deserialize None """
|
||||
deserialized = self.deserialize(None, "datetime")
|
||||
self.assertIsNone(deserialized)
|
||||
|
||||
Reference in New Issue
Block a user