Open mwilby opened 10 months ago
This is because updateEnumVarsWithExtensions() is never called and to fix it, its a simple matter of adding
can you please file a PR with the suggested fix?
@wing328 @mwilby
Any updates on a fix for this issue? I'm encountering this as well.
I'm encountering the same problem and this is very annoying. It would be great to have some news 😄
openapi: 3.0.0
info:
version: 1.0.0
title: Weather API
paths: {}
components:
schemas:
WeatherType:
type: integer
format: int32
enum:
- 42
- 18
- 56
x-enum-descriptions:
- 'Blue sky'
- 'Slightly overcast'
- 'Take an umbrella with you'
x-enum-varnames:
- Sunny
- Cloudy
- Rainy
The command i used
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/mon_api.yaml -g python-flask -o /local/dist
The generated python file:
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from openapi_server.models.base_model import Model
from openapi_server import util
class WeatherType(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""
"""
allowed enum values
"""
NUMBER_42 = 42
NUMBER_18 = 18
NUMBER_56 = 56
def __init__(self): # noqa: E501
"""WeatherType - a model defined in OpenAPI
"""
self.openapi_types = {
}
self.attribute_map = {
}
@classmethod
def from_dict(cls, dikt) -> 'WeatherType':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The WeatherType of this WeatherType. # noqa: E501
:rtype: WeatherType
"""
return util.deserialize_model(dikt, cls)
While postProcessModelsEnum
is called here: https://github.com/OpenAPITools/openapi-generator/blob/73f2d8289b2d4069675c79ea5375d9c58ea1853c/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java#L870
its effects are overwritten by the code block further down: https://github.com/OpenAPITools/openapi-generator/blob/73f2d8289b2d4069675c79ea5375d9c58ea1853c/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java#L986C1-L998C14
I created PR #18566 preventing the NUMBER_X
transformation to run if x-enum-varnames
is provided.
Bug Report Checklist
There is no need for a detailed report. This is a simple problem with a simple fix and it applies to all versions.
Description
There is a problem with the Python family of converters when processing
enums
. Basically none of them substitutes the enum var extensions.So using a simple scheme definition
The python converter creates this:
If you look at the generated model info, the relevant part is found to be.
This is because
updateEnumVarsWithExtensions()
is never called and to fix it, its a simple matter of addingto the relevant Python????Codegen.java module.
There are a fair number of other language models that don't include a
postProcessModels
override, not sure if it matters, or not, but it probably does.Taking a language that does include the call, in this case, csharp, you generate the correct form of
enum
, i.e.This is because the model has been processed and looks like this.
Suggest a fix
Repeat adding
to the relevant Python????Codegen.java module.