Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

✨ Allow hiding from OpenAPI (and Swagger UI)Query,Cookie,Header, andPath parameters#3144

Merged
tiangolo merged 20 commits intofastapi:masterfrom
astraldawn:hide-request-parameters-in-openapi-spec
Jan 23, 2022
Merged

✨ Allow hiding from OpenAPI (and Swagger UI)Query,Cookie,Header, andPath parameters#3144
tiangolo merged 20 commits intofastapi:masterfrom
astraldawn:hide-request-parameters-in-openapi-spec

Conversation

@astraldawn
Copy link
Contributor

@astraldawnastraldawn commentedApr 29, 2021
edited
Loading

Add parameterinclude_in_schema to partially address#1708 for subclasses ofParam:Cookie,Header,Path andQuery

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

fromfastapiimportFastAPI,Queryapp=FastAPI()@app.get("/")defread_root(hidden_param:str=Query(None,include_in_schema=False)):ifhidden_param:return {"Hello":"Master!"}else:return {"Hello":"World"}

nakanoasaservice, marlenekoh, felixthebeard, dvdblk, awendland, stefankraus-wf, hmoravec, jo47011, nicolai92, jc16180, and 7 more reacted with thumbs up emojiphuong, yezz123, Ran4, thomasleveil, p1utoze, and Jamim reacted with heart emojiyezz123, phuong, thomasleveil, and Jamim reacted with rocket emoji
@codecov
Copy link

codecovbot commentedMay 1, 2021
edited
Loading

Codecov Report

Merging#3144 (fcf3c1c) intomaster (347e391) willnot change coverage.
The diff coverage is100.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 FilesCoverage Δ
fastapi/param_functions.py100.00% <ø> (ø)
...cs_src/query_params_str_validations/tutorial014.py100.00% <100.00%> (ø)
.../query_params_str_validations/tutorial014_py310.py100.00% <100.00%> (ø)
fastapi/openapi/utils.py100.00% <100.00%> (ø)
fastapi/params.py100.00% <100.00%> (ø)
tests/test_param_include_in_schema.py100.00% <100.00%> (ø)
...t_query_params_str_validations/test_tutorial014.py100.00% <100.00%> (ø)
...y_params_str_validations/test_tutorial014_py310.py100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last update347e391...fcf3c1c. Read thecomment docs.

@github-actions
Copy link
Contributor

📝 Docs preview for commit685532c at:https://608d27c8521eb7158616ef14--fastapi.netlify.app

@astraldawn
Copy link
ContributorAuthor

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

elrik75 and BlueMagma2 reacted with thumbs up emoji

@HIRANO-Satoshi
Copy link

This is a useful PR for me, too.

elrik75, dvdblk, kamilnowakflyps, and BlueMagma2 reacted with thumbs up emoji

@elrik75
Copy link

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

chrisantha-nirvana, jc16180, and BlueMagma2 reacted with thumbs up emoji

@marlenekoh
Copy link

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

elrik75, dvdblk, mamicahencarnacion, chrisantha-nirvana, nakanoasaservice, stefankraus-wf, kamilnowakflyps, mark19971, hmoravec, phuong, and 3 more reacted with thumbs up emoji

@mamicahencarnacion
Copy link

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

elrik75, chrisantha-nirvana, Whatapalaver, nakanoasaservice, stefankraus-wf, kamilnowakflyps, phuong, sanyi, BlueMagma2, and hmoravec reacted with thumbs up emoji

@jordantshaw
Copy link

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

stefankraus-wf, kamilnowakflyps, mark19971, jo47011, marshall007, phuong, sanyi, BlueMagma2, hmoravec, jordantshaw, and salioglu reacted with thumbs up emoji

@einstux
Copy link

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

Manawyrm, stefankraus-wf, jc16180, Bartket, jordantshaw, phuong, sanyi, BlueMagma2, hmoravec, and salioglu reacted with thumbs up emoji

@phuong
Copy link

@tiangolo Any update for this, really helpful

hoangbits, phuong, vanhongts, sanyi, BlueMagma2, hmoravec, and salioglu reacted with thumbs up emoji

Copy link
Contributor

@yezz123yezz123 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 🌟

phuong, hoangbits, jordantshaw, BlueMagma2, and hmoravec reacted with thumbs up emojiphuong reacted with heart emoji
@BlueMagma2
Copy link

Joining the gang, I would find this very useful too

jordantshaw reacted with thumbs up emoji

@tiangolotiangolo changed the titleAllow subclasses of Param to be hidden in openapi spec✨ Allow hiding from OpenAPI (and Swagger UI)Query,Cookie,Header, andPath parametersJan 23, 2022
@github-actions
Copy link
Contributor

📝 Docs preview for commit8b60572 at:https://61ed7670c8634ec6d8ce1542--fastapi.netlify.app

@github-actions
Copy link
Contributor

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

@github-actions
Copy link
Contributor

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

@tiangolo
Copy link
Member

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-routeinclude_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 version0.73.0 (released in a couple of hours). 🎉

thomasleveil and stefankraus-wf reacted with hooray emojijc16180 reacted with rocket emoji

@tiangolotiangolo merged commitca5d57e intofastapi:masterJan 23, 2022
JeanArhancet pushed a commit to JeanArhancet/fastapi that referenced this pull requestAug 20, 2022
…er`, and `Path` parameters (fastapi#3144)Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
@mangiahsan
Copy link

mangiahsan commentedDec 24, 2024
edited
Loading

This is a fantastic feature addition—thank you for this! 🎉

I wanted to share an alternative approach I’ve used in a similar context where I needed to exclude certain fields from the OpenAPI schema for a cleaner API documentation. My use case involved building an OAuth2-like authentication schema where fields likegrant_type andaccess_token are essential for internal processing but irrelevant for API consumers to see in the documentation.

Here’s the implementation I used, leveragingpydantic.json_schema.SkipJsonSchema:

from pydantic import BaseModel, Field, root_validatorfrom pydantic.json_schema import SkipJsonSchemaclass UserSignInSchema(BaseModel):    grant_type: SkipJsonSchema[GrantType] = GrantType.PASSWORD    access_token: SkipJsonSchema[str] = None    username: str = Field(..., alias="email")    password: str    @root_validator(pre=True)    def validate_fields(cls, values):        grant_type = values.get('grant_type')        if grant_type == GrantType.PASSWORD:            values['access_token'] = 'Null'          elif grant_type in (GrantType.GOOGLE, GrantType.FACEBOOK):            values['username'] = 'null@null.com'            values['password'] = 'Null1234567'        return values

In this approach,SkipJsonSchema ensures that fields likegrant_type andaccess_token are excluded from the OpenAPI spec, allowing us to focus the documentation on the fields users need to interact with, like username and password.

I’m curious about how this compares to the include_in_schema parameter introduced here. Both approaches achieve field exclusion but might cater to slightly different needs. For instance, does include_in_schema offer better control in dynamically configurable scenarios, or are there limitations when usingSkipJsonSchema?

Thank you again for this valuable addition—it’s going to make handling such use cases a lot more intuitive! 😊

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@tiangolotiangolotiangolo left review comments

+2 more reviewers

@tokikannotokikannotokikanno left review comments

@yezz123yezz123yezz123 approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

13 participants

@astraldawn@HIRANO-Satoshi@elrik75@marlenekoh@mamicahencarnacion@jordantshaw@einstux@phuong@BlueMagma2@tiangolo@mangiahsan@tokikanno@yezz123

[8]ページ先頭

©2009-2026 Movatter.jp