This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Swagger KeyError when two classes contain inner classes with the same name #1505
Comments
Why would you create a Pydantic class inside of other Pydantic class? I think that's not really supported by Pydantic... But yeah, it wouldn't be supported by FastAPI, as there wouldn't be a clean way to get unique IDs for the models. |
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues. |
I suppose this would matter when using modules that return customized pydantic models. I am playing with the pydantic_jsonapi module with FastAPI and encountering the same error. It uses GenericModel from Pydantic to accomplish a jsonapi model. Interestingly, this doesn't seem to happen with the same models used as "response_model" in the decorator and it works fine outside of Fast API.
https://pydantic-docs.helpmanual.io/usage/models/#generic-models |
I just ran into this today. In terms of "Why would you create a Pydantic class inside of other Pydantic class" - in my case, the problem happened with two Schemas that had the same inner enum class (not Pydantic inner classes). The reason for it is that the purpose of the type is semantically the same, while happening to have different values. I can't seem to get string literals to show up in OpenAPI documentation, otherwise I wouldn't use the enums. Of note: Not a big deal, as there are many workarounds - I just wish the call stack was a bit more descriptive in terms of which object threw the exception, rather than just the enum key :) |
@sureshjoshi @tanyaofei reading this issue saved my day. I had a duplicated Enum class with the same name across two Pydantic model. Naming differently the two Enum class solve the problem. |
I generate endpoints dynamically based on some config, and generate models for those endpoints with |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the bug
KeyError when two classes contain inner classes with the same name. If i rename one of the inner classes, app runs good.
To Reproduce
Steps to reproduce the behavior with a minimum self-contained file.
Replace each part with your own scenario:
/docs
.Fetch error Internal Server Error /openapi.json
and the app raise an errorEnvironment
The text was updated successfully, but these errors were encountered: