Imagine there is an app like that:
from fastapi import FastAPI
app = FastAPI()
@app.get("/items/{item_id}")
async def read_item(item_id: int):
return {"item_id": item_id}
How could one add description for path parameter item_id in swagger?
You can add description for a specific parameter by using the description argument to the parameter type object:
item_id: int = Path(..., description="An id representing an item")
The ... represents the default value and should be included*.
Edit*: The current version of FastAPI throws an error if ... is included for Path objects, so leave it out if you're using a recent (2023) version.
Like this
@app.get("/items/{item_id}")
async def read_item(item_id: int):
"""
item_id: Your item ID description will be here
"""
return {"item_id": item_id}
swagger doc

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With