Alveona
Alveona

Reputation: 978

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} 

Upvotes: 9

Views: 14408

Answers (2)

Koushik Das
Koushik Das

Reputation: 10813

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

Upvotes: 10

Yagiz Degirmenci
Yagiz Degirmenci

Reputation: 20766

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.

Upvotes: 5

Related Questions