Skip to content

refactor: Replace the models package with one models module, which contains all models #636

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

Closed
mtovt opened this issue Jun 20, 2022 · 1 comment
Labels
✨ enhancement New feature or improvement

Comments

@mtovt
Copy link
Contributor

mtovt commented Jun 20, 2022

Is your feature request related to a problem? Please describe.
One of the issues that block implementation of #466 or #563 is circular import occurs in the case of circular and recursive references.

Describe the solution you'd like
I want to move the generated models to one module because it simplifies the support of circular and recursive reference development. See #563 and #466. Seems @maz808's pull request #563 solves several problems with references and would be great to finish it and merge. But it contains a circular import problem. I've described it this message.

I've already implemented a possible solution in this branch. Maybe it's done not enough accurately but seems it's working. I want to receive feedback to complete this and #563.

Describe alternatives you've considered
The alternate solution is to continue using package models with a separate module for each model. We may prevent the circular import problem by David Beasley hack, using this statement in the model template:

try:
    from ..models import a_circular_model
except ImportError:
    import sys

    change = sys.modules[__package__ + "a_circular_model"]

It also will produce the working client code, but it has more complexity. I believe the one module is more ergonomic. Because for instance one of my OpenAPI specs has a lot of circular references. In that case, it produces a lot of strings with the statements, I've mentioned above. It will look like

        try:
            from ..models import user as user_m
            # ... 15 lines 
        except ImportError:
            import sys

            user_m = sys.modules[__package__ + "user"]
            # ... 15 lines 

And I believe I have models with more recursive references 😅

Additional context

@dbanty
Copy link
Collaborator

dbanty commented Sep 18, 2022

Superseded by the approach in #670!

@dbanty dbanty closed this as completed Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or improvement
Projects
None yet
Development

No branches or pull requests

2 participants