-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG][PYTHON][PLUSS OTHERS] Enum variable names not update in all python converters #16560
Comments
can you please file a PR with the suggested fix? |
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 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 Line 870 in 73f2d82
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 |
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.
The text was updated successfully, but these errors were encountered: