turkerdev / fastify-type-provider-zod

MIT License
337 stars 21 forks source link

Openapi schema #45

Open balkarika opened 1 year ago

balkarika commented 1 year ago

Is there a way to define the zod types so that the @fastify/swagger can generate an openapi which uses schemas to define the expected schemas for the routes, and the routes only to use $ref to the schema section?

Right now all the types I defined with zod get generated under each route and nothing gets generated under schema section.

willo-icon commented 2 months ago

This library seems to use zod-to-json-schema for the schema it generates, and it looks to be hard-coded to have a $refStrategy: "none": https://github.com/turkerdev/fastify-type-provider-zod/blob/c1fa086e134821fdc146b7e51df881aff51197b6/src/index.ts#L36-L39

I think in order for this to work, you would need some way to configure $refStrategy. Not sure how much work that would be beyond just adding it as an argument. But I suspect the author specifically chose none for some reason.