From a1f8623141a1f9090e06ab47559f00b2fc17835b Mon Sep 17 00:00:00 2001 From: "Vikrant Balyan (vvb)" Date: Sat, 14 Aug 2021 20:00:22 +0530 Subject: [PATCH 01/10] fixes a breakage while deserializing the read-only attributes --- .../src/main/resources/python/model_utils.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/python/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/model_utils.mustache index 4615a34ec335..5b1327ba544c 100644 --- a/modules/openapi-generator/src/main/resources/python/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_utils.mustache @@ -1450,7 +1450,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class(**model_args, **constant_args) + allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( From 338a79bcfa12b18423e6a9d59a26e2ab047fde36 Mon Sep 17 00:00:00 2001 From: "Vikrant Balyan (vvb)" Date: Sat, 14 Aug 2021 20:33:46 +0530 Subject: [PATCH 02/10] updating generated samples --- samples/client/petstore/python/petstore_api/model_utils.py | 2 +- .../petstore_api/model_utils.py | 2 +- .../x-auth-id-alias/python/x_auth_id_alias/model_utils.py | 2 +- .../dynamic-servers/python/dynamic_servers/model_utils.py | 2 +- .../openapi3/client/petstore/python/petstore_api/model_utils.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/samples/client/petstore/python/petstore_api/model_utils.py b/samples/client/petstore/python/petstore_api/model_utils.py index aa747a3f9a8a..ee694b2a97a0 100644 --- a/samples/client/petstore/python/petstore_api/model_utils.py +++ b/samples/client/petstore/python/petstore_api/model_utils.py @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class(**model_args, **constant_args) + allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( 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 aa747a3f9a8a..ee694b2a97a0 100644 --- a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class(**model_args, **constant_args) + allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( 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 13277887d394..2e6ae914ebe4 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 @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class(**model_args, **constant_args) + allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( 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 fa10b2d24f93..c953b93fc1d5 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 @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class(**model_args, **constant_args) + allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( 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 aa747a3f9a8a..ee694b2a97a0 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python/petstore_api/model_utils.py @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class(**model_args, **constant_args) + allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( From 26d1ebdac2a533cb9b2e6e7f79bab483e283a68f Mon Sep 17 00:00:00 2001 From: "Vikrant Balyan (vvb)" Date: Tue, 17 Aug 2021 22:15:10 +0530 Subject: [PATCH 03/10] taking care of the PR comments --- .../resources/python/model_utils.mustache | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/model_utils.mustache index 5b1327ba544c..11291fa99b9d 100644 --- a/modules/openapi-generator/src/main/resources/python/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_utils.mustache @@ -1450,7 +1450,10 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) + else: + allof_instance = allof_class(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( @@ -1512,10 +1515,16 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) + else: + oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - oneof_instance = oneof_class(model_arg, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) + else: + oneof_instance = oneof_class(model_arg, **constant_kwargs) elif oneof_class in PRIMITIVE_TYPES: oneof_instance = validate_and_convert_types( model_arg, @@ -1570,7 +1579,10 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - anyof_instance = anyof_class(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) + else: + anyof_instance = anyof_class(**model_args, **constant_args) anyof_instances.append(anyof_instance) except Exception: pass From 7fbcc7a60ccfa97d473b51afba2719d72401fd03 Mon Sep 17 00:00:00 2001 From: "Vikrant Balyan (vvb)" Date: Tue, 17 Aug 2021 22:19:46 +0530 Subject: [PATCH 04/10] updating samples --- .../python/petstore_api/model_utils.py | 20 +++++++++++++++---- .../petstore_api/model_utils.py | 20 +++++++++++++++---- .../python/x_auth_id_alias/model_utils.py | 20 +++++++++++++++---- .../python/dynamic_servers/model_utils.py | 20 +++++++++++++++---- .../python/petstore_api/model_utils.py | 20 +++++++++++++++---- 5 files changed, 80 insertions(+), 20 deletions(-) diff --git a/samples/client/petstore/python/petstore_api/model_utils.py b/samples/client/petstore/python/petstore_api/model_utils.py index ee694b2a97a0..97d6a5b4f3e5 100644 --- a/samples/client/petstore/python/petstore_api/model_utils.py +++ b/samples/client/petstore/python/petstore_api/model_utils.py @@ -1747,7 +1747,10 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) + else: + allof_instance = allof_class(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( @@ -1809,10 +1812,16 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) + else: + oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - oneof_instance = oneof_class(model_arg, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) + else: + oneof_instance = oneof_class(model_arg, **constant_kwargs) elif oneof_class in PRIMITIVE_TYPES: oneof_instance = validate_and_convert_types( model_arg, @@ -1867,7 +1876,10 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - anyof_instance = anyof_class(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) + else: + anyof_instance = anyof_class(**model_args, **constant_args) anyof_instances.append(anyof_instance) except Exception: pass 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 ee694b2a97a0..97d6a5b4f3e5 100644 --- a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py @@ -1747,7 +1747,10 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) + else: + allof_instance = allof_class(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( @@ -1809,10 +1812,16 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) + else: + oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - oneof_instance = oneof_class(model_arg, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) + else: + oneof_instance = oneof_class(model_arg, **constant_kwargs) elif oneof_class in PRIMITIVE_TYPES: oneof_instance = validate_and_convert_types( model_arg, @@ -1867,7 +1876,10 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - anyof_instance = anyof_class(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) + else: + anyof_instance = anyof_class(**model_args, **constant_args) anyof_instances.append(anyof_instance) except Exception: pass 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 2e6ae914ebe4..7be08794c6d9 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 @@ -1747,7 +1747,10 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) + else: + allof_instance = allof_class(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( @@ -1809,10 +1812,16 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) + else: + oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - oneof_instance = oneof_class(model_arg, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) + else: + oneof_instance = oneof_class(model_arg, **constant_kwargs) elif oneof_class in PRIMITIVE_TYPES: oneof_instance = validate_and_convert_types( model_arg, @@ -1867,7 +1876,10 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - anyof_instance = anyof_class(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) + else: + anyof_instance = anyof_class(**model_args, **constant_args) anyof_instances.append(anyof_instance) except Exception: pass 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 c953b93fc1d5..a1e131ffc4f0 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 @@ -1747,7 +1747,10 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) + else: + allof_instance = allof_class(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( @@ -1809,10 +1812,16 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) + else: + oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - oneof_instance = oneof_class(model_arg, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) + else: + oneof_instance = oneof_class(model_arg, **constant_kwargs) elif oneof_class in PRIMITIVE_TYPES: oneof_instance = validate_and_convert_types( model_arg, @@ -1867,7 +1876,10 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - anyof_instance = anyof_class(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) + else: + anyof_instance = anyof_class(**model_args, **constant_args) anyof_instances.append(anyof_instance) except Exception: pass 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 ee694b2a97a0..97d6a5b4f3e5 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python/petstore_api/model_utils.py @@ -1747,7 +1747,10 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - allof_instance = allof_class._new_from_openapi_data(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) + else: + allof_instance = allof_class(**model_args, **constant_args) composed_instances.append(allof_instance) except Exception as ex: raise ApiValueError( @@ -1809,10 +1812,16 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) + else: + oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - oneof_instance = oneof_class(model_arg, **constant_kwargs) + if constant_kwargs['_spec_property_naming']: + oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) + else: + oneof_instance = oneof_class(model_arg, **constant_kwargs) elif oneof_class in PRIMITIVE_TYPES: oneof_instance = validate_and_convert_types( model_arg, @@ -1867,7 +1876,10 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - anyof_instance = anyof_class(**model_args, **constant_args) + if constant_args['_spec_property_naming']: + anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) + else: + anyof_instance = anyof_class(**model_args, **constant_args) anyof_instances.append(anyof_instance) except Exception: pass From ea0db136d86f586a5d06edf5efdac6bed1c0aafa Mon Sep 17 00:00:00 2001 From: "Vikrant Balyan (vvb)" Date: Wed, 18 Aug 2021 00:37:09 +0530 Subject: [PATCH 05/10] protect against cases where _spec_property_naming may not be present --- .../src/main/resources/python/model_utils.mustache | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/model_utils.mustache index 11291fa99b9d..87eabae4cb7f 100644 --- a/modules/openapi-generator/src/main/resources/python/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_utils.mustache @@ -1450,7 +1450,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1515,13 +1515,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1579,7 +1579,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args) From fbf04eba662eb13cee9b4312e80a9230e7aa8a4d Mon Sep 17 00:00:00 2001 From: "Vikrant Balyan (vvb)" Date: Wed, 18 Aug 2021 00:48:19 +0530 Subject: [PATCH 06/10] updating samples --- .../client/petstore/python/petstore_api/model_utils.py | 8 ++++---- .../petstore_api/model_utils.py | 8 ++++---- .../x-auth-id-alias/python/x_auth_id_alias/model_utils.py | 8 ++++---- .../dynamic-servers/python/dynamic_servers/model_utils.py | 8 ++++---- .../client/petstore/python/petstore_api/model_utils.py | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/samples/client/petstore/python/petstore_api/model_utils.py b/samples/client/petstore/python/petstore_api/model_utils.py index 97d6a5b4f3e5..cd928b48918f 100644 --- a/samples/client/petstore/python/petstore_api/model_utils.py +++ b/samples/client/petstore/python/petstore_api/model_utils.py @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1812,13 +1812,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1876,7 +1876,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args) 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 97d6a5b4f3e5..cd928b48918f 100644 --- a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1812,13 +1812,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1876,7 +1876,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args) 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 7be08794c6d9..aba9104a8dcd 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 @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1812,13 +1812,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1876,7 +1876,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args) 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 a1e131ffc4f0..9ee494cf8654 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 @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1812,13 +1812,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1876,7 +1876,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args) 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 97d6a5b4f3e5..cd928b48918f 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python/petstore_api/model_utils.py @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1812,13 +1812,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if constant_kwargs['_spec_property_naming']: + if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1876,7 +1876,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if constant_args['_spec_property_naming']: + if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args) From a5035a4882522a890fb6268602abae97595857c0 Mon Sep 17 00:00:00 2001 From: "Vikrant Balyan (vvb)" Date: Wed, 18 Aug 2021 01:29:20 +0530 Subject: [PATCH 07/10] adding tests for this issue --- ...odels-for-testing-with-http-signature.yaml | 4 ++ .../python/tests_manual/test_issue10155.py | 61 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 samples/openapi3/client/petstore/python/tests_manual/test_issue10155.py diff --git a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 763de9dc2e03..c78f42836063 100644 --- a/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1666,6 +1666,10 @@ components: color: type: string default: red + tail: + type: boolean + default: true + readOnly: true AnimalFarm: type: array items: diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_issue10155.py b/samples/openapi3/client/petstore/python/tests_manual/test_issue10155.py new file mode 100755 index 000000000000..b9b2f7301605 --- /dev/null +++ b/samples/openapi3/client/petstore/python/tests_manual/test_issue10155.py @@ -0,0 +1,61 @@ +# coding: utf-8 + +""" + OpenAPI Petstore + + This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501 + + The version of the OpenAPI document: 1.0.0 + Generated by: https://openapi-generator.tech +""" + + +import sys +import unittest +import json +from collections import namedtuple + + +import petstore_api +try: + from petstore_api.model import ( + animal, + dog, + ) + from petstore_api.api_client import ApiClient +except ImportError: + animal = sys.modules[ + 'petstore_api.model.animal'] + dog = sys.modules[ + 'petstore_api.model.dog'] + + +class TestReadOnlyForComposedSchema(unittest.TestCase): + """TestReadOnlyForComposedSchema unit test""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testReadOnlyForComposedSchema(self): + """Test ReadOnlyForComposedSchema""" + MockResponse = namedtuple('MockResponse', 'data') + client = ApiClient() + """ deserialize dict(str, Enum_Test) """ + data = { + "Dog": { + "class_name": "Dog", + "breed": "BullDog", + "color": "Black", + "tail": True + } + } + response = MockResponse(data=json.dumps(data)) + deserialized = client.deserialize(response, ({str: (dog.Dog,)},), True) + assert isinstance(deserialized, dict) + + +if __name__ == '__main__': + unittest.main() From 47718a1c403cb51af44e0186524fa66c1bd11215 Mon Sep 17 00:00:00 2001 From: "Vikrant Balyan (vvb)" Date: Wed, 18 Aug 2021 01:29:58 +0530 Subject: [PATCH 08/10] other generated files --- samples/openapi3/client/petstore/python/docs/Animal.md | 1 + samples/openapi3/client/petstore/python/docs/Cat.md | 1 + .../python/docs/ComposedOneOfNumberWithValidations.md | 1 + samples/openapi3/client/petstore/python/docs/Dog.md | 1 + .../client/petstore/python/petstore_api/model/animal.py | 5 +++++ .../client/petstore/python/petstore_api/model/cat.py | 5 +++++ .../model/composed_one_of_number_with_validations.py | 5 +++++ .../client/petstore/python/petstore_api/model/dog.py | 5 +++++ 8 files changed, 24 insertions(+) diff --git a/samples/openapi3/client/petstore/python/docs/Animal.md b/samples/openapi3/client/petstore/python/docs/Animal.md index d36c66a5d882..2c3e499ed438 100644 --- a/samples/openapi3/client/petstore/python/docs/Animal.md +++ b/samples/openapi3/client/petstore/python/docs/Animal.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **class_name** | **str** | | **color** | **str** | | [optional] if omitted the server will use the default value of "red" +**tail** | **bool** | | [optional] [readonly] if omitted the server will use the default value of True **any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/Cat.md b/samples/openapi3/client/petstore/python/docs/Cat.md index 082715a28421..771510d15b81 100644 --- a/samples/openapi3/client/petstore/python/docs/Cat.md +++ b/samples/openapi3/client/petstore/python/docs/Cat.md @@ -7,6 +7,7 @@ Name | Type | Description | Notes **class_name** | **str** | | **declawed** | **bool** | | [optional] **color** | **str** | | [optional] if omitted the server will use the default value of "red" +**tail** | **bool** | | [optional] [readonly] if omitted the server will use the default value of True **any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/docs/ComposedOneOfNumberWithValidations.md b/samples/openapi3/client/petstore/python/docs/ComposedOneOfNumberWithValidations.md index 14c3f2ea4933..e71647c52247 100644 --- a/samples/openapi3/client/petstore/python/docs/ComposedOneOfNumberWithValidations.md +++ b/samples/openapi3/client/petstore/python/docs/ComposedOneOfNumberWithValidations.md @@ -6,6 +6,7 @@ this is a model that allows payloads of type object or number Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **color** | **str** | | [optional] if omitted the server will use the default value of "red" +**tail** | **bool** | | [optional] [readonly] if omitted the server will use the default value of True **class_name** | **str** | | [optional] **any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] diff --git a/samples/openapi3/client/petstore/python/docs/Dog.md b/samples/openapi3/client/petstore/python/docs/Dog.md index 51b5b32bdacb..a3564c227f5a 100644 --- a/samples/openapi3/client/petstore/python/docs/Dog.md +++ b/samples/openapi3/client/petstore/python/docs/Dog.md @@ -7,6 +7,7 @@ Name | Type | Description | Notes **class_name** | **str** | | **breed** | **str** | | [optional] **color** | **str** | | [optional] if omitted the server will use the default value of "red" +**tail** | **bool** | | [optional] [readonly] if omitted the server will use the default value of True **any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python/petstore_api/model/animal.py b/samples/openapi3/client/petstore/python/petstore_api/model/animal.py index fda6c283ebdc..cc070a6d8fe6 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/model/animal.py +++ b/samples/openapi3/client/petstore/python/petstore_api/model/animal.py @@ -91,6 +91,7 @@ def openapi_types(): return { 'class_name': (str,), # noqa: E501 'color': (str,), # noqa: E501 + 'tail': (bool,), # noqa: E501 } @cached_property @@ -107,9 +108,11 @@ def discriminator(): attribute_map = { 'class_name': 'className', # noqa: E501 'color': 'color', # noqa: E501 + 'tail': 'tail', # noqa: E501 } read_only_vars = { + 'tail', # noqa: E501 } _composed_schemas = {} @@ -154,6 +157,7 @@ def _from_openapi_data(cls, class_name, *args, **kwargs): # noqa: E501 through its discriminator because we passed in _visited_composed_classes = (Animal,) color (str): [optional] if omitted the server will use the default value of "red" # noqa: E501 + tail (bool): [optional] if omitted the server will use the default value of True # noqa: E501 """ _check_type = kwargs.pop('_check_type', True) @@ -240,6 +244,7 @@ def __init__(self, class_name, *args, **kwargs): # noqa: E501 through its discriminator because we passed in _visited_composed_classes = (Animal,) color (str): [optional] if omitted the server will use the default value of "red" # noqa: E501 + tail (bool): [optional] if omitted the server will use the default value of True # noqa: E501 """ _check_type = kwargs.pop('_check_type', True) diff --git a/samples/openapi3/client/petstore/python/petstore_api/model/cat.py b/samples/openapi3/client/petstore/python/petstore_api/model/cat.py index be46fe5abd8c..882376f11a6d 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/model/cat.py +++ b/samples/openapi3/client/petstore/python/petstore_api/model/cat.py @@ -92,6 +92,7 @@ def openapi_types(): 'class_name': (str,), # noqa: E501 'declawed': (bool,), # noqa: E501 'color': (str,), # noqa: E501 + 'tail': (bool,), # noqa: E501 } @cached_property @@ -106,9 +107,11 @@ def discriminator(): 'class_name': 'className', # noqa: E501 'declawed': 'declawed', # noqa: E501 'color': 'color', # noqa: E501 + 'tail': 'tail', # noqa: E501 } read_only_vars = { + 'tail', # noqa: E501 } @classmethod @@ -150,6 +153,7 @@ def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 _visited_composed_classes = (Animal,) declawed (bool): [optional] # noqa: E501 color (str): [optional] if omitted the server will use the default value of "red" # noqa: E501 + tail (bool): [optional] if omitted the server will use the default value of True # noqa: E501 """ _check_type = kwargs.pop('_check_type', True) @@ -252,6 +256,7 @@ def __init__(self, *args, **kwargs): # noqa: E501 _visited_composed_classes = (Animal,) declawed (bool): [optional] # noqa: E501 color (str): [optional] if omitted the server will use the default value of "red" # noqa: E501 + tail (bool): [optional] if omitted the server will use the default value of True # noqa: E501 """ _check_type = kwargs.pop('_check_type', True) diff --git a/samples/openapi3/client/petstore/python/petstore_api/model/composed_one_of_number_with_validations.py b/samples/openapi3/client/petstore/python/petstore_api/model/composed_one_of_number_with_validations.py index 68847c276eee..062902afb308 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/model/composed_one_of_number_with_validations.py +++ b/samples/openapi3/client/petstore/python/petstore_api/model/composed_one_of_number_with_validations.py @@ -90,6 +90,7 @@ def openapi_types(): lazy_import() return { 'color': (str,), # noqa: E501 + 'tail': (bool,), # noqa: E501 'class_name': (str,), # noqa: E501 } @@ -100,10 +101,12 @@ def discriminator(): attribute_map = { 'color': 'color', # noqa: E501 + 'tail': 'tail', # noqa: E501 'class_name': 'className', # noqa: E501 } read_only_vars = { + 'tail', # noqa: E501 } @classmethod @@ -143,6 +146,7 @@ def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 through its discriminator because we passed in _visited_composed_classes = (Animal,) color (str): [optional] if omitted the server will use the default value of "red" # noqa: E501 + tail (bool): [optional] if omitted the server will use the default value of True # noqa: E501 class_name (str): [optional] # noqa: E501 """ @@ -244,6 +248,7 @@ def __init__(self, *args, **kwargs): # noqa: E501 through its discriminator because we passed in _visited_composed_classes = (Animal,) color (str): [optional] if omitted the server will use the default value of "red" # noqa: E501 + tail (bool): [optional] if omitted the server will use the default value of True # noqa: E501 class_name (str): [optional] # noqa: E501 """ diff --git a/samples/openapi3/client/petstore/python/petstore_api/model/dog.py b/samples/openapi3/client/petstore/python/petstore_api/model/dog.py index 4a20dafa46cc..671fbe3dae2c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/model/dog.py +++ b/samples/openapi3/client/petstore/python/petstore_api/model/dog.py @@ -92,6 +92,7 @@ def openapi_types(): 'class_name': (str,), # noqa: E501 'breed': (str,), # noqa: E501 'color': (str,), # noqa: E501 + 'tail': (bool,), # noqa: E501 } @cached_property @@ -106,9 +107,11 @@ def discriminator(): 'class_name': 'className', # noqa: E501 'breed': 'breed', # noqa: E501 'color': 'color', # noqa: E501 + 'tail': 'tail', # noqa: E501 } read_only_vars = { + 'tail', # noqa: E501 } @classmethod @@ -150,6 +153,7 @@ def _from_openapi_data(cls, *args, **kwargs): # noqa: E501 _visited_composed_classes = (Animal,) breed (str): [optional] # noqa: E501 color (str): [optional] if omitted the server will use the default value of "red" # noqa: E501 + tail (bool): [optional] if omitted the server will use the default value of True # noqa: E501 """ _check_type = kwargs.pop('_check_type', True) @@ -252,6 +256,7 @@ def __init__(self, *args, **kwargs): # noqa: E501 _visited_composed_classes = (Animal,) breed (str): [optional] # noqa: E501 color (str): [optional] if omitted the server will use the default value of "red" # noqa: E501 + tail (bool): [optional] if omitted the server will use the default value of True # noqa: E501 """ _check_type = kwargs.pop('_check_type', True) From 8b3a66e1fa76eb8fb3128beb525336b809ec323b Mon Sep 17 00:00:00 2001 From: "Vikrant Balyan (vvb)" Date: Wed, 18 Aug 2021 23:20:11 +0530 Subject: [PATCH 09/10] taking care of the comments --- .../resources/python/model_utils.mustache | 8 ++++---- .../python/tests_manual/test_issue10155.py | 19 +++++-------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/model_utils.mustache index 87eabae4cb7f..4a99eab52a20 100644 --- a/modules/openapi-generator/src/main/resources/python/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_utils.mustache @@ -1450,7 +1450,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1515,13 +1515,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1579,7 +1579,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args) diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_issue10155.py b/samples/openapi3/client/petstore/python/tests_manual/test_issue10155.py index b9b2f7301605..7c14b5f7e7a4 100755 --- a/samples/openapi3/client/petstore/python/tests_manual/test_issue10155.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_issue10155.py @@ -15,19 +15,9 @@ import json from collections import namedtuple - import petstore_api -try: - from petstore_api.model import ( - animal, - dog, - ) - from petstore_api.api_client import ApiClient -except ImportError: - animal = sys.modules[ - 'petstore_api.model.animal'] - dog = sys.modules[ - 'petstore_api.model.dog'] +from petstore_api.model.animal import Animal +from petstore_api.model.dog import Dog class TestReadOnlyForComposedSchema(unittest.TestCase): @@ -42,7 +32,7 @@ def tearDown(self): def testReadOnlyForComposedSchema(self): """Test ReadOnlyForComposedSchema""" MockResponse = namedtuple('MockResponse', 'data') - client = ApiClient() + client = petstore_api.ApiClient() """ deserialize dict(str, Enum_Test) """ data = { "Dog": { @@ -53,8 +43,9 @@ def testReadOnlyForComposedSchema(self): } } response = MockResponse(data=json.dumps(data)) - deserialized = client.deserialize(response, ({str: (dog.Dog,)},), True) + deserialized = client.deserialize(response, ({str: (Dog,)},), True) assert isinstance(deserialized, dict) + assert isinstance(deserialized['Dog'], Dog) if __name__ == '__main__': From a8c3449935c9acd1a13423e072e6935923c08722 Mon Sep 17 00:00:00 2001 From: "Vikrant Balyan (vvb)" Date: Wed, 18 Aug 2021 23:20:42 +0530 Subject: [PATCH 10/10] updating the generated samples --- .../client/petstore/python/petstore_api/model_utils.py | 8 ++++---- .../petstore_api/model_utils.py | 8 ++++---- .../x-auth-id-alias/python/x_auth_id_alias/model_utils.py | 8 ++++---- .../dynamic-servers/python/dynamic_servers/model_utils.py | 8 ++++---- .../client/petstore/python/petstore_api/model_utils.py | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/samples/client/petstore/python/petstore_api/model_utils.py b/samples/client/petstore/python/petstore_api/model_utils.py index cd928b48918f..e7ef88f64f83 100644 --- a/samples/client/petstore/python/petstore_api/model_utils.py +++ b/samples/client/petstore/python/petstore_api/model_utils.py @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1812,13 +1812,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1876,7 +1876,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args) 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 cd928b48918f..e7ef88f64f83 100644 --- a/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py +++ b/samples/client/petstore/python_disallowAdditionalPropertiesIfNotPresent/petstore_api/model_utils.py @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1812,13 +1812,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1876,7 +1876,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args) 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 aba9104a8dcd..cef4b6c2373b 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 @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1812,13 +1812,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1876,7 +1876,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args) 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 9ee494cf8654..2ad3e5bdeab6 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 @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1812,13 +1812,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1876,7 +1876,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args) 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 cd928b48918f..e7ef88f64f83 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python/petstore_api/model_utils.py @@ -1747,7 +1747,7 @@ def get_allof_instances(self, model_args, constant_args): for allof_class in self._composed_schemas['allOf']: try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): allof_instance = allof_class._from_openapi_data(**model_args, **constant_args) else: allof_instance = allof_class(**model_args, **constant_args) @@ -1812,13 +1812,13 @@ def get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None): try: if not single_value_input: - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(**model_kwargs, **constant_kwargs) else: oneof_instance = oneof_class(**model_kwargs, **constant_kwargs) else: if issubclass(oneof_class, ModelSimple): - if '_spec_property_naming' in constant_kwargs and constant_kwargs['_spec_property_naming']: + if constant_kwargs.get('_spec_property_naming'): oneof_instance = oneof_class._from_openapi_data(model_arg, **constant_kwargs) else: oneof_instance = oneof_class(model_arg, **constant_kwargs) @@ -1876,7 +1876,7 @@ def get_anyof_instances(self, model_args, constant_args): continue try: - if '_spec_property_naming' in constant_args and constant_args['_spec_property_naming']: + if constant_args.get('_spec_property_naming'): anyof_instance = anyof_class._from_openapi_data(**model_args, **constant_args) else: anyof_instance = anyof_class(**model_args, **constant_args)