zx.SchemaGenerator
A zod schema generator that can be interpreted to produce an arbitrary zod schema (v4, classic).
zod
The generator supports a wide range of configuration options that are discoverable via the optional options argument.
options
Many of those options are forwarded to the corresponding fast-check arbitrary.
fast-check
To use it, you'll need to have fast-check installed.
See also:
zx.SeedGenerator
import * as fc from 'fast-check'import { z } from 'zod'import { zx } from '@traversable/zod'const tenSchemas = fc.sample(zx.SchemaGenerator({ include: ['null', 'boolean', 'number', 'string', 'array', 'object'] }), 10)tenSchemas.forEach((s) => console.log(zx.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() }) }) Copy
import * as fc from 'fast-check'import { z } from 'zod'import { zx } from '@traversable/zod'const tenSchemas = fc.sample(zx.SchemaGenerator({ include: ['null', 'boolean', 'number', 'string', 'array', 'object'] }), 10)tenSchemas.forEach((s) => console.log(zx.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() }) })
zx.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.See also:
zx.SeedGenerator
Example