Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[python] remove imports from models #7905

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

Open
tomplus wants to merge 6 commits into swagger-api:master
base: master
Choose a base branch
Loading
from tomplus:fix/remove-imports

Conversation

@tomplus
Copy link
Contributor

@tomplus tomplus commented Mar 25, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

It resolves the issue #7541 (circular dependencies in Python models), based on @wy-z work, thanks.

PTAL @taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11)

Amoki, wheelsandmetal, allburov, and Sarek-Wyona reacted with thumbs up emoji
@@ -1 +1 @@
2.4.0-SNAPSHOT No newline at end of file
2.3.0-SNAPSHOT No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that the version should be 2.4.0~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mvn clean was needed 🤦‍♂️ thanks for spotting this.

import re # noqa: F401

import six
{{#imports}}{{#-first}}
Copy link
Contributor

@kenjones-cisco kenjones-cisco Mar 26, 2018

Choose a reason for hiding this comment

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

What about the scenario where the discriminator is used?
The lack of import will result in invalid code due to the missing import.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this discriminator work if modules can't be imported due to circular dependencies ?

Maybe there is another way to provide paths/data for the discriminator - I don't know, I don't use it. Such imports make more problems for standard usage of generated code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kenjones-cisco I dig into it. Finally I've written a test and I also had to fix discriminator to make it working ;)

Now it works without these imports. Child models are created dynamically on the parsing step and models with discriminator don't refer to them - only as a string with name of class.

I still recommend to merge this PR.

Thanks.

Copy link

@Sarek-Wyona Sarek-Wyona Oct 26, 2018

Choose a reason for hiding this comment

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

What is the status of this PR? I have a similar fix and was about to submit it before stumbling into this PR.
We are seeing models created with circular imports too which makes the generated code useless unless they are manually commented out!

Copy link
Contributor

LGTM! Thanks!

Amoki reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

3 more reviewers

@wy-z wy-z wy-z left review comments

@kenjones-cisco kenjones-cisco kenjones-cisco left review comments

@Sarek-Wyona Sarek-Wyona Sarek-Wyona approved these changes

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /