If you want to generate Schemas, pass the responses.
1 2 3 4 5 6 7 8 9101112131415161718192021222324
classBookBodyWithID(BaseModel):bid:int=Field(...,description='book id')age:Optional[int]=Field(None,ge=2,le=4,description='Age')author:str=Field(None,min_length=2,max_length=4,description='Author')classBookResponse(BaseModel):code:int=Field(0,description="status code")message:str=Field("ok",description="exception information")data:BookBodyWithID@app.get('/book/<int:bid>',tags=[book_tag],responses={200:BookResponse,# Version 2.4.0 starts supporting response for dictionary types201:{"content":{"text/csv":{"schema":{"type":"string"}}}}})defget_book(path:BookPath,query:BookBody):"""get a book get book by id, age or author """return{"code":0,"message":"ok","data":{}}
Now you can use string, int, and HTTPStatus as response's key.