-
-
Notifications
You must be signed in to change notification settings - Fork 228
Support of recursive and circular references #466
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
Comments
This would be great! I want to use openapi-python-client, but this issue is a blocker. I'll keep an eye on #467... |
Hello, @barakalon! The branch #467 does not work and I do not plan to finish it. Instead, I wrote another one that allows to generate a client that supports circular, recursive references and inheritance in By the way, I think it is better to use try:
from ..models import user as user_m
# ... 15 lines
except ImportError:
import sys
user_m = sys.modules[__package__ + "user"]
# ... 15 lines |
A note for the eventual fix of this, I've added an explicit check and warning to reduce user confusion when this issue presents itself in #519 which should be removed once this is supported. |
This commit adds support for recursive and circular references in object properties and additionalProperties, but not in allOf. The changes include: -Delayed processing of schema model properties -Cascading removal of invalid schema reference dependencies -Prevention of self import in ModelProperty relative imports -Prevention of forward recursive type reference errors in generated modules -Logging for detection of recursive references in allOf
This commit adds support for recursive and circular references in object properties and additionalProperties, but not in allOf. The changes include: -Delayed processing of schema model properties -Cascading removal of invalid schema reference dependencies -Prevention of self import in ModelProperty relative imports -Prevention of forward recursive type reference errors in generated modules -Logging for detection of recursive references in allOf
What release is this scheduled to go into? when will that release go out? and what can I do to help? as this is a feature I need. |
There's currently no schedule for it. There is a new attempt at implementing it in #582 but I have to have time to test & review it before it can be merged. If you're able to test out that branch and give feedback on any problems you encounter, that would definitely be valuable. |
I am not sure how you usually work but is it possible to create a branch with the code changes that have been made then I could then add some test schemas and code along with any other changes that may be required |
@penske-file If you have GitHub cli and have cloned the I worked on this branch so please let me know if you have questions or run into any issues with your use cases. |
I think this is related to an issue that I ran into. If it is helpful to anybody, I found that modifying the example as follows results in an error-free generation-
|
@ayemiller As far as I'm aware, the second example you've given isn't valid OpenAPI spec. The |
Here I just wanted to add that instead of pydantic, the use of attrs (modern interface) and especially cattrs (for structuring/unstructuring) could be really good. There is a lot of stuff now in attrs and cattrs that overall is more flexible than pydantic. |
#670, #338, #466]. Thanks @mtovt! Co-authored-by: maz808 <[email protected]> Co-authored-by: Dylan Anthony <[email protected]>
Closed by #670 🥳 |
Is your feature request related to a problem? Please describe.
References to schemas that have not been processed yet are not supported now. See the example.
Describe the solution you'd like
I suggest to add models that are referenced without properties. And fill in the properties later. This adds the ability to refer to schemas that have not been processed yet.
Describe alternatives you've considered
Also it may also be easier to create all models without properties first, then add properties with second pass.
Additional context
Example OpenAPI:
Generator produces warnings and models package is empty.
I expect the generated models for
Brother
andSister
. Something like:The text was updated successfully, but these errors were encountered: