Skip to content
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

Allow return type of endpoint to be response model #5216

Conversation

JarroVGIT
Copy link
Contributor

@JarroVGIT JarroVGIT commented Jul 31, 2022

Based on the discussion here:

Fixes #5215

This would allow the developer to choose between using something like

@app.get("/", response_model=MyModel)
def root():
    pass

and

@app.get("/")
def root() -> MyModel:
    pass

The latter is more idiomatic. In this PR, the reponse_model= method takes precedence, as all documentation is in that style. That means if both are set, then the return type will be ignored.

@codecov
Copy link

codecov bot commented Jul 31, 2022

Codecov Report

Merging #5216 (d790941) into master (5c576e4) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##            master    #5216      +/-   ##
===========================================
- Coverage   100.00%   99.98%   -0.02%     
===========================================
  Files          532      533       +1     
  Lines        13684    13728      +44     
===========================================
+ Hits         13684    13726      +42     
- Misses           0        2       +2     
Impacted Files Coverage Δ
fastapi/routing.py 100.00% <100.00%> (ø)
fastapi/utils.py 100.00% <100.00%> (ø)
tests/test_endpoint_response_model_return_type.py 100.00% <100.00%> (ø)
fastapi/concurrency.py 90.00% <0.00%> (-10.00%) ⬇️

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 5c576e4...d790941. Read the comment docs.

@github-actions
Copy link
Contributor

📝 Docs preview for commit 8a07b01 at: https://62e6d9aef71fda183aa15bc0--fastapi.netlify.app

@github-actions
Copy link
Contributor

📝 Docs preview for commit d6efeb6 at: https://62e6dfaef9d4021787025f37--fastapi.netlify.app

@github-actions
Copy link
Contributor

📝 Docs preview for commit d790941 at: https://62e6e959ab662b1a31cc19ed--fastapi.netlify.app

@JarroVGIT
Copy link
Contributor Author

This has been discussed and rejected in #101 :(

@JarroVGIT JarroVGIT closed this Jul 31, 2022
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.

Ability to define response_model with native typing
1 participant