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
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
Problem
When generating the OpenAPI JSON via app.openapi(), FastAPI internally remaps $ref names.
Identical model names (Data, Response) across routers are remapped non-deterministically, resulting in inconsistent OpenAPI JSON between runs.
Example:
{'$ref': '#/components/schemas/routers__one__Response'},
{'$ref': '#/components/schemas/routers__two__Response'},
{'$ref': '#/components/schemas/Data'}
Depending on the run, Data may be mapped to routers__one__Data or routers__two__Data, breaking CI checks.
Attempts
I’ve tried adding docstrings to models to disambiguate names.
Sorting router inclusion order doesn’t help.
Manually renaming models per router works but is cumbersome in large projects.
Question
Is this non-deterministic behavior expected in FastAPI v0.121+ when generating OpenAPI for multiple routers with identically named models?
Are there recommended best practices for multi-router projects to avoid $ref collisions without manually renaming every model?
Would it make sense for FastAPI to implement a deterministic $ref remapping internally to avoid CI flakiness?
Any insights or suggestions would be appreciated!
Thank you 🙏
Operating System
Windows
Operating System Details
No response
FastAPI Version
python -c "import fastapi; print(fastapi.version)"
Pydantic Version
python -c "import pydantic; print(pydantic.version.VERSION)"
Python Version
python --version
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions