fix: Zod 4 compatibility for prefault, transform pipes, and refined schema omit#155
Merged
Merged
Conversation
…ed schema omit - Handle Zod 4's `prefault` type in `unwrapZodType` (same unwrap logic as `default`) - In `pipe` handling, check if `def.out` is a `transform` type and follow `def.in` instead, since `.transform().superRefine()` in Zod 4 creates a pipe where `def.out` is an opaque transform - Wrap `.omit()` in try/catch in `getRequestBodyObject` to handle refined schemas that throw in Zod 4, falling back to manual shape filtering Fixes mcampa#153
|
Would love to see this merged if possible. |
|
@mcampa Any chance to get this merged? |
Author
|
To everyone waiting for the merge, just give this pr link to your agent of choice and ask it to patch it for you. |
Owner
|
Hey, Sorry I haven't have time to look at PRs here. Going to merge it and publish a release |
|
I will leave this here for other people. If you are using bun just create a folder |
Owner
|
Published |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes compatibility issues when using trpc-to-openapi with Zod 4:
prefaulttype support: Zod 4 introduces aprefaulttype (similar todefault). Added handling inunwrapZodTypeto unwrap it via.unwrap(), matching the existingdefaultbehavior..transform()pipe handling: In Zod 4,.transform().superRefine()creates apipewheredef.outis an opaquetransformtype rather than a usable schema. When this is detected, the unwrapper now followsdef.in(the input schema shape) instead..omit()fallback: Zod 4 throws when calling.omit()on object schemas that have refinements. Wrapped the.omit()call ingetRequestBodyObjectwith a try/catch that falls back to manually filtering path parameter keys fromschema.shape.Fixes #153
Test plan
unwrapZodTypecorrectly unwrapsz.prefault()schemasunwrapZodTypefollowsdef.infor pipes wheredef.outis a transformgetRequestBodyObjectworks with refined object schemas that have path parameters