diff --git a/modules/openapi-generator/src/main/resources/python/model_templates/methods_shared.mustache b/modules/openapi-generator/src/main/resources/python/model_templates/methods_shared.mustache index 5ffef97f6b..e38832a4a5 100644 --- a/modules/openapi-generator/src/main/resources/python/model_templates/methods_shared.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_templates/methods_shared.mustache @@ -27,7 +27,7 @@ if self.get("_spec_property_naming", False): new_inst = cls._new_from_openapi_data() else: - new_inst = cls.__new__(cls) + new_inst = cls.__new__(cls, **self.__dict__) for k, v in self.__dict__.items(): setattr(new_inst, k, deepcopy(v, memo)) diff --git a/samples/client/petstore/python/petstore_api/model_utils.py b/samples/client/petstore/python/petstore_api/model_utils.py index 933ceec6fa..ab2d0087df 100644 --- a/samples/client/petstore/python/petstore_api/model_utils.py +++ b/samples/client/petstore/python/petstore_api/model_utils.py @@ -205,7 +205,7 @@ class OpenApiModel(object): if self.get("_spec_property_naming", False): new_inst = cls._new_from_openapi_data() else: - new_inst = cls.__new__(cls) + new_inst = cls.__new__(cls, **self.__dict__) for k, v in self.__dict__.items(): setattr(new_inst, k, deepcopy(v, memo)) diff --git a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py index 933ceec6fa..ab2d0087df 100644 --- a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py @@ -205,7 +205,7 @@ class OpenApiModel(object): if self.get("_spec_property_naming", False): new_inst = cls._new_from_openapi_data() else: - new_inst = cls.__new__(cls) + new_inst = cls.__new__(cls, **self.__dict__) for k, v in self.__dict__.items(): setattr(new_inst, k, deepcopy(v, memo)) diff --git a/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/model_utils.py b/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/model_utils.py index a2711d1362..d90e2383d8 100644 --- a/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/model_utils.py +++ b/samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/model_utils.py @@ -205,7 +205,7 @@ class OpenApiModel(object): if self.get("_spec_property_naming", False): new_inst = cls._new_from_openapi_data() else: - new_inst = cls.__new__(cls) + new_inst = cls.__new__(cls, **self.__dict__) for k, v in self.__dict__.items(): setattr(new_inst, k, deepcopy(v, memo)) diff --git a/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/model_utils.py b/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/model_utils.py index 38902e7afd..a7da81cfaf 100644 --- a/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/model_utils.py +++ b/samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/model_utils.py @@ -205,7 +205,7 @@ class OpenApiModel(object): if self.get("_spec_property_naming", False): new_inst = cls._new_from_openapi_data() else: - new_inst = cls.__new__(cls) + new_inst = cls.__new__(cls, **self.__dict__) for k, v in self.__dict__.items(): setattr(new_inst, k, deepcopy(v, memo)) diff --git a/samples/openapi3/client/petstore/python/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python/petstore_api/model_utils.py index 933ceec6fa..ab2d0087df 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python/petstore_api/model_utils.py @@ -205,7 +205,7 @@ class OpenApiModel(object): if self.get("_spec_property_naming", False): new_inst = cls._new_from_openapi_data() else: - new_inst = cls.__new__(cls) + new_inst = cls.__new__(cls, **self.__dict__) for k, v in self.__dict__.items(): setattr(new_inst, k, deepcopy(v, memo)) diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_copy.py b/samples/openapi3/client/petstore/python/tests_manual/test_copy.py index 35bd9a31a2..e70fd67b34 100644 --- a/samples/openapi3/client/petstore/python/tests_manual/test_copy.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_copy.py @@ -2,7 +2,7 @@ from copy import deepcopy import unittest from petstore_api.model.mammal import Mammal from petstore_api.model.triangle import Triangle - +from petstore_api.model.dog import Dog class TestCopy(unittest.TestCase): """TestCopy unit test stubs""" @@ -29,6 +29,14 @@ class TestCopy(unittest.TestCase): assert id(deepcopy(obj)) != id(obj) assert deepcopy(obj) == obj + obj = Dog._new_from_openapi_data(class_name='Dog', color='white', breed='Jack Russel Terrier') + assert id(deepcopy(obj)) != id(obj) + assert deepcopy(obj) == obj + + obj = Dog(class_name='Dog', color='white', breed='Jack Russel Terrier') + assert id(deepcopy(obj)) != id(obj) + assert deepcopy(obj) == obj + if __name__ == '__main__': unittest.main()