Fix same function names in different modules with composite bodies - #347
#347Merged
tiangolo merged 3 commits intoJun 28, 2019
masterfastapi/fastapi:masterfrom
fix-same-function-name-composite-bodyfastapi/fastapi:fix-same-function-name-composite-bodyCopy head branch name to clipboard
Merged
Fix same function names in different modules with composite bodies#347tiangolo merged 3 commits intomasterfastapi/fastapi:masterfrom fix-same-function-name-composite-bodyfastapi/fastapi:fix-same-function-name-composite-bodyCopy head branch name to clipboard
tiangolo merged 3 commits into
masterfastapi/fastapi:masterfrom
fix-same-function-name-composite-bodyfastapi/fastapi:fix-same-function-name-composite-bodyCopy head branch name to clipboard
Conversation
like those used for composite bodies and responses. IDs based on path (not only on function name, as it can be duplicated in a different module).
lmignon
pushed a commit
to acsone/fastapi
that referenced
this pull request
Sep 19, 2024
Signed-off-by sbidoul
zashed
approved these changes
Jan 4, 2026
zashed
approved these changes
Jan 4, 2026
zashed
approved these changes
Jan 4, 2026
zashed
approved these changes
Jan 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix same function names in different modules with composite bodies.
Currently, if two path operation functions are named the same, in two separate modules, and receive several body parameters, they are converted into a composite body JSON Schema for OpenAPI.
But the names are generated based on the path operation name, and if the name is not assigned but autogenerated (based on the function name), two JSON Schemas could have the same name, breaking the OpenAPI generation.
This PR re-implements the name generation for composite bodies and response JSON Schemas in OpenAPI.
An explicit example can be found in the added tests.
This also means that it's now possible to use
.include_routermultiple times with the same router, under differentprefixes, and it will work. For example, it can be used to expose the same router under different API prefixes (e.g./api/v2and/api/latest).This fixes #284