Skip to content
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

[Python] fix numeric enum in python flask, aiohttp #5019

Merged
merged 3 commits into from
Jan 19, 2020

Conversation

wing328
Copy link
Member

@wing328 wing328 commented Jan 17, 2020

  • Plotted the fix from Python client generator
  • Tested locally with numeric enum

cc @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @Jyhess (2019/01) @slash-arun (2019/11) @spacether (2019/11)

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@@ -116,6 +118,7 @@ class {{classname}}(Model):
{{/isMapContainer}}
{{/isContainer}}
{{^isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#isString}}"{{/isString}}{{{this}}}{{#isString}}"{{/isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are tying to minimize the usage of flake8 E501 and other flake8 opt out lines.
Can you spread this to a multiline statement so we won't need # noqa: E501?

{{#isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#items.isString}}"{{/items.isString}}{{{this}}}{{#items.isString}}"{{/items.isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are tying to minimize the usage of flake8 E501 and other flake8 opt out lines.
Can you spread this to a multiline statement so we won't need # noqa: E501?

@@ -109,6 +109,7 @@ class {{classname}}(Model):
{{/isMapContainer}}
{{/isContainer}}
{{^isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#isString}}"{{/isString}}{{{this}}}{{#isString}}"{{/isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are tying to minimize the usage of flake8 E501 and other flake8 opt out lines.
Can you spread this to a multiline statement so we won't need # noqa: E501?

{{#isContainer}}
allowed_values = [{{#isNullable}}None,{{/isNullable}}{{#allowableValues}}{{#values}}{{#items.isString}}"{{/items.isString}}{{{this}}}{{#items.isString}}"{{/items.isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are tying to minimize the usage of flake8 E501 and other flake8 opt out lines.
Can you spread this to a multiline statement so we won't need # noqa: E501?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this in a separate PR instead. I'll open an issue to track it to see if anyone has the time to improve it.

(this PR simply plots the fix from the python client template)

Copy link
Contributor

@spacether spacether Jan 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting that we remove the E501s in a separate PR? That sounds good.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #5030 for tracking.

@@ -32,7 +32,7 @@ paths:
required: true
x-body-name: body
responses:
405:
"405":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These spec updates are unexpected in this pull review because we did not edit the spec file.
Can you please add the below sample generation files to https://github.com/OpenAPITools/openapi-generator/blob/master/bin/utils/ensure-up-to-date?

  • python-aiohttp
  • python-flask-python2
  • python-flask

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to ensure-up-to-date.

These scripts are using petstore.yaml (original) but not the fake petstore spec (which has numeric enums)

Copy link
Contributor

@spacether spacether Jan 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a model with numeric enums in petstore.yaml?
That lets us verify this fix in the repo and this PR. Or a java test like I mention below also verifies the fix.

Copy link
Member Author

@wing328 wing328 Jan 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update the script to use the fake petstore spec instead (petstore.yaml shouldn't be updated)

When a generator gets mature, we will use fake petstore spec instead of petstore.yaml/json as the generator should be able to handle those edge cases in fake petstore spec.

I'm not sure if these generators can handle the edge cases in fake petstore spec.

@spacether
Copy link
Contributor

spacether commented Jan 17, 2020

  • Tested locally with numeric enum

I am seeing that our sample spec has numeric enums, including numeric enums in models.
Why are we not seeing a model update including this case?

If we don't have a spec of this use case, could you add a minimal spec with it?

  • Adding this spec will also allow other generators to test for this condition.

If we do have a spec with this use case can you use it?
Can you add JAVA test here with that spec using one of fromModel/fromOperation/fromProperty etc verifying that the generated enum is correct?

@wing328
Copy link
Member Author

wing328 commented Jan 19, 2020

Can you add JAVA test here with that spec using one of fromModel/fromOperation/fromProperty etc verifying that the generated enum is correct?

If you look at the fix, it cannot be tested in the Java class because it uses isString in the mustache template to determine whether a double quote is required.

Later after switching these scripts from petstore.yaml to fake petstore petstore, we can add test(s) in the samples to ensure the output is correct.

Copy link
Contributor

@spacether spacether left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about the testing. This looks good as is.

@wing328 wing328 merged commit fff759b into master Jan 19, 2020
@wing328 wing328 deleted the python_flask_fix_enum branch January 19, 2020 07:25
jimschubert added a commit that referenced this pull request Jan 19, 2020
* master:
  Use HTTPS Maven URL in Kotlin meta generator (#5043)
  [Python] fix numeric enum in python flask, aiohttp (#5019)
  add multipleOf to various codegen classes (#5021)
  Add a link to a youtube video on Pulp and OpenAPI Generator (#5038)
jimschubert added a commit that referenced this pull request Jan 26, 2020
* 5.0.x: (92 commits)
  [Rust Server] Handle array of objects inside an object correctly (#5044)
  [Rust Server] Sanitise enum values (#5042)
  [Rust Server] Add support for primitive arrays (#5041)
  [elm] Fix duplicate coder names (#5100)
  [elm] enum items and parameters (#5051)
  [elm] Fix decoding empty operation responses (#5055)
  resolve merge conflicts in VERSION files
  undo restoring ElmClientCodegenTest.java
  fix merge conflicts
  [dart-dio] Various fixes (#5027)
  Add java code comments based on explanation from Jim Schubert (#5048)
  Execute ./bin/openapi3/go-experimental-petstore.sh script (#5049)
  [docs] Sorted doc outputs and clean up duplicated CliOptions (#5046)
  Add docs/installation.md and docsite index to version update script (#5037)
  [gradle] consistent use of maven url in gradle files (#5045)
  Use HTTPS Maven URL in Kotlin meta generator (#5043)
  [Python] fix numeric enum in python flask, aiohttp (#5019)
  add multipleOf to various codegen classes (#5021)
  Add a link to a youtube video on Pulp and OpenAPI Generator (#5038)
  [scripts] Remove misspelled OPENAPI_GENERATOR_DOWLOAD_CACHE_DIR (#5035)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants