diff --git a/modules/swagger-codegen/src/main/resources/python/api_client.mustache b/modules/swagger-codegen/src/main/resources/python/api_client.mustache index 761a034e18..9188c85132 100644 --- a/modules/swagger-codegen/src/main/resources/python/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api_client.mustache @@ -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)) + setattr(instance, attr, self.__deserialize(value, attr_type)) return instance diff --git a/samples/client/petstore/python/swagger_client/api_client.py b/samples/client/petstore/python/swagger_client/api_client.py index 761a034e18..9188c85132 100644 --- a/samples/client/petstore/python/swagger_client/api_client.py +++ b/samples/client/petstore/python/swagger_client/api_client.py @@ -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)) + setattr(instance, attr, self.__deserialize(value, attr_type)) return instance diff --git a/samples/client/petstore/python/tests/test_deserialization.py b/samples/client/petstore/python/tests/test_deserialization.py index 8d9be6d57a..7451f2fbc2 100644 --- a/samples/client/petstore/python/tests/test_deserialization.py +++ b/samples/client/petstore/python/tests/test_deserialization.py @@ -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)