From e08e05a2c7ff4f406f3e311e21c109f5b0249996 Mon Sep 17 00:00:00 2001 From: Sebastien Rosset Date: Fri, 21 Feb 2020 14:51:24 -0800 Subject: [PATCH] [Python] add discard_unknown_keys parameter (#5362) * add discard_unknown_key parameter * add discard_unknown_key parameter * add discard_unknown_key parameter * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * discard unknown keys in composed schema if configuration.discard_unknown_keys is set * run sample scripts for python * code reformatting * execute script in bin directory * improve unit tests for discarding properties --- .../resources/python/configuration.mustache | 13 ++ .../method_init_composed.mustache | 13 +- .../method_init_normal.mustache | 12 +- .../method_init_shared.mustache | 8 +- .../python-experimental/model_utils.mustache | 28 ++-- ...odels-for-testing-with-http-signature.yaml | 5 + .../petstore_api/configuration.py | 13 ++ .../petstore_api/configuration.py | 13 ++ .../petstore_api/model_utils.py | 28 ++-- .../models/additional_properties_any_type.py | 6 + .../models/additional_properties_array.py | 6 + .../models/additional_properties_boolean.py | 6 + .../models/additional_properties_class.py | 6 + .../models/additional_properties_integer.py | 6 + .../models/additional_properties_number.py | 6 + .../models/additional_properties_object.py | 6 + .../models/additional_properties_string.py | 6 + .../petstore_api/models/animal.py | 6 + .../petstore_api/models/api_response.py | 6 + .../models/array_of_array_of_number_only.py | 6 + .../models/array_of_number_only.py | 6 + .../petstore_api/models/array_test.py | 6 + .../petstore_api/models/capitalization.py | 6 + .../petstore_api/models/cat.py | 7 + .../petstore_api/models/cat_all_of.py | 6 + .../petstore_api/models/category.py | 6 + .../petstore_api/models/child.py | 7 + .../petstore_api/models/child_all_of.py | 6 + .../petstore_api/models/child_cat.py | 7 + .../petstore_api/models/child_cat_all_of.py | 6 + .../petstore_api/models/child_dog.py | 7 + .../petstore_api/models/child_dog_all_of.py | 6 + .../petstore_api/models/child_lizard.py | 7 + .../models/child_lizard_all_of.py | 6 + .../petstore_api/models/class_model.py | 6 + .../petstore_api/models/client.py | 6 + .../petstore_api/models/dog.py | 7 + .../petstore_api/models/dog_all_of.py | 6 + .../petstore_api/models/enum_arrays.py | 6 + .../petstore_api/models/enum_class.py | 6 + .../petstore_api/models/enum_test.py | 6 + .../petstore_api/models/file.py | 6 + .../models/file_schema_test_class.py | 6 + .../petstore_api/models/format_test.py | 6 + .../petstore_api/models/grandparent.py | 6 + .../petstore_api/models/grandparent_animal.py | 6 + .../petstore_api/models/has_only_read_only.py | 6 + .../petstore_api/models/list.py | 6 + .../petstore_api/models/map_test.py | 6 + ...perties_and_additional_properties_class.py | 6 + .../petstore_api/models/model200_response.py | 6 + .../petstore_api/models/model_return.py | 6 + .../petstore_api/models/name.py | 6 + .../petstore_api/models/number_only.py | 6 + .../petstore_api/models/order.py | 6 + .../petstore_api/models/outer_composite.py | 6 + .../petstore_api/models/outer_enum.py | 6 + .../petstore_api/models/outer_number.py | 6 + .../petstore_api/models/parent.py | 7 + .../petstore_api/models/parent_all_of.py | 6 + .../petstore_api/models/parent_pet.py | 7 + .../petstore_api/models/pet.py | 6 + .../petstore_api/models/player.py | 6 + .../petstore_api/models/read_only_first.py | 6 + .../petstore_api/models/special_model_name.py | 6 + .../petstore_api/models/string_boolean_map.py | 6 + .../petstore_api/models/tag.py | 6 + .../models/type_holder_default.py | 6 + .../models/type_holder_example.py | 6 + .../petstore_api/models/user.py | 6 + .../petstore_api/models/xml_item.py | 6 + .../petstore_api/configuration.py | 13 ++ .../python/petstore_api/configuration.py | 13 ++ .../go-petstore/api/openapi.yaml | 5 + .../petstore/python-experimental/README.md | 1 + .../python-experimental/docs/Address.md | 10 ++ .../petstore_api/__init__.py | 1 + .../petstore_api/configuration.py | 13 ++ .../petstore_api/model_utils.py | 28 ++-- .../models/additional_properties_class.py | 6 + .../petstore_api/models/address.py | 130 ++++++++++++++++++ .../petstore_api/models/animal.py | 6 + .../petstore_api/models/api_response.py | 6 + .../models/array_of_array_of_number_only.py | 6 + .../models/array_of_number_only.py | 6 + .../petstore_api/models/array_test.py | 6 + .../petstore_api/models/capitalization.py | 6 + .../petstore_api/models/cat.py | 13 ++ .../petstore_api/models/cat_all_of.py | 6 + .../petstore_api/models/category.py | 6 + .../petstore_api/models/class_model.py | 6 + .../petstore_api/models/client.py | 6 + .../petstore_api/models/dog.py | 7 + .../petstore_api/models/dog_all_of.py | 6 + .../petstore_api/models/enum_arrays.py | 6 + .../petstore_api/models/enum_class.py | 6 + .../petstore_api/models/enum_test.py | 6 + .../petstore_api/models/file.py | 6 + .../models/file_schema_test_class.py | 6 + .../petstore_api/models/foo.py | 6 + .../petstore_api/models/format_test.py | 6 + .../petstore_api/models/has_only_read_only.py | 6 + .../models/health_check_result.py | 6 + .../petstore_api/models/inline_object.py | 6 + .../petstore_api/models/inline_object1.py | 6 + .../petstore_api/models/inline_object2.py | 6 + .../petstore_api/models/inline_object3.py | 6 + .../petstore_api/models/inline_object4.py | 6 + .../petstore_api/models/inline_object5.py | 6 + .../models/inline_response_default.py | 6 + .../petstore_api/models/list.py | 6 + .../petstore_api/models/map_test.py | 6 + ...perties_and_additional_properties_class.py | 6 + .../petstore_api/models/model200_response.py | 6 + .../petstore_api/models/model_return.py | 6 + .../petstore_api/models/name.py | 6 + .../petstore_api/models/nullable_class.py | 6 + .../petstore_api/models/number_only.py | 6 + .../petstore_api/models/order.py | 6 + .../petstore_api/models/outer_composite.py | 6 + .../petstore_api/models/outer_enum.py | 6 + .../models/outer_enum_default_value.py | 6 + .../petstore_api/models/outer_enum_integer.py | 6 + .../outer_enum_integer_default_value.py | 6 + .../petstore_api/models/pet.py | 6 + .../petstore_api/models/read_only_first.py | 6 + .../petstore_api/models/special_model_name.py | 6 + .../petstore_api/models/string_boolean_map.py | 6 + .../petstore_api/models/tag.py | 6 + .../petstore_api/models/user.py | 6 + .../python-experimental/test/test_address.py | 37 +++++ .../tests/test_discard_unknown_properties.py | 123 +++++++++++++++++ .../python/petstore_api/configuration.py | 13 ++ 133 files changed, 1156 insertions(+), 52 deletions(-) create mode 100644 samples/openapi3/client/petstore/python-experimental/docs/Address.md create mode 100644 samples/openapi3/client/petstore/python-experimental/petstore_api/models/address.py create mode 100644 samples/openapi3/client/petstore/python-experimental/test/test_address.py create mode 100644 samples/openapi3/client/petstore/python-experimental/tests/test_discard_unknown_properties.py diff --git a/modules/openapi-generator/src/main/resources/python/configuration.mustache b/modules/openapi-generator/src/main/resources/python/configuration.mustache index 0645bc46755..8228fff6a86 100644 --- a/modules/openapi-generator/src/main/resources/python/configuration.mustache +++ b/modules/openapi-generator/src/main/resources/python/configuration.mustache @@ -31,6 +31,17 @@ class Configuration(object): The dict value is an API key prefix when generating the auth data. :param username: Username for HTTP basic authentication :param password: Password for HTTP basic authentication + :param discard_unknown_keys: Boolean value indicating whether to discard + unknown properties. A server may send a response that includes additional + properties that are not known by the client in the following scenarios: + 1. The OpenAPI document is incomplete, i.e. it does not match the server + implementation. + 2. The client was generated using an older version of the OpenAPI document + and the server has been upgraded since then. + If a schema in the OpenAPI document defines the additionalProperties attribute, + then all undeclared properties received by the server are injected into the + additional properties map. In that case, there are undeclared properties, and + nothing to discard. {{#hasHttpSignatureMethods}} :param signing_info: Configuration parameters for the HTTP signature security scheme. Must be an instance of {{{packageName}}}.signing.HttpSigningConfiguration @@ -120,6 +131,7 @@ class Configuration(object): def __init__(self, host="{{{basePath}}}", api_key=None, api_key_prefix=None, username=None, password=None, + discard_unknown_keys=False, {{#hasHttpSignatureMethods}} signing_info=None, {{/hasHttpSignatureMethods}} @@ -152,6 +164,7 @@ class Configuration(object): self.password = password """Password for HTTP basic authentication """ + self.discard_unknown_keys = discard_unknown_keys {{#hasHttpSignatureMethods}} if signing_info is not None: signing_info.host = host diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_composed.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_composed.mustache index 5ed5993fe9f..5a1ece1f926 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_composed.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_composed.mustache @@ -11,12 +11,6 @@ {{> python-experimental/model_templates/method_init_shared }} - self._data_store = {} - self._check_type = _check_type - self._from_server = _from_server - self._path_to_item = _path_to_item - self._configuration = _configuration - constant_args = { '_check_type': _check_type, '_path_to_item': _path_to_item, @@ -34,9 +28,16 @@ self._composed_instances = composed_info[0] self._var_name_to_model_instances = composed_info[1] self._additional_properties_model_instances = composed_info[2] + unused_args = composed_info[3] {{#requiredVars}} self.{{name}} = {{name}} {{/requiredVars}} for var_name, var_value in six.iteritems(kwargs): + if var_name in unused_args and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + not self._additional_properties_model_instances: + # discard variable. + continue setattr(self, var_name, var_value) \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_normal.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_normal.mustache index b053427a799..d26506c56c3 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_normal.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_normal.mustache @@ -8,14 +8,14 @@ {{> python-experimental/model_templates/method_init_shared }} - self._data_store = {} - self._check_type = _check_type - self._from_server = _from_server - self._path_to_item = _path_to_item - self._configuration = _configuration - {{#requiredVars}} self.{{name}} = {{name}} {{/requiredVars}} for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_shared.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_shared.mustache index 2f3b70ea690..318d693e15d 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_shared.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/method_init_shared.mustache @@ -20,4 +20,10 @@ If passed, type conversion is attempted If omitted no type conversion is done.{{#optionalVars}} {{name}} ({{{dataType}}}):{{#description}} {{description}}.{{/description}} [optional]{{#defaultValue}} if omitted the server will use the default value of {{{defaultValue}}}{{/defaultValue}} # noqa: E501{{/optionalVars}} - """ \ No newline at end of file + """ + + self._data_store = {} + self._check_type = _check_type + self._from_server = _from_server + self._path_to_item = _path_to_item + self._configuration = _configuration \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache index c3d9e7d5362..8193d8a3b2a 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_utils.mustache @@ -677,8 +677,9 @@ def attempt_convert_item(input_value, valid_classes, path_to_item, if not valid_classes_coercible or key_type: # we do not handle keytype errors, json will take care # of this for us - raise get_type_error(input_value, path_to_item, valid_classes, - key_type=key_type) + if configuration is None or not configuration.discard_unknown_keys: + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=key_type) for valid_class in valid_classes_coercible: try: if issubclass(valid_class, OpenApiModel): @@ -1117,16 +1118,16 @@ def validate_get_composed_info(constant_args, model_args, self): # set any remaining values unused_args = get_unused_args(self, composed_instances, model_args) - if len(unused_args) > 0: - if len(additional_properties_model_instances) == 0: - raise ApiValueError( - "Invalid input arguments input when making an instance of " - "class %s. Not all inputs were used. The unused input data " - "is %s" % (self.__class__.__name__, unused_args) - ) - for var_name, var_value in six.iteritems(unused_args): - for instance in additional_properties_model_instances: - setattr(instance, var_name, var_value) + if len(unused_args) > 0 and \ + len(additional_properties_model_instances) == 0 and \ + (self._configuration is None or + not self._configuration.discard_unknown_keys): + raise ApiValueError( + "Invalid input arguments input when making an instance of " + "class %s. Not all inputs were used. The unused input data " + "is %s" % (self.__class__.__name__, unused_args) + ) + # no need to add additional_properties to var_name_to_model_instances here # because additional_properties_model_instances will direct us to that # instance when we use getattr or setattr @@ -1135,5 +1136,6 @@ def validate_get_composed_info(constant_args, model_args, self): return [ composed_instances, var_name_to_model_instances, - additional_properties_model_instances + additional_properties_model_instances, + unused_args ] diff --git a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml index 59d96166c7e..ecc6f66f3b0 100644 --- a/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml @@ -1362,10 +1362,15 @@ components: Cat: allOf: - $ref: '#/components/schemas/Animal' + - $ref: '#/components/schemas/Address' - type: object properties: declawed: type: boolean + Address: + type: object + additionalProperties: + type: integer Animal: type: object discriminator: diff --git a/samples/client/petstore/python-asyncio/petstore_api/configuration.py b/samples/client/petstore/python-asyncio/petstore_api/configuration.py index 82fd3361968..9a615116a1d 100644 --- a/samples/client/petstore/python-asyncio/petstore_api/configuration.py +++ b/samples/client/petstore/python-asyncio/petstore_api/configuration.py @@ -36,6 +36,17 @@ class Configuration(object): The dict value is an API key prefix when generating the auth data. :param username: Username for HTTP basic authentication :param password: Password for HTTP basic authentication + :param discard_unknown_keys: Boolean value indicating whether to discard + unknown properties. A server may send a response that includes additional + properties that are not known by the client in the following scenarios: + 1. The OpenAPI document is incomplete, i.e. it does not match the server + implementation. + 2. The client was generated using an older version of the OpenAPI document + and the server has been upgraded since then. + If a schema in the OpenAPI document defines the additionalProperties attribute, + then all undeclared properties received by the server are injected into the + additional properties map. In that case, there are undeclared properties, and + nothing to discard. :Example: @@ -74,6 +85,7 @@ class Configuration(object): def __init__(self, host="http://petstore.swagger.io:80/v2", api_key=None, api_key_prefix=None, username=None, password=None, + discard_unknown_keys=False, ): """Constructor """ @@ -103,6 +115,7 @@ class Configuration(object): self.password = password """Password for HTTP basic authentication """ + self.discard_unknown_keys = discard_unknown_keys self.access_token = None """access token for OAuth/Bearer """ diff --git a/samples/client/petstore/python-experimental/petstore_api/configuration.py b/samples/client/petstore/python-experimental/petstore_api/configuration.py index faadfd56055..1234504debb 100644 --- a/samples/client/petstore/python-experimental/petstore_api/configuration.py +++ b/samples/client/petstore/python-experimental/petstore_api/configuration.py @@ -37,6 +37,17 @@ class Configuration(object): The dict value is an API key prefix when generating the auth data. :param username: Username for HTTP basic authentication :param password: Password for HTTP basic authentication + :param discard_unknown_keys: Boolean value indicating whether to discard + unknown properties. A server may send a response that includes additional + properties that are not known by the client in the following scenarios: + 1. The OpenAPI document is incomplete, i.e. it does not match the server + implementation. + 2. The client was generated using an older version of the OpenAPI document + and the server has been upgraded since then. + If a schema in the OpenAPI document defines the additionalProperties attribute, + then all undeclared properties received by the server are injected into the + additional properties map. In that case, there are undeclared properties, and + nothing to discard. :Example: @@ -75,6 +86,7 @@ class Configuration(object): def __init__(self, host="http://petstore.swagger.io:80/v2", api_key=None, api_key_prefix=None, username=None, password=None, + discard_unknown_keys=False, ): """Constructor """ @@ -104,6 +116,7 @@ class Configuration(object): self.password = password """Password for HTTP basic authentication """ + self.discard_unknown_keys = discard_unknown_keys self.access_token = None """access token for OAuth/Bearer """ diff --git a/samples/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/client/petstore/python-experimental/petstore_api/model_utils.py index 6d6a88edb7e..074e597cbd2 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -931,8 +931,9 @@ def attempt_convert_item(input_value, valid_classes, path_to_item, if not valid_classes_coercible or key_type: # we do not handle keytype errors, json will take care # of this for us - raise get_type_error(input_value, path_to_item, valid_classes, - key_type=key_type) + if configuration is None or not configuration.discard_unknown_keys: + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=key_type) for valid_class in valid_classes_coercible: try: if issubclass(valid_class, OpenApiModel): @@ -1371,16 +1372,16 @@ def validate_get_composed_info(constant_args, model_args, self): # set any remaining values unused_args = get_unused_args(self, composed_instances, model_args) - if len(unused_args) > 0: - if len(additional_properties_model_instances) == 0: - raise ApiValueError( - "Invalid input arguments input when making an instance of " - "class %s. Not all inputs were used. The unused input data " - "is %s" % (self.__class__.__name__, unused_args) - ) - for var_name, var_value in six.iteritems(unused_args): - for instance in additional_properties_model_instances: - setattr(instance, var_name, var_value) + if len(unused_args) > 0 and \ + len(additional_properties_model_instances) == 0 and \ + (self._configuration is None or + not self._configuration.discard_unknown_keys): + raise ApiValueError( + "Invalid input arguments input when making an instance of " + "class %s. Not all inputs were used. The unused input data " + "is %s" % (self.__class__.__name__, unused_args) + ) + # no need to add additional_properties to var_name_to_model_instances here # because additional_properties_model_instances will direct us to that # instance when we use getattr or setattr @@ -1389,5 +1390,6 @@ def validate_get_composed_info(constant_args, model_args, self): return [ composed_instances, var_name_to_model_instances, - additional_properties_model_instances + additional_properties_model_instances, + unused_args ] diff --git a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_any_type.py b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_any_type.py index c9e1d7389dd..440ca367274 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_any_type.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_any_type.py @@ -124,4 +124,10 @@ class AdditionalPropertiesAnyType(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_array.py b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_array.py index 340e6389270..4c5054603ee 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_array.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_array.py @@ -124,4 +124,10 @@ class AdditionalPropertiesArray(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_boolean.py b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_boolean.py index 78f9ac1bb6d..676c97d2915 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_boolean.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_boolean.py @@ -124,4 +124,10 @@ class AdditionalPropertiesBoolean(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_class.py b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_class.py index 2f0d79a7993..d0dcda0f193 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_class.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_class.py @@ -154,4 +154,10 @@ class AdditionalPropertiesClass(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_integer.py b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_integer.py index b716a6ec6cd..e51a3ada19d 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_integer.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_integer.py @@ -124,4 +124,10 @@ class AdditionalPropertiesInteger(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_number.py b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_number.py index 17b717ebf0b..c8cceb76440 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_number.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_number.py @@ -124,4 +124,10 @@ class AdditionalPropertiesNumber(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_object.py b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_object.py index 8bd9c9e0853..56d227c144d 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_object.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_object.py @@ -124,4 +124,10 @@ class AdditionalPropertiesObject(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_string.py b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_string.py index 20180ba810d..c4a066f0042 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_string.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/additional_properties_string.py @@ -124,4 +124,10 @@ class AdditionalPropertiesString(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/animal.py b/samples/client/petstore/python-experimental/petstore_api/models/animal.py index abb0d49e74c..4971ab17ab5 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/animal.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/animal.py @@ -144,6 +144,12 @@ class Animal(ModelNormal): self.class_name = class_name for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) @classmethod diff --git a/samples/client/petstore/python-experimental/petstore_api/models/api_response.py b/samples/client/petstore/python-experimental/petstore_api/models/api_response.py index cc3d2cea442..893024a80b9 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/api_response.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/api_response.py @@ -130,4 +130,10 @@ class ApiResponse(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/array_of_array_of_number_only.py b/samples/client/petstore/python-experimental/petstore_api/models/array_of_array_of_number_only.py index 3c0175acdd8..faa9b5c44cc 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/array_of_array_of_number_only.py @@ -124,4 +124,10 @@ class ArrayOfArrayOfNumberOnly(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/array_of_number_only.py b/samples/client/petstore/python-experimental/petstore_api/models/array_of_number_only.py index 28bacd7021d..2909708136d 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/array_of_number_only.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/array_of_number_only.py @@ -124,4 +124,10 @@ class ArrayOfNumberOnly(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/array_test.py b/samples/client/petstore/python-experimental/petstore_api/models/array_test.py index c99bc985cab..7f4f1090663 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/array_test.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/array_test.py @@ -135,4 +135,10 @@ class ArrayTest(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/capitalization.py b/samples/client/petstore/python-experimental/petstore_api/models/capitalization.py index 8311ed65ba2..b4be4b15e71 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/capitalization.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/capitalization.py @@ -139,4 +139,10 @@ class Capitalization(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/cat.py b/samples/client/petstore/python-experimental/petstore_api/models/cat.py index 229d0445554..2683db83580 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/cat.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/cat.py @@ -154,9 +154,16 @@ class Cat(ModelComposed): self._composed_instances = composed_info[0] self._var_name_to_model_instances = composed_info[1] self._additional_properties_model_instances = composed_info[2] + unused_args = composed_info[3] self.class_name = class_name for var_name, var_value in six.iteritems(kwargs): + if var_name in unused_args and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + not self._additional_properties_model_instances: + # discard variable. + continue setattr(self, var_name, var_value) @staticmethod diff --git a/samples/client/petstore/python-experimental/petstore_api/models/cat_all_of.py b/samples/client/petstore/python-experimental/petstore_api/models/cat_all_of.py index 00b0cfae654..1c3fe2578a4 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/cat_all_of.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/cat_all_of.py @@ -124,4 +124,10 @@ class CatAllOf(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/category.py b/samples/client/petstore/python-experimental/petstore_api/models/category.py index 2530a19b2f3..fcdb58cb956 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/category.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/category.py @@ -129,4 +129,10 @@ class Category(ModelNormal): self.name = name for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/child.py b/samples/client/petstore/python-experimental/petstore_api/models/child.py index 9721a0b684f..efbce35e8ba 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/child.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/child.py @@ -152,8 +152,15 @@ class Child(ModelComposed): self._composed_instances = composed_info[0] self._var_name_to_model_instances = composed_info[1] self._additional_properties_model_instances = composed_info[2] + unused_args = composed_info[3] for var_name, var_value in six.iteritems(kwargs): + if var_name in unused_args and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + not self._additional_properties_model_instances: + # discard variable. + continue setattr(self, var_name, var_value) @staticmethod diff --git a/samples/client/petstore/python-experimental/petstore_api/models/child_all_of.py b/samples/client/petstore/python-experimental/petstore_api/models/child_all_of.py index f52720359c0..c4b55ed362b 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/child_all_of.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/child_all_of.py @@ -124,4 +124,10 @@ class ChildAllOf(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/child_cat.py b/samples/client/petstore/python-experimental/petstore_api/models/child_cat.py index 7828dba8cb8..eab41ebbf11 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/child_cat.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/child_cat.py @@ -151,9 +151,16 @@ class ChildCat(ModelComposed): self._composed_instances = composed_info[0] self._var_name_to_model_instances = composed_info[1] self._additional_properties_model_instances = composed_info[2] + unused_args = composed_info[3] self.pet_type = pet_type for var_name, var_value in six.iteritems(kwargs): + if var_name in unused_args and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + not self._additional_properties_model_instances: + # discard variable. + continue setattr(self, var_name, var_value) @staticmethod diff --git a/samples/client/petstore/python-experimental/petstore_api/models/child_cat_all_of.py b/samples/client/petstore/python-experimental/petstore_api/models/child_cat_all_of.py index 1870b3ff31f..11b8c5d2c12 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/child_cat_all_of.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/child_cat_all_of.py @@ -124,4 +124,10 @@ class ChildCatAllOf(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/child_dog.py b/samples/client/petstore/python-experimental/petstore_api/models/child_dog.py index 36180f15713..adbc33daf77 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/child_dog.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/child_dog.py @@ -151,9 +151,16 @@ class ChildDog(ModelComposed): self._composed_instances = composed_info[0] self._var_name_to_model_instances = composed_info[1] self._additional_properties_model_instances = composed_info[2] + unused_args = composed_info[3] self.pet_type = pet_type for var_name, var_value in six.iteritems(kwargs): + if var_name in unused_args and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + not self._additional_properties_model_instances: + # discard variable. + continue setattr(self, var_name, var_value) @staticmethod diff --git a/samples/client/petstore/python-experimental/petstore_api/models/child_dog_all_of.py b/samples/client/petstore/python-experimental/petstore_api/models/child_dog_all_of.py index edc47f75b49..21fee1506a6 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/child_dog_all_of.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/child_dog_all_of.py @@ -124,4 +124,10 @@ class ChildDogAllOf(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/child_lizard.py b/samples/client/petstore/python-experimental/petstore_api/models/child_lizard.py index cb79d4ad604..20c04d3f2fc 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/child_lizard.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/child_lizard.py @@ -151,9 +151,16 @@ class ChildLizard(ModelComposed): self._composed_instances = composed_info[0] self._var_name_to_model_instances = composed_info[1] self._additional_properties_model_instances = composed_info[2] + unused_args = composed_info[3] self.pet_type = pet_type for var_name, var_value in six.iteritems(kwargs): + if var_name in unused_args and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + not self._additional_properties_model_instances: + # discard variable. + continue setattr(self, var_name, var_value) @staticmethod diff --git a/samples/client/petstore/python-experimental/petstore_api/models/child_lizard_all_of.py b/samples/client/petstore/python-experimental/petstore_api/models/child_lizard_all_of.py index 00eb1360931..f429c864d5b 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/child_lizard_all_of.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/child_lizard_all_of.py @@ -124,4 +124,10 @@ class ChildLizardAllOf(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/class_model.py b/samples/client/petstore/python-experimental/petstore_api/models/class_model.py index f268d8576d5..e4f1d63a264 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/class_model.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/class_model.py @@ -124,4 +124,10 @@ class ClassModel(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/client.py b/samples/client/petstore/python-experimental/petstore_api/models/client.py index 1097c624d72..f3f645da382 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/client.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/client.py @@ -124,4 +124,10 @@ class Client(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/dog.py b/samples/client/petstore/python-experimental/petstore_api/models/dog.py index b29e31d4e5d..462869ffbd2 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/dog.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/dog.py @@ -154,9 +154,16 @@ class Dog(ModelComposed): self._composed_instances = composed_info[0] self._var_name_to_model_instances = composed_info[1] self._additional_properties_model_instances = composed_info[2] + unused_args = composed_info[3] self.class_name = class_name for var_name, var_value in six.iteritems(kwargs): + if var_name in unused_args and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + not self._additional_properties_model_instances: + # discard variable. + continue setattr(self, var_name, var_value) @staticmethod diff --git a/samples/client/petstore/python-experimental/petstore_api/models/dog_all_of.py b/samples/client/petstore/python-experimental/petstore_api/models/dog_all_of.py index 316ec102b91..ec62d18e637 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/dog_all_of.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/dog_all_of.py @@ -124,4 +124,10 @@ class DogAllOf(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/enum_arrays.py b/samples/client/petstore/python-experimental/petstore_api/models/enum_arrays.py index d997d53fac7..59f73c8f1c9 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/enum_arrays.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/enum_arrays.py @@ -135,4 +135,10 @@ class EnumArrays(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/enum_class.py b/samples/client/petstore/python-experimental/petstore_api/models/enum_class.py index bda8183ce78..994d7723842 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/enum_class.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/enum_class.py @@ -123,4 +123,10 @@ class EnumClass(ModelSimple): self.value = value for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/enum_test.py b/samples/client/petstore/python-experimental/petstore_api/models/enum_test.py index 42a4c562150..2d5efd84b26 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/enum_test.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/enum_test.py @@ -161,4 +161,10 @@ class EnumTest(ModelNormal): self.enum_string_required = enum_string_required for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/file.py b/samples/client/petstore/python-experimental/petstore_api/models/file.py index ecc56b0cd00..46f02f4436c 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/file.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/file.py @@ -124,4 +124,10 @@ class File(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/file_schema_test_class.py b/samples/client/petstore/python-experimental/petstore_api/models/file_schema_test_class.py index f1abb16cbc3..9c5cb0c6366 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/file_schema_test_class.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/file_schema_test_class.py @@ -132,4 +132,10 @@ class FileSchemaTestClass(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/format_test.py b/samples/client/petstore/python-experimental/petstore_api/models/format_test.py index 7646127e37a..9325e5888e9 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/format_test.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/format_test.py @@ -200,4 +200,10 @@ class FormatTest(ModelNormal): self.date = date self.password = password for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/grandparent.py b/samples/client/petstore/python-experimental/petstore_api/models/grandparent.py index 36ec14bf408..dc71d92196f 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/grandparent.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/grandparent.py @@ -124,4 +124,10 @@ class Grandparent(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/grandparent_animal.py b/samples/client/petstore/python-experimental/petstore_api/models/grandparent_animal.py index c089ebf9bc0..127de0d2e04 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/grandparent_animal.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/grandparent_animal.py @@ -126,4 +126,10 @@ class GrandparentAnimal(ModelNormal): self.pet_type = pet_type for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/has_only_read_only.py b/samples/client/petstore/python-experimental/petstore_api/models/has_only_read_only.py index 90c4908aa89..cf66f3fc02e 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/has_only_read_only.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/has_only_read_only.py @@ -127,4 +127,10 @@ class HasOnlyReadOnly(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/list.py b/samples/client/petstore/python-experimental/petstore_api/models/list.py index e6816fb51a0..d4cd4c4eb46 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/list.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/list.py @@ -124,4 +124,10 @@ class List(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/map_test.py b/samples/client/petstore/python-experimental/petstore_api/models/map_test.py index e996e27991c..95d680e9ebd 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/map_test.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/map_test.py @@ -142,4 +142,10 @@ class MapTest(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/client/petstore/python-experimental/petstore_api/models/mixed_properties_and_additional_properties_class.py index 60b89762456..7eb5df3cc68 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -135,4 +135,10 @@ class MixedPropertiesAndAdditionalPropertiesClass(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/model200_response.py b/samples/client/petstore/python-experimental/petstore_api/models/model200_response.py index cdfb0db9d60..4eb1672966a 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/model200_response.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/model200_response.py @@ -127,4 +127,10 @@ class Model200Response(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/model_return.py b/samples/client/petstore/python-experimental/petstore_api/models/model_return.py index a145f8e706c..740c8e14056 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/model_return.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/model_return.py @@ -124,4 +124,10 @@ class ModelReturn(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/name.py b/samples/client/petstore/python-experimental/petstore_api/models/name.py index e3b0378bab6..c85f89a118c 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/name.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/name.py @@ -135,4 +135,10 @@ class Name(ModelNormal): self.name = name for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/number_only.py b/samples/client/petstore/python-experimental/petstore_api/models/number_only.py index 6a30356c5e9..a3f20cd4b4b 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/number_only.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/number_only.py @@ -124,4 +124,10 @@ class NumberOnly(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/order.py b/samples/client/petstore/python-experimental/petstore_api/models/order.py index 6e4e8af79fa..15c23366e43 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/order.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/order.py @@ -144,4 +144,10 @@ class Order(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/outer_composite.py b/samples/client/petstore/python-experimental/petstore_api/models/outer_composite.py index 067ac6a1400..e643f6e73bd 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/outer_composite.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/outer_composite.py @@ -135,4 +135,10 @@ class OuterComposite(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/outer_enum.py b/samples/client/petstore/python-experimental/petstore_api/models/outer_enum.py index fb040a6785a..8796d7d3f2b 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/outer_enum.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/outer_enum.py @@ -123,4 +123,10 @@ class OuterEnum(ModelSimple): self.value = value for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/outer_number.py b/samples/client/petstore/python-experimental/petstore_api/models/outer_number.py index 1ff253f826d..faab717c987 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/outer_number.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/outer_number.py @@ -122,4 +122,10 @@ class OuterNumber(ModelSimple): self.value = value for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/parent.py b/samples/client/petstore/python-experimental/petstore_api/models/parent.py index 70534d8026e..e75f035ec76 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/parent.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/parent.py @@ -149,8 +149,15 @@ class Parent(ModelComposed): self._composed_instances = composed_info[0] self._var_name_to_model_instances = composed_info[1] self._additional_properties_model_instances = composed_info[2] + unused_args = composed_info[3] for var_name, var_value in six.iteritems(kwargs): + if var_name in unused_args and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + not self._additional_properties_model_instances: + # discard variable. + continue setattr(self, var_name, var_value) @staticmethod diff --git a/samples/client/petstore/python-experimental/petstore_api/models/parent_all_of.py b/samples/client/petstore/python-experimental/petstore_api/models/parent_all_of.py index 1842c83edb2..49639b57566 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/parent_all_of.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/parent_all_of.py @@ -124,4 +124,10 @@ class ParentAllOf(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/parent_pet.py b/samples/client/petstore/python-experimental/petstore_api/models/parent_pet.py index 16d00f42da5..9ef05ab1a4a 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/parent_pet.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/parent_pet.py @@ -164,9 +164,16 @@ class ParentPet(ModelComposed): self._composed_instances = composed_info[0] self._var_name_to_model_instances = composed_info[1] self._additional_properties_model_instances = composed_info[2] + unused_args = composed_info[3] self.pet_type = pet_type for var_name, var_value in six.iteritems(kwargs): + if var_name in unused_args and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + not self._additional_properties_model_instances: + # discard variable. + continue setattr(self, var_name, var_value) @staticmethod diff --git a/samples/client/petstore/python-experimental/petstore_api/models/pet.py b/samples/client/petstore/python-experimental/petstore_api/models/pet.py index 11ffa6ff44f..1682c3cb51b 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/pet.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/pet.py @@ -157,4 +157,10 @@ class Pet(ModelNormal): self.name = name self.photo_urls = photo_urls for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/player.py b/samples/client/petstore/python-experimental/petstore_api/models/player.py index 75b3ca33767..4e2933ab419 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/player.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/player.py @@ -129,4 +129,10 @@ class Player(ModelNormal): self.name = name for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/read_only_first.py b/samples/client/petstore/python-experimental/petstore_api/models/read_only_first.py index d2239f91920..6a18e6331f6 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/read_only_first.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/read_only_first.py @@ -127,4 +127,10 @@ class ReadOnlyFirst(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/special_model_name.py b/samples/client/petstore/python-experimental/petstore_api/models/special_model_name.py index 607ddacbc05..006f9454b85 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/special_model_name.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/special_model_name.py @@ -124,4 +124,10 @@ class SpecialModelName(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/string_boolean_map.py b/samples/client/petstore/python-experimental/petstore_api/models/string_boolean_map.py index a5425b412ac..d7b0b0a9450 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/string_boolean_map.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/string_boolean_map.py @@ -121,4 +121,10 @@ class StringBooleanMap(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/tag.py b/samples/client/petstore/python-experimental/petstore_api/models/tag.py index fe8f0cc3540..6c529a5785d 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/tag.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/tag.py @@ -130,4 +130,10 @@ class Tag(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/type_holder_default.py b/samples/client/petstore/python-experimental/petstore_api/models/type_holder_default.py index da0ca9ea986..8579bfc1a17 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/type_holder_default.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/type_holder_default.py @@ -148,4 +148,10 @@ class TypeHolderDefault(ModelNormal): self.bool_item = bool_item self.array_item = array_item for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/type_holder_example.py b/samples/client/petstore/python-experimental/petstore_api/models/type_holder_example.py index 1b8c1639867..8c78ff54a7d 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/type_holder_example.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/type_holder_example.py @@ -151,4 +151,10 @@ class TypeHolderExample(ModelNormal): self.bool_item = bool_item self.array_item = array_item for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/user.py b/samples/client/petstore/python-experimental/petstore_api/models/user.py index 62c3bd48a16..3776e7e7f3f 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/user.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/user.py @@ -145,4 +145,10 @@ class User(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-experimental/petstore_api/models/xml_item.py b/samples/client/petstore/python-experimental/petstore_api/models/xml_item.py index 8b5096a4bd9..142c5ea2d6f 100644 --- a/samples/client/petstore/python-experimental/petstore_api/models/xml_item.py +++ b/samples/client/petstore/python-experimental/petstore_api/models/xml_item.py @@ -208,4 +208,10 @@ class XmlItem(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/client/petstore/python-tornado/petstore_api/configuration.py b/samples/client/petstore/python-tornado/petstore_api/configuration.py index faadfd56055..1234504debb 100644 --- a/samples/client/petstore/python-tornado/petstore_api/configuration.py +++ b/samples/client/petstore/python-tornado/petstore_api/configuration.py @@ -37,6 +37,17 @@ class Configuration(object): The dict value is an API key prefix when generating the auth data. :param username: Username for HTTP basic authentication :param password: Password for HTTP basic authentication + :param discard_unknown_keys: Boolean value indicating whether to discard + unknown properties. A server may send a response that includes additional + properties that are not known by the client in the following scenarios: + 1. The OpenAPI document is incomplete, i.e. it does not match the server + implementation. + 2. The client was generated using an older version of the OpenAPI document + and the server has been upgraded since then. + If a schema in the OpenAPI document defines the additionalProperties attribute, + then all undeclared properties received by the server are injected into the + additional properties map. In that case, there are undeclared properties, and + nothing to discard. :Example: @@ -75,6 +86,7 @@ class Configuration(object): def __init__(self, host="http://petstore.swagger.io:80/v2", api_key=None, api_key_prefix=None, username=None, password=None, + discard_unknown_keys=False, ): """Constructor """ @@ -104,6 +116,7 @@ class Configuration(object): self.password = password """Password for HTTP basic authentication """ + self.discard_unknown_keys = discard_unknown_keys self.access_token = None """access token for OAuth/Bearer """ diff --git a/samples/client/petstore/python/petstore_api/configuration.py b/samples/client/petstore/python/petstore_api/configuration.py index faadfd56055..1234504debb 100644 --- a/samples/client/petstore/python/petstore_api/configuration.py +++ b/samples/client/petstore/python/petstore_api/configuration.py @@ -37,6 +37,17 @@ class Configuration(object): The dict value is an API key prefix when generating the auth data. :param username: Username for HTTP basic authentication :param password: Password for HTTP basic authentication + :param discard_unknown_keys: Boolean value indicating whether to discard + unknown properties. A server may send a response that includes additional + properties that are not known by the client in the following scenarios: + 1. The OpenAPI document is incomplete, i.e. it does not match the server + implementation. + 2. The client was generated using an older version of the OpenAPI document + and the server has been upgraded since then. + If a schema in the OpenAPI document defines the additionalProperties attribute, + then all undeclared properties received by the server are injected into the + additional properties map. In that case, there are undeclared properties, and + nothing to discard. :Example: @@ -75,6 +86,7 @@ class Configuration(object): def __init__(self, host="http://petstore.swagger.io:80/v2", api_key=None, api_key_prefix=None, username=None, password=None, + discard_unknown_keys=False, ): """Constructor """ @@ -104,6 +116,7 @@ class Configuration(object): self.password = password """Password for HTTP basic authentication """ + self.discard_unknown_keys = discard_unknown_keys self.access_token = None """access token for OAuth/Bearer """ diff --git a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml index 177b761d6b6..b141d4d19b7 100644 --- a/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml +++ b/samples/openapi3/client/petstore/go-experimental/go-petstore/api/openapi.yaml @@ -1456,7 +1456,12 @@ components: Cat: allOf: - $ref: '#/components/schemas/Animal' + - $ref: '#/components/schemas/Address' - $ref: '#/components/schemas/Cat_allOf' + Address: + additionalProperties: + type: integer + type: object Animal: discriminator: propertyName: className diff --git a/samples/openapi3/client/petstore/python-experimental/README.md b/samples/openapi3/client/petstore/python-experimental/README.md index 1fa0ed6f66e..7c1b27f95a4 100644 --- a/samples/openapi3/client/petstore/python-experimental/README.md +++ b/samples/openapi3/client/petstore/python-experimental/README.md @@ -117,6 +117,7 @@ Class | Method | HTTP request | Description ## Documentation For Models - [additional_properties_class.AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md) + - [address.Address](docs/Address.md) - [animal.Animal](docs/Animal.md) - [api_response.ApiResponse](docs/ApiResponse.md) - [array_of_array_of_number_only.ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md) diff --git a/samples/openapi3/client/petstore/python-experimental/docs/Address.md b/samples/openapi3/client/petstore/python-experimental/docs/Address.md new file mode 100644 index 00000000000..23a2f2b1aec --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/docs/Address.md @@ -0,0 +1,10 @@ +# address.Address + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**any string name** | **int** | 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-experimental/petstore_api/__init__.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/__init__.py index 597e3243e31..fbe114c9177 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/__init__.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/__init__.py @@ -41,6 +41,7 @@ from petstore_api.exceptions import ApiException # import models into sdk package from petstore_api.models.additional_properties_class import AdditionalPropertiesClass +from petstore_api.models.address import Address from petstore_api.models.animal import Animal from petstore_api.models.api_response import ApiResponse from petstore_api.models.array_of_array_of_number_only import ArrayOfArrayOfNumberOnly diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/configuration.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/configuration.py index cce89b13aca..bcd43f160f5 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/configuration.py @@ -37,6 +37,17 @@ class Configuration(object): The dict value is an API key prefix when generating the auth data. :param username: Username for HTTP basic authentication :param password: Password for HTTP basic authentication + :param discard_unknown_keys: Boolean value indicating whether to discard + unknown properties. A server may send a response that includes additional + properties that are not known by the client in the following scenarios: + 1. The OpenAPI document is incomplete, i.e. it does not match the server + implementation. + 2. The client was generated using an older version of the OpenAPI document + and the server has been upgraded since then. + If a schema in the OpenAPI document defines the additionalProperties attribute, + then all undeclared properties received by the server are injected into the + additional properties map. In that case, there are undeclared properties, and + nothing to discard. :param signing_info: Configuration parameters for the HTTP signature security scheme. Must be an instance of petstore_api.signing.HttpSigningConfiguration @@ -116,6 +127,7 @@ class Configuration(object): def __init__(self, host="http://petstore.swagger.io:80/v2", api_key=None, api_key_prefix=None, username=None, password=None, + discard_unknown_keys=False, signing_info=None, ): """Constructor @@ -146,6 +158,7 @@ class Configuration(object): self.password = password """Password for HTTP basic authentication """ + self.discard_unknown_keys = discard_unknown_keys if signing_info is not None: signing_info.host = host self.signing_info = signing_info diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py index 6d6a88edb7e..074e597cbd2 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model_utils.py @@ -931,8 +931,9 @@ def attempt_convert_item(input_value, valid_classes, path_to_item, if not valid_classes_coercible or key_type: # we do not handle keytype errors, json will take care # of this for us - raise get_type_error(input_value, path_to_item, valid_classes, - key_type=key_type) + if configuration is None or not configuration.discard_unknown_keys: + raise get_type_error(input_value, path_to_item, valid_classes, + key_type=key_type) for valid_class in valid_classes_coercible: try: if issubclass(valid_class, OpenApiModel): @@ -1371,16 +1372,16 @@ def validate_get_composed_info(constant_args, model_args, self): # set any remaining values unused_args = get_unused_args(self, composed_instances, model_args) - if len(unused_args) > 0: - if len(additional_properties_model_instances) == 0: - raise ApiValueError( - "Invalid input arguments input when making an instance of " - "class %s. Not all inputs were used. The unused input data " - "is %s" % (self.__class__.__name__, unused_args) - ) - for var_name, var_value in six.iteritems(unused_args): - for instance in additional_properties_model_instances: - setattr(instance, var_name, var_value) + if len(unused_args) > 0 and \ + len(additional_properties_model_instances) == 0 and \ + (self._configuration is None or + not self._configuration.discard_unknown_keys): + raise ApiValueError( + "Invalid input arguments input when making an instance of " + "class %s. Not all inputs were used. The unused input data " + "is %s" % (self.__class__.__name__, unused_args) + ) + # no need to add additional_properties to var_name_to_model_instances here # because additional_properties_model_instances will direct us to that # instance when we use getattr or setattr @@ -1389,5 +1390,6 @@ def validate_get_composed_info(constant_args, model_args, self): return [ composed_instances, var_name_to_model_instances, - additional_properties_model_instances + additional_properties_model_instances, + unused_args ] diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/additional_properties_class.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/additional_properties_class.py index 1539b694b56..19b97e69b6a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/additional_properties_class.py @@ -127,4 +127,10 @@ class AdditionalPropertiesClass(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/address.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/address.py new file mode 100644 index 00000000000..39cec075013 --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/address.py @@ -0,0 +1,130 @@ +# 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 +""" + + +from __future__ import absolute_import +import re # noqa: F401 +import sys # noqa: F401 + +import six # noqa: F401 + +from petstore_api.model_utils import ( # noqa: F401 + ModelComposed, + ModelNormal, + ModelSimple, + date, + datetime, + file_type, + int, + none_type, + str, + validate_get_composed_info, +) + + +class Address(ModelNormal): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + + Attributes: + allowed_values (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + with a capitalized key describing the allowed value and an allowed + value. These dicts store the allowed enum values. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + discriminator_value_class_map (dict): A dict to go from the discriminator + variable value to the discriminator class name. + validations (dict): The key is the tuple path to the attribute + and the for var_name this is (var_name,). The value is a dict + that stores validations for max_length, min_length, max_items, + min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, + inclusive_minimum, and regex. + additional_properties_type (tuple): A tuple of classes accepted + as additional properties values. + """ + + allowed_values = { + } + + validations = { + } + + additional_properties_type = (int,) # noqa: E501 + + @staticmethod + def openapi_types(): + """ + This must be a class method so a model may have properties that are + of type self, this ensures that we don't create a cyclic import + + Returns + openapi_types (dict): The key is attribute name + and the value is attribute type. + """ + return { + } + + @staticmethod + def discriminator(): + return None + + attribute_map = { + } + + @staticmethod + def _composed_schemas(): + return None + + required_properties = set([ + '_data_store', + '_check_type', + '_from_server', + '_path_to_item', + '_configuration', + ]) + + def __init__(self, _check_type=True, _from_server=False, _path_to_item=(), _configuration=None, **kwargs): # noqa: E501 + """address.Address - a model defined in OpenAPI + + + Keyword Args: + _check_type (bool): if True, values for parameters in openapi_types + will be type checked and a TypeError will be + raised if the wrong type is input. + Defaults to True + _path_to_item (tuple/list): This is a list of keys or values to + drill down to the model in received_data + when deserializing a response + _from_server (bool): True if the data is from the server + False if the data is from the client (default) + _configuration (Configuration): the instance to use when + deserializing a file_type parameter. + If passed, type conversion is attempted + If omitted no type conversion is done. + """ + + self._data_store = {} + self._check_type = _check_type + self._from_server = _from_server + self._path_to_item = _path_to_item + self._configuration = _configuration + + for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue + setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/animal.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/animal.py index abb0d49e74c..4971ab17ab5 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/animal.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/animal.py @@ -144,6 +144,12 @@ class Animal(ModelNormal): self.class_name = class_name for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) @classmethod diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/api_response.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/api_response.py index cc3d2cea442..893024a80b9 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/api_response.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/api_response.py @@ -130,4 +130,10 @@ class ApiResponse(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_of_array_of_number_only.py index 3c0175acdd8..faa9b5c44cc 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_of_array_of_number_only.py @@ -124,4 +124,10 @@ class ArrayOfArrayOfNumberOnly(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_of_number_only.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_of_number_only.py index 28bacd7021d..2909708136d 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_of_number_only.py @@ -124,4 +124,10 @@ class ArrayOfNumberOnly(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_test.py index c99bc985cab..7f4f1090663 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_test.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/array_test.py @@ -135,4 +135,10 @@ class ArrayTest(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/capitalization.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/capitalization.py index 8311ed65ba2..b4be4b15e71 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/capitalization.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/capitalization.py @@ -139,4 +139,10 @@ class Capitalization(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/cat.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/cat.py index 229d0445554..4106ff709bb 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/cat.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/cat.py @@ -28,6 +28,11 @@ from petstore_api.model_utils import ( # noqa: F401 str, validate_get_composed_info, ) +try: + from petstore_api.models import address +except ImportError: + address = sys.modules[ + 'petstore_api.models.address'] try: from petstore_api.models import animal except ImportError: @@ -154,9 +159,16 @@ class Cat(ModelComposed): self._composed_instances = composed_info[0] self._var_name_to_model_instances = composed_info[1] self._additional_properties_model_instances = composed_info[2] + unused_args = composed_info[3] self.class_name = class_name for var_name, var_value in six.iteritems(kwargs): + if var_name in unused_args and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + not self._additional_properties_model_instances: + # discard variable. + continue setattr(self, var_name, var_value) @staticmethod @@ -172,6 +184,7 @@ class Cat(ModelComposed): 'anyOf': [ ], 'allOf': [ + address.Address, animal.Animal, cat_all_of.CatAllOf, ], diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/cat_all_of.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/cat_all_of.py index 00b0cfae654..1c3fe2578a4 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/cat_all_of.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/cat_all_of.py @@ -124,4 +124,10 @@ class CatAllOf(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/category.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/category.py index 2530a19b2f3..fcdb58cb956 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/category.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/category.py @@ -129,4 +129,10 @@ class Category(ModelNormal): self.name = name for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/class_model.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/class_model.py index f268d8576d5..e4f1d63a264 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/class_model.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/class_model.py @@ -124,4 +124,10 @@ class ClassModel(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/client.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/client.py index 1097c624d72..f3f645da382 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/client.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/client.py @@ -124,4 +124,10 @@ class Client(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/dog.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/dog.py index b29e31d4e5d..462869ffbd2 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/dog.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/dog.py @@ -154,9 +154,16 @@ class Dog(ModelComposed): self._composed_instances = composed_info[0] self._var_name_to_model_instances = composed_info[1] self._additional_properties_model_instances = composed_info[2] + unused_args = composed_info[3] self.class_name = class_name for var_name, var_value in six.iteritems(kwargs): + if var_name in unused_args and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + not self._additional_properties_model_instances: + # discard variable. + continue setattr(self, var_name, var_value) @staticmethod diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/dog_all_of.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/dog_all_of.py index 316ec102b91..ec62d18e637 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/dog_all_of.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/dog_all_of.py @@ -124,4 +124,10 @@ class DogAllOf(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_arrays.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_arrays.py index d997d53fac7..59f73c8f1c9 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_arrays.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_arrays.py @@ -135,4 +135,10 @@ class EnumArrays(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_class.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_class.py index bda8183ce78..994d7723842 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_class.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_class.py @@ -123,4 +123,10 @@ class EnumClass(ModelSimple): self.value = value for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_test.py index 9c6fc29d458..bb39c26a871 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_test.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/enum_test.py @@ -185,4 +185,10 @@ class EnumTest(ModelNormal): self.enum_string_required = enum_string_required for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/file.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/file.py index ecc56b0cd00..46f02f4436c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/file.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/file.py @@ -124,4 +124,10 @@ class File(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/file_schema_test_class.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/file_schema_test_class.py index f1abb16cbc3..9c5cb0c6366 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/file_schema_test_class.py @@ -132,4 +132,10 @@ class FileSchemaTestClass(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/foo.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/foo.py index 757cebbc1ed..c9503266fc2 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/foo.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/foo.py @@ -124,4 +124,10 @@ class Foo(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/format_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/format_test.py index 7486b49cfe4..cd42a4b11ed 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/format_test.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/format_test.py @@ -212,4 +212,10 @@ class FormatTest(ModelNormal): self.date = date self.password = password for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/has_only_read_only.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/has_only_read_only.py index 90c4908aa89..cf66f3fc02e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/has_only_read_only.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/has_only_read_only.py @@ -127,4 +127,10 @@ class HasOnlyReadOnly(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/health_check_result.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/health_check_result.py index 04a46b759db..84e6ba56231 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/health_check_result.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/health_check_result.py @@ -124,4 +124,10 @@ class HealthCheckResult(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object.py index 5d3ffe93c5a..0879d7cf296 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object.py @@ -127,4 +127,10 @@ class InlineObject(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object1.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object1.py index 93c0ec594c5..bbdd1f9d3c0 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object1.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object1.py @@ -127,4 +127,10 @@ class InlineObject1(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object2.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object2.py index 17ef9471842..1e97636581d 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object2.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object2.py @@ -136,4 +136,10 @@ class InlineObject2(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object3.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object3.py index 8fd4f33ead3..210fe669dc7 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object3.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object3.py @@ -202,4 +202,10 @@ class InlineObject3(ModelNormal): self.pattern_without_delimiter = pattern_without_delimiter self.byte = byte for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object4.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object4.py index ed787c2e253..cb472058943 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object4.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object4.py @@ -130,4 +130,10 @@ class InlineObject4(ModelNormal): self.param = param self.param2 = param2 for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object5.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object5.py index 44e1572bb3b..feaa8525c6d 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object5.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_object5.py @@ -129,4 +129,10 @@ class InlineObject5(ModelNormal): self.required_file = required_file for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_response_default.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_response_default.py index 0154a9e6c40..f1649f46890 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_response_default.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/inline_response_default.py @@ -129,4 +129,10 @@ class InlineResponseDefault(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/list.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/list.py index e6816fb51a0..d4cd4c4eb46 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/list.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/list.py @@ -124,4 +124,10 @@ class List(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/map_test.py index e996e27991c..95d680e9ebd 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/map_test.py @@ -142,4 +142,10 @@ class MapTest(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/mixed_properties_and_additional_properties_class.py index 60b89762456..7eb5df3cc68 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/mixed_properties_and_additional_properties_class.py @@ -135,4 +135,10 @@ class MixedPropertiesAndAdditionalPropertiesClass(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/model200_response.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/model200_response.py index cdfb0db9d60..4eb1672966a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/model200_response.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/model200_response.py @@ -127,4 +127,10 @@ class Model200Response(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/model_return.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/model_return.py index a145f8e706c..740c8e14056 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/model_return.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/model_return.py @@ -124,4 +124,10 @@ class ModelReturn(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/name.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/name.py index e3b0378bab6..c85f89a118c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/name.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/name.py @@ -135,4 +135,10 @@ class Name(ModelNormal): self.name = name for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/nullable_class.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/nullable_class.py index 286f98f1a99..1fad5bd94e7 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/nullable_class.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/nullable_class.py @@ -157,4 +157,10 @@ class NullableClass(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/number_only.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/number_only.py index 6a30356c5e9..a3f20cd4b4b 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/number_only.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/number_only.py @@ -124,4 +124,10 @@ class NumberOnly(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/order.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/order.py index 6e4e8af79fa..15c23366e43 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/order.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/order.py @@ -144,4 +144,10 @@ class Order(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_composite.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_composite.py index 99b7406df90..382e84df252 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_composite.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_composite.py @@ -130,4 +130,10 @@ class OuterComposite(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum.py index 90f65c56cef..39e533a3ecf 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum.py @@ -124,4 +124,10 @@ class OuterEnum(ModelSimple): self.value = value for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_default_value.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_default_value.py index 35f86a699e6..5a05e121f52 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_default_value.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_default_value.py @@ -123,4 +123,10 @@ class OuterEnumDefaultValue(ModelSimple): self.value = value for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_integer.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_integer.py index 2a80e1133c8..b2d55e484b9 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_integer.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_integer.py @@ -123,4 +123,10 @@ class OuterEnumInteger(ModelSimple): self.value = value for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_integer_default_value.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_integer_default_value.py index 3de92379cb3..7a3b77cb824 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_integer_default_value.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/outer_enum_integer_default_value.py @@ -123,4 +123,10 @@ class OuterEnumIntegerDefaultValue(ModelSimple): self.value = value for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/pet.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/pet.py index 11ffa6ff44f..1682c3cb51b 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/pet.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/pet.py @@ -157,4 +157,10 @@ class Pet(ModelNormal): self.name = name self.photo_urls = photo_urls for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/read_only_first.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/read_only_first.py index d2239f91920..6a18e6331f6 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/read_only_first.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/read_only_first.py @@ -127,4 +127,10 @@ class ReadOnlyFirst(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/special_model_name.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/special_model_name.py index 607ddacbc05..006f9454b85 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/special_model_name.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/special_model_name.py @@ -124,4 +124,10 @@ class SpecialModelName(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/string_boolean_map.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/string_boolean_map.py index a5425b412ac..d7b0b0a9450 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/string_boolean_map.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/string_boolean_map.py @@ -121,4 +121,10 @@ class StringBooleanMap(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/tag.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/tag.py index ce06e651ee7..8585d19c710 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/tag.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/tag.py @@ -127,4 +127,10 @@ class Tag(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py index 62c3bd48a16..3776e7e7f3f 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/models/user.py @@ -145,4 +145,10 @@ class User(ModelNormal): self._configuration = _configuration for var_name, var_value in six.iteritems(kwargs): + if var_name not in self.attribute_map and \ + self._configuration is not None and \ + self._configuration.discard_unknown_keys and \ + self.additional_properties_type is None: + # discard variable. + continue setattr(self, var_name, var_value) diff --git a/samples/openapi3/client/petstore/python-experimental/test/test_address.py b/samples/openapi3/client/petstore/python-experimental/test/test_address.py new file mode 100644 index 00000000000..7aa36d745cf --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/test/test_address.py @@ -0,0 +1,37 @@ +# 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 +""" + + +from __future__ import absolute_import + +import unittest + +import petstore_api + + +class TestAddress(unittest.TestCase): + """Address unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def testAddress(self): + """Test Address""" + # FIXME: construct object with mandatory attributes with example values + # model = petstore_api.Address() # noqa: E501 + pass + + +if __name__ == '__main__': + unittest.main() diff --git a/samples/openapi3/client/petstore/python-experimental/tests/test_discard_unknown_properties.py b/samples/openapi3/client/petstore/python-experimental/tests/test_discard_unknown_properties.py new file mode 100644 index 00000000000..769ee23937d --- /dev/null +++ b/samples/openapi3/client/petstore/python-experimental/tests/test_discard_unknown_properties.py @@ -0,0 +1,123 @@ +# coding: utf-8 + +# flake8: noqa + +""" +Run the tests. +$ docker pull swaggerapi/petstore +$ docker run -d -e SWAGGER_HOST=http://petstore.swagger.io -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/petstore +$ pip install nose (optional) +$ cd petstore_api-python +$ nosetests -v +""" +from collections import namedtuple +import json +import os +import re +import shutil +import unittest +from six.moves.urllib.parse import urlencode, urlparse + +import petstore_api +from petstore_api import Configuration, signing +from petstore_api.rest import ( + RESTClientObject, + RESTResponse +) + +from petstore_api.model_utils import ( + file_type, + int, + model_to_dict, + str, +) + +MockResponse = namedtuple('MockResponse', 'data') + +class DiscardUnknownPropertiesTests(unittest.TestCase): + + def test_deserialize_dog_do_not_discard_unknown_properties(self): + """ deserialize str, Dog) with unknown properties, strict validation is enabled """ + config = Configuration(discard_unknown_keys=False) + api_client = petstore_api.ApiClient(config) + data = { + "class_name": "Dog", + "color": "black", + "breed": "husky", + "unknown_property": "a-value" + } + response = MockResponse(data=json.dumps(data)) + + # Deserializing with strict validation raises an exception because the 'unknown_property' + # is undeclared. + with self.assertRaises(petstore_api.ApiValueError) as cm: + deserialized = api_client.deserialize(response, ((petstore_api.Dog),), True) + self.assertTrue(re.match('.*Not all inputs were used.*unknown_property.*', str(cm.exception)), + 'Exception message: {0}'.format(str(cm.exception))) + + def test_deserialize_dog_discard_unknown_properties(self): + """ deserialize str, Dog) with unknown properties, discard unknown properties """ + config = Configuration(discard_unknown_keys=True) + api_client = petstore_api.ApiClient(config) + data = { + "class_name": "Dog", + "color": "black", + "breed": "husky", + "unknown_property": "a-value", + "more-unknown": [ + "a" + ] + } + # The 'unknown_property' is undeclared, which would normally raise an exception, but + # when discard_unknown_keys is set to True, the unknown properties are discarded. + response = MockResponse(data=json.dumps(data)) + deserialized = api_client.deserialize(response, ((petstore_api.Dog),), True) + self.assertTrue(isinstance(deserialized, petstore_api.Dog)) + # Check the 'unknown_property' and 'more-unknown' properties are not present in the + # output. + self.assertIn("breed", deserialized.to_dict().keys()) + self.assertNotIn("unknown_property", deserialized.to_dict().keys()) + self.assertNotIn("more-unknown", deserialized.to_dict().keys()) + + def test_deserialize_cat_do_not_discard_unknown_properties(self): + """ deserialize str, Cat) with unknown properties, strict validation is enabled """ + config = Configuration(discard_unknown_keys=False) + api_client = petstore_api.ApiClient(config) + data = { + "class_name": "Cat", + "color": "black", + "declawed": True, + "dynamic-property": 12345, + } + response = MockResponse(data=json.dumps(data)) + + # Deserializing with strict validation does not raise an exception because the even though + # the 'dynamic-property' is undeclared, the 'Cat' schema defines the additionalProperties + # attribute. + deserialized = api_client.deserialize(response, ((petstore_api.Cat),), True) + self.assertTrue(isinstance(deserialized, petstore_api.Cat)) + self.assertIn('color', deserialized.to_dict()) + self.assertEqual(deserialized['color'], 'black') + + def test_deserialize_cat_discard_unknown_properties(self): + """ deserialize str, Cat) with unknown properties. + Request to discard unknown properties, but Cat is composed schema + with one inner schema that has 'additionalProperties' set to true. """ + config = Configuration(discard_unknown_keys=True) + api_client = petstore_api.ApiClient(config) + data = { + "class_name": "Cat", + "color": "black", + "declawed": True, + "my_additional_property": 123, + } + # The 'my_additional_property' is undeclared, but 'Cat' has a 'Address' type through + # the allOf: [ $ref: '#/components/schemas/Address' ]. + response = MockResponse(data=json.dumps(data)) + deserialized = api_client.deserialize(response, ((petstore_api.Cat),), True) + self.assertTrue(isinstance(deserialized, petstore_api.Cat)) + # Check the 'unknown_property' and 'more-unknown' properties are not present in the + # output. + self.assertIn("declawed", deserialized.to_dict().keys()) + self.assertIn("my_additional_property", deserialized.to_dict().keys()) + diff --git a/samples/openapi3/client/petstore/python/petstore_api/configuration.py b/samples/openapi3/client/petstore/python/petstore_api/configuration.py index 131534656e3..007c4ae2036 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/configuration.py +++ b/samples/openapi3/client/petstore/python/petstore_api/configuration.py @@ -37,6 +37,17 @@ class Configuration(object): The dict value is an API key prefix when generating the auth data. :param username: Username for HTTP basic authentication :param password: Password for HTTP basic authentication + :param discard_unknown_keys: Boolean value indicating whether to discard + unknown properties. A server may send a response that includes additional + properties that are not known by the client in the following scenarios: + 1. The OpenAPI document is incomplete, i.e. it does not match the server + implementation. + 2. The client was generated using an older version of the OpenAPI document + and the server has been upgraded since then. + If a schema in the OpenAPI document defines the additionalProperties attribute, + then all undeclared properties received by the server are injected into the + additional properties map. In that case, there are undeclared properties, and + nothing to discard. :Example: @@ -75,6 +86,7 @@ class Configuration(object): def __init__(self, host="http://petstore.swagger.io:80/v2", api_key=None, api_key_prefix=None, username=None, password=None, + discard_unknown_keys=False, ): """Constructor """ @@ -104,6 +116,7 @@ class Configuration(object): self.password = password """Password for HTTP basic authentication """ + self.discard_unknown_keys = discard_unknown_keys self.access_token = None """access token for OAuth/Bearer """