I'm working in develop an middleware with FastAPI. I want keep the same response for all the responses like:
/foo/
{
"status": "success",
"code": 200,
"msg": [foo, foo, foo]
}
/foo/1/
{
"status": "success",
"code": 200,
"msg": foo
}
It's works with the following code:
class AppOutputSchema(pydantic.BaseModel):
"""
Standard output schema class of the application
"""
status: str = "success"
code: int = 200
msg: Any
@router.get("/", response_model=AppOutputSchema, status_code=200)
async def read_all_foo() -> AppOutputSchema:
foo_list = await read_all_foo()
return AppOutputSchema(msg=foo_list)
But the documentation generated in /docs it's wrong. The response schema is always {status, code, msg} for all the endpoints.
The documentation should have the foo schema definition.
I read the documentation and I can't find anything about it.
Any idea?
question from:
https://stackoverflow.com/questions/65907509/fastapi-return-same-structure-in-all-the-responses 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…