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

[zod-mock] Schema's array().min() value disregarded if >5 #198

Open
dietrich-iti opened this issue Apr 4, 2024 · 0 comments
Open

[zod-mock] Schema's array().min() value disregarded if >5 #198

dietrich-iti opened this issue Apr 4, 2024 · 0 comments

Comments

@dietrich-iti
Copy link

If the schema specifies an array (or set) with a min value greater than 5, and no max value, that constraint is effectively ignored, and min and max both become 5. This is due to the following:

One way to remedy this might be: if the schema provides min but not max, set the effective max to min (or min plus some reasonable delta). 5 could remain as a sensible default, but only for when neither constraint is set.

Example from Node REPL:

> const { z } = await import('zod')
> const { generateMock } = await import('@anatine/zod-mock')
> const arrayTwenty = z.number().array().min(20)
> generateMock(arrayTwenty)
[
  1034714246807552,
  5067818718461952,
  6212181381087232,
  2363641296846848,
  4675637484716032
]
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

1 participant