If multiple dependencies use the same body parameter, the openapi example gets broken.
from enum import Enum
from fastapi import Depends, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Title(str, Enum):
mr = 'Mr.'
ms = 'Ms.'
mrs = 'Mrs.'
class GreetRequest(BaseModel):
name: str
title: Title
def get_title(body: GreetRequest):
return body.title
def get_name(body: GreetRequest):
return body.name
@app.post('/greet')
def greet(name: str = Depends(get_name), title: Title = Depends(get_title)):
return f"greetings {title} {name}!"
# For debugging purposes the script can be run directly
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
localhost:8000/docs{
"body": {
"name": "string",
"title": "Mr."
}
}
422 Unprocessable EntityThe request body example should be:
{
"name": "string",
"title": "Mr."
}
I think this was recently fixed, please try with the latest version 0.54.1.
I just tried with your example and it seems to be working as expected.
Assuming the original issue was solved, it will be automatically closed now. But feel free to add more comments or create new issues.
Most helpful comment
I think this was recently fixed, please try with the latest version
0.54.1.I just tried with your example and it seems to be working as expected.