anatine / zod-plugins

Plugins and utilities for Zod
591 stars 84 forks source link

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

Open dietrich-iti opened 3 months ago

dietrich-iti commented 3 months ago

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
]