openapi-python-client
openapi-python-client copied to clipboard
Add support for recursively defined schemas
Describe the bug
I tried to create a python client from an OpenApi-Spec with the command openapi-python-client generate --path secret_server_openapi3.json. Then I got multple warnings:
- invalid data in items of array settings
- Could not find reference in parsed models or enums
- Cannot parse response for status code 200, response will be ommitted from generated client I searched the schemas, which are responsible for the errors and they all had in common, that they either reference another schema which is recursively defined or reference themself. For example one of the problematic schemas:
{
"SecretDependencySetting": {
"type": "object",
"properties": {
"active": {
"type": "boolean",
"description": "Indicates the setting is active."
},
"childSettings": {
"type": "array",
"description": "The Child Settings that would be used for list of options.",
"items": {
"$ref": "#/components/schemas/SecretDependencySetting"
}
}
},
"description": "Secret Dependency Settings - Mostly used internally"
}
}
To Reproduce Define a schema recursively and then try to create a client from it.
Expected behavior The software can also parse a recursively defined schema.
OpenAPI Spec File It's 66000 Lines, so I'm not sure if this will help you, or github will allow me to post it :smile: Just ask if you need specific parts of the spec, aside from what I already provided above.
Desktop (please complete the following information):
- OS: Linux Manjaro
- Python Version: 3.9.1
- openapi-python-client version 0.7.3
Thanks for reporting @sp-schoen! This should be fixed by #329 which all being well should make it into the 0.8 release we have coming up.
I checked out the PR you suggested and tried it, but I still get the same error.
Ah, looking it over again you're totally right. The stuff in there will be needed to make recursive schemas work however, so whenever that is reviewed/merged work can begin on adding support for recursive definitions.
Just FYI @sp-schoen, @p1-ra has graciously begun working on supporting recursive definitions in the aforementioned PR!
Was this fixed by #366 ?
I'm not sure 😅 probably not though. #366 was just about fixing reference resolution in general, my guess is that generation will still fail for recursive models, we'll need to add a special case to those.
Cool, thanks! It wasn't clear given that #329 was closed in favor of #366. :)
Based on @p1-ra's feedback in #366, it seems like recursive references do in fact work - @jkinkead if you could try using your schema with 0.9.0 and let us know how it shakes out that'd be awesome!
Hmm, I still get errors with 0.9.0. :/
The repro file at the top of the issue still produces errors:
$ openapi-python-client --version
openapi-python-client version: 0.9.0
$ openapi-python-client generate --path repro.json
Error(s) encountered while generating, client was not created
Failed to parse OpenAPI document
3 validation errors for OpenAPI
info
field required (type=value_error.missing)
paths
field required (type=value_error.missing)
openapi
field required (type=value_error.missing)
If you believe this was a mistake or this tool is missing a feature you need, please open an issue at https://github.com/triaxtec/openapi-python-client/issues/new/choose
Does that repro.json that you made just contain the block at the top of the issue? You'll need to provide a full OpenAPI document with all of the required fields in it - try one of the samples @p1-ra provided in #366 (assuming they match what your use case is).
@emann
I also tried it again with 0.9.0 and still get the same errors.
Sorry, yes - I was using just that json file, but my local repro is much too large to paste in.
I'll add a shorter repro if I have time!
My bad, It was to early on the morning it looks I've messed up with my tests; probably did them on the wrong branch ....; I've redo the tests using today main branch, I still have the issues.
All sample define here are NOK