forked from loafle/openapi-generator-original
* Fixed invalid enum array validation in Python client mustache model * Updated the Petstore Python client tests * Removed superfluous array enum test * Added test cases for Python client array and map enums * Improved map enum error message
This commit is contained in:
@@ -61,11 +61,31 @@ class {{classname}}(object):
|
||||
"""
|
||||
{{#isEnum}}
|
||||
allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
|
||||
{{#isContainer}}
|
||||
{{#isListContainer}}
|
||||
if not set({{{name}}}).issubset(set(allowed_values)):
|
||||
raise ValueError(
|
||||
"Invalid values for `{{{name}}}` [{0}], must be a subset of [{1}]"
|
||||
.format(", ".join(map(str, set({{{name}}})-set(allowed_values))),
|
||||
", ".join(map(str, allowed_values)))
|
||||
)
|
||||
{{/isListContainer}}
|
||||
{{#isMapContainer}}
|
||||
if not set({{{name}}}.keys()).issubset(set(allowed_values)):
|
||||
raise ValueError(
|
||||
"Invalid keys in `{{{name}}}` [{0}], must be a subset of [{1}]"
|
||||
.format(", ".join(map(str, set({{{name}}}.keys())-set(allowed_values))),
|
||||
", ".join(map(str, allowed_values)))
|
||||
)
|
||||
{{/isMapContainer}}
|
||||
{{/isContainer}}
|
||||
{{^isContainer}}
|
||||
if {{{name}}} not in allowed_values:
|
||||
raise ValueError(
|
||||
"Invalid value for `{{{name}}}` ({0}), must be one of {1}"
|
||||
.format({{{name}}}, allowed_values)
|
||||
)
|
||||
{{/isContainer}}
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
{{#hasValidation}}
|
||||
|
||||
Reference in New Issue
Block a user