Const
Optional
options: OptionsOptional
overrides: Partial<import * as fc from 'fast-check'
import { z } from 'zod'
import { zx } from '@traversable/zod'
const Json = zx.SeedGenerator({ include: ['null', 'boolean', 'number', 'string', 'array', 'object'] })
const [jsonNumber, jsonObject, anyJson] = [
fc.sample(Json.number, 1)[0],
fc.sample(Json.object, 1)[0],
fc.sample(Json['*'], 1)[0],
] as const
console.log(JSON.stringify(jsonNumber))
// => [200,[2.96e-322,1,null,false,true]]
console.log(zx.toString(zx.seedToSchema(jsonNumber)))
// => z.number().min(2.96e-322).lt(1)
console.log(JSON.stringify(jsonObject))
// => [7500,[["n;}289K~",[250,[null,null]]]]]
console.log(zx.toString(zx.seedToSchema(jsonObject)))
// => z.object({ "n;}289K~": z.string() })
console.log(anyJson)
// => [250,[23,64]]
console.log(zx.toString(zx.seedToSchema(anyJson)))
// => z.string().min(23).max(64)
SeedGenerator
Pseudo-random seed generator.
The generator supports a wide range of discoverable configuration options 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:
SeedGenerator