Skip to content

Fix same function names in different modules with composite bodies #347

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

Merged
merged 3 commits into from
Jun 28, 2019

Conversation

tiangolo
Copy link
Member

@tiangolo tiangolo commented Jun 28, 2019

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_router multiple times with the same router, under different prefixes, and it will work. For example, it can be used to expose the same router under different API prefixes (e.g. /api/v2 and /api/latest).

This fixes #284

tiangolo added 3 commits June 28, 2019 19:18
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).
@codecov
Copy link

codecov bot commented Jun 28, 2019

Codecov Report

Merging #347 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #347   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files         232    236    +4     
  Lines        5495   5539   +44     
=====================================
+ Hits         5495   5539   +44
Impacted Files Coverage Δ
..._tutorial/test_sql_databases/test_sql_databases.py 100% <ø> (ø) ⬆️
...tutorial/test_extra_data_types/test_tutorial001.py 100% <ø> (ø) ⬆️
...est_tutorial/test_extra_models/test_tutorial004.py 100% <ø> (ø) ⬆️
...l/test_request_forms_and_files/test_tutorial001.py 100% <ø> (ø) ⬆️
tests/test_security_oauth2.py 100% <ø> (ø) ⬆️
...orial/test_async_sql_databases/test_tutorial001.py 100% <ø> (ø) ⬆️
...st_tutorial/test_request_forms/test_tutorial001.py 100% <ø> (ø) ⬆️
...est_tutorial/test_extra_models/test_tutorial003.py 100% <ø> (ø) ⬆️
...st_tutorial/test_request_files/test_tutorial001.py 100% <ø> (ø) ⬆️
...ts/test_tutorial/test_security/test_tutorial003.py 100% <ø> (ø) ⬆️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b30cca8...e106ca4. Read the comment docs.

@tiangolo tiangolo merged commit 6870655 into master Jun 28, 2019
@tiangolo tiangolo deleted the fix-same-function-name-composite-body branch June 28, 2019 17:35
tiangolo added a commit that referenced this pull request Jul 12, 2019
lmignon pushed a commit to acsone/fastapi that referenced this pull request Sep 19, 2024
Signed-off-by sbidoul
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenAPI fails when forcing query params to be body and multiple params in each
1 participant