Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23305

How do I receive a non primitive object as query parameter?

$
0
0

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?


Viewing all articles
Browse latest Browse all 23305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>