diff --git a/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/methods_setattr_getattr_composed.mustache b/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/methods_setattr_getattr_composed.mustache index 9adb2a08a1fb..9420fe1582c7 100644 --- a/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/methods_setattr_getattr_composed.mustache +++ b/modules/openapi-generator/src/main/resources/python/python-experimental/model_templates/methods_setattr_getattr_composed.mustache @@ -41,11 +41,17 @@ if self._path_to_item: path_to_item.extend(self._path_to_item) path_to_item.append(name) - values = set() + values = [] + # A composed model stores child (oneof/anyOf/allOf) models under + # self._var_name_to_model_instances. A named property can exist in + # multiple child models. If the property is present in more than one + # child model, the value must be the same across all the child models. if model_instances: for model_instance in model_instances: if name in model_instance._data_store: - values.add(model_instance._data_store[name]) + v = model_instance._data_store[name] + if v not in values: + values.append(v) len_values = len(values) if len_values == 0: raise ApiKeyError( @@ -53,10 +59,10 @@ path_to_item ) elif len_values == 1: - return list(values)[0] + return values[0] elif len_values > 1: raise ApiValueError( - "Values stored for property {0} in {1} difffer when looking " + "Values stored for property {0} in {1} differ when looking " "at self and self's composed instances. All values must be " "the same".format(name, type(self).__name__), path_to_item 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 eed501c84502..10385c4646d2 100644 --- a/samples/client/petstore/python-experimental/petstore_api/model_utils.py +++ b/samples/client/petstore/python-experimental/petstore_api/model_utils.py @@ -274,11 +274,17 @@ def __getattr__(self, name): if self._path_to_item: path_to_item.extend(self._path_to_item) path_to_item.append(name) - values = set() + values = [] + # A composed model stores child (oneof/anyOf/allOf) models under + # self._var_name_to_model_instances. A named property can exist in + # multiple child models. If the property is present in more than one + # child model, the value must be the same across all the child models. if model_instances: for model_instance in model_instances: if name in model_instance._data_store: - values.add(model_instance._data_store[name]) + v = model_instance._data_store[name] + if v not in values: + values.append(v) len_values = len(values) if len_values == 0: raise ApiKeyError( @@ -286,10 +292,10 @@ def __getattr__(self, name): path_to_item ) elif len_values == 1: - return list(values)[0] + return values[0] elif len_values > 1: raise ApiValueError( - "Values stored for property {0} in {1} difffer when looking " + "Values stored for property {0} in {1} differ when looking " "at self and self's composed instances. All values must be " "the same".format(name, type(self).__name__), path_to_item 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 eed501c84502..10385c4646d2 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 @@ -274,11 +274,17 @@ def __getattr__(self, name): if self._path_to_item: path_to_item.extend(self._path_to_item) path_to_item.append(name) - values = set() + values = [] + # A composed model stores child (oneof/anyOf/allOf) models under + # self._var_name_to_model_instances. A named property can exist in + # multiple child models. If the property is present in more than one + # child model, the value must be the same across all the child models. if model_instances: for model_instance in model_instances: if name in model_instance._data_store: - values.add(model_instance._data_store[name]) + v = model_instance._data_store[name] + if v not in values: + values.append(v) len_values = len(values) if len_values == 0: raise ApiKeyError( @@ -286,10 +292,10 @@ def __getattr__(self, name): path_to_item ) elif len_values == 1: - return list(values)[0] + return values[0] elif len_values > 1: raise ApiValueError( - "Values stored for property {0} in {1} difffer when looking " + "Values stored for property {0} in {1} differ when looking " "at self and self's composed instances. All values must be " "the same".format(name, type(self).__name__), path_to_item