Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate FastAPI docs from msgspec.Struct json schema #661

Open
Arseniy-Popov opened this issue Mar 23, 2024 · 2 comments
Open

Generate FastAPI docs from msgspec.Struct json schema #661

Arseniy-Popov opened this issue Mar 23, 2024 · 2 comments

Comments

@Arseniy-Popov
Copy link

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.

@provinzkraut
Copy link

The answer here is, unfortunately, that FastAPI simply does not support this for types that are not natively supported by Pydantic. There's not much that can be done from msgspec's side here, as it's a design decision/constraint on FastAPI's side.

@kemingy
Copy link

kemingy commented Apr 3, 2024

I'm also using msgspec in a micro-service to validate the requests and generate the OpenAPI doc. I build a simple tool defspec to generate the OpenAPI schema and render it with Swagger/Redoc/Scalar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants