I’m trying to receive a nontrivial query parameter object. At the moment it looks like this:
@router.get("/my/route")
def get_vhist_snap_pnl(
param: pydantic.types.Json = fastapi.Query(
...,
description="json-encoded dictionary",
)
):
...
But I want “param” to be parsed as some arbitrary pydantic object, e.g.:
class MyParam(pydantic.BaseClass):
param1: list[str]
param2: typing.Dict[str, SomeOtherPydanticType]
I can use param
to construct an instance of MyParam
but it would be nice for fastapi
to do this for me because I’d get better swagger docs and it would be less code to write. How can I do this?