Skip to main content

Function: walkSchema()

Call Signature

walkSchema(schema, options): WalkResult

Defined in: packages/core/src/walker.ts:287

Walk a Zod schema and produce a FormField[] tree. When optimization option is set, returns WalkResult with fields + schemaLite.

Parameters

schema

$ZodType

options

WalkOptions & object

Returns

WalkResult

Remarks

Recursively walks a Zod schema tree and produces a FormField[] intermediate representation. Dispatches by def.type to a processor registry. Each processor extracts structure and constraints from _zod.def + _zod.bag. Uses WeakSet per top-level field for cycle detection — reused schema instances (e.g., z.string() in two fields) don't trigger false positives. The walker is STATELESS — call it repeatedly with different formRegistry values.

Use When

  • You need direct schema-to-fields conversion in runtime contexts
  • You're building a custom codegen pipeline on top of FormField[]

Avoid When

  • You just want generated components — use the CLI instead
  • Your schema is not z.object() at the root level

Pitfalls

  • NEVER pass a non-object schema at the root — throws immediately
  • NEVER bypass the processor registry for custom types — extend via options.processors
  • NEVER skip normalizeFormValues() before schema.safeParse() — empty strings from HTML inputs fail optional field validation

Call Signature

walkSchema(schema, options?): FormField[]

Defined in: packages/core/src/walker.ts:291

Walk a Zod schema and produce a FormField[] tree. When optimization option is set, returns WalkResult with fields + schemaLite.

Parameters

schema

$ZodType

options?

WalkOptions

Returns

FormField[]

Remarks

Recursively walks a Zod schema tree and produces a FormField[] intermediate representation. Dispatches by def.type to a processor registry. Each processor extracts structure and constraints from _zod.def + _zod.bag. Uses WeakSet per top-level field for cycle detection — reused schema instances (e.g., z.string() in two fields) don't trigger false positives. The walker is STATELESS — call it repeatedly with different formRegistry values.

Use When

  • You need direct schema-to-fields conversion in runtime contexts
  • You're building a custom codegen pipeline on top of FormField[]

Avoid When

  • You just want generated components — use the CLI instead
  • Your schema is not z.object() at the root level

Pitfalls

  • NEVER pass a non-object schema at the root — throws immediately
  • NEVER bypass the processor registry for custom types — extend via options.processors
  • NEVER skip normalizeFormValues() before schema.safeParse() — empty strings from HTML inputs fail optional field validation