swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
The setter method in the Python model.mustache template has special handling for list and map properties which are also tagged as enumerated. The list validation checks the list members as expected, but the map validation checks the map keys, when it should check the values. Therefore, given a map property with string keys and enumerated values, the check fails because the map keys are not in the enumeration. This causes deserialization to fail.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
Using Swagger annotations on a Java model class, with enum type MyEnum:
@ApiModelProperty
private final Map<String, MyEnum> mapOfMyEnum;
Command line used for generation
Generated using Maven plugin 2.3.1.
Steps to reproduce
Generate a model class with a property that is a map with string keys and enum values. Note that the allowed_values variable in the setter method for the property lists what's permitted for the enum type, not for keys.
Create a model object with valid values in the map.
Switch "keys" to "values" in Python model.mustache.
if not set({{{name}}}.values()).issubset(set(allowed_values)):
raise ValueError(
"Invalid values in `{{{name}}}` [{0}], must be a subset of [{1}]" # noqa: E501
.format(", ".join(map(str, set({{{name}}}.values()) - set(allowed_values))), # noqa: E501
", ".join(map(str, allowed_values)))
)
Description
The setter method in the Python model.mustache template has special handling for list and map properties which are also tagged as enumerated. The list validation checks the list members as expected, but the map validation checks the map keys, when it should check the values. Therefore, given a map property with string keys and enumerated values, the check fails because the map keys are not in the enumeration. This causes deserialization to fail.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
Using Swagger annotations on a Java model class, with enum type MyEnum:
Command line used for generation
Generated using Maven plugin 2.3.1.
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
Switch "keys" to "values" in Python model.mustache.