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

z.pipe can create impossible validation schemas #97

Closed
ciscoheat opened this issue Dec 10, 2023 · 3 comments
Closed

z.pipe can create impossible validation schemas #97

ciscoheat opened this issue Dec 10, 2023 · 3 comments

Comments

@ciscoheat
Copy link
Contributor

I noticed that z.pipe can create conflicting schemas due to the allOf inclusion of the types. A crude example:

const schema = z.object({
  len: z.string().transform((val) => val.length).pipe(z.number().min(5))
});
{
  type: 'object',
  properties: {
    // Can never validate, conflicting types
    len: { allOf: [ { type: 'string' }, { type: 'number', minimum: 5 } ] }
  },
  required: [ 'len' ],
  additionalProperties: false,
  '$schema': 'http://json-schema.org/draft-07/schema#'
}

I saw that pipeStrategy can be used to only get the input type, so would you be open to an output option for that, if possible? If it's relatively simple, I'll make a PR for it.

@StefanTerdell
Copy link
Owner

That's the thing, short of using a compiler you can't get the output type to serialize it. But I guess an option to pick the last schema in the pipe could work.

@StefanTerdell
Copy link
Owner

🚀 3.22.2

@ciscoheat
Copy link
Contributor Author

Thank you for a very quick merge! :)

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