Skip to content

Schema Support

A list of Zod schemas supported by zod-v4-mocks.

Primitives

MethodStatusNotes
string()Fully supportedmin/max/regex/startsWith/endsWith/includes/trim etc. supported
number()Fully supportedmin/max/int/float supported
bigint()Fully supportedmin/max supported
boolean()Fully supported-
date()Fully supported-
null()Fully supported-
undefined()Fully supported-
void()Fully supported-
any()SupportedGenerates a string
unknown()SupportedGenerates a string
nan()Fully supported-
symbol()Fully supported-
never()Special handlingSkipped internally (excluded from arrays, keys omitted from objects)

Collection Types

MethodStatusNotes
object()Fully supportedNesting supported
array()Fully supportedmin/max/nonempty/length supported
tuple()Fully supportedPreserves each element's type
record()Fully supportedEntry count is configurable
partialRecord()Fully supportedDetails
map()Fully supportedmin/max/nonempty supported
set()Fully supportedmin/max/nonempty supported

partialRecord and ZodNever

partialRecord() internally uses the same generation logic as record(). Since Zod internally transforms partialRecord(keys, value) into a value type of union([value, never()]), entries where never() is selected are automatically skipped during generation.

ts
const schema = z.partialRecord(z.enum(['id', 'name', 'email']), z.string());

const mock = generator.generate(schema);
// => { id: "subito" } (only some keys are included)
// => {} (may result in an empty object)

schema.parse(mock); // OK - all keys are optional

This allows partialRecord() to naturally generate objects with only a subset of keys, unlike record(). The record min/max settings affect the number of entry generation attempts, but the actual number of keys may be fewer due to ZodNever skipping.

Union and Intersection Types

MethodStatusNotes
union()Fully supportedSelected uniformly
discriminatedUnion()SupportedSelected uniformly
xor()Fully supportedExclusive union
intersection()Partially supportedDetails

Literal and Enum Types

MethodStatusNotes
literal()Fully supported-
enum()Fully supported-
templateLiteral()Fully supportedSupports string/number/boolean/literal/union/null/undefined/nullable/optional

templateLiteral Notes

When using templateLiteral with z.undefined(), be aware of the value Zod expects.

ts
const schema = z.templateLiteral(['Value: ', z.undefined()]);
type Schema = z.infer<typeof schema>;
// TypeScript infers `"Value: "`, but
// Zod expects `"Value: undefined"`

const mock = generator.generate(schema);
// => "Value: undefined" (follows Zod's behavior)

Date/Time Formats

MethodStatusFormat
datetime()Fully supportedISO 8601
isodate()Fully supportedYYYY-MM-DD
isotime()Fully supportedHH:MM:SS
isoduration()Fully supportedISO 8601 Duration

String Formats

MethodStatus
email()Fully supported
url()Fully supported
uuid()Fully supported (v1-v8)
guid()Fully supported
nanoid()Fully supported
ulid()Fully supported
cuid() / cuid2()Fully supported
xid() / ksuid()Fully supported
jwt()Fully supported
emoji()Fully supported
ipv4() / ipv6()Fully supported
cidrv4() / cidrv6()Fully supported
base64() / base64url()Fully supported
e164()Fully supported
hostname()Fully supported

String Constraint Support

String schemas support a rich set of method-style constraints.

ConstraintExampleSupported
Lengthlength(10), min(5), max(20)Yes
Regexregex(/^[A-Z]+$/)Yes
Starts withstartsWith('PREFIX')Yes
Ends withendsWith('SUFFIX')Yes
Containsincludes('KEYWORD')Yes
UppercasetoUpperCase(), uppercase()Yes
LowercasetoLowerCase(), lowercase()Yes
Trimtrim()Yes
Normalizenormalize()Yes
Slugifyslugify()Yes

Multiple constraints can be combined:

ts
const schema = z
  .string()
  .min(10)
  .max(30)
  .startsWith('PRE')
  .includes('X')
  .toLowerCase();

const mock = generator.generate(schema);
// => "prexqwerty..." (10-30 chars, starts with "PRE", contains "X", lowercase)

Note on constraint combinations

Some combinations may be contradictory (e.g., regex(/^[a-z]+$/) and toUpperCase()). Specifying contradictory constraints may result in generated values that fail validation.

Effects and Pipeline

MethodStatusNotes
transform()Fully supportedTransform is applied
preprocess()Fully supported-
pipe()Fully supportedGenerated from the output schema
codec()SupportedSupports stringbool etc.
brand()SupportedType-level only (no runtime impact)
refine()Constraints ignoredDetails
check()Partially supportedDetails

Special Types

MethodStatusNotes
lazy()Partially supportedDetails
success()Supported-
catch()Supported-
file()SupportedGenerates an empty test.txt file
apply()SupportedSchema transformation helper

Modifiers

MethodStatusNotes
optional()Fully supportedControlled by optionalProbability
exactOptional()Fully supportedKey omitted entirely (not undefined)
nullable()Fully supportedControlled by nullableProbability
default()Fully supportedControlled by defaultProbability
prefault()Fully supportedControlled by defaultProbability
nonoptional()Fully supportedRemoves optional
readonly()Fully supportedType-level only

Partially Supported Details

ZodIntersection (Intersection)

Status: Partially supported

Intersections between the same types are generally supported, but intersections between different types are limited.

Working Examples

ts
// Intersection of objects
const schema = z.intersection(
  z.object({ a: z.string() }),
  z.object({ b: z.number() }),
);
// => { a: "subito", b: 123 }

// Intersection of number ranges
const rangeSchema = z.intersection(
  z.number().min(0).max(100),
  z.number().min(50).max(150),
);
// => a number between 50 and 100

Limitations

  • Same-type intersections are generally supported
  • Different-type intersections are generally unsupported (the following are exceptions):
    • ZodObject and ZodRecord
    • ZodArray and ZodTuple
  • If one side is ZodAny / ZodUnknown, the other type is used
  • Errors occur if Map/Set/Array/Enum/Union elements are incompatible

ZodLazy (Recursive Type)

Status: Partially supported

Recursive schemas are supported, but with a depth limit. Getter-based circular references are also supported in the same way.

Working Examples

ts
// Self-reference via z.lazy()
type Category = {
  name: string;
  subcategories: Category[];
};

const categorySchema: z.ZodType<Category> = z.lazy(() =>
  z.object({
    name: z.string(),
    subcategories: z.array(categorySchema),
  }),
);

// Self-reference via getters (recommended pattern in Zod v4)
const Node = z.object({
  value: z.number(),
  get next() {
    return Node.optional();
  },
});

// Mutual references
const User = z.object({
  email: z.email(),
  get posts() {
    return z.array(Post);
  },
});

const Post = z.object({
  title: z.string(),
  get author() {
    return User;
  },
});

Limitations

  • Depth limited (default: 5 levels, configurable via recursiveDepthLimit)
  • An empty object {} is returned when the depth limit is reached
  • Possible errors when union is at the top level
  • z.lazy() and getters are guaranteed to reach the same depth
ts
const gen = initGenerator({ recursiveDepthLimit: 3 });
const result = gen.generate(categorySchema);
// truncated at 3 levels

refine() (Validation)

Status: Constraints ignored

refine() validation conditions are ignored during mock generation.

ts
const schema = z.number().refine((val) => val > 0, {
  message: 'Must be positive',
});

const mock = generator.generate(schema);
// => a number is generated, but > 0 is not guaranteed

As a workaround, you can use override to generate values that satisfy the condition.

check() (Validation Checks)

Status: Partially supported

Validations via the check() function only support transformation-type checks such as z.overwrite() / z.trim() / z.toLowerCase() / z.toUpperCase().

APIStatusNotes
regex(/pattern/)SupportedMethod-style (recommended)
check(z.regex(/pattern/))UnsupportedVia check() function
trim()SupportedMethod-style (recommended)
check(z.trim())SupportedOverwrite helper
check(z.overwrite(...))SupportedTransform is applied
check(z.minLength(...))Unsupported-
with(z.minLength(5), z.toLowerCase())SupportedEquivalent to check()

Recommendation

Use method-style validation (regex(), min(), max(), etc.). All method-style validations are supported.


Unsupported

SchemaReasonWorkaround
custom() / instanceof()Cannot analyze custom validationsProvide values via override
function()Generating function mocks is complexProvide mock functions via override
nativeEnum()Deprecated in Zod v4Use enum() instead
catchall()Ignored (no impact on mock generation)-

Workaround Examples for Unsupported Schemas

ts
// Workaround for z.custom()
const myCustomSchema = z.custom<MyClass>((val) => val instanceof MyClass);

const mock = initGenerator()
  .override((schema) => {
    if (schema === myCustomSchema) {
      return new MyClass();
    }
  })
  .generate(myCustomSchema);
ts
// Workaround for z.function()
const fnSchema = z.function().args(z.string()).returns(z.boolean());

const mock = initGenerator()
  .override((schema) => {
    if (schema instanceof z.ZodFunction) {
      return (str: string) => str.length > 0;
    }
  })
  .generate(fnSchema);