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 hiding from OpenAPI (and Swagger UI) Query, Cookie, Header, and Path parameters #3144

Merged

Conversation

astraldawn
Copy link
Contributor

@astraldawn astraldawn commented Apr 29, 2021

Add parameter include_in_schema to partially address #1708 for subclasses of Param: Cookie, Header, Path and Query

Implements the Param portion of #1708 (comment), relevant parts of code sample reproduced below:

from fastapi import FastAPI, Query

app = FastAPI()


@app.get("/")
def read_root(hidden_param: str = Query(None, include_in_schema=False)):
    if hidden_param:
        return {"Hello": "Master!"}
    else:
        return {"Hello": "World"}

@codecov
Copy link

codecov bot commented May 1, 2021

Codecov Report

Merging #3144 (fcf3c1c) into master (347e391) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##            master     #3144    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          504       509     +5     
  Lines        12707     12807   +100     
==========================================
+ Hits         12707     12807   +100     
Impacted Files Coverage Δ
fastapi/param_functions.py 100.00% <ø> (ø)
...cs_src/query_params_str_validations/tutorial014.py 100.00% <100.00%> (ø)
.../query_params_str_validations/tutorial014_py310.py 100.00% <100.00%> (ø)
fastapi/openapi/utils.py 100.00% <100.00%> (ø)
fastapi/params.py 100.00% <100.00%> (ø)
tests/test_param_include_in_schema.py 100.00% <100.00%> (ø)
...t_query_params_str_validations/test_tutorial014.py 100.00% <100.00%> (ø)
...y_params_str_validations/test_tutorial014_py310.py 100.00% <100.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 347e391...fcf3c1c. Read the comment docs.

@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2021

📝 Docs preview for commit 685532c at: https://608d27c8521eb7158616ef14--fastapi.netlify.app

@astraldawn
Copy link
Contributor Author

@jordantshaw no idea but I have updated the request with a code sample from the original issue. Hope that will speed up the review.

@HIRANO-Satoshi
Copy link

This is a useful PR for me, too.

@elrik75
Copy link

elrik75 commented May 28, 2021

Very useful for me too to remove all X-Forwarded-* headers in the doc.

@marlenekoh
Copy link

Please merge this!! This is a super useful feature! 😊😊

@mamicahencarnacion
Copy link

hello, any updates on this? this will be a really helpful additiona feature 👍

@jordantshaw
Copy link

@tiangolo Any updates on when this will merged? Looks like a lot of people would find this very helpful.

@sirtux
Copy link

sirtux commented Aug 23, 2021

@tiangolo Ping? I would also be very delighted to see this feature :3

@phuong
Copy link

phuong commented Sep 16, 2021

@tiangolo Any update for this, really helpful

Copy link
Contributor

@yezz123 yezz123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great Pull request LGTM!
@Kludex @tiangolo this one need to be approved 🌟

@BlueMagma2
Copy link

Joining the gang, I would find this very useful too

fastapi/openapi/utils.py Outdated Show resolved Hide resolved
@tiangolo tiangolo changed the title Allow subclasses of Param to be hidden in openapi spec ✨ Allow hiding from OpenAPI (and Swagger UI) Query, Cookie, Header, and Path parameters Jan 23, 2022
@github-actions
Copy link
Contributor

📝 Docs preview for commit 8b60572 at: https://61ed7670c8634ec6d8ce1542--fastapi.netlify.app

@github-actions
Copy link
Contributor

📝 Docs preview for commit c49e01c at: https://61ed78f66a86fc22f4026592--fastapi.netlify.app

@github-actions
Copy link
Contributor

📝 Docs preview for commit fcf3c1c at: https://61ed79c4bc1bd1bb22e41376--fastapi.netlify.app

@tiangolo
Copy link
Owner

Awesome, thank you @astraldawn! ☕

Thanks everyone for the discussion! 🍰

I updated a bit the tests and added source examples (and tests) for Python 3.10.

I was thinking that maybe it could make sense to support also body/form-data, but the implementation would be non-trivial, or it would have to be a per-route include_body_in_schema or something like that. But at the same time, I don't easily see a use case where hiding the entire body would be wanted without just hiding the entire route, so let's just have this for now and I'll see if anyone finds later a use case that would benefit from hiding the body before implementing that. 🤓

This is available in FastAPI version 0.73.0 (released in a couple of hours). 🎉

@tiangolo tiangolo merged commit ca5d57e into tiangolo:master Jan 23, 2022
JeanArhancet pushed a commit to JeanArhancet/fastapi that referenced this pull request Aug 20, 2022
…er`, and `Path` parameters (tiangolo#3144)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
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.

None yet