With FastAPI I am trying to inject two dependent functions, each of which have their own pydantic request bodies and form part of separate endpoints into path operation of another endpoint. Please see the example below just for illustration:
from fastapi import FastAPI, Depends
from pydantic import BaseModel
app = FastAPI()
class RequestBodyChild1(BaseModel):
item1: float
item2: float
class RequestBody1(BaseModel):
parent1: RequestBodyChild1
@app.post("/function_1")
def function_1(request: RequestBody1):
return request
class RequestBodyChild2(BaseModel):
itemA: float
itemB: float
class RequestBody2(BaseModel):
parent2: RequestBodyChild2
@app.post("/function_2")
def function_2(request: RequestBody2):
return request
@app.post("/function_3")
def function_3(request_1: dict = Depends(function_1), request_2: dict = Depends(function_2)):
merged_dict = dict(request_1.items() + request_2.items())
return merged_dict
The issue is that for the function_3 endpoint OpenAPI/Swagger only shows the request body/example schema for request_1: dict = Depends(function_1):
{
"parent1": {
"item1": 0,
"item2": 0
}
}
How can I make sure that both request bodies are included? Along the lines of:
{
"parent1": {
"item1": 0,
"item2": 0
},
"parent2": {
"itemA": 0,
"itemB": 0
}
}