Const
import * as fc from 'fast-check'
import { z } from 'zod'
import { zxTest } from '@traversable/zod-test'
const tenSchemas = fc.sample(zxTest.SchemaGenerator({
include: ['null', 'boolean', 'number', 'string', 'array', 'object']
}), 10)
tenSchemas.forEach((s) => console.log(zxTest.toString(s)))
// => z.number()
// => z.string().max(64)
// => z.null()
// => z.array(z.boolean())
// => z.boolean()
// => z.object({ "": z.object({ "/d2P} {/": z.boolean() }), "svH2]L'x": z.number().lt(-65536) })
// => z.null()
// => z.string()
// => z.array(z.array(z.null()))
// => z.object({ "y(Qza": z.boolean(), "G1S\\U 4Y6i": z.object({ "YtO3]ia0cM": z.boolean() }) })
zxTest.SchemaGenerator
A zod schema generator that can be interpreted to produce an arbitrary
zod
schema (v4, classic).The generator supports a wide range of configuration options that are discoverable via the optional
options
argument.Many of those options are forwarded to the corresponding
fast-check
arbitrary.To use it, you'll need to have
fast-check
installed.Note: support for
options.minDepth
is experimental. If you use it, be advised that even with a minimum depth of 1, the schemas produced will be quite large. Using this option in your CI/CD pipeline is not recommended.See also:
zxTest.SeedGenerator