Skip to content
Discussion options

You must be logged in to vote

Since FastAPI 0.115.0 you can oficially use Pydantic models to define Query parameters.
And descriptions work fine:

from typing import List

from fastapi import FastAPI, Query
from pydantic import BaseModel, Field


class A(BaseModel):
    foo: str = Field(description="This is Foo")

class B(A):
    bar: str = Field(
        description="This is Bar with alias",
        alias="bar2",
    )

app = FastAPI(docs_url=None, redoc_url="/redocs")

@app.get("/test1", response_model=List[B])
async def test(bdata: B = Query()):
    return [bdata]


@app.get("/test2", response_model=List[B])
async def test2(bdata: B):
    return [bdata]

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@canwaf
Comment options

Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem question-migrate
5 participants
Converted from issue

This discussion was converted from issue #5162 on February 28, 2023 15:39.