【问题标题】:How to add description to OpenAPI schema using FastApi Dependencies如何使用 FastApi 依赖项向 OpenAPI 模式添加描述
【发布时间】:2021-01-27 20:08:46
【问题描述】:

如果我使用依赖系统,有没有办法将字段描述添加到 FastAPI swagger 架构?

我看不到在FastAPI docs的简单示例中添加描述的地方

async def common_parameters(q: str = None, skip: int = 0, limit: int = 100):
    return {"q": q, "skip": skip, "limit": limit} 

【问题讨论】:

    标签: python swagger openapi fastapi


    【解决方案1】:

    您可以使用QueryBody 添加描述,具体取决于您的用例。

    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")):
        ...
    

    您可以添加更多元数据,请参阅documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-14
      • 2017-07-22
      • 2017-02-19
      • 2021-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多