Skip to content
Discussion options

You must be logged in to vote

The correct way to specify description for request body is to use openapi_extra={"requestBody": {"description": "Request body description"}}:

from fastapi import Body, FastAPI
from pydantic import BaseModel

app = FastAPI()


class Item(BaseModel):
    name: str


@app.post(
    "/items",
    openapi_extra={"requestBody": {"description": "Request body description"}},
)
async def create_item(item: Item = Body()):
    pass

FastAPI doesn't take description from Body(description="...") because there might be multiple body parameters in your endpoint:

@app.post("/items")
async def create_item(
    item: Item = Body(description="Description 1"),
    something: AnotherModel = Body(description="D…

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@venkat5554
Comment options

@clemens-tolboom
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
5 participants