Duplicate description in OpenAPI Query schema
#13473
Replies: 2 comments 1 reply
-
|
I would recommend to create an issue for that or submit PR to fix this inconsistency. That's happening because we don't rewrite the description by I agree that the description should stay only at the parameter level. @YuriiMotov, what do you think? |
Beta Was this translation helpful? Give feedback.
-
|
Removing from typing import Annotated
from fastapi import FastAPI, Query
from pydantic import BaseModel
app = FastAPI()
class MyClass(BaseModel):
q: Annotated[
str,
Query(
description="Query description",
json_schema_extra={"description": None},
),
]
@app.get("/")
async def root(q: Annotated[MyClass, Query()]):
return {"message": "Hello World"}
@app.post("/items")
async def items(q: MyClass):
return {"message": "Hello World"}If I'm not mistaken, there are some issues with query model support that force people to use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Exhibit 1
Exhibit 2
Description
Generated OpenAPI part for Query for Exhibit 1:
{ "name": "q", "in": "query", "required": true, "schema": { "type": "string", "title": "Query title", "description": "Query description" }, "description": "Query description" }As you see,
descriptionis pasted twice: into the description of the query and the description of its schema. Note thattitledoesn't behave like that. Moreover, if you run Exhibit 2, you geti.e. removing
descriptionwith the help ofjson_schema_extraremoves its from the schema but keeps it for the query.That seems to be unintuitive and probably incorrect behaviour.
Operating System
macOS
Operating System Details
No response
FastAPI Version
0.115.11
Pydantic Version
2.10.6
Python Version
3.11.11
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions