Skip to content
Discussion options

You must be logged in to vote

The following works fine in current version (0.115.13).

from typing import Annotated
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi import Query


class TestModelBase(BaseModel):
    weight: int = Query(..., example=10, description="Weight of an animal.")


class TestModelDogs(TestModelBase):
    pass


class TestModelCats(TestModelBase):
    weight: int = Query(..., example=3)


app = FastAPI()


@app.get("/Dogs")
def test1(a: Annotated[TestModelDogs, Query()]) -> str:
    return "Hello World Dogs"


@app.get("/Cats")
def test2(a: Annotated[TestModelCats, Query()]) -> str:
    return "Hello Worlds Cats"

See Docs: https://fastapi.tiangolo.com/tutorial/query-param-…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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
2 participants
Converted from issue

This discussion was converted from issue #3606 on February 28, 2023 16:35.