msgspec icon indicating copy to clipboard operation
msgspec copied to clipboard

Generate FastAPI docs from msgspec.Struct json schema

Open Arseniy-Popov opened this issue 11 months ago • 3 comments

Question

One can generate a json schema from a msgspec.Struct using msgspec.json.schema. Where does one put that schema so that FastAPI uses it as the schema for the endpoint's response body in the OpenAPI docs that it generates?

There doesn't seem to be a way to achive this in FastAPI despite some schema customization options. Nor is it possible to generate a pydantic model (so that it could be used for the docs) from a json schema.

Although the question relates to FastAPI rather than to msgspec directly I'm still posting it here as using Structs with FastAPI is probably a very common use-case.

Arseniy-Popov avatar Mar 23 '24 22:03 Arseniy-Popov