Query parameters from Depends do not show description in docs
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
from fastapi import Depends, FastAPI, Query
from pydantic import BaseModel, Field
app = FastAPI()
class CommonParams(BaseModel):
a: int = Field(
1,
description="Description does not show up in docs",
)
b: int = Query(2, description="Using query changes nothing")
@app.get("/")
async def get_root(
params: CommonParams = Depends(),
q: int = Query(5, description="This description shows up"),
):
return {
"a": params.a,
"b": params.b,
"q": q,
}
Description
Open browser, go to docs page, look at parameters for default route.
Note that description shows up for q parameter, but not for a or b. The schema for a and b in openapi.json does not have a description, but q does.
I expect the description for the fields to show up.
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.75.0
Python Version
3.8.11
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Set description for query parameter in swagger doc using ...
Am I missing anything to get the description for QueryParams(model) in swagger ui? python · fastapi · Share.
Read more >Use query parameters to customize responses - Microsoft Graph
Microsoft Graph provides optional query parameters that you can use to specify and control the amount of data returned in a response.
Read more >Create & use named functions - Google Docs Editors Help
Named functions let you create custom functions that can use built-in Sheets ... These arguments are placeholders and descriptions of the type of...
Read more >Query Parameters and String Validations - FastAPI
This will validate the data, show a clear error when the data is not valid, and document the parameter in the OpenAPI schema...
Read more >Parameters - Cypher Manual - Neo4j
Setting parameters when running a query is dependent on the client ... For more information refer to Operations Manual → Cypher Shell -...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a workaround, and I see that it works with python dataclasses, too, but I still think it should work with pydantic models.
By reading source code I found solution:
The code is here: https://github.com/tiangolo/fastapi/blob/master/fastapi/dependencies/utils.py#L361
Which is not so obvious, but really effective.