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
I am generating the OpenAPI schema using app.openapi() and noticed that models with the same name in different routers (like Data and Response) sometimes generate duplicate $ref entries.
Sometimes #/components/schemas/Data is remapped to routers__one__Data or routers__two__Data nondeterministically.
This causes CI checks on the OpenAPI schema to fail intermittently.
Adding docstrings or renaming the models works as a workaround, but it’s not ideal.
Is there a recommended way to prevent FastAPI from generating nondeterministic $ref names when multiple routers use models with the same name?
Operating System
Windows
Operating System Details
No response
FastAPI Version
FastAPI Version: 0.121.x
Pydantic Version
Pydantic Version: 2.x
Python Version
Python Version: 3.11+
Additional Context
I want to reliably generate OpenAPI schemas for CI testing and code generation, without manually renaming models for every router.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
I am generating the OpenAPI schema using app.openapi() and noticed that models with the same name in different routers (like Data and Response) sometimes generate duplicate $ref entries.
Sometimes #/components/schemas/Data is remapped to routers__one__Data or routers__two__Data nondeterministically.
This causes CI checks on the OpenAPI schema to fail intermittently.
Adding docstrings or renaming the models works as a workaround, but it’s not ideal.
Is there a recommended way to prevent FastAPI from generating nondeterministic $ref names when multiple routers use models with the same name?
Operating System
Windows
Operating System Details
No response
FastAPI Version
FastAPI Version: 0.121.x
Pydantic Version
Pydantic Version: 2.x
Python Version
Python Version: 3.11+
Additional Context
I want to reliably generate OpenAPI schemas for CI testing and code generation, without manually renaming models for every router.
Beta Was this translation helpful? Give feedback.
All reactions