Skip to content

Commit

Permalink
Merge branch 'fix-map-enums' of https://github.com/vcutrona/openapi-g…
Browse files Browse the repository at this point in the history
…enerator into vcutrona-fix-map-enums
  • Loading branch information
wing328 committed Oct 10, 2024
2 parents 30e6612 + 1c32109 commit 9334b34
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9334b34

Please sign in to comment.