You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Generator produces warnings and models package is empty.
Could not find reference in parsed models or enums
Reference(ref='#/components/schemas/Sister')
Could not find reference in parsed models or enums
Reference(ref='#/components/schemas/Brother')
I expect the generated models for Brother and Sister. Something like:
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 allOf cases . But it is of low quality, unfinished branch. Please PM if you need such a code. I don’t want to publish it because it’s unfinished. I don’t have time to refactor it. I think it’s the right idea, some things in model generation have to be redesigned to make it clear and high quality with support of circular references and inheritance.
By the way, I think it is better to use pydantic in models generation as it is done in datamodel-code-generator it looks cleaner. Also
I don’t really like to put the classes in one module, but it also lets not write a bunch of ugly local try ... except ... in case with circular references.
For my OpenAPI, I got a lot of local pieces like,
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.
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
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 openapi-generators/openapi-python-client repo, you can use this command within the repo directory on your machine to checkout the PR branch: gh pr checkout 582
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 schema keyword isn't meant to be used in that context. If it's not throwing errors, that may be indicative of another issue.
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.
Activity
[-]Support of references to unprocessed schemas[/-][+]Support of recursive and circular references[/+]barakalon commentedon Aug 31, 2021
This would be great!
I want to use openapi-python-client, but this issue is a blocker.
I'll keep an eye on #467...
mtovts commentedon Aug 31, 2021
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
allOfcases . But it is of low quality, unfinished branch. Please PM if you need such a code. I don’t want to publish it because it’s unfinished. I don’t have time to refactor it. I think it’s the right idea, some things in model generation have to be redesigned to make it clear and high quality with support of circular references and inheritance.By the way, I think it is better to use
pydanticin models generation as it is done in datamodel-code-generator it looks cleaner. AlsoI don’t really like to put the classes in one module, but it also lets not write a bunch of ugly local
try ... except ...in case with circular references.For my OpenAPI, I got a lot of local pieces like,
dbanty commentedon Oct 17, 2021
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.
feat: Add support for recursive/circular refs
Add support for recursive/circular refs
penske-file commentedon Feb 25, 2022
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.
dbanty commentedon Feb 27, 2022
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.
penske-file commentedon Feb 27, 2022
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
maz808 commentedon Feb 27, 2022
@penske-file If you have GitHub cli and have cloned the
openapi-generators/openapi-python-clientrepo, you can use this command within the repo directory on your machine to checkout the PR branch:gh pr checkout 582I worked on this branch so please let me know if you have questions or run into any issues with your use cases.
ayemiller commentedon Apr 9, 2022
@maz808 @penske-file @dbanty
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-
maz808 commentedon Apr 9, 2022
@ayemiller As far as I'm aware, the second example you've given isn't valid OpenAPI spec. The
schemakeyword isn't meant to be used in that context. If it's not throwing errors, that may be indicative of another issue.hhoeflin commentedon May 24, 2022
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.
feat: Support for recursive and circular references using lazy imports [
dbanty commentedon Nov 12, 2022
Closed by #670 🥳