From 25cb4fec0cbe16d062123460d3ca2ed2669b3738 Mon Sep 17 00:00:00 2001 From: Tal Leibman Date: Fri, 25 Dec 2020 11:10:43 +0200 Subject: [PATCH] msgpack.py: allow pydantic BaseModel in content --- etebase_fastapi/msgpack.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/etebase_fastapi/msgpack.py b/etebase_fastapi/msgpack.py index 53e18cb..399f3d0 100644 --- a/etebase_fastapi/msgpack.py +++ b/etebase_fastapi/msgpack.py @@ -1,6 +1,7 @@ import typing as t import msgpack from fastapi.routing import APIRoute, get_request_handler +from pydantic import BaseModel from starlette.requests import Request from starlette.responses import Response @@ -19,6 +20,8 @@ class MsgpackResponse(Response): media_type = "application/msgpack" def render(self, content: t.Any) -> bytes: + if isinstance(content, BaseModel): + content = content.dict() return msgpack.packb(content, use_bin_type=True)