I'd like to set up a POST
route with some dynamic parameters, e.g.:
@router.post("/", response_model=MyResponseModel, status_code=201)
def create_foo(
foo: Union[FooCreate, BarCreate],
type: FooBarType,
config: Optional[FooBarConfig],
session: Session = Depends(get_session),
) -> Any:
Depending on the value of type
, config
can be different things. For example:
type
= A
, config
can be 1
or 2
type
= B
, config
can be 1
or 3
type
= C
, config
is None
I know I could handle this manually, but I'd like to keep FastAPI documentation up to date also and have dynamic boxes from where to choose parameters for the request. Is it possible to achieve this somehow or do I need to separate this into multiple POST routes?