-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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][FLASK] enum name issue #16557
Comments
Thanks for reporting the issue. To fix it, one needs to use Is that something you can help file a PR with? |
Thanks for the help! I've tried to touch on the file I'd be happy to try more, but I think I need some more guidance. |
@wing328 diff --git a/modules/openapi-generator/src/main/resources/python-flask/model.mustache b/modules/openapi-generator/src/main/resources/python-flask/model.mustache
index b9603345..a0790fb2 100644
--- a/modules/openapi-generator/src/main/resources/python-flask/model.mustache
+++ b/modules/openapi-generator/src/main/resources/python-flask/model.mustache
@@ -29,12 +29,12 @@ class {{classname}}(Model):
allowed enum values
"""
{{#enumVars}}
- {{name}} = {{{value}}}{{^-last}}
+ {{{name}}} = {{{value}}}{{^-last}}
{{/-last}}
{{/enumVars}}
{{/allowableValues}}
- def __init__(self{{#vars}}, {{name}}={{{defaultValue}}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}): # noqa: E501
+ def __init__(self{{#vars}}, {{{name}}}={{{defaultValue}}}{{^defaultValue}}None{{/defaultValue}}{{/vars}}): # noqa: E501
"""{{classname}} - a model defined in OpenAPI
{{#vars}}
@@ -160,7 +160,7 @@ class {{classname}}(Model):
{{/hasValidation}}
{{/isEnum}}
- self._{{name}} = {{name}}{{^-last}}
+ self._{{{name}}} = {{{name}}}{{^-last}}
{{/-last}}
{{/vars}} |
I got the following after updating the template:
Looks like we need to fix the issue in the python flask generator (java class) as well. |
UPDATE: filed #16576 to fix the issue. |
Result after the PR:
, which seems correct, thank you! I had to manually move the previously generated Very grateful, thanks! |
Bug Report Checklist
-> Nope, but tested with the docker image, which I think is at most 17 days old.
Description
Generated flask server code has bad Python syntax for
enum
.openapi-generator version
7.0.1-SNAPSHOT (got it from Docker)
OpenAPI declaration file content or url
https://github.com/TALQ-consortium/TALQ_specification/tree/main/oas
Steps to reproduce
I'm trying to generate a TALQ gateway in flask, from their OpenAPI specs.
I've download these OpenAPI specs into my local folder, and tried to generate a server as per the Docker instructions.
Generation gave a wall of text, a lot of
INFO
, someWARN
, but the code was generated. I couldn't find anything special about the offending identifiers in this text. Return value in CLI is OK.Then I followed the instructions in
out/flask/README.md
:This results in an error in
openapi_server/models/event_type.py
, the generated python code is invalid:NUMBER_'
is probably wrong, ' is an apostrophe that did not translate correctly. But I'm not sure what the expected result should be.Related issues/PRs
Related issue: #13689
The text was updated successfully, but these errors were encountered: