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

Switching to using zod-openapi from zod-to-jsonschema to solve things like definition? #415

Open
tonyxiao opened this issue Oct 25, 2023 · 4 comments

Comments

@tonyxiao
Copy link

Related issue here samchungy/zod-openapi#181

zod-openapi seems to have much better metadata and openapi support. In particular it could be extremely helpful for things like re-using definitions across the API endpoints. Could we look into adopting it?

@LilyRose2798
Copy link

LilyRose2798 commented Nov 8, 2023

I've just pushed out a version on my fork with working zod-openapi integration if you're interested:
https://github.com/LilyRose2798/trpc-openapi
The only things I've found that don't work yet are using z.undefined() inside a tRPC request/response zod schema, and using .transform on tRPC output schemas (works on all other schemas though), but none of these are things I've needed yet so I haven't gone to the effort of getting them working.

@tonyxiao
Copy link
Author

tonyxiao commented Nov 8, 2023

amazing! any usage differences?

@tonyxiao
Copy link
Author

tonyxiao commented Nov 8, 2023

in particular how does it support openapi defs?

@LilyRose2798
Copy link

LilyRose2798 commented Nov 8, 2023

There aren't any major usage differences other than the few current compatibility issues mentioned above which you might need to work around depending on your schema. Headers are also now provided using a Zod schema so if you were using those you might need to change that. Other than those nothing should need to change about your definition. The request/response schemas used in the procedure definition are just passed to zod-openapi with minimal modification (just extracting out any fields needed for path/query params) which then creates the spec document, so all info set in the .openapi meta works as you'd expect, including using $ref and having the schema be extracted out/de-duplicated automatically.

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

2 participants