Is it possible to have different parameter examples for each endpoint? #8760
-
DescriptionHi, With the example code, both endpoints will show '10' as example. Thanks in advance :) ExampleHere's a self-contained, minimal, reproducible, example with my use case: from fastapi import FastAPI, Depends
import uvicorn
from fastapi import Query
from pydantic.dataclasses import dataclass
@dataclass
class TestModelBase:
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: TestModelDogs = Depends()) -> str:
return "Hello World Dogs"
@app.get("/Cats")
def test2(a: TestModelCats = Depends()) -> str:
return "Hello Worlds Cats"
if __name__ == "__main__":
uvicorn.run(app='app.__main__:app', reload=True, access_log=False)Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
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-models/ |
Beta Was this translation helpful? Give feedback.
The following works fine in current version (0.115.13).
See Docs: https://fastapi.tiangolo.com/tutorial/query-param-…