You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my example (OAS 3.0), fields is a key-value dictionary (defined as documented here).
Also, the additionalProperties keyword is used to specify the type of values in that dictionary.
In my example, fields accepts strings as values, in particular only those matching an enum (i.e., "STRING", "BOOLEAN", "NUMBER").
The python generator can indeed recognize this spec, generating the MeasurementDescriptorDto class as it follows:
Please note the type of fields declared as Optional[Dict[str, StrictStr]].
Given that fields is a dictionary (optional), the following validator cannot work.
Indeed, the fields_validate_enum is not expecting a dictionary as input:
@field_validator('fields')deffields_validate_enum(cls, value):
"""Validates the enum"""ifvalueisNone:
returnvalueifvaluenotinset(['STRING', 'BOOLEAN', 'NUMBER']):
raiseValueError("must be one of enum values ('STRING', 'BOOLEAN', 'NUMBER')")
returnvalue
The suggested PR #19316 applies the validation function to the values of the dictionary (i.e., value.values()), not to the dictionary itself (i.e., value).
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Bug Report Checklist
Description
The model validation is wrong for dictionaries with values in Enums. The
fields_validate_enum
method is not expecting a dict as input.openapi-generator version
Docker image: openapitools/openapi-generator-cli
Versions: v7.7.0
OpenAPI declaration file content or url
YAML code
Generation Details
Generated via Docker, using the following command:
docker run --rm -v $(pwd):/api openapitools/openapi-generator-cli:v7.7.0 \ generate -g python \ -c /api/python.yml \ -i /api/openapi.yaml \ -o /api/clients/python
Here is the
python.yml
config file:Steps to reproduce
OS: Ubuntu 22.04
Python: 3.10.12
curl https://gist.githubusercontent.com/vcutrona/adb7571338fce6cb5c495ba4abd725f7/raw/b736a812adcaac6a118f0f7c8d714f81084b63c4/openapi.yaml -o openapi.yaml
python.yml
file with the config specified abovedocker run --rm -v $(pwd):/api openapitools/openapi-generator-cli:v7.7.0 generate -g python -c /api/python.yml -i /api/openapi.yaml -o /api/clients/python
pip install -e clients/python
Exception thrown:
Related issues/PRs
Suggest a fix
In my example (OAS 3.0),
fields
is a key-value dictionary (defined as documented here).Also, the
additionalProperties
keyword is used to specify the type of values in that dictionary.In my example,
fields
accepts strings as values, in particular only those matching an enum (i.e., "STRING", "BOOLEAN", "NUMBER").The python generator can indeed recognize this spec, generating the
MeasurementDescriptorDto
class as it follows:Please note the type of
fields
declared asOptional[Dict[str, StrictStr]]
.Given that
fields
is a dictionary (optional), the following validator cannot work.Indeed, the
fields_validate_enum
is not expecting a dictionary as input:The suggested PR #19316 applies the validation function to the values of the dictionary (i.e.,
value.values()
), not to the dictionary itself (i.e.,value
).The text was updated successfully, but these errors were encountered: