[英]How to add description to OpenAPI schema using FastApi Dependencies
Is there a way to add field description to FastAPI swagger schema if I use dependency system?如果我使用依赖系统,有没有办法将字段描述添加到 FastAPI swagger 模式?
I see no place to add descriptions in simple example from FastAPI docs我看不到在FastAPI 文档的简单示例中添加描述的地方
async def common_parameters(q: str = None, skip: int = 0, limit: int = 100):
return {"q": q, "skip": skip, "limit": limit}
You can add description using Query
or Body
depends on your use case.您可以使用Query
或Body
添加描述,具体取决于您的用例。
from typing import Optional
from fastapi import FastAPI, Query
app = FastAPI()
@app.get("/dummy")
async def dummy(q: Optional[str] = Query(None, description="My description")):
...
You can add even more metadata, see the documentation .您可以添加更多元数据,请参阅文档。
You can also use this你也可以使用这个
@app.get("/dummy")
async def dummy(q: Optional[str] = Query(None, )):
"""
This is my description of the API endpoint
"""
pass
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.