I have router in my application that dependency on some function. They both have separate pydantic
model as an argument. Problem is when I look at generated documentation, request body only shows parameters from router function argument and ones from dependency function is not included.
So, my question is is there a way I can include those fields? or it was designed this way specifically for some reason?
Code example:
import uvicorn
from fastapi import FastAPI, APIRouter, Depends
from fastapi.responses import JSONResponse
from pydantic import BaseModel
app = FastAPI()
class TestModel(BaseModel):
field_1: str
field_2: float
class OtherTestModel(BaseModel):
some_field_1: int
some_field_2: bool
router = APIRouter()
def test_dependency(data: OtherTestModel) -> None:
# do something here
print(data.dict())
if data.some_field_1 > 100:
pass
@router.post(
path='/',
dependencies=[Depends(test_dependency)]
)
def test(data: TestModel) -> JSONResponse:
return JSONResponse(
content=data.dict()
)
app.include_router(router)
if __name__ == '__main__':
uvicorn.run(
app='app:app',
host='0.0.0.0',
port=8000,
log_level='info',
debug=True,
)
Desired result would be to see some_field_1
and some_field_2
also included in this doc.