例子
在 Path 中设置 description 参数,可以在 Swagger‑UI 显示详细信息(仅在此处有用)
如下:
from fastapi import FastAPI,Path
app = FastAPI()
@app.get('/student/{age}')
async def get_student(age: int=Path(...,ge=10,le=120,description="年龄大于等于10岁,小于等于120岁")):
return {'msg': f'年龄{age}'}
访问Swagger‑UI
访问:http://127.0.0.1:8000/docs ,显示如下:
