Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
532 views
in Technique[技术] by (71.8m points)

python - 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?

I see no place to add descriptions in simple example from FastAPI docs

async def common_parameters(q: str = None, skip: int = 0, limit: int = 100):
    return {"q": q, "skip": skip, "limit": limit} 
question from:https://stackoverflow.com/questions/65926628/how-to-add-description-to-openapi-schema-using-fastapi-dependencies

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can add description using Query or Body depends on your use case.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...