From 1fa68b23911acb18bf497e199e6967ab34665965 Mon Sep 17 00:00:00 2001 From: Vincenzo Cutrona Date: Mon, 5 Aug 2024 15:05:10 +0200 Subject: [PATCH 1/2] checks if input is Array or Map in validate_enum --- .../src/main/resources/python/model_generic.mustache | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python/model_generic.mustache b/modules/openapi-generator/src/main/resources/python/model_generic.mustache index 768f4f75072f..b18464dad9a8 100644 --- a/modules/openapi-generator/src/main/resources/python/model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/python/model_generic.mustache @@ -73,15 +73,22 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}} {{/isNullable}} {{/required}} + {{#isContainer}} {{#isArray}} for i in value: if i not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]): raise ValueError("each list item must be one of ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") {{/isArray}} - {{^isArray}} + {{#isMap}} + for i in value.values(): + if i not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]): + raise ValueError("dict values must be one of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") + {{/isMap}} + {{/isContainer}} + {{^isContainer}} if value not in set([{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]): raise ValueError("must be one of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})") - {{/isArray}} + {{/isContainer}} return value {{/isEnum}} {{/vars}} From 1c321095922d957b593e3d79869acbfc92660522 Mon Sep 17 00:00:00 2001 From: Vincenzo Cutrona Date: Wed, 7 Aug 2024 14:22:30 +0200 Subject: [PATCH 2/2] update samples --- .../petstore/python-aiohttp/petstore_api/models/map_test.py | 5 +++-- .../client/petstore/python/petstore_api/models/map_test.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py index eb0cd2456097..2a056ab5532a 100644 --- a/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python-aiohttp/petstore_api/models/map_test.py @@ -38,8 +38,9 @@ def map_of_enum_string_validate_enum(cls, value): if value is None: return value - if value not in set(['UPPER', 'lower']): - raise ValueError("must be one of enum values ('UPPER', 'lower')") + for i in value.values(): + if i not in set(['UPPER', 'lower']): + raise ValueError("dict values must be one of enum values ('UPPER', 'lower')") return value model_config = ConfigDict( diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py b/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py index 153a14a90d3d..4cefd36427f9 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/map_test.py @@ -39,8 +39,9 @@ def map_of_enum_string_validate_enum(cls, value): if value is None: return value - if value not in set(['UPPER', 'lower']): - raise ValueError("must be one of enum values ('UPPER', 'lower')") + for i in value.values(): + if i not in set(['UPPER', 'lower']): + raise ValueError("dict values must be one of enum values ('UPPER', 'lower')") return value model_config = ConfigDict(