[BUG][python-nextgen] validation of list of enums doesn't work
Created by: t0mk
def {{{name}}}_validate_enum(cls, v):
{{^required}}
if v is None:
return v
{{/required}}
if v not in ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}):
raise ValueError("must validate the enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})")
return v
.. is called also when "v" is a list, and it checks ["v1", "v2"] not in ["v1","v2"]
, and fails for a legit use case.
It should be sth like
def {{{name}}}_validate_enum(cls, v):
{{^required}}
if v is None:
return v
{{/required}}
if type(v) is list:
for i in v:
if i not in ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}):
raise ValueError("each list item must be one of ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})")
else:
if v not in ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}):
raise ValueError("must be on of enum values ({{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}})")
return v
Example of enum list can be found in spec at: https://github.com/t0mk/metal-python/blob/05f4599ebe3ee42727bf5117403571a739fa52ba/metal_openapi.fixed.yaml#L2662
I'm a bit in a hurry but I hope I wrote it clear.