types

package
v0.11.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package types provides public schema implementations for GoZod validation types.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilArrayPtr = errors.New("nil pointer to array")
	ErrNilPtr      = errors.New("nil pointer")
	ErrNotArray    = errors.New("expected array or slice")
)

Sentinel errors for array validation.

View Source
var (
	ErrSchemaIsNil                = errors.New("schema is nil")
	ErrSchemaInternalsIsNil       = errors.New("schema internals is nil")
	ErrNoDiscriminatorValues      = errors.New("no discriminator values found for field")
	ErrOptionIsNil                = errors.New("option is nil")
	ErrDuplicateDiscriminator     = errors.New("duplicate discriminator value")
	ErrFailedToBuildDiscriminator = errors.New("failed to build discriminator map")
	ErrNoValidDiscriminators      = errors.New("no valid discriminator values found for field")
)
View Source
var (
	PrecisionMinute      = new(-1) // no seconds component
	PrecisionSecond      = new(0)  // seconds, no fraction
	PrecisionDecisecond  = new(1)  // 1 fractional digit
	PrecisionCentisecond = new(2)  // 2 fractional digits
	PrecisionMillisecond = new(3)  // 3 fractional digits
	PrecisionMicrosecond = new(6)  // 6 fractional digits
	PrecisionNanosecond  = new(9)  // 9 fractional digits
)

Precision constants control fractional-second digits in ISO 8601 strings.

View Source
var (
	// ErrNilObjectPointer is returned when a nil pointer is converted to an object.
	ErrNilObjectPointer = errors.New("nil pointer cannot convert to object")
	// ErrPickRefinements is returned when Pick is used on a schema with refinements.
	ErrPickRefinements = errors.New("pick cannot be used on schemas with refinements")
	// ErrOmitRefinements is returned when Omit is used on a schema with refinements.
	ErrOmitRefinements = errors.New("omit cannot be used on schemas with refinements")
	// ErrExtendRefinements is returned when Extend would overwrite keys on a schema with refinements.
	ErrExtendRefinements = errors.New("extend cannot overwrite keys on schemas with refinements, use SafeExtend")
	// ErrUnrecognizedKey is returned when strict object parsing encounters an unknown key.
	ErrUnrecognizedKey = errors.New("unrecognized key")
)
View Source
var (
	ErrInternalMapType             = errors.New("internal error: T is not a map type")
	ErrInternalMapKeyNotString     = errors.New("internal error: map key is not string")
	ErrInternalCannotConvertValue  = errors.New("internal error: cannot convert value type")
	ErrInternalCannotConvertRecord = errors.New("internal error: cannot convert validated record back to T")
	ErrNilPointerToRecord          = errors.New("nil pointer to record")
	ErrNonStringKeyInMap           = errors.New("non-string key found in map, records require string keys")
	ErrExpectedMapStringAny        = errors.New("expected map[string]any")
	ErrValueValidationFailed       = errors.New("value validation failed for key")
)

Sentinel errors for record schema operations.

View Source
var (
	// ErrFieldNotFoundOrNotSettable is returned when a struct field cannot be found or set.
	ErrFieldNotFoundOrNotSettable = errors.New("field not found or not settable")
	// ErrCannotAssignToField is returned when a value cannot be assigned to a struct field.
	ErrCannotAssignToField = errors.New("cannot assign value to field of type")
	// ErrValueMustBeStruct is returned when a value is not a struct or pointer to struct.
	ErrValueMustBeStruct = errors.New("value must be a struct or pointer to struct")
)

Functions

func ValidateStruct added in v0.9.0

func ValidateStruct(value any, opts ...FromStructOption) (any, error)

ValidateStruct validates a struct using tags and returns the parsed result. Returns the struct with defaults applied, coercions performed, and all validation issues.

This is the runtime equivalent of FromStruct[T]().Parse(value).

Example:

type Config struct {
    Host string `validate:"default=localhost"`
    Port int    `validate:"min=1000"`
}
result, err := types.ValidateStruct(&Config{Port: 8080}, types.WithTagName("validate"))
config := result.(*Config)  // Host is now "localhost"

Types

type BigIntegerConstraint added in v0.3.0

type BigIntegerConstraint interface {
	*big.Int | **big.Int
}

BigIntegerConstraint restricts values to *big.Int or **big.Int.

type BoolConstraint added in v0.3.0

type BoolConstraint interface {
	~bool | ~*bool
}

BoolConstraint restricts values to bool or *bool.

type Complex64Constraint added in v0.3.0

type Complex64Constraint interface {
	complex64 | *complex64
}

Complex64Constraint restricts values to complex64 or *complex64.

type Complex128Constraint added in v0.3.0

type Complex128Constraint interface {
	complex128 | *complex128
}

Complex128Constraint restricts values to complex128 or *complex128.

type ComplexConstraint added in v0.3.0

type ComplexConstraint interface {
	complex64 | complex128 | *complex64 | *complex128
}

ComplexConstraint restricts values to complex64, complex128, or their pointers.

type EmailConstraint added in v0.3.0

type EmailConstraint interface {
	string | *string
}

EmailConstraint restricts values to string or *string.

type FloatConstraint added in v0.3.0

type FloatConstraint interface {
	~float32 | ~float64 | ~*float32 | ~*float64
}

FloatConstraint restricts values to supported float types or their pointers.

type FromStructOption added in v0.8.0

type FromStructOption func(*fromStructConfig)

FromStructOption configures FromStruct and FromStructPtr.

func WithFieldNameTag added in v0.11.6

func WithFieldNameTag(name string) FromStructOption

WithFieldNameTag sets the struct tag used for field names (e.g. "yaml", "toml"). It defaults to "json" and controls JSON Schema property names and validation error paths.

func WithTagName added in v0.8.0

func WithTagName(name string) FromStructOption

WithTagName sets the struct tag name used by FromStruct helpers.

type FunctionConstraint added in v0.3.0

type FunctionConstraint interface {
	any | *any
}

FunctionConstraint restricts values to function or *function.

type FunctionParams

type FunctionParams struct {
	Input  core.ZodType[any] `json:"input,omitempty"`
	Output core.ZodType[any] `json:"output,omitempty"`
}

FunctionParams defines parameters for function schema creation.

type IntegerConstraint added in v0.3.0

type IntegerConstraint interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~*int | ~*int8 | ~*int16 | ~*int32 | ~*int64 |
		~*uint | ~*uint8 | ~*uint16 | ~*uint32 | ~*uint64
}

IntegerConstraint restricts values to supported integer types or their pointers.

type IsoConstraint added in v0.3.0

type IsoConstraint interface {
	string | *string
}

IsoConstraint restricts generic type parameters to string or *string.

type IsoDatetimeOptions added in v0.3.0

type IsoDatetimeOptions struct {
	Precision *int // fractional-second digits; nil = any
	Offset    bool // allow timezone offsets like +08:00
	Local     bool // make trailing "Z" optional
}

IsoDatetimeOptions configures ISO 8601 datetime validation.

type IsoTimeOptions added in v0.3.0

type IsoTimeOptions struct {
	Precision *int // fractional-second digits; nil = any, -1 = minute
}

IsoTimeOptions configures ISO 8601 time validation.

type JWTOptions added in v0.3.0

type JWTOptions struct {
	// Algorithm specifies the expected signing algorithm.
	// If empty, any algorithm is accepted (basic structure validation only).
	Algorithm string
}

JWTOptions configures JWT validation behavior.

type LazyConstraint added in v0.3.0

type LazyConstraint interface {
	any | *any
}

LazyConstraint restricts values to any or *any for lazy schema types.

type ObjectMode

type ObjectMode string

ObjectMode defines how object validation handles unknown keys.

const (
	// ObjectModeStrict rejects unknown keys.
	ObjectModeStrict ObjectMode = "strict"
	// ObjectModeStrip removes unknown keys from the parsed result.
	ObjectModeStrip ObjectMode = "strip"
	// ObjectModePassthrough preserves unknown keys in the parsed result.
	ObjectModePassthrough ObjectMode = "passthrough"
)

type StringBoolConstraint added in v0.3.0

type StringBoolConstraint interface {
	bool | *bool
}

StringBoolConstraint restricts values to bool or *bool.

type StringBoolOptions

type StringBoolOptions struct {
	Truthy []string // Values that evaluate to true.
	Falsy  []string // Values that evaluate to false.
	Case   string   // "sensitive" or "insensitive".
}

StringBoolOptions configures truthy/falsy values and case sensitivity.

type StringConstraint added in v0.3.0

type StringConstraint interface {
	~string | ~*string
}

StringConstraint restricts values to string or *string.

type TimeConstraint added in v0.3.0

type TimeConstraint interface {
	time.Time | *time.Time
}

TimeConstraint restricts values to time.Time or *time.Time.

type TupleConstraint added in v0.5.4

type TupleConstraint interface {
	[]any | *[]any
}

TupleConstraint defines valid constraint types for tuple schemas.

type URLOptions added in v0.3.0

type URLOptions struct {
	// Hostname is a pattern that the URL's hostname must match.
	Hostname *regexp.Regexp
	// Protocol is a pattern that the URL's protocol must match.
	Protocol *regexp.Regexp
}

URLOptions configures validation for URL schemas.

type ZodAny

type ZodAny[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodAny validates any value with dual generic parameters. T is the base type, and R is the constraint type (T or *T).

func Any

func Any(params ...any) *ZodAny[any, any]

Any creates a schema that accepts any value.

func AnyPtr added in v0.3.0

func AnyPtr(params ...any) *ZodAny[any, *any]

AnyPtr creates a schema that accepts any value with pointer constraint.

func AnyTyped added in v0.3.0

func AnyTyped[T any, R any](params ...any) *ZodAny[T, R]

AnyTyped creates a typed any schema with generic constraints.

func (*ZodAny[T, R]) And added in v0.6.0

func (z *ZodAny[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodAny[T, R]) Check

func (z *ZodAny[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodAny[T, R]

Check adds a custom validation function that can push multiple issues.

func (*ZodAny[T, R]) CloneFrom

func (z *ZodAny[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodAny[T, R]) Default

func (z *ZodAny[T, R]) Default(v T) *ZodAny[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodAny[T, R]) DefaultFunc

func (z *ZodAny[T, R]) DefaultFunc(fn func() T) *ZodAny[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodAny[T, R]) Describe added in v0.5.4

func (z *ZodAny[T, R]) Describe(desc string) *ZodAny[T, R]

Describe registers a description in the global registry.

func (*ZodAny[T, R]) ExactOptional added in v0.6.0

func (z *ZodAny[T, R]) ExactOptional() *ZodAny[T, R]

ExactOptional returns a schema that accepts absent keys but rejects explicit nil values.

func (*ZodAny[T, R]) Internals added in v0.6.0

func (z *ZodAny[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodAny[T, R]) IsNilable added in v0.3.0

func (z *ZodAny[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodAny[T, R]) IsOptional added in v0.3.0

func (z *ZodAny[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodAny[T, R]) Meta added in v0.3.1

func (z *ZodAny[T, R]) Meta(meta core.GlobalMeta) *ZodAny[T, R]

Meta stores the provided metadata in the global registry.

func (*ZodAny[T, R]) MustParse

func (z *ZodAny[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates the input and panics if validation fails.

func (*ZodAny[T, R]) MustStrictParse added in v0.6.0

func (z *ZodAny[T, R]) MustStrictParse(input R, ctx ...*core.ParseContext) R

MustStrictParse validates the input with compile-time type safety and panics if validation fails.

func (*ZodAny[T, R]) Nilable

func (z *ZodAny[T, R]) Nilable() *ZodAny[T, *T]

Nilable returns a pointer-typed schema that accepts nil values.

func (*ZodAny[T, R]) NonOptional added in v0.3.0

func (z *ZodAny[T, R]) NonOptional() *ZodAny[T, T]

NonOptional removes the optional flag and forces the return type to T.

func (*ZodAny[T, R]) Nullish

func (z *ZodAny[T, R]) Nullish() *ZodAny[T, *T]

Nullish returns a schema that combines optional and nilable modifiers.

func (*ZodAny[T, R]) Optional

func (z *ZodAny[T, R]) Optional() *ZodAny[T, *T]

Optional returns a pointer-typed schema that accepts missing values.

func (*ZodAny[T, R]) Or added in v0.6.0

func (z *ZodAny[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodAny[T, R]) Overwrite added in v0.3.0

func (z *ZodAny[T, R]) Overwrite(transform func(T) T, params ...any) *ZodAny[T, R]

Overwrite applies data transformation while preserving the type structure.

func (*ZodAny[T, R]) Parse

func (z *ZodAny[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates the input and returns a value matching the generic type R.

func (*ZodAny[T, R]) ParseAny added in v0.3.0

func (z *ZodAny[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates the input and returns an untyped result.

func (*ZodAny[T, R]) Pipe

func (z *ZodAny[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a pipeline to another schema.

func (*ZodAny[T, R]) Prefault

func (z *ZodAny[T, R]) Prefault(v T) *ZodAny[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodAny[T, R]) PrefaultFunc

func (z *ZodAny[T, R]) PrefaultFunc(fn func() T) *ZodAny[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodAny[T, R]) Refine

func (z *ZodAny[T, R]) Refine(fn func(R) bool, params ...any) *ZodAny[T, R]

Refine applies a custom validation function that matches the schema's output type R.

func (*ZodAny[T, R]) RefineAny

func (z *ZodAny[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodAny[T, R]

RefineAny provides flexible validation without type conversion.

func (*ZodAny[T, R]) StrictParse added in v0.4.0

func (z *ZodAny[T, R]) StrictParse(input R, ctx ...*core.ParseContext) (R, error)

StrictParse provides type-safe parsing with compile-time guarantees.

func (*ZodAny[T, R]) Transform

func (z *ZodAny[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function.

func (*ZodAny[T, R]) With added in v0.6.0

func (z *ZodAny[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodAny[T, R]

With is an alias for Check that provides Zod v4 API compatibility.

type ZodAnyDef

type ZodAnyDef struct {
	core.ZodTypeDef
}

ZodAnyDef holds the configuration for any-value validation.

type ZodAnyInternals

type ZodAnyInternals struct {
	core.ZodTypeInternals
	Def *ZodAnyDef
}

ZodAnyInternals contains the internal state of an any validator.

type ZodArray

type ZodArray[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodArray is a type-safe fixed-length array validation schema. T is the base array type, R is the constraint type (T or *T).

func Array

func Array(args ...any) *ZodArray[[]any, []any]

Array creates a tuple schema with fixed elements.

Array()                               - empty tuple
Array([]any{String(), Int()})         - fixed length tuple
Array([]any{String(), Int()}, Bool()) - tuple with rest parameter

func ArrayPtr added in v0.3.0

func ArrayPtr(args ...any) *ZodArray[[]any, *[]any]

ArrayPtr creates a pointer-capable tuple schema.

func ArrayTyped added in v0.3.0

func ArrayTyped[T any, R any](items []any, args ...any) *ZodArray[T, R]

ArrayTyped is the generic constructor for tuple schemas.

func (*ZodArray[T, R]) And added in v0.5.4

func (z *ZodArray[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodArray[T, R]) Check

func (z *ZodArray[T, R]) Check(fn func(R, *core.ParsePayload), params ...any) *ZodArray[T, R]

Check adds a custom validation function that can report multiple issues.

func (*ZodArray[T, R]) CloneFrom

func (z *ZodArray[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodArray[T, R]) Default

func (z *ZodArray[T, R]) Default(v T) *ZodArray[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodArray[T, R]) DefaultFunc

func (z *ZodArray[T, R]) DefaultFunc(fn func() T) *ZodArray[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodArray[T, R]) Describe added in v0.5.4

func (z *ZodArray[T, R]) Describe(description string) *ZodArray[T, R]

Describe sets a description for this schema in the global registry.

func (*ZodArray[T, R]) Element

func (z *ZodArray[T, R]) Element(index int) core.ZodSchema

Element returns the schema at the given index, or nil if out of range.

func (*ZodArray[T, R]) ExactOptional added in v0.5.4

func (z *ZodArray[T, R]) ExactOptional() *ZodArray[T, R]

ExactOptional accepts absent keys but rejects explicit nil values. Unlike Optional, ExactOptional only accepts absent keys in object fields.

func (*ZodArray[T, R]) Internals added in v0.6.0

func (z *ZodArray[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state for framework usage.

func (*ZodArray[T, R]) IsNilable added in v0.3.0

func (z *ZodArray[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodArray[T, R]) IsOptional added in v0.3.0

func (z *ZodArray[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodArray[T, R]) Items

func (z *ZodArray[T, R]) Items() []core.ZodSchema

Items returns a copy of all element schemas.

func (*ZodArray[T, R]) Length

func (z *ZodArray[T, R]) Length(n int, args ...any) *ZodArray[T, R]

Length adds an exact element count constraint.

func (*ZodArray[T, R]) Max

func (z *ZodArray[T, R]) Max(n int, args ...any) *ZodArray[T, R]

Max adds a maximum element count constraint.

func (*ZodArray[T, R]) Meta added in v0.3.1

func (z *ZodArray[T, R]) Meta(meta core.GlobalMeta) *ZodArray[T, R]

Meta stores metadata for this array schema in the global registry.

func (*ZodArray[T, R]) Min

func (z *ZodArray[T, R]) Min(n int, args ...any) *ZodArray[T, R]

Min adds a minimum element count constraint.

func (*ZodArray[T, R]) MustParse

func (z *ZodArray[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates the input value and panics on failure.

func (*ZodArray[T, R]) MustStrictParse added in v0.4.0

func (z *ZodArray[T, R]) MustStrictParse(input T, ctx ...*core.ParseContext) R

MustStrictParse validates input with compile-time type safety and panics on failure.

func (*ZodArray[T, R]) Nilable

func (z *ZodArray[T, R]) Nilable() *ZodArray[T, *T]

Nilable returns a schema that accepts nil values with pointer constraint.

func (*ZodArray[T, R]) NonEmpty

func (z *ZodArray[T, R]) NonEmpty(args ...any) *ZodArray[T, R]

NonEmpty requires at least one element.

func (*ZodArray[T, R]) NonOptional added in v0.3.0

func (z *ZodArray[T, R]) NonOptional() *ZodArray[T, T]

NonOptional enforces non-nil value constraint, producing a "expected = nonoptional" error when input is nil.

func (*ZodArray[T, R]) Nullish

func (z *ZodArray[T, R]) Nullish() *ZodArray[T, *T]

Nullish combines optional and nilable modifiers.

func (*ZodArray[T, R]) Optional

func (z *ZodArray[T, R]) Optional() *ZodArray[T, *T]

Optional returns a schema that accepts nil values with pointer constraint.

func (*ZodArray[T, R]) Or added in v0.5.4

func (z *ZodArray[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodArray[T, R]) Overwrite added in v0.3.0

func (z *ZodArray[T, R]) Overwrite(fn func(R) R, params ...any) *ZodArray[T, R]

Overwrite transforms the value while preserving the original type.

func (*ZodArray[T, R]) Parse

func (z *ZodArray[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input and returns the parsed array value.

func (*ZodArray[T, R]) ParseAny added in v0.3.0

func (z *ZodArray[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodArray[T, R]) Pipe

func (z *ZodArray[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe passes the parsed value to a target schema.

func (*ZodArray[T, R]) Prefault

func (z *ZodArray[T, R]) Prefault(v T) *ZodArray[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodArray[T, R]) PrefaultFunc

func (z *ZodArray[T, R]) PrefaultFunc(fn func() T) *ZodArray[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodArray[T, R]) Refine

func (z *ZodArray[T, R]) Refine(fn func(R) bool, params ...any) *ZodArray[T, R]

Refine adds type-safe custom validation.

func (*ZodArray[T, R]) RefineAny

func (z *ZodArray[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodArray[T, R]

RefineAny adds custom validation without type conversion.

func (*ZodArray[T, R]) Rest added in v0.3.0

func (z *ZodArray[T, R]) Rest() core.ZodSchema

Rest returns the rest parameter schema, or nil if none.

func (*ZodArray[T, R]) StrictParse added in v0.4.0

func (z *ZodArray[T, R]) StrictParse(input T, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodArray[T, R]) Transform

func (z *ZodArray[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed value.

type ZodArrayDef

type ZodArrayDef struct {
	core.ZodTypeDef
	Items []core.ZodSchema // Element schemas per position.
	Rest  core.ZodSchema   // Rest schema for variadic elements (nil if none).
}

ZodArrayDef holds the schema definition for fixed-length array validation.

type ZodArrayInternals

type ZodArrayInternals struct {
	core.ZodTypeInternals
	Def   *ZodArrayDef
	Items []core.ZodSchema
	Rest  core.ZodSchema
}

ZodArrayInternals contains the internal state for an array schema.

type ZodBase64 added in v0.3.0

type ZodBase64[T StringConstraint] struct {
	*ZodString[T]
}

ZodBase64 validates Base64 encoded strings. String modifiers (Min, Max, etc.) are promoted from the embedded *ZodString[T].

func Base64 added in v0.3.0

func Base64(params ...any) *ZodBase64[string]

Base64 creates a Base64 encoded string validation schema.

func Base64Ptr added in v0.3.0

func Base64Ptr(params ...any) *ZodBase64[*string]

Base64Ptr creates a pointer Base64 encoded string validation schema.

func (*ZodBase64[T]) Default added in v0.10.5

func (z *ZodBase64[T]) Default(v string) *ZodBase64[T]

Default sets a fallback value returned when input is nil.

func (*ZodBase64[T]) DefaultFunc added in v0.10.5

func (z *ZodBase64[T]) DefaultFunc(fn func() string) *ZodBase64[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodBase64[T]) Describe added in v0.10.5

func (z *ZodBase64[T]) Describe(description string) *ZodBase64[T]

Describe attaches a description to this schema via the global registry.

func (*ZodBase64[T]) Meta added in v0.10.5

func (z *ZodBase64[T]) Meta(meta core.GlobalMeta) *ZodBase64[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodBase64[T]) MustStrictParse added in v0.4.0

func (z *ZodBase64[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodBase64[T]) Nilable added in v0.6.0

func (z *ZodBase64[T]) Nilable() *ZodBase64[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodBase64[T]) Nullish added in v0.6.0

func (z *ZodBase64[T]) Nullish() *ZodBase64[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodBase64[T]) Optional added in v0.6.0

func (z *ZodBase64[T]) Optional() *ZodBase64[*string]

Optional returns a new schema that accepts nil values.

func (*ZodBase64[T]) Prefault added in v0.10.5

func (z *ZodBase64[T]) Prefault(v string) *ZodBase64[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodBase64[T]) PrefaultFunc added in v0.10.5

func (z *ZodBase64[T]) PrefaultFunc(fn func() string) *ZodBase64[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodBase64[T]) RefineAny added in v0.10.5

func (z *ZodBase64[T]) RefineAny(fn func(any) bool, params ...any) *ZodBase64[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodBase64[T]) StrictParse added in v0.4.0

func (z *ZodBase64[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodBase64URL added in v0.3.0

type ZodBase64URL[T StringConstraint] struct {
	*ZodString[T]
}

ZodBase64URL validates Base64URL encoded strings. String modifiers (Min, Max, etc.) are promoted from the embedded *ZodString[T].

func Base64URL added in v0.3.0

func Base64URL(params ...any) *ZodBase64URL[string]

Base64URL creates a Base64URL encoded string validation schema.

func Base64URLPtr added in v0.3.0

func Base64URLPtr(params ...any) *ZodBase64URL[*string]

Base64URLPtr creates a pointer Base64URL encoded string validation schema.

func (*ZodBase64URL[T]) Default added in v0.10.5

func (z *ZodBase64URL[T]) Default(v string) *ZodBase64URL[T]

Default sets a fallback value returned when input is nil.

func (*ZodBase64URL[T]) DefaultFunc added in v0.10.5

func (z *ZodBase64URL[T]) DefaultFunc(fn func() string) *ZodBase64URL[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodBase64URL[T]) Describe added in v0.10.5

func (z *ZodBase64URL[T]) Describe(description string) *ZodBase64URL[T]

Describe attaches a description to this schema via the global registry.

func (*ZodBase64URL[T]) Meta added in v0.10.5

func (z *ZodBase64URL[T]) Meta(meta core.GlobalMeta) *ZodBase64URL[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodBase64URL[T]) MustStrictParse added in v0.4.0

func (z *ZodBase64URL[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodBase64URL[T]) Nilable added in v0.6.0

func (z *ZodBase64URL[T]) Nilable() *ZodBase64URL[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodBase64URL[T]) Nullish added in v0.6.0

func (z *ZodBase64URL[T]) Nullish() *ZodBase64URL[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodBase64URL[T]) Optional added in v0.6.0

func (z *ZodBase64URL[T]) Optional() *ZodBase64URL[*string]

Optional returns a new schema that accepts nil values.

func (*ZodBase64URL[T]) Prefault added in v0.10.5

func (z *ZodBase64URL[T]) Prefault(v string) *ZodBase64URL[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodBase64URL[T]) PrefaultFunc added in v0.10.5

func (z *ZodBase64URL[T]) PrefaultFunc(fn func() string) *ZodBase64URL[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodBase64URL[T]) RefineAny added in v0.10.5

func (z *ZodBase64URL[T]) RefineAny(fn func(any) bool, params ...any) *ZodBase64URL[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodBase64URL[T]) StrictParse added in v0.4.0

func (z *ZodBase64URL[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodBigInt

type ZodBigInt[T BigIntegerConstraint] struct {
	// contains filtered or unexported fields
}

ZodBigInt is a type-safe big.Int validation schema.

func BigInt

func BigInt(params ...any) *ZodBigInt[*big.Int]

BigInt creates a *big.Int validation schema.

func BigIntPtr added in v0.3.0

func BigIntPtr(params ...any) *ZodBigInt[**big.Int]

BigIntPtr creates a **big.Int validation schema.

func BigIntTyped added in v0.3.0

func BigIntTyped[T BigIntegerConstraint](params ...any) *ZodBigInt[T]

BigIntTyped is the generic constructor for big.Int schemas.

func CoercedBigInt added in v0.2.1

func CoercedBigInt(params ...any) *ZodBigInt[*big.Int]

CoercedBigInt creates a coerced *big.Int schema.

func CoercedBigIntPtr added in v0.3.0

func CoercedBigIntPtr(params ...any) *ZodBigInt[**big.Int]

CoercedBigIntPtr creates a coerced **big.Int schema.

func (*ZodBigInt[T]) CloneFrom

func (z *ZodBigInt[T]) CloneFrom(src any)

CloneFrom copies configuration from another schema of the same type.

func (*ZodBigInt[T]) Coerce

func (z *ZodBigInt[T]) Coerce(input any) (any, bool)

Coerce converts input to *big.Int.

func (*ZodBigInt[T]) Default

func (z *ZodBigInt[T]) Default(v *big.Int) *ZodBigInt[T]

Default sets a fallback value returned when input is nil (short-circuits).

func (*ZodBigInt[T]) DefaultFunc

func (z *ZodBigInt[T]) DefaultFunc(fn func() *big.Int) *ZodBigInt[T]

DefaultFunc sets a fallback function called when input is nil (short-circuits).

func (*ZodBigInt[T]) Describe added in v0.5.4

func (z *ZodBigInt[T]) Describe(desc string) *ZodBigInt[T]

Describe registers a description in the global registry.

func (*ZodBigInt[T]) Gt

func (z *ZodBigInt[T]) Gt(n *big.Int, params ...any) *ZodBigInt[T]

Gt adds greater-than validation.

func (*ZodBigInt[T]) Gte

func (z *ZodBigInt[T]) Gte(n *big.Int, params ...any) *ZodBigInt[T]

Gte adds greater-than-or-equal validation.

func (*ZodBigInt[T]) Internals added in v0.6.0

func (z *ZodBigInt[T]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodBigInt[T]) IsNilable added in v0.3.0

func (z *ZodBigInt[T]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodBigInt[T]) IsOptional added in v0.3.0

func (z *ZodBigInt[T]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodBigInt[T]) Lt

func (z *ZodBigInt[T]) Lt(n *big.Int, params ...any) *ZodBigInt[T]

Lt adds less-than validation.

func (*ZodBigInt[T]) Lte

func (z *ZodBigInt[T]) Lte(n *big.Int, params ...any) *ZodBigInt[T]

Lte adds less-than-or-equal validation.

func (*ZodBigInt[T]) Max

func (z *ZodBigInt[T]) Max(n *big.Int, params ...any) *ZodBigInt[T]

Max adds maximum value validation (<=).

func (*ZodBigInt[T]) Meta added in v0.3.1

func (z *ZodBigInt[T]) Meta(meta core.GlobalMeta) *ZodBigInt[T]

Meta stores metadata for this schema in the global registry.

func (*ZodBigInt[T]) Min

func (z *ZodBigInt[T]) Min(n *big.Int, params ...any) *ZodBigInt[T]

Min adds minimum value validation (>=).

func (*ZodBigInt[T]) MultipleOf

func (z *ZodBigInt[T]) MultipleOf(n *big.Int, params ...any) *ZodBigInt[T]

MultipleOf adds multiple-of validation.

func (*ZodBigInt[T]) MustParse

func (z *ZodBigInt[T]) MustParse(input any, ctx ...*core.ParseContext) T

MustParse panics on validation failure.

func (*ZodBigInt[T]) MustStrictParse added in v0.4.0

func (z *ZodBigInt[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse panics on validation failure with compile-time type safety.

func (*ZodBigInt[T]) Negative

func (z *ZodBigInt[T]) Negative(params ...any) *ZodBigInt[T]

Negative adds negative number validation (< 0).

func (*ZodBigInt[T]) Nilable

func (z *ZodBigInt[T]) Nilable() *ZodBigInt[**big.Int]

Nilable returns a schema that accepts nil values with pointer constraint.

func (*ZodBigInt[T]) NonNegative

func (z *ZodBigInt[T]) NonNegative(params ...any) *ZodBigInt[T]

NonNegative adds non-negative number validation (>= 0).

func (*ZodBigInt[T]) NonOptional added in v0.3.0

func (z *ZodBigInt[T]) NonOptional() *ZodBigInt[*big.Int]

NonOptional removes the optional flag, returning a *big.Int constraint.

func (*ZodBigInt[T]) NonPositive

func (z *ZodBigInt[T]) NonPositive(params ...any) *ZodBigInt[T]

NonPositive adds non-positive number validation (<= 0).

func (*ZodBigInt[T]) Nullish

func (z *ZodBigInt[T]) Nullish() *ZodBigInt[**big.Int]

Nullish combines optional and nilable modifiers.

func (*ZodBigInt[T]) Optional

func (z *ZodBigInt[T]) Optional() *ZodBigInt[**big.Int]

Optional returns a schema that accepts nil values with pointer constraint.

func (*ZodBigInt[T]) Overwrite added in v0.3.0

func (z *ZodBigInt[T]) Overwrite(transform func(T) T, params ...any) *ZodBigInt[T]

Overwrite transforms the value while preserving the same type.

func (*ZodBigInt[T]) Parse

func (z *ZodBigInt[T]) Parse(input any, ctx ...*core.ParseContext) (T, error)

Parse validates input and returns a value matching the generic type T.

func (*ZodBigInt[T]) ParseAny added in v0.3.0

func (z *ZodBigInt[T]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodBigInt[T]) Pipe

func (z *ZodBigInt[T]) Pipe(target core.ZodType[any]) *core.ZodPipe[T, any]

Pipe creates a validation pipeline to another schema.

func (*ZodBigInt[T]) Positive

func (z *ZodBigInt[T]) Positive(params ...any) *ZodBigInt[T]

Positive adds positive number validation (> 0).

func (*ZodBigInt[T]) Prefault

func (z *ZodBigInt[T]) Prefault(v *big.Int) *ZodBigInt[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodBigInt[T]) PrefaultFunc

func (z *ZodBigInt[T]) PrefaultFunc(fn func() *big.Int) *ZodBigInt[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodBigInt[T]) Refine

func (z *ZodBigInt[T]) Refine(fn func(T) bool, params ...any) *ZodBigInt[T]

Refine applies a type-safe custom validation function.

func (*ZodBigInt[T]) RefineAny

func (z *ZodBigInt[T]) RefineAny(fn func(any) bool, params ...any) *ZodBigInt[T]

RefineAny applies a custom validation function on the raw value.

func (*ZodBigInt[T]) StrictParse added in v0.4.0

func (z *ZodBigInt[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

func (*ZodBigInt[T]) Transform

func (z *ZodBigInt[T]) Transform(
	fn func(*big.Int, *core.RefinementContext) (any, error),
) *core.ZodTransform[T, any]

Transform creates a type-safe transformation pipeline.

type ZodBigIntDef

type ZodBigIntDef struct {
	core.ZodTypeDef
}

ZodBigIntDef holds the configuration for big.Int validation.

type ZodBigIntInternals

type ZodBigIntInternals struct {
	core.ZodTypeInternals
	Def *ZodBigIntDef
}

ZodBigIntInternals contains the internal state of a big.Int validator.

type ZodBool

type ZodBool[T BoolConstraint] struct {
	// contains filtered or unexported fields
}

ZodBool is a type-safe boolean validation schema.

func Bool

func Bool(params ...any) *ZodBool[bool]

Bool creates a bool validation schema.

func BoolPtr added in v0.3.0

func BoolPtr(params ...any) *ZodBool[*bool]

BoolPtr creates a *bool validation schema.

func BoolTyped added in v0.3.0

func BoolTyped[T BoolConstraint](params ...any) *ZodBool[T]

BoolTyped is the generic constructor for boolean schemas.

func CoercedBool added in v0.2.1

func CoercedBool(args ...any) *ZodBool[bool]

CoercedBool creates a coerced bool schema that converts input.

func CoercedBoolPtr added in v0.3.0

func CoercedBoolPtr(args ...any) *ZodBool[*bool]

CoercedBoolPtr creates a coerced *bool schema that converts input.

func (*ZodBool[T]) And added in v0.5.4

func (z *ZodBool[T]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodBool[T]) Check added in v0.3.0

func (z *ZodBool[T]) Check(fn func(value T, payload *core.ParsePayload), params ...any) *ZodBool[T]

Check adds a custom validation function that can push multiple issues.

func (*ZodBool[T]) CloneFrom

func (z *ZodBool[T]) CloneFrom(source any)

CloneFrom copies configuration from another schema of the same type.

func (*ZodBool[T]) Coerce

func (z *ZodBool[T]) Coerce(input any) (any, bool)

Coerce converts input to bool.

func (*ZodBool[T]) Default

func (z *ZodBool[T]) Default(v bool) *ZodBool[T]

Default sets a fallback value returned when input is nil (short-circuits).

func (*ZodBool[T]) DefaultFunc

func (z *ZodBool[T]) DefaultFunc(fn func() bool) *ZodBool[T]

DefaultFunc sets a fallback function called when input is nil (short-circuits).

func (*ZodBool[T]) Describe added in v0.5.4

func (z *ZodBool[T]) Describe(desc string) *ZodBool[T]

Describe registers a description in the global registry.

func (*ZodBool[T]) ExactOptional added in v0.5.4

func (z *ZodBool[T]) ExactOptional() *ZodBool[T]

ExactOptional accepts absent keys but rejects explicit nil values.

func (*ZodBool[T]) Internals added in v0.6.0

func (z *ZodBool[T]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodBool[T]) IsNilable added in v0.3.0

func (z *ZodBool[T]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodBool[T]) IsOptional added in v0.3.0

func (z *ZodBool[T]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodBool[T]) Meta added in v0.3.1

func (z *ZodBool[T]) Meta(meta core.GlobalMeta) *ZodBool[T]

Meta stores metadata in the global registry.

func (*ZodBool[T]) MustParse

func (z *ZodBool[T]) MustParse(input any, ctx ...*core.ParseContext) T

MustParse panics on validation failure.

func (*ZodBool[T]) MustStrictParse added in v0.4.0

func (z *ZodBool[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse panics on validation failure with compile-time type safety.

func (*ZodBool[T]) Nilable

func (z *ZodBool[T]) Nilable() *ZodBool[*bool]

Nilable returns a schema that accepts nil values with pointer constraint.

func (*ZodBool[T]) NonOptional added in v0.3.0

func (z *ZodBool[T]) NonOptional() *ZodBool[bool]

NonOptional removes the optional flag, returning a bool constraint.

func (*ZodBool[T]) Nullish

func (z *ZodBool[T]) Nullish() *ZodBool[*bool]

Nullish combines optional and nilable modifiers.

func (*ZodBool[T]) Optional

func (z *ZodBool[T]) Optional() *ZodBool[*bool]

Optional returns a schema that accepts nil values with pointer constraint.

func (*ZodBool[T]) Or added in v0.5.4

func (z *ZodBool[T]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodBool[T]) Overwrite added in v0.3.0

func (z *ZodBool[T]) Overwrite(transform func(T) T, params ...any) *ZodBool[T]

Overwrite transforms the input value while preserving the original type.

func (*ZodBool[T]) Parse

func (z *ZodBool[T]) Parse(input any, ctx ...*core.ParseContext) (T, error)

Parse validates input and returns a value matching the generic type T.

func (*ZodBool[T]) ParseAny added in v0.3.0

func (z *ZodBool[T]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodBool[T]) Pipe

func (z *ZodBool[T]) Pipe(target core.ZodType[any]) *core.ZodPipe[T, any]

Pipe creates a validation pipeline with another schema.

func (*ZodBool[T]) Prefault

func (z *ZodBool[T]) Prefault(v bool) *ZodBool[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodBool[T]) PrefaultFunc

func (z *ZodBool[T]) PrefaultFunc(fn func() bool) *ZodBool[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodBool[T]) Refine

func (z *ZodBool[T]) Refine(fn func(T) bool, params ...any) *ZodBool[T]

Refine applies a custom validation function matching the schema's output type T.

func (*ZodBool[T]) RefineAny

func (z *ZodBool[T]) RefineAny(fn func(any) bool, params ...any) *ZodBool[T]

RefineAny applies a custom validation function that receives the raw value.

func (*ZodBool[T]) StrictParse added in v0.4.0

func (z *ZodBool[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

func (*ZodBool[T]) Transform

func (z *ZodBool[T]) Transform(fn func(bool, *core.RefinementContext) (any, error)) *core.ZodTransform[T, any]

Transform applies a transformation function to the parsed value.

func (*ZodBool[T]) With added in v0.5.4

func (z *ZodBool[T]) With(fn func(value T, payload *core.ParsePayload), params ...any) *ZodBool[T]

With is an alias for Check (Zod v4 API compatibility).

type ZodBoolDef

type ZodBoolDef struct {
	core.ZodTypeDef
}

ZodBoolDef holds the configuration for boolean validation.

type ZodBoolInternals

type ZodBoolInternals struct {
	core.ZodTypeInternals
	Def *ZodBoolDef
}

ZodBoolInternals contains the internal state of a boolean validator.

type ZodCIDRv4

type ZodCIDRv4[T StringConstraint] struct{ *ZodString[T] }

ZodCIDRv4 validates strings in CIDRv4 notation format.

func CIDRv4

func CIDRv4(params ...any) *ZodCIDRv4[string]

CIDRv4 creates a CIDRv4 notation validation schema.

func CIDRv4Ptr added in v0.3.0

func CIDRv4Ptr(params ...any) *ZodCIDRv4[*string]

CIDRv4Ptr creates a pointer CIDRv4 notation validation schema.

func CoercedCIDRv4 added in v0.3.0

func CoercedCIDRv4(params ...any) *ZodCIDRv4[string]

CoercedCIDRv4 creates a coerced CIDRv4 schema that attempts string conversion.

func (*ZodCIDRv4[T]) Default

func (z *ZodCIDRv4[T]) Default(v string) *ZodCIDRv4[T]

Default sets a fallback value returned when input is nil.

func (*ZodCIDRv4[T]) DefaultFunc

func (z *ZodCIDRv4[T]) DefaultFunc(fn func() string) *ZodCIDRv4[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodCIDRv4[T]) Describe added in v0.10.5

func (z *ZodCIDRv4[T]) Describe(description string) *ZodCIDRv4[T]

Describe attaches a description to this schema via the global registry.

func (*ZodCIDRv4[T]) Meta added in v0.10.5

func (z *ZodCIDRv4[T]) Meta(meta core.GlobalMeta) *ZodCIDRv4[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodCIDRv4[T]) MustStrictParse added in v0.4.0

func (z *ZodCIDRv4[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodCIDRv4[T]) Nilable

func (z *ZodCIDRv4[T]) Nilable() *ZodCIDRv4[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodCIDRv4[T]) Nullish added in v0.3.0

func (z *ZodCIDRv4[T]) Nullish() *ZodCIDRv4[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodCIDRv4[T]) Optional

func (z *ZodCIDRv4[T]) Optional() *ZodCIDRv4[*string]

Optional returns a new schema that accepts nil values.

func (*ZodCIDRv4[T]) Prefault

func (z *ZodCIDRv4[T]) Prefault(v string) *ZodCIDRv4[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodCIDRv4[T]) PrefaultFunc

func (z *ZodCIDRv4[T]) PrefaultFunc(fn func() string) *ZodCIDRv4[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodCIDRv4[T]) RefineAny

func (z *ZodCIDRv4[T]) RefineAny(fn func(any) bool, params ...any) *ZodCIDRv4[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodCIDRv4[T]) StrictParse added in v0.4.0

func (z *ZodCIDRv4[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodCIDRv6

type ZodCIDRv6[T StringConstraint] struct{ *ZodString[T] }

ZodCIDRv6 validates strings in CIDRv6 notation format.

func CIDRv6

func CIDRv6(params ...any) *ZodCIDRv6[string]

CIDRv6 creates a CIDRv6 notation validation schema.

func CIDRv6Ptr added in v0.3.0

func CIDRv6Ptr(params ...any) *ZodCIDRv6[*string]

CIDRv6Ptr creates a pointer CIDRv6 notation validation schema.

func CoercedCIDRv6 added in v0.3.0

func CoercedCIDRv6(params ...any) *ZodCIDRv6[string]

CoercedCIDRv6 creates a coerced CIDRv6 schema that attempts string conversion.

func (*ZodCIDRv6[T]) Default

func (z *ZodCIDRv6[T]) Default(v string) *ZodCIDRv6[T]

Default sets a fallback value returned when input is nil.

func (*ZodCIDRv6[T]) DefaultFunc

func (z *ZodCIDRv6[T]) DefaultFunc(fn func() string) *ZodCIDRv6[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodCIDRv6[T]) Describe added in v0.10.5

func (z *ZodCIDRv6[T]) Describe(description string) *ZodCIDRv6[T]

Describe attaches a description to this schema via the global registry.

func (*ZodCIDRv6[T]) Meta added in v0.10.5

func (z *ZodCIDRv6[T]) Meta(meta core.GlobalMeta) *ZodCIDRv6[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodCIDRv6[T]) MustStrictParse added in v0.4.0

func (z *ZodCIDRv6[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodCIDRv6[T]) Nilable

func (z *ZodCIDRv6[T]) Nilable() *ZodCIDRv6[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodCIDRv6[T]) Nullish added in v0.3.0

func (z *ZodCIDRv6[T]) Nullish() *ZodCIDRv6[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodCIDRv6[T]) Optional

func (z *ZodCIDRv6[T]) Optional() *ZodCIDRv6[*string]

Optional returns a new schema that accepts nil values.

func (*ZodCIDRv6[T]) Prefault added in v0.3.0

func (z *ZodCIDRv6[T]) Prefault(v string) *ZodCIDRv6[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodCIDRv6[T]) PrefaultFunc added in v0.3.0

func (z *ZodCIDRv6[T]) PrefaultFunc(fn func() string) *ZodCIDRv6[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodCIDRv6[T]) RefineAny

func (z *ZodCIDRv6[T]) RefineAny(fn func(any) bool, params ...any) *ZodCIDRv6[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodCIDRv6[T]) StrictParse added in v0.4.0

func (z *ZodCIDRv6[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodCUID added in v0.3.0

type ZodCUID[T StringConstraint] struct{ *ZodString[T] }

ZodCUID validates strings in CUID format.

func CUID added in v0.7.0

func CUID(params ...any) *ZodCUID[string]

CUID creates a CUID schema for collision-resistant unique identifiers.

func CUIDPtr added in v0.7.0

func CUIDPtr(params ...any) *ZodCUID[*string]

CUIDPtr creates a pointer CUID schema.

func (*ZodCUID[T]) Default added in v0.10.5

func (z *ZodCUID[T]) Default(v string) *ZodCUID[T]

Default sets a fallback value returned when input is nil.

func (*ZodCUID[T]) DefaultFunc added in v0.10.5

func (z *ZodCUID[T]) DefaultFunc(fn func() string) *ZodCUID[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodCUID[T]) Describe added in v0.10.5

func (z *ZodCUID[T]) Describe(description string) *ZodCUID[T]

Describe attaches a description to this schema via the global registry.

func (*ZodCUID[T]) Meta added in v0.10.5

func (z *ZodCUID[T]) Meta(meta core.GlobalMeta) *ZodCUID[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodCUID[T]) MustStrictParse added in v0.4.0

func (z *ZodCUID[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodCUID[T]) Nilable added in v0.6.0

func (z *ZodCUID[T]) Nilable() *ZodCUID[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodCUID[T]) Nullish added in v0.6.0

func (z *ZodCUID[T]) Nullish() *ZodCUID[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodCUID[T]) Optional added in v0.6.0

func (z *ZodCUID[T]) Optional() *ZodCUID[*string]

Optional returns a new schema that accepts nil values.

func (*ZodCUID[T]) Prefault added in v0.10.5

func (z *ZodCUID[T]) Prefault(v string) *ZodCUID[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodCUID[T]) PrefaultFunc added in v0.10.5

func (z *ZodCUID[T]) PrefaultFunc(fn func() string) *ZodCUID[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodCUID[T]) RefineAny added in v0.10.5

func (z *ZodCUID[T]) RefineAny(fn func(any) bool, params ...any) *ZodCUID[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodCUID[T]) StrictParse added in v0.4.0

func (z *ZodCUID[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodCUID2 added in v0.3.0

type ZodCUID2[T StringConstraint] struct{ *ZodString[T] }

ZodCUID2 validates strings in CUID2 format.

func CUID2 added in v0.7.0

func CUID2(params ...any) *ZodCUID2[string]

CUID2 creates a CUID2 schema for next-generation collision-resistant identifiers.

func CUID2Ptr added in v0.7.0

func CUID2Ptr(params ...any) *ZodCUID2[*string]

CUID2Ptr creates a pointer CUID2 schema.

func (*ZodCUID2[T]) Default added in v0.10.5

func (z *ZodCUID2[T]) Default(v string) *ZodCUID2[T]

Default sets a fallback value returned when input is nil.

func (*ZodCUID2[T]) DefaultFunc added in v0.10.5

func (z *ZodCUID2[T]) DefaultFunc(fn func() string) *ZodCUID2[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodCUID2[T]) Describe added in v0.10.5

func (z *ZodCUID2[T]) Describe(description string) *ZodCUID2[T]

Describe attaches a description to this schema via the global registry.

func (*ZodCUID2[T]) Meta added in v0.10.5

func (z *ZodCUID2[T]) Meta(meta core.GlobalMeta) *ZodCUID2[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodCUID2[T]) MustStrictParse added in v0.4.0

func (z *ZodCUID2[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodCUID2[T]) Nilable added in v0.6.0

func (z *ZodCUID2[T]) Nilable() *ZodCUID2[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodCUID2[T]) Nullish added in v0.6.0

func (z *ZodCUID2[T]) Nullish() *ZodCUID2[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodCUID2[T]) Optional added in v0.6.0

func (z *ZodCUID2[T]) Optional() *ZodCUID2[*string]

Optional returns a new schema that accepts nil values.

func (*ZodCUID2[T]) Prefault added in v0.10.5

func (z *ZodCUID2[T]) Prefault(v string) *ZodCUID2[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodCUID2[T]) PrefaultFunc added in v0.10.5

func (z *ZodCUID2[T]) PrefaultFunc(fn func() string) *ZodCUID2[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodCUID2[T]) RefineAny added in v0.10.5

func (z *ZodCUID2[T]) RefineAny(fn func(any) bool, params ...any) *ZodCUID2[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodCUID2[T]) StrictParse added in v0.4.0

func (z *ZodCUID2[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodComplex

type ZodComplex[T ComplexConstraint] struct {
	// contains filtered or unexported fields
}

ZodComplex is a type-safe complex number validation schema.

func CoercedComplex added in v0.3.0

func CoercedComplex(params ...any) *ZodComplex[complex128]

CoercedComplex creates a coerced complex128 schema (default alias).

func CoercedComplex64 added in v0.2.1

func CoercedComplex64(params ...any) *ZodComplex[complex64]

CoercedComplex64 creates a coerced complex64 schema.

func CoercedComplex64Ptr added in v0.3.0

func CoercedComplex64Ptr(params ...any) *ZodComplex[*complex64]

CoercedComplex64Ptr creates a coerced *complex64 schema.

func CoercedComplex128 added in v0.2.1

func CoercedComplex128(params ...any) *ZodComplex[complex128]

CoercedComplex128 creates a coerced complex128 schema.

func CoercedComplex128Ptr added in v0.3.0

func CoercedComplex128Ptr(params ...any) *ZodComplex[*complex128]

CoercedComplex128Ptr creates a coerced *complex128 schema.

func CoercedComplexPtr added in v0.3.0

func CoercedComplexPtr(params ...any) *ZodComplex[*complex128]

CoercedComplexPtr creates a coerced *complex128 schema (default alias).

func Complex

func Complex(params ...any) *ZodComplex[complex128]

Complex creates a complex128 schema (default alias).

func Complex64

func Complex64(params ...any) *ZodComplex[complex64]

Complex64 creates a complex64 schema.

func Complex64Ptr added in v0.3.0

func Complex64Ptr(params ...any) *ZodComplex[*complex64]

Complex64Ptr creates a *complex64 schema.

func Complex128

func Complex128(params ...any) *ZodComplex[complex128]

Complex128 creates a complex128 schema.

func Complex128Ptr added in v0.3.0

func Complex128Ptr(params ...any) *ZodComplex[*complex128]

Complex128Ptr creates a *complex128 schema.

func ComplexPtr added in v0.3.0

func ComplexPtr(params ...any) *ZodComplex[*complex128]

ComplexPtr creates a *complex128 schema (default alias).

func ComplexTyped added in v0.3.0

func ComplexTyped[T ComplexConstraint](params ...any) *ZodComplex[T]

ComplexTyped creates a generic complex schema with automatic type inference.

func (*ZodComplex[T]) And added in v0.6.0

func (z *ZodComplex[T]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodComplex[T]) CloneFrom

func (z *ZodComplex[T]) CloneFrom(source any)

CloneFrom copies configuration from another schema of the same type.

func (*ZodComplex[T]) Coerce

func (z *ZodComplex[T]) Coerce(input any) (any, bool)

Coerce converts input to the target complex type.

func (*ZodComplex[T]) Default

func (z *ZodComplex[T]) Default(v complex128) *ZodComplex[T]

Default sets a fallback value returned when input is nil (short-circuits).

func (*ZodComplex[T]) DefaultFunc

func (z *ZodComplex[T]) DefaultFunc(fn func() complex128) *ZodComplex[T]

DefaultFunc sets a fallback function called when input is nil (short-circuits).

func (*ZodComplex[T]) Describe added in v0.5.4

func (z *ZodComplex[T]) Describe(desc string) *ZodComplex[T]

Describe registers a description in the global registry.

func (*ZodComplex[T]) ExactOptional added in v0.6.0

func (z *ZodComplex[T]) ExactOptional() *ZodComplex[T]

ExactOptional accepts absent keys but rejects explicit nil values.

func (*ZodComplex[T]) Finite added in v0.3.0

func (z *ZodComplex[T]) Finite(params ...any) *ZodComplex[T]

Finite validates that both real and imaginary parts are finite.

func (*ZodComplex[T]) Gt

func (z *ZodComplex[T]) Gt(value float64, params ...any) *ZodComplex[T]

Gt adds greater-than magnitude validation (exclusive).

func (*ZodComplex[T]) Gte

func (z *ZodComplex[T]) Gte(value float64, params ...any) *ZodComplex[T]

Gte adds greater-than-or-equal magnitude validation (inclusive).

func (*ZodComplex[T]) Internals added in v0.6.0

func (z *ZodComplex[T]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodComplex[T]) IsNilable added in v0.3.0

func (z *ZodComplex[T]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodComplex[T]) IsOptional added in v0.3.0

func (z *ZodComplex[T]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodComplex[T]) Lt

func (z *ZodComplex[T]) Lt(value float64, params ...any) *ZodComplex[T]

Lt adds less-than magnitude validation (exclusive).

func (*ZodComplex[T]) Lte

func (z *ZodComplex[T]) Lte(value float64, params ...any) *ZodComplex[T]

Lte adds less-than-or-equal magnitude validation (inclusive).

func (*ZodComplex[T]) Max

func (z *ZodComplex[T]) Max(maximum float64, params ...any) *ZodComplex[T]

Max adds maximum magnitude validation.

func (*ZodComplex[T]) Meta added in v0.3.1

func (z *ZodComplex[T]) Meta(meta core.GlobalMeta) *ZodComplex[T]

Meta stores metadata in the global registry.

func (*ZodComplex[T]) Min

func (z *ZodComplex[T]) Min(minimum float64, params ...any) *ZodComplex[T]

Min adds minimum magnitude validation.

func (*ZodComplex[T]) MustParse

func (z *ZodComplex[T]) MustParse(input any, ctx ...*core.ParseContext) T

MustParse panics on validation failure.

func (*ZodComplex[T]) MustStrictParse added in v0.4.0

func (z *ZodComplex[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse panics on validation failure with compile-time type safety.

func (*ZodComplex[T]) Negative

func (z *ZodComplex[T]) Negative(params ...any) *ZodComplex[T]

Negative adds negative validation (< 0) for complex magnitude.

func (*ZodComplex[T]) Nilable

func (z *ZodComplex[T]) Nilable() *ZodComplex[*complex128]

Nilable returns a schema that accepts nil values with pointer constraint.

func (*ZodComplex[T]) NonNegative

func (z *ZodComplex[T]) NonNegative(params ...any) *ZodComplex[T]

NonNegative adds non-negative validation (>= 0) for complex magnitude.

func (*ZodComplex[T]) NonPositive

func (z *ZodComplex[T]) NonPositive(params ...any) *ZodComplex[T]

NonPositive adds non-positive validation (<= 0) for complex magnitude.

func (*ZodComplex[T]) Nullish

func (z *ZodComplex[T]) Nullish() *ZodComplex[*complex128]

Nullish combines optional and nilable modifiers.

func (*ZodComplex[T]) Optional

func (z *ZodComplex[T]) Optional() *ZodComplex[*complex128]

Optional returns a schema that accepts nil values with pointer constraint.

func (*ZodComplex[T]) Or added in v0.6.0

func (z *ZodComplex[T]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodComplex[T]) Overwrite added in v0.3.0

func (z *ZodComplex[T]) Overwrite(transform func(T) T, params ...any) *ZodComplex[T]

Overwrite transforms the input value while preserving the original type.

func (*ZodComplex[T]) Parse

func (z *ZodComplex[T]) Parse(input any, ctx ...*core.ParseContext) (T, error)

Parse validates input and returns a value matching the generic type T.

func (*ZodComplex[T]) ParseAny added in v0.3.0

func (z *ZodComplex[T]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodComplex[T]) Pipe

func (z *ZodComplex[T]) Pipe(target core.ZodType[any]) *core.ZodPipe[T, any]

Pipe creates a validation pipeline with another schema.

func (*ZodComplex[T]) Positive

func (z *ZodComplex[T]) Positive(params ...any) *ZodComplex[T]

Positive adds positive magnitude validation (> 0).

func (*ZodComplex[T]) Prefault

func (z *ZodComplex[T]) Prefault(v complex128) *ZodComplex[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodComplex[T]) PrefaultFunc

func (z *ZodComplex[T]) PrefaultFunc(fn func() complex128) *ZodComplex[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodComplex[T]) Refine

func (z *ZodComplex[T]) Refine(fn func(T) bool, params ...any) *ZodComplex[T]

Refine applies a custom validation function matching the schema's output type T.

func (*ZodComplex[T]) RefineAny

func (z *ZodComplex[T]) RefineAny(fn func(any) bool, params ...any) *ZodComplex[T]

RefineAny applies a custom validation function that receives the raw value.

func (*ZodComplex[T]) StrictParse added in v0.4.0

func (z *ZodComplex[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

func (*ZodComplex[T]) Transform

func (z *ZodComplex[T]) Transform(fn func(complex128, *core.RefinementContext) (any, error)) *core.ZodTransform[T, any]

Transform applies a transformation function to the parsed value.

type ZodComplexDef

type ZodComplexDef struct {
	core.ZodTypeDef
}

ZodComplexDef holds the configuration for complex number validation.

type ZodComplexInternals

type ZodComplexInternals struct {
	core.ZodTypeInternals
	Def *ZodComplexDef
}

ZodComplexInternals contains the internal state of a complex validator.

type ZodDiscriminatedUnion

type ZodDiscriminatedUnion[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodDiscriminatedUnion is a type-safe discriminated union validation schema.

func DiscriminatedUnion

func DiscriminatedUnion(disc string, options []any, args ...any) *ZodDiscriminatedUnion[any, any]

DiscriminatedUnion creates a discriminated union schema with value constraint.

func DiscriminatedUnionPtr added in v0.3.0

func DiscriminatedUnionPtr(disc string, options []any, args ...any) *ZodDiscriminatedUnion[any, *any]

DiscriminatedUnionPtr creates a discriminated union schema with pointer constraint.

func DiscriminatedUnionTyped added in v0.3.0

func DiscriminatedUnionTyped[T any, R any](disc string, options []any, args ...any) *ZodDiscriminatedUnion[T, R]

DiscriminatedUnionTyped creates a typed discriminated union schema.

func (*ZodDiscriminatedUnion[T, R]) CloneFrom

func (z *ZodDiscriminatedUnion[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema of the same type.

func (*ZodDiscriminatedUnion[T, R]) Default

func (z *ZodDiscriminatedUnion[T, R]) Default(v T) *ZodDiscriminatedUnion[T, R]

Default sets a fallback value returned when input is nil (short-circuits).

func (*ZodDiscriminatedUnion[T, R]) DefaultFunc

func (z *ZodDiscriminatedUnion[T, R]) DefaultFunc(fn func() T) *ZodDiscriminatedUnion[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits).

func (*ZodDiscriminatedUnion[T, R]) Describe added in v0.5.4

func (z *ZodDiscriminatedUnion[T, R]) Describe(desc string) *ZodDiscriminatedUnion[T, R]

Describe registers a description in the global registry.

func (*ZodDiscriminatedUnion[T, R]) Discriminator

func (z *ZodDiscriminatedUnion[T, R]) Discriminator() string

Discriminator returns the discriminator field name.

func (*ZodDiscriminatedUnion[T, R]) DiscriminatorMap added in v0.3.0

func (z *ZodDiscriminatedUnion[T, R]) DiscriminatorMap() map[any]core.ZodSchema

DiscriminatorMap returns a copy of the discriminator-to-schema mapping.

func (*ZodDiscriminatedUnion[T, R]) Internals added in v0.6.0

func (z *ZodDiscriminatedUnion[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodDiscriminatedUnion[T, R]) IsNilable added in v0.3.0

func (z *ZodDiscriminatedUnion[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodDiscriminatedUnion[T, R]) IsOptional added in v0.3.0

func (z *ZodDiscriminatedUnion[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodDiscriminatedUnion[T, R]) Meta added in v0.3.1

func (z *ZodDiscriminatedUnion[T, R]) Meta(meta core.GlobalMeta) *ZodDiscriminatedUnion[T, R]

Meta stores metadata in the global registry.

func (*ZodDiscriminatedUnion[T, R]) MustParse

func (z *ZodDiscriminatedUnion[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse panics on validation failure.

func (*ZodDiscriminatedUnion[T, R]) MustStrictParse added in v0.4.0

func (z *ZodDiscriminatedUnion[T, R]) MustStrictParse(input T, ctx ...*core.ParseContext) R

MustStrictParse panics on validation failure with compile-time type safety.

func (*ZodDiscriminatedUnion[T, R]) Nilable

func (z *ZodDiscriminatedUnion[T, R]) Nilable() *ZodDiscriminatedUnion[T, *T]

Nilable returns a schema that accepts nil values with pointer constraint.

func (*ZodDiscriminatedUnion[T, R]) Nullish added in v0.3.0

func (z *ZodDiscriminatedUnion[T, R]) Nullish() *ZodDiscriminatedUnion[T, *T]

Nullish combines optional and nilable modifiers.

func (*ZodDiscriminatedUnion[T, R]) Optional

func (z *ZodDiscriminatedUnion[T, R]) Optional() *ZodDiscriminatedUnion[T, *T]

Optional returns a schema that accepts nil values with pointer constraint.

func (*ZodDiscriminatedUnion[T, R]) Options

func (z *ZodDiscriminatedUnion[T, R]) Options() []core.ZodSchema

Options returns a copy of all union member schemas.

func (*ZodDiscriminatedUnion[T, R]) Parse

func (z *ZodDiscriminatedUnion[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input and returns a value matching the constraint type R.

func (*ZodDiscriminatedUnion[T, R]) ParseAny added in v0.3.0

func (z *ZodDiscriminatedUnion[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodDiscriminatedUnion[T, R]) Pipe

func (z *ZodDiscriminatedUnion[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a validation pipeline with another schema.

func (*ZodDiscriminatedUnion[T, R]) Prefault

func (z *ZodDiscriminatedUnion[T, R]) Prefault(v T) *ZodDiscriminatedUnion[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodDiscriminatedUnion[T, R]) PrefaultFunc

func (z *ZodDiscriminatedUnion[T, R]) PrefaultFunc(fn func() T) *ZodDiscriminatedUnion[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodDiscriminatedUnion[T, R]) Refine

func (z *ZodDiscriminatedUnion[T, R]) Refine(fn func(R) bool, params ...any) *ZodDiscriminatedUnion[T, R]

Refine applies a custom validation function matching the schema's output type R.

func (*ZodDiscriminatedUnion[T, R]) RefineAny

func (z *ZodDiscriminatedUnion[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodDiscriminatedUnion[T, R]

RefineAny applies a custom validation function that receives the raw value.

func (*ZodDiscriminatedUnion[T, R]) StrictParse added in v0.4.0

func (z *ZodDiscriminatedUnion[T, R]) StrictParse(input T, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodDiscriminatedUnion[T, R]) Transform

func (z *ZodDiscriminatedUnion[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed value.

type ZodDiscriminatedUnionDef

type ZodDiscriminatedUnionDef struct {
	core.ZodTypeDef
	Discriminator string
	Options       []core.ZodSchema
}

ZodDiscriminatedUnionDef holds the configuration for discriminated union validation.

type ZodDiscriminatedUnionInternals

type ZodDiscriminatedUnionInternals struct {
	core.ZodTypeInternals
	Def           *ZodDiscriminatedUnionDef
	Discriminator string
	Options       []core.ZodSchema
	DiscMap       map[any]core.ZodSchema
}

ZodDiscriminatedUnionInternals contains the internal state of a discriminated union validator.

type ZodE164 added in v0.5.4

type ZodE164[T StringConstraint] struct{ *ZodString[T] }

ZodE164 validates strings in E.164 phone number format.

func CoercedE164 added in v0.6.0

func CoercedE164(params ...any) *ZodE164[string]

CoercedE164 creates a coerced E164 schema that attempts string conversion.

func E164 added in v0.5.4

func E164(params ...any) *ZodE164[string]

E164 creates an E.164 phone number validation schema.

func E164Ptr added in v0.5.4

func E164Ptr(params ...any) *ZodE164[*string]

E164Ptr creates a pointer E.164 phone number validation schema.

func (*ZodE164[T]) Default added in v0.5.4

func (z *ZodE164[T]) Default(v string) *ZodE164[T]

Default sets a fallback value returned when input is nil.

func (*ZodE164[T]) DefaultFunc added in v0.10.5

func (z *ZodE164[T]) DefaultFunc(fn func() string) *ZodE164[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodE164[T]) Describe added in v0.5.4

func (z *ZodE164[T]) Describe(description string) *ZodE164[T]

Describe attaches a description to this schema via the global registry.

func (*ZodE164[T]) Meta added in v0.10.5

func (z *ZodE164[T]) Meta(meta core.GlobalMeta) *ZodE164[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodE164[T]) MustStrictParse added in v0.5.4

func (z *ZodE164[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodE164[T]) Nilable added in v0.5.4

func (z *ZodE164[T]) Nilable() *ZodE164[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodE164[T]) Nullish added in v0.6.0

func (z *ZodE164[T]) Nullish() *ZodE164[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodE164[T]) Optional added in v0.5.4

func (z *ZodE164[T]) Optional() *ZodE164[*string]

Optional returns a new schema that accepts nil values.

func (*ZodE164[T]) Prefault added in v0.10.5

func (z *ZodE164[T]) Prefault(v string) *ZodE164[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodE164[T]) PrefaultFunc added in v0.10.5

func (z *ZodE164[T]) PrefaultFunc(fn func() string) *ZodE164[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodE164[T]) RefineAny added in v0.5.7

func (z *ZodE164[T]) RefineAny(fn func(any) bool, params ...any) *ZodE164[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodE164[T]) StrictParse added in v0.5.4

func (z *ZodE164[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodEmail added in v0.3.0

type ZodEmail[T EmailConstraint] struct {
	*ZodString[T]
}

ZodEmail validates strings as email addresses. String modifiers (Min, Max, Regex, etc.) and Pipe/Transform are promoted from the embedded *ZodString[T].

func Email added in v0.3.0

func Email(params ...any) *ZodEmail[string]

Email creates a string email validation schema.

func EmailPtr added in v0.3.0

func EmailPtr(params ...any) *ZodEmail[*string]

EmailPtr creates a *string email validation schema.

func EmailTyped added in v0.3.0

func EmailTyped[T EmailConstraint](params ...any) *ZodEmail[T]

EmailTyped creates an email validation schema with the given type constraint.

func (*ZodEmail[T]) Browser added in v0.3.0

func (z *ZodEmail[T]) Browser(params ...any) *ZodEmail[T]

Browser switches to the browser-compatible email pattern.

func (*ZodEmail[T]) Default added in v0.10.5

func (z *ZodEmail[T]) Default(v string) *ZodEmail[T]

Default sets a fallback value returned when input is nil.

func (*ZodEmail[T]) DefaultFunc added in v0.10.5

func (z *ZodEmail[T]) DefaultFunc(fn func() string) *ZodEmail[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodEmail[T]) Describe added in v0.10.5

func (z *ZodEmail[T]) Describe(description string) *ZodEmail[T]

Describe attaches a description to this schema via the global registry.

func (*ZodEmail[T]) HTML5 added in v0.6.0

func (z *ZodEmail[T]) HTML5(params ...any) *ZodEmail[T]

HTML5 switches to the HTML5 email pattern.

func (*ZodEmail[T]) Meta added in v0.10.5

func (z *ZodEmail[T]) Meta(meta core.GlobalMeta) *ZodEmail[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodEmail[T]) MustStrictParse added in v0.4.0

func (z *ZodEmail[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodEmail[T]) Nilable added in v0.3.0

func (z *ZodEmail[T]) Nilable() *ZodEmail[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodEmail[T]) Nullish added in v0.3.0

func (z *ZodEmail[T]) Nullish() *ZodEmail[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodEmail[T]) Optional added in v0.3.0

func (z *ZodEmail[T]) Optional() *ZodEmail[*string]

Optional returns a new schema that accepts nil values.

func (*ZodEmail[T]) Prefault added in v0.10.5

func (z *ZodEmail[T]) Prefault(v string) *ZodEmail[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodEmail[T]) PrefaultFunc added in v0.10.5

func (z *ZodEmail[T]) PrefaultFunc(fn func() string) *ZodEmail[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodEmail[T]) RFC5322 added in v0.6.0

func (z *ZodEmail[T]) RFC5322(params ...any) *ZodEmail[T]

RFC5322 switches to the RFC 5322 email pattern.

func (*ZodEmail[T]) RefineAny added in v0.10.5

func (z *ZodEmail[T]) RefineAny(fn func(any) bool, params ...any) *ZodEmail[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodEmail[T]) StrictParse added in v0.4.0

func (z *ZodEmail[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

func (*ZodEmail[T]) Unicode added in v0.3.0

func (z *ZodEmail[T]) Unicode(params ...any) *ZodEmail[T]

Unicode switches to the Unicode-aware email pattern.

type ZodEmoji added in v0.3.0

type ZodEmoji[T StringConstraint] struct {
	*ZodString[T]
}

ZodEmoji validates strings containing only emoji characters. String modifiers (Min, Max, Regex, etc.) are promoted from the embedded *ZodString[T].

func Emoji added in v0.3.0

func Emoji(params ...any) *ZodEmoji[string]

Emoji creates an emoji validation schema.

func EmojiPtr added in v0.3.0

func EmojiPtr(params ...any) *ZodEmoji[*string]

EmojiPtr creates a pointer emoji validation schema.

func (*ZodEmoji[T]) Default added in v0.10.5

func (z *ZodEmoji[T]) Default(v string) *ZodEmoji[T]

Default sets a fallback value returned when input is nil.

func (*ZodEmoji[T]) DefaultFunc added in v0.10.5

func (z *ZodEmoji[T]) DefaultFunc(fn func() string) *ZodEmoji[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodEmoji[T]) Describe added in v0.10.5

func (z *ZodEmoji[T]) Describe(description string) *ZodEmoji[T]

Describe attaches a description to this schema via the global registry.

func (*ZodEmoji[T]) Meta added in v0.10.5

func (z *ZodEmoji[T]) Meta(meta core.GlobalMeta) *ZodEmoji[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodEmoji[T]) MustStrictParse added in v0.4.0

func (z *ZodEmoji[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodEmoji[T]) Nilable added in v0.6.0

func (z *ZodEmoji[T]) Nilable() *ZodEmoji[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodEmoji[T]) Nullish added in v0.6.0

func (z *ZodEmoji[T]) Nullish() *ZodEmoji[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodEmoji[T]) Optional added in v0.6.0

func (z *ZodEmoji[T]) Optional() *ZodEmoji[*string]

Optional returns a new schema that accepts nil values.

func (*ZodEmoji[T]) Prefault added in v0.10.5

func (z *ZodEmoji[T]) Prefault(v string) *ZodEmoji[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodEmoji[T]) PrefaultFunc added in v0.10.5

func (z *ZodEmoji[T]) PrefaultFunc(fn func() string) *ZodEmoji[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodEmoji[T]) RefineAny added in v0.10.5

func (z *ZodEmoji[T]) RefineAny(fn func(any) bool, params ...any) *ZodEmoji[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodEmoji[T]) StrictParse added in v0.4.0

func (z *ZodEmoji[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodEnum

type ZodEnum[T comparable, R any] struct {
	// contains filtered or unexported fields
}

ZodEnum represents a type-safe enum validation schema. The type parameter T is the base comparable type, and R is the constraint type (either T or *T).

func Enum

func Enum[T comparable](values ...T) *ZodEnum[T, T]

Enum creates an enum schema from the provided values with automatic type inference.

func EnumMap

func EnumMap[T comparable](entries map[string]T, params ...any) *ZodEnum[T, T]

EnumMap creates an enum schema from a key-value mapping.

func EnumMapPtr added in v0.3.0

func EnumMapPtr[T comparable](entries map[string]T, params ...any) *ZodEnum[T, *T]

EnumMapPtr creates a pointer-capable enum schema from a key-value mapping.

func EnumMapTyped added in v0.3.0

func EnumMapTyped[T comparable, R any](entries map[string]T, args ...any) *ZodEnum[T, R]

EnumMapTyped is the generic constructor for enum schemas.

func EnumPtr added in v0.3.0

func EnumPtr[T comparable](values ...T) *ZodEnum[T, *T]

EnumPtr creates a pointer-capable enum schema from values.

func EnumSlice

func EnumSlice[T comparable](values []T) *ZodEnum[T, T]

EnumSlice creates an enum schema from a slice of values.

func EnumSlicePtr added in v0.3.0

func EnumSlicePtr[T comparable](values []T) *ZodEnum[T, *T]

EnumSlicePtr creates a pointer-capable enum schema from a slice of values.

func (*ZodEnum[T, R]) And added in v0.6.0

func (z *ZodEnum[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodEnum[T, R]) Check added in v0.6.0

func (z *ZodEnum[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodEnum[T, R]

Check adds a custom validation function that can push multiple issues.

func (*ZodEnum[T, R]) CloneFrom added in v0.3.0

func (z *ZodEnum[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema while preserving the original checks.

func (*ZodEnum[T, R]) Default

func (z *ZodEnum[T, R]) Default(v T) *ZodEnum[T, R]

Default sets a fallback value returned when input is nil. This short-circuits validation and returns the default value immediately.

func (*ZodEnum[T, R]) DefaultFunc

func (z *ZodEnum[T, R]) DefaultFunc(fn func() T) *ZodEnum[T, R]

DefaultFunc sets a fallback function called when input is nil. This short-circuits validation and returns the default value immediately.

func (*ZodEnum[T, R]) Describe added in v0.5.4

func (z *ZodEnum[T, R]) Describe(desc string) *ZodEnum[T, R]

Describe registers a description in the global registry.

func (*ZodEnum[T, R]) Enum

func (z *ZodEnum[T, R]) Enum() map[string]T

Enum returns a copy of the enum key-value mapping.

func (*ZodEnum[T, R]) ExactOptional added in v0.6.0

func (z *ZodEnum[T, R]) ExactOptional() *ZodEnum[T, R]

ExactOptional returns a schema that accepts absent keys but rejects explicit nil values. Unlike Optional, ExactOptional only accepts absent keys in object fields.

func (*ZodEnum[T, R]) Exclude

func (z *ZodEnum[T, R]) Exclude(keys []string, params ...any) *ZodEnum[T, R]

Exclude creates a sub-enum without the specified keys. Non-existent keys are silently ignored.

func (*ZodEnum[T, R]) Extract

func (z *ZodEnum[T, R]) Extract(keys []string, params ...any) *ZodEnum[T, R]

Extract creates a sub-enum containing only the specified keys. Non-existent keys are silently ignored.

func (*ZodEnum[T, R]) Internals added in v0.6.0

func (z *ZodEnum[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodEnum[T, R]) IsNilable added in v0.3.0

func (z *ZodEnum[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodEnum[T, R]) IsOptional added in v0.3.0

func (z *ZodEnum[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodEnum[T, R]) Meta added in v0.3.1

func (z *ZodEnum[T, R]) Meta(meta core.GlobalMeta) *ZodEnum[T, R]

Meta stores metadata for this enum schema in the global registry.

func (*ZodEnum[T, R]) MustParse

func (z *ZodEnum[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates input and panics on failure.

func (*ZodEnum[T, R]) MustStrictParse added in v0.4.0

func (z *ZodEnum[T, R]) MustStrictParse(input R, ctx ...*core.ParseContext) R

MustStrictParse provides compile-time type safety and panics on failure.

func (*ZodEnum[T, R]) Nilable

func (z *ZodEnum[T, R]) Nilable() *ZodEnum[T, *T]

Nilable returns a new schema that accepts nil values, with *T constraint.

func (*ZodEnum[T, R]) NonOptional added in v0.6.0

func (z *ZodEnum[T, R]) NonOptional() *ZodEnum[T, T]

NonOptional removes the optional flag, returning a T constraint.

func (*ZodEnum[T, R]) Nullish

func (z *ZodEnum[T, R]) Nullish() *ZodEnum[T, *T]

Nullish returns a new schema combining optional and nilable modifiers.

func (*ZodEnum[T, R]) Optional

func (z *ZodEnum[T, R]) Optional() *ZodEnum[T, *T]

Optional returns a new schema that accepts nil, with *T constraint.

func (*ZodEnum[T, R]) Options

func (z *ZodEnum[T, R]) Options() []T

Options returns all possible enum values.

func (*ZodEnum[T, R]) Or added in v0.6.0

func (z *ZodEnum[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodEnum[T, R]) Parse

func (z *ZodEnum[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input and returns a value matching the generic type R.

func (*ZodEnum[T, R]) ParseAny added in v0.3.0

func (z *ZodEnum[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns any type for runtime interface usage.

func (*ZodEnum[T, R]) Pipe

func (z *ZodEnum[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a validation pipeline to a target schema.

func (*ZodEnum[T, R]) Prefault

func (z *ZodEnum[T, R]) Prefault(v T) *ZodEnum[T, R]

Prefault sets a fallback value that goes through the full validation pipeline when input is nil.

func (*ZodEnum[T, R]) PrefaultFunc

func (z *ZodEnum[T, R]) PrefaultFunc(fn func() T) *ZodEnum[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline when input is nil.

func (*ZodEnum[T, R]) Refine

func (z *ZodEnum[T, R]) Refine(fn func(R) bool, params ...any) *ZodEnum[T, R]

Refine applies type-safe validation matching the schema's output type R. The callback receives nil for *T schemas when the value is nil (Zod v4 semantics).

func (*ZodEnum[T, R]) RefineAny

func (z *ZodEnum[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodEnum[T, R]

RefineAny applies validation without type conversion.

func (*ZodEnum[T, R]) StrictParse added in v0.4.0

func (z *ZodEnum[T, R]) StrictParse(input R, ctx ...*core.ParseContext) (R, error)

StrictParse provides compile-time type safety by requiring exact type R.

func (*ZodEnum[T, R]) Transform

func (z *ZodEnum[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed enum value.

func (*ZodEnum[T, R]) With added in v0.6.0

func (z *ZodEnum[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodEnum[T, R]

With is an alias for Check (Zod v4 API compatibility).

type ZodEnumDef

type ZodEnumDef[T comparable] struct {
	core.ZodTypeDef
	// Entries maps enum keys to enum values.
	Entries map[string]T
}

ZodEnumDef defines the configuration for enum validation.

type ZodEnumInternals

type ZodEnumInternals[T comparable] struct {
	core.ZodTypeInternals
	// Def points to the schema definition.
	Def *ZodEnumDef[T]
	// Entries maps enum keys to enum values.
	Entries map[string]T
	// Values stores the allowed enum values for membership checks.
	Values map[T]struct{}
}

ZodEnumInternals contains the internal state for enum validators.

type ZodFile

type ZodFile[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodFile validates file inputs with constraint types T (base) and R (output). Supported types: *os.File, *multipart.FileHeader, multipart.File.

func File

func File(params ...any) *ZodFile[any, any]

File creates a new file validation schema.

func FilePtr added in v0.3.0

func FilePtr(params ...any) *ZodFile[any, *any]

FilePtr creates a new file validation schema with pointer constraint.

func FileTyped added in v0.3.0

func FileTyped[T any, R any](params ...any) *ZodFile[T, R]

FileTyped creates a new file schema with specific constraint types.

func (*ZodFile[T, R]) And added in v0.6.0

func (z *ZodFile[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodFile[T, R]) Check added in v0.6.0

func (z *ZodFile[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodFile[T, R]

Check adds a custom validation function that can push multiple issues.

func (*ZodFile[T, R]) CloneFrom

func (z *ZodFile[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema of the same type.

func (*ZodFile[T, R]) Default

func (z *ZodFile[T, R]) Default(v T) *ZodFile[T, R]

Default sets a fallback value when input is nil (short-circuits validation).

func (*ZodFile[T, R]) DefaultFunc

func (z *ZodFile[T, R]) DefaultFunc(fn func() T) *ZodFile[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodFile[T, R]) Describe added in v0.5.4

func (z *ZodFile[T, R]) Describe(desc string) *ZodFile[T, R]

Describe registers a description in the global registry.

func (*ZodFile[T, R]) ExactOptional added in v0.6.0

func (z *ZodFile[T, R]) ExactOptional() *ZodFile[T, R]

ExactOptional accepts absent keys but rejects explicit nil values.

func (*ZodFile[T, R]) Internals added in v0.6.0

func (z *ZodFile[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodFile[T, R]) IsNilable added in v0.3.0

func (z *ZodFile[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodFile[T, R]) IsOptional added in v0.3.0

func (z *ZodFile[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodFile[T, R]) Max

func (z *ZodFile[T, R]) Max(maximum int64, params ...any) *ZodFile[T, R]

Max sets maximum file size validation.

func (*ZodFile[T, R]) Meta added in v0.3.1

func (z *ZodFile[T, R]) Meta(meta core.GlobalMeta) *ZodFile[T, R]

Meta stores metadata for this file schema in the global registry.

func (*ZodFile[T, R]) Mime

func (z *ZodFile[T, R]) Mime(mimeTypes []string, params ...any) *ZodFile[T, R]

Mime sets MIME type validation.

func (*ZodFile[T, R]) Min

func (z *ZodFile[T, R]) Min(minimum int64, params ...any) *ZodFile[T, R]

Min sets minimum file size validation.

func (*ZodFile[T, R]) MustParse

func (z *ZodFile[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates input and panics on failure.

func (*ZodFile[T, R]) MustStrictParse added in v0.4.0

func (z *ZodFile[T, R]) MustStrictParse(input T, ctx ...*core.ParseContext) R

MustStrictParse provides compile-time type safety and panics on failure.

func (*ZodFile[T, R]) Nilable

func (z *ZodFile[T, R]) Nilable() *ZodFile[T, *T]

Nilable returns a new schema that accepts nil values, with pointer constraint.

func (*ZodFile[T, R]) Nullish

func (z *ZodFile[T, R]) Nullish() *ZodFile[T, *T]

Nullish returns a new schema combining optional and nilable modifiers.

func (*ZodFile[T, R]) Optional

func (z *ZodFile[T, R]) Optional() *ZodFile[T, *T]

Optional returns a new schema that accepts nil with pointer constraint.

func (*ZodFile[T, R]) Or added in v0.6.0

func (z *ZodFile[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodFile[T, R]) Overwrite added in v0.3.0

func (z *ZodFile[T, R]) Overwrite(transform func(R) R, params ...any) *ZodFile[T, R]

Overwrite transforms the input value while preserving the original type.

func (*ZodFile[T, R]) Parse

func (z *ZodFile[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input and returns a value of type R.

func (*ZodFile[T, R]) ParseAny added in v0.3.0

func (z *ZodFile[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns any type for runtime interface usage.

func (*ZodFile[T, R]) Pipe

func (z *ZodFile[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a validation pipeline with another schema.

func (*ZodFile[T, R]) Prefault

func (z *ZodFile[T, R]) Prefault(v T) *ZodFile[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodFile[T, R]) PrefaultFunc

func (z *ZodFile[T, R]) PrefaultFunc(fn func() T) *ZodFile[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodFile[T, R]) Refine

func (z *ZodFile[T, R]) Refine(fn func(R) bool, params ...any) *ZodFile[T, R]

Refine applies a custom validation function for output type R.

func (*ZodFile[T, R]) RefineAny

func (z *ZodFile[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodFile[T, R]

RefineAny applies a custom validation function receiving the raw value.

func (*ZodFile[T, R]) Size

func (z *ZodFile[T, R]) Size(expected int64, params ...any) *ZodFile[T, R]

Size sets exact file size validation.

func (*ZodFile[T, R]) StrictParse added in v0.4.0

func (z *ZodFile[T, R]) StrictParse(input T, ctx ...*core.ParseContext) (R, error)

StrictParse provides compile-time type safety by requiring exact type T.

func (*ZodFile[T, R]) Transform

func (z *ZodFile[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed value.

func (*ZodFile[T, R]) With added in v0.6.0

func (z *ZodFile[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodFile[T, R]

With is an alias for Check (Zod v4 API compatibility).

type ZodFileDef

type ZodFileDef struct {
	core.ZodTypeDef
}

ZodFileDef defines the configuration for file validation.

type ZodFileInternals

type ZodFileInternals struct {
	core.ZodTypeInternals
	Def *ZodFileDef
}

ZodFileInternals contains file validator internal state.

type ZodFloat

type ZodFloat[T FloatConstraint, R any] = ZodFloatTyped[T, R]

ZodFloat is a generic type alias for ZodFloatTyped.

type ZodFloatDef

type ZodFloatDef struct {
	core.ZodTypeDef
}

ZodFloatDef defines the configuration for float validation.

type ZodFloatInternals

type ZodFloatInternals struct {
	core.ZodTypeInternals
	Def *ZodFloatDef
}

ZodFloatInternals contains float validator internal state.

type ZodFloatTyped added in v0.3.0

type ZodFloatTyped[T FloatConstraint, R any] struct {
	// contains filtered or unexported fields
}

ZodFloatTyped represents a floating-point validation schema with dual generic parameters. T is the base type (float32, float64), R is the constraint type (T or *T).

func CoercedFloat added in v0.3.0

func CoercedFloat[T FloatConstraint](params ...any) *ZodFloatTyped[T, T]

CoercedFloat creates a flexible float schema with coercion enabled.

func CoercedFloat32 added in v0.2.1

func CoercedFloat32(params ...any) *ZodFloatTyped[float32, float32]

CoercedFloat32 creates a float32 schema with coercion enabled.

func CoercedFloat32Ptr added in v0.3.0

func CoercedFloat32Ptr(params ...any) *ZodFloatTyped[float32, *float32]

CoercedFloat32Ptr creates a *float32 schema with coercion enabled.

func CoercedFloat64 added in v0.2.1

func CoercedFloat64(params ...any) *ZodFloatTyped[float64, float64]

CoercedFloat64 creates a float64 schema with coercion enabled.

func CoercedFloat64Ptr added in v0.3.0

func CoercedFloat64Ptr(params ...any) *ZodFloatTyped[float64, *float64]

CoercedFloat64Ptr creates a *float64 schema with coercion enabled.

func CoercedFloatPtr added in v0.3.0

func CoercedFloatPtr(params ...any) *ZodFloatTyped[float64, *float64]

CoercedFloatPtr creates a *float64 schema with coercion enabled.

func CoercedNumber added in v0.2.1

func CoercedNumber(params ...any) *ZodFloatTyped[float64, float64]

CoercedNumber creates a number schema with coercion enabled (alias for CoercedFloat64).

func CoercedNumberPtr added in v0.3.0

func CoercedNumberPtr(params ...any) *ZodFloatTyped[float64, *float64]

CoercedNumberPtr creates a *number schema with coercion enabled (alias for CoercedFloat64Ptr).

func Float

func Float(params ...any) *ZodFloatTyped[float64, float64]

Float creates a flexible float64 schema (alias for Float64).

func Float32

func Float32(params ...any) *ZodFloatTyped[float32, float32]

Float32 creates a float32 schema.

func Float32Ptr added in v0.3.0

func Float32Ptr(params ...any) *ZodFloatTyped[float32, *float32]

Float32Ptr creates a schema for *float32.

func Float64

func Float64(params ...any) *ZodFloatTyped[float64, float64]

Float64 creates a float64 schema.

func Float64Ptr added in v0.3.0

func Float64Ptr(params ...any) *ZodFloatTyped[float64, *float64]

Float64Ptr creates a schema for *float64.

func FloatPtr added in v0.3.0

func FloatPtr(params ...any) *ZodFloatTyped[float64, *float64]

FloatPtr creates a schema for *float64 (alias for Float64Ptr).

func FloatTyped added in v0.3.0

func FloatTyped[T FloatConstraint](params ...any) *ZodFloatTyped[T, T]

FloatTyped creates a generic float schema with automatic type inference. Usage: FloatTyped[float32](), FloatTyped[float64](), etc.

func Number

func Number(params ...any) *ZodFloatTyped[float64, float64]

Number creates a number schema (alias for Float64).

func NumberPtr added in v0.3.0

func NumberPtr(params ...any) *ZodFloatTyped[float64, *float64]

NumberPtr creates a schema for *float64 (alias for Float64Ptr).

func (*ZodFloatTyped[T, R]) And added in v0.5.4

func (z *ZodFloatTyped[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodFloatTyped[T, R]) Check added in v0.3.0

func (z *ZodFloatTyped[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodFloatTyped[T, R]

Check adds a custom validation function that can report multiple issues.

Example:

schema := Float64().Check(func(value float64, payload *core.ParsePayload) {
    if value < 0 {
        payload.AddIssue(core.NewIssue("value must be positive"))
    }
})

func (*ZodFloatTyped[T, R]) CloneFrom added in v0.3.0

func (z *ZodFloatTyped[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodFloatTyped[T, R]) Coerce added in v0.3.0

func (z *ZodFloatTyped[T, R]) Coerce(input any) (any, bool)

Coerce converts input to the target float type.

func (*ZodFloatTyped[T, R]) Default added in v0.3.0

func (z *ZodFloatTyped[T, R]) Default(v float64) *ZodFloatTyped[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodFloatTyped[T, R]) DefaultFunc added in v0.3.0

func (z *ZodFloatTyped[T, R]) DefaultFunc(fn func() float64) *ZodFloatTyped[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodFloatTyped[T, R]) Describe added in v0.5.4

func (z *ZodFloatTyped[T, R]) Describe(description string) *ZodFloatTyped[T, R]

Describe registers a description in the global registry.

func (*ZodFloatTyped[T, R]) ExactOptional added in v0.5.4

func (z *ZodFloatTyped[T, R]) ExactOptional() *ZodFloatTyped[T, R]

ExactOptional accepts absent keys but rejects explicit nil values.

func (*ZodFloatTyped[T, R]) Finite added in v0.3.0

func (z *ZodFloatTyped[T, R]) Finite(params ...any) *ZodFloatTyped[T, R]

Finite adds finite number validation (not NaN or Infinity).

func (*ZodFloatTyped[T, R]) Gt added in v0.3.0

func (z *ZodFloatTyped[T, R]) Gt(value float64, params ...any) *ZodFloatTyped[T, R]

Gt adds greater-than validation (exclusive).

func (*ZodFloatTyped[T, R]) Gte added in v0.3.0

func (z *ZodFloatTyped[T, R]) Gte(value float64, params ...any) *ZodFloatTyped[T, R]

Gte adds greater-than-or-equal validation (inclusive).

func (*ZodFloatTyped[T, R]) Int added in v0.3.0

func (z *ZodFloatTyped[T, R]) Int(params ...any) *ZodFloatTyped[T, R]

Int adds integer validation (no decimal part).

func (*ZodFloatTyped[T, R]) Internals added in v0.6.0

func (z *ZodFloatTyped[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodFloatTyped[T, R]) IsNilable added in v0.3.0

func (z *ZodFloatTyped[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodFloatTyped[T, R]) IsOptional added in v0.3.0

func (z *ZodFloatTyped[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodFloatTyped[T, R]) Lt added in v0.3.0

func (z *ZodFloatTyped[T, R]) Lt(value float64, params ...any) *ZodFloatTyped[T, R]

Lt adds less-than validation (exclusive).

func (*ZodFloatTyped[T, R]) Lte added in v0.3.0

func (z *ZodFloatTyped[T, R]) Lte(value float64, params ...any) *ZodFloatTyped[T, R]

Lte adds less-than-or-equal validation (inclusive).

func (*ZodFloatTyped[T, R]) Max added in v0.3.0

func (z *ZodFloatTyped[T, R]) Max(maximum float64, params ...any) *ZodFloatTyped[T, R]

Max adds maximum value validation (alias for Lte).

func (*ZodFloatTyped[T, R]) Meta added in v0.3.1

func (z *ZodFloatTyped[T, R]) Meta(meta core.GlobalMeta) *ZodFloatTyped[T, R]

Meta stores metadata for this float schema in the global registry.

func (*ZodFloatTyped[T, R]) Min added in v0.3.0

func (z *ZodFloatTyped[T, R]) Min(minimum float64, params ...any) *ZodFloatTyped[T, R]

Min adds minimum value validation (alias for Gte).

func (*ZodFloatTyped[T, R]) MultipleOf added in v0.3.0

func (z *ZodFloatTyped[T, R]) MultipleOf(value float64, params ...any) *ZodFloatTyped[T, R]

MultipleOf adds multiple-of validation.

func (*ZodFloatTyped[T, R]) MustParse added in v0.3.0

func (z *ZodFloatTyped[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse is the type-safe variant that panics on error.

func (*ZodFloatTyped[T, R]) MustStrictParse added in v0.4.0

func (z *ZodFloatTyped[T, R]) MustStrictParse(input R, ctx ...*core.ParseContext) R

MustStrictParse validates with compile-time type safety and panics on error.

func (*ZodFloatTyped[T, R]) Negative added in v0.3.0

func (z *ZodFloatTyped[T, R]) Negative(params ...any) *ZodFloatTyped[T, R]

Negative adds negative number validation (< 0).

func (*ZodFloatTyped[T, R]) Nilable added in v0.3.0

func (z *ZodFloatTyped[T, R]) Nilable() *ZodFloatTyped[T, *T]

Nilable returns a schema that accepts the base type T or nil, with constraint type *T.

func (*ZodFloatTyped[T, R]) NonNegative added in v0.3.0

func (z *ZodFloatTyped[T, R]) NonNegative(params ...any) *ZodFloatTyped[T, R]

NonNegative adds non-negative number validation (>= 0).

func (*ZodFloatTyped[T, R]) NonOptional added in v0.3.0

func (z *ZodFloatTyped[T, R]) NonOptional() *ZodFloatTyped[T, T]

NonOptional removes optional flag and returns value constraint T.

func (*ZodFloatTyped[T, R]) NonPositive added in v0.3.0

func (z *ZodFloatTyped[T, R]) NonPositive(params ...any) *ZodFloatTyped[T, R]

NonPositive adds non-positive number validation (<= 0).

func (*ZodFloatTyped[T, R]) Nullish added in v0.3.0

func (z *ZodFloatTyped[T, R]) Nullish() *ZodFloatTyped[T, *T]

Nullish combines optional and nilable modifiers.

func (*ZodFloatTyped[T, R]) Optional added in v0.3.0

func (z *ZodFloatTyped[T, R]) Optional() *ZodFloatTyped[T, *T]

Optional returns a schema that accepts the base type T or nil, with constraint type *T.

func (*ZodFloatTyped[T, R]) Or added in v0.5.4

func (z *ZodFloatTyped[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodFloatTyped[T, R]) Overwrite added in v0.3.0

func (z *ZodFloatTyped[T, R]) Overwrite(transform func(T) T, params ...any) *ZodFloatTyped[T, R]

Overwrite transforms the input value while preserving the original type. Unlike Transform, this doesn't change the inferred type.

func (*ZodFloatTyped[T, R]) Parse added in v0.3.0

func (z *ZodFloatTyped[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input and returns a value matching the constraint type R.

func (*ZodFloatTyped[T, R]) ParseAny added in v0.3.0

func (z *ZodFloatTyped[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodFloatTyped[T, R]) Pipe added in v0.3.0

func (z *ZodFloatTyped[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a pipeline that feeds the parsed value into another schema.

func (*ZodFloatTyped[T, R]) Positive added in v0.3.0

func (z *ZodFloatTyped[T, R]) Positive(params ...any) *ZodFloatTyped[T, R]

Positive adds positive number validation (> 0).

func (*ZodFloatTyped[T, R]) Prefault added in v0.3.0

func (z *ZodFloatTyped[T, R]) Prefault(v float64) *ZodFloatTyped[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodFloatTyped[T, R]) PrefaultFunc added in v0.3.0

func (z *ZodFloatTyped[T, R]) PrefaultFunc(fn func() float64) *ZodFloatTyped[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodFloatTyped[T, R]) Refine added in v0.3.0

func (z *ZodFloatTyped[T, R]) Refine(fn func(T) bool, params ...any) *ZodFloatTyped[T, R]

Refine applies type-safe validation using the base type T. Nil values bypass validation for nilable schemas per Zod v4 semantics.

Example:

schema := Float64().Refine(func(f float64) bool {
    return f > 0 && f < 100
}, "value must be between 0 and 100")

func (*ZodFloatTyped[T, R]) RefineAny added in v0.3.0

func (z *ZodFloatTyped[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodFloatTyped[T, R]

RefineAny adds flexible custom validation logic that accepts any type.

func (*ZodFloatTyped[T, R]) Safe added in v0.3.0

func (z *ZodFloatTyped[T, R]) Safe(params ...any) *ZodFloatTyped[T, R]

Safe adds safe number validation (within JavaScript safe integer range).

func (*ZodFloatTyped[T, R]) Step added in v0.3.0

func (z *ZodFloatTyped[T, R]) Step(step float64, params ...any) *ZodFloatTyped[T, R]

Step adds step validation (alias for MultipleOf).

func (*ZodFloatTyped[T, R]) StrictParse added in v0.4.0

func (z *ZodFloatTyped[T, R]) StrictParse(input R, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodFloatTyped[T, R]) Transform added in v0.3.0

func (z *ZodFloatTyped[T, R]) Transform(fn func(float64, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed float value.

Example:

schema := Float64().Min(0.0).Transform(func(f float64, ctx *RefinementContext) (string, error) {
    return fmt.Sprintf("%.2f", f), nil
})

func (*ZodFloatTyped[T, R]) With added in v0.5.4

func (z *ZodFloatTyped[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodFloatTyped[T, R]

With is an alias for Check (Zod v4 API compatibility).

type ZodFunction

type ZodFunction[T FunctionConstraint] struct {
	// contains filtered or unexported fields
}

ZodFunction represents a function validation schema with type safety.

func Function

func Function(params ...any) *ZodFunction[any]

Function creates a function validation schema with constraint type any.

func FunctionPtr added in v0.3.0

func FunctionPtr(params ...any) *ZodFunction[*any]

FunctionPtr creates a function validation schema with constraint type *any.

func FunctionTyped added in v0.3.0

func FunctionTyped[T FunctionConstraint](params ...any) *ZodFunction[T]

FunctionTyped creates a function validation schema with the specified constraint type.

func (*ZodFunction[T]) CloneFrom added in v0.3.0

func (z *ZodFunction[T]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodFunction[T]) Default

func (z *ZodFunction[T]) Default(v any) *ZodFunction[T]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodFunction[T]) DefaultFunc

func (z *ZodFunction[T]) DefaultFunc(fn func() any) *ZodFunction[T]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodFunction[T]) Describe added in v0.5.4

func (z *ZodFunction[T]) Describe(description string) *ZodFunction[T]

Describe registers a description in the global registry.

func (*ZodFunction[T]) Implement

func (z *ZodFunction[T]) Implement(fn any) (any, error)

Implement wraps a function with input/output validation.

func (*ZodFunction[T]) Input

func (z *ZodFunction[T]) Input(schema core.ZodType[any]) *ZodFunction[T]

Input sets the input schema for function arguments.

func (*ZodFunction[T]) Internals added in v0.6.0

func (z *ZodFunction[T]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodFunction[T]) IsNilable added in v0.3.0

func (z *ZodFunction[T]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodFunction[T]) IsOptional added in v0.3.0

func (z *ZodFunction[T]) IsOptional() bool

IsOptional reports whether this schema accepts undefined or missing values.

func (*ZodFunction[T]) Meta added in v0.3.1

func (z *ZodFunction[T]) Meta(meta core.GlobalMeta) *ZodFunction[T]

Meta stores metadata for this function schema.

func (*ZodFunction[T]) MustParse

func (z *ZodFunction[T]) MustParse(input any, ctx ...*core.ParseContext) T

MustParse validates input and panics on error.

func (*ZodFunction[T]) MustStrictParse added in v0.4.0

func (z *ZodFunction[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates with compile-time type safety and panics on error.

func (*ZodFunction[T]) Nilable

func (z *ZodFunction[T]) Nilable() *ZodFunction[*any]

Nilable returns a schema that accepts nil with constraint type *any.

func (*ZodFunction[T]) Nullish

func (z *ZodFunction[T]) Nullish() *ZodFunction[*any]

Nullish combines optional and nilable modifiers.

func (*ZodFunction[T]) Optional

func (z *ZodFunction[T]) Optional() *ZodFunction[*any]

Optional returns a schema that accepts nil with constraint type *any.

func (*ZodFunction[T]) Output

func (z *ZodFunction[T]) Output(schema core.ZodType[any]) *ZodFunction[T]

Output sets the output schema for function return values.

func (*ZodFunction[T]) Overwrite added in v0.3.0

func (z *ZodFunction[T]) Overwrite(transform func(T) T, params ...any) *ZodFunction[T]

Overwrite transforms the input value while preserving the original type.

func (*ZodFunction[T]) Parse

func (z *ZodFunction[T]) Parse(input any, ctx ...*core.ParseContext) (T, error)

Parse validates input and returns a function value.

func (*ZodFunction[T]) ParseAny added in v0.3.0

func (z *ZodFunction[T]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodFunction[T]) Pipe

func (z *ZodFunction[T]) Pipe(target core.ZodType[any]) *core.ZodPipe[T, any]

Pipe creates a validation pipeline to another schema.

func (*ZodFunction[T]) Prefault

func (z *ZodFunction[T]) Prefault(v any) *ZodFunction[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodFunction[T]) PrefaultFunc

func (z *ZodFunction[T]) PrefaultFunc(fn func() any) *ZodFunction[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodFunction[T]) Refine

func (z *ZodFunction[T]) Refine(fn func(T) bool, params ...any) *ZodFunction[T]

Refine adds a custom validation function.

func (*ZodFunction[T]) RefineAny

func (z *ZodFunction[T]) RefineAny(fn func(any) bool, params ...any) *ZodFunction[T]

RefineAny adds a custom validation function that accepts any type.

func (*ZodFunction[T]) StrictParse added in v0.4.0

func (z *ZodFunction[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

func (*ZodFunction[T]) Transform

func (z *ZodFunction[T]) Transform(fn func(any, *core.RefinementContext) (any, error)) *core.ZodTransform[T, any]

Transform creates a transformation pipeline.

type ZodFunctionDef

type ZodFunctionDef struct {
	core.ZodTypeDef
	Input  core.ZodType[any]
	Output core.ZodType[any]
}

ZodFunctionDef defines the configuration for function validation.

type ZodFunctionInternals

type ZodFunctionInternals struct {
	core.ZodTypeInternals
	Def    *ZodFunctionDef
	Input  core.ZodType[any]
	Output core.ZodType[any]
}

ZodFunctionInternals contains function validator internal state.

type ZodGUID added in v0.5.5

type ZodGUID[T StringConstraint] struct{ *ZodString[T] }

ZodGUID validates strings in GUID format (8-4-4-4-12 hex pattern).

func GUID added in v0.7.0

func GUID(params ...any) *ZodGUID[string]

GUID creates a GUID schema (8-4-4-4-12 hex pattern).

func GUIDPtr added in v0.7.0

func GUIDPtr(params ...any) *ZodGUID[*string]

GUIDPtr creates a pointer GUID schema.

func (*ZodGUID[T]) Default added in v0.10.5

func (z *ZodGUID[T]) Default(v string) *ZodGUID[T]

Default sets a fallback value returned when input is nil.

func (*ZodGUID[T]) DefaultFunc added in v0.10.5

func (z *ZodGUID[T]) DefaultFunc(fn func() string) *ZodGUID[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodGUID[T]) Describe added in v0.10.5

func (z *ZodGUID[T]) Describe(description string) *ZodGUID[T]

Describe attaches a description to this schema via the global registry.

func (*ZodGUID[T]) Meta added in v0.10.5

func (z *ZodGUID[T]) Meta(meta core.GlobalMeta) *ZodGUID[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodGUID[T]) MustStrictParse added in v0.5.5

func (z *ZodGUID[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodGUID[T]) Nilable added in v0.6.0

func (z *ZodGUID[T]) Nilable() *ZodGUID[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodGUID[T]) Nullish added in v0.6.0

func (z *ZodGUID[T]) Nullish() *ZodGUID[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodGUID[T]) Optional added in v0.6.0

func (z *ZodGUID[T]) Optional() *ZodGUID[*string]

Optional returns a new schema that accepts nil values.

func (*ZodGUID[T]) Prefault added in v0.10.5

func (z *ZodGUID[T]) Prefault(v string) *ZodGUID[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodGUID[T]) PrefaultFunc added in v0.10.5

func (z *ZodGUID[T]) PrefaultFunc(fn func() string) *ZodGUID[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodGUID[T]) RefineAny added in v0.10.5

func (z *ZodGUID[T]) RefineAny(fn func(any) bool, params ...any) *ZodGUID[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodGUID[T]) StrictParse added in v0.5.5

func (z *ZodGUID[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodHex added in v0.5.4

type ZodHex[T StringConstraint] struct {
	*ZodString[T]
}

ZodHex validates hexadecimal strings. String modifiers (Min, Max, etc.) are promoted from the embedded *ZodString[T].

func Hex added in v0.5.4

func Hex(params ...any) *ZodHex[string]

Hex creates a hexadecimal string validation schema.

func HexPtr added in v0.5.4

func HexPtr(params ...any) *ZodHex[*string]

HexPtr creates a pointer hexadecimal string validation schema.

func (*ZodHex[T]) Default added in v0.10.5

func (z *ZodHex[T]) Default(v string) *ZodHex[T]

Default sets a fallback value returned when input is nil.

func (*ZodHex[T]) DefaultFunc added in v0.10.5

func (z *ZodHex[T]) DefaultFunc(fn func() string) *ZodHex[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodHex[T]) Describe added in v0.10.5

func (z *ZodHex[T]) Describe(description string) *ZodHex[T]

Describe attaches a description to this schema via the global registry.

func (*ZodHex[T]) Meta added in v0.10.5

func (z *ZodHex[T]) Meta(meta core.GlobalMeta) *ZodHex[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodHex[T]) MustStrictParse added in v0.5.4

func (z *ZodHex[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodHex[T]) Nilable added in v0.6.0

func (z *ZodHex[T]) Nilable() *ZodHex[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodHex[T]) Nullish added in v0.6.0

func (z *ZodHex[T]) Nullish() *ZodHex[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodHex[T]) Optional added in v0.6.0

func (z *ZodHex[T]) Optional() *ZodHex[*string]

Optional returns a new schema that accepts nil values.

func (*ZodHex[T]) Prefault added in v0.10.5

func (z *ZodHex[T]) Prefault(v string) *ZodHex[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodHex[T]) PrefaultFunc added in v0.10.5

func (z *ZodHex[T]) PrefaultFunc(fn func() string) *ZodHex[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodHex[T]) RefineAny added in v0.10.5

func (z *ZodHex[T]) RefineAny(fn func(any) bool, params ...any) *ZodHex[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodHex[T]) StrictParse added in v0.5.4

func (z *ZodHex[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodHostname added in v0.5.4

type ZodHostname[T StringConstraint] struct{ *ZodString[T] }

ZodHostname validates strings in hostname format.

func CoercedHostname added in v0.6.0

func CoercedHostname(params ...any) *ZodHostname[string]

CoercedHostname creates a coerced hostname schema that attempts string conversion.

func Hostname added in v0.5.4

func Hostname(params ...any) *ZodHostname[string]

Hostname creates a hostname validation schema.

func HostnamePtr added in v0.5.4

func HostnamePtr(params ...any) *ZodHostname[*string]

HostnamePtr creates a pointer hostname validation schema.

func (*ZodHostname[T]) Default added in v0.5.4

func (z *ZodHostname[T]) Default(v string) *ZodHostname[T]

Default sets a fallback value returned when input is nil.

func (*ZodHostname[T]) DefaultFunc added in v0.10.5

func (z *ZodHostname[T]) DefaultFunc(fn func() string) *ZodHostname[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodHostname[T]) Describe added in v0.5.4

func (z *ZodHostname[T]) Describe(description string) *ZodHostname[T]

Describe attaches a description to this schema via the global registry.

func (*ZodHostname[T]) Meta added in v0.10.5

func (z *ZodHostname[T]) Meta(meta core.GlobalMeta) *ZodHostname[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodHostname[T]) MustStrictParse added in v0.5.4

func (z *ZodHostname[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodHostname[T]) Nilable added in v0.5.4

func (z *ZodHostname[T]) Nilable() *ZodHostname[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodHostname[T]) Nullish added in v0.6.0

func (z *ZodHostname[T]) Nullish() *ZodHostname[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodHostname[T]) Optional added in v0.5.4

func (z *ZodHostname[T]) Optional() *ZodHostname[*string]

Optional returns a new schema that accepts nil values.

func (*ZodHostname[T]) Prefault added in v0.10.5

func (z *ZodHostname[T]) Prefault(v string) *ZodHostname[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodHostname[T]) PrefaultFunc added in v0.10.5

func (z *ZodHostname[T]) PrefaultFunc(fn func() string) *ZodHostname[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodHostname[T]) RefineAny added in v0.5.7

func (z *ZodHostname[T]) RefineAny(fn func(any) bool, params ...any) *ZodHostname[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodHostname[T]) StrictParse added in v0.5.4

func (z *ZodHostname[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodIPv4

type ZodIPv4[T StringConstraint] struct{ *ZodString[T] }

ZodIPv4 validates strings in IPv4 address format.

func CoercedIPv4 added in v0.3.0

func CoercedIPv4(params ...any) *ZodIPv4[string]

CoercedIPv4 creates a coerced IPv4 schema that attempts string conversion.

func IPv4

func IPv4(params ...any) *ZodIPv4[string]

IPv4 creates an IPv4 address validation schema.

func IPv4Ptr added in v0.3.0

func IPv4Ptr(params ...any) *ZodIPv4[*string]

IPv4Ptr creates a pointer IPv4 address validation schema.

func (*ZodIPv4[T]) Default

func (z *ZodIPv4[T]) Default(v string) *ZodIPv4[T]

Default sets a fallback value returned when input is nil.

func (*ZodIPv4[T]) DefaultFunc

func (z *ZodIPv4[T]) DefaultFunc(fn func() string) *ZodIPv4[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodIPv4[T]) Describe added in v0.10.5

func (z *ZodIPv4[T]) Describe(description string) *ZodIPv4[T]

Describe attaches a description to this schema via the global registry.

func (*ZodIPv4[T]) Meta added in v0.10.5

func (z *ZodIPv4[T]) Meta(meta core.GlobalMeta) *ZodIPv4[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodIPv4[T]) MustStrictParse added in v0.4.0

func (z *ZodIPv4[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodIPv4[T]) Nilable

func (z *ZodIPv4[T]) Nilable() *ZodIPv4[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodIPv4[T]) Nullish added in v0.3.0

func (z *ZodIPv4[T]) Nullish() *ZodIPv4[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodIPv4[T]) Optional

func (z *ZodIPv4[T]) Optional() *ZodIPv4[*string]

Optional returns a new schema that accepts nil values.

func (*ZodIPv4[T]) Prefault

func (z *ZodIPv4[T]) Prefault(v string) *ZodIPv4[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodIPv4[T]) PrefaultFunc

func (z *ZodIPv4[T]) PrefaultFunc(fn func() string) *ZodIPv4[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodIPv4[T]) RefineAny

func (z *ZodIPv4[T]) RefineAny(fn func(any) bool, params ...any) *ZodIPv4[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodIPv4[T]) StrictParse added in v0.4.0

func (z *ZodIPv4[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodIPv6

type ZodIPv6[T StringConstraint] struct{ *ZodString[T] }

ZodIPv6 validates strings in IPv6 address format.

func CoercedIPv6 added in v0.3.0

func CoercedIPv6(params ...any) *ZodIPv6[string]

CoercedIPv6 creates a coerced IPv6 schema that attempts string conversion.

func IPv6

func IPv6(params ...any) *ZodIPv6[string]

IPv6 creates an IPv6 address validation schema.

func IPv6Ptr added in v0.3.0

func IPv6Ptr(params ...any) *ZodIPv6[*string]

IPv6Ptr creates a pointer IPv6 address validation schema.

func (*ZodIPv6[T]) Default

func (z *ZodIPv6[T]) Default(v string) *ZodIPv6[T]

Default sets a fallback value returned when input is nil.

func (*ZodIPv6[T]) DefaultFunc

func (z *ZodIPv6[T]) DefaultFunc(fn func() string) *ZodIPv6[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodIPv6[T]) Describe added in v0.10.5

func (z *ZodIPv6[T]) Describe(description string) *ZodIPv6[T]

Describe attaches a description to this schema via the global registry.

func (*ZodIPv6[T]) Meta added in v0.10.5

func (z *ZodIPv6[T]) Meta(meta core.GlobalMeta) *ZodIPv6[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodIPv6[T]) MustStrictParse added in v0.4.0

func (z *ZodIPv6[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodIPv6[T]) Nilable

func (z *ZodIPv6[T]) Nilable() *ZodIPv6[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodIPv6[T]) Nullish added in v0.3.0

func (z *ZodIPv6[T]) Nullish() *ZodIPv6[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodIPv6[T]) Optional

func (z *ZodIPv6[T]) Optional() *ZodIPv6[*string]

Optional returns a new schema that accepts nil values.

func (*ZodIPv6[T]) Prefault

func (z *ZodIPv6[T]) Prefault(v string) *ZodIPv6[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodIPv6[T]) PrefaultFunc

func (z *ZodIPv6[T]) PrefaultFunc(fn func() string) *ZodIPv6[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodIPv6[T]) RefineAny

func (z *ZodIPv6[T]) RefineAny(fn func(any) bool, params ...any) *ZodIPv6[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodIPv6[T]) StrictParse added in v0.4.0

func (z *ZodIPv6[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodInteger

type ZodInteger[T IntegerConstraint, R any] = ZodIntegerTyped[T, R]

ZodInteger is a type alias for ZodIntegerTyped providing a unified interface.

func Integer

func Integer(params ...any) *ZodInteger[int64, int64]

Integer creates a flexible integer schema (alias for Int64).

type ZodIntegerDef

type ZodIntegerDef struct {
	core.ZodTypeDef
}

ZodIntegerDef is the configuration for integer validation.

type ZodIntegerInternals

type ZodIntegerInternals struct {
	core.ZodTypeInternals
	Def *ZodIntegerDef
}

ZodIntegerInternals holds the internal state of an integer validator.

type ZodIntegerTyped added in v0.3.0

type ZodIntegerTyped[T IntegerConstraint, R any] struct {
	// contains filtered or unexported fields
}

ZodIntegerTyped is an integer validation schema with dual generic parameters.

T is the base type (int, int32, int64, etc.) and R is the constraint type (T or *T).

func Byte

func Byte(params ...any) *ZodIntegerTyped[uint8, uint8]

Byte creates a uint8 schema (alias for byte).

func BytePtr added in v0.3.0

func BytePtr(params ...any) *ZodIntegerTyped[uint8, *uint8]

BytePtr creates a schema for *uint8 (alias for *byte).

func CoercedInt added in v0.2.1

func CoercedInt(params ...any) *ZodIntegerTyped[int, int]

CoercedInt creates an int schema with coercion enabled.

func CoercedInt8 added in v0.2.1

func CoercedInt8(params ...any) *ZodIntegerTyped[int8, int8]

CoercedInt8 creates an int8 schema with coercion enabled.

func CoercedInt8Ptr added in v0.3.0

func CoercedInt8Ptr(params ...any) *ZodIntegerTyped[int8, *int8]

CoercedInt8Ptr creates a *int8 schema with coercion enabled.

func CoercedInt16 added in v0.2.1

func CoercedInt16(params ...any) *ZodIntegerTyped[int16, int16]

CoercedInt16 creates an int16 schema with coercion enabled.

func CoercedInt16Ptr added in v0.3.0

func CoercedInt16Ptr(params ...any) *ZodIntegerTyped[int16, *int16]

CoercedInt16Ptr creates a *int16 schema with coercion enabled.

func CoercedInt32 added in v0.2.1

func CoercedInt32(params ...any) *ZodIntegerTyped[int32, int32]

CoercedInt32 creates an int32 schema with coercion enabled.

func CoercedInt32Ptr added in v0.3.0

func CoercedInt32Ptr(params ...any) *ZodIntegerTyped[int32, *int32]

CoercedInt32Ptr creates a *int32 schema with coercion enabled.

func CoercedInt64 added in v0.2.1

func CoercedInt64(params ...any) *ZodIntegerTyped[int64, int64]

CoercedInt64 creates an int64 schema with coercion enabled.

func CoercedInt64Ptr added in v0.3.0

func CoercedInt64Ptr(params ...any) *ZodIntegerTyped[int64, *int64]

CoercedInt64Ptr creates a *int64 schema with coercion enabled.

func CoercedIntPtr added in v0.3.0

func CoercedIntPtr(params ...any) *ZodIntegerTyped[int, *int]

CoercedIntPtr creates a *int schema with coercion enabled.

func CoercedInteger added in v0.3.0

func CoercedInteger(params ...any) *ZodIntegerTyped[int64, int64]

CoercedInteger creates an int64 schema with coercion enabled.

func CoercedIntegerPtr added in v0.3.0

func CoercedIntegerPtr(params ...any) *ZodIntegerTyped[int64, *int64]

CoercedIntegerPtr creates a *int64 schema with coercion enabled.

func CoercedUint added in v0.2.1

func CoercedUint(params ...any) *ZodIntegerTyped[uint, uint]

CoercedUint creates a uint schema with coercion enabled.

func CoercedUint8 added in v0.2.1

func CoercedUint8(params ...any) *ZodIntegerTyped[uint8, uint8]

CoercedUint8 creates a uint8 schema with coercion enabled.

func CoercedUint8Ptr added in v0.3.0

func CoercedUint8Ptr(params ...any) *ZodIntegerTyped[uint8, *uint8]

CoercedUint8Ptr creates a *uint8 schema with coercion enabled.

func CoercedUint16 added in v0.2.1

func CoercedUint16(params ...any) *ZodIntegerTyped[uint16, uint16]

CoercedUint16 creates a uint16 schema with coercion enabled.

func CoercedUint16Ptr added in v0.3.0

func CoercedUint16Ptr(params ...any) *ZodIntegerTyped[uint16, *uint16]

CoercedUint16Ptr creates a *uint16 schema with coercion enabled.

func CoercedUint32 added in v0.2.1

func CoercedUint32(params ...any) *ZodIntegerTyped[uint32, uint32]

CoercedUint32 creates a uint32 schema with coercion enabled.

func CoercedUint32Ptr added in v0.3.0

func CoercedUint32Ptr(params ...any) *ZodIntegerTyped[uint32, *uint32]

CoercedUint32Ptr creates a *uint32 schema with coercion enabled.

func CoercedUint64 added in v0.2.1

func CoercedUint64(params ...any) *ZodIntegerTyped[uint64, uint64]

CoercedUint64 creates a uint64 schema with coercion enabled.

func CoercedUint64Ptr added in v0.3.0

func CoercedUint64Ptr(params ...any) *ZodIntegerTyped[uint64, *uint64]

CoercedUint64Ptr creates a *uint64 schema with coercion enabled.

func CoercedUintPtr added in v0.3.0

func CoercedUintPtr(params ...any) *ZodIntegerTyped[uint, *uint]

CoercedUintPtr creates a *uint schema with coercion enabled.

func Int

func Int(params ...any) *ZodIntegerTyped[int, int]

Int creates a standard int schema.

func Int8

func Int8(params ...any) *ZodIntegerTyped[int8, int8]

Int8 creates an int8 schema.

func Int8Ptr added in v0.3.0

func Int8Ptr(params ...any) *ZodIntegerTyped[int8, *int8]

Int8Ptr creates a schema for *int8.

func Int16

func Int16(params ...any) *ZodIntegerTyped[int16, int16]

Int16 creates an int16 schema.

func Int16Ptr added in v0.3.0

func Int16Ptr(params ...any) *ZodIntegerTyped[int16, *int16]

Int16Ptr creates a schema for *int16.

func Int32

func Int32(params ...any) *ZodIntegerTyped[int32, int32]

Int32 creates an int32 schema.

func Int32Ptr added in v0.3.0

func Int32Ptr(params ...any) *ZodIntegerTyped[int32, *int32]

Int32Ptr creates a schema for *int32.

func Int64

func Int64(params ...any) *ZodIntegerTyped[int64, int64]

Int64 creates an int64 schema.

func Int64Ptr added in v0.3.0

func Int64Ptr(params ...any) *ZodIntegerTyped[int64, *int64]

Int64Ptr creates a schema for *int64.

func IntPtr added in v0.3.0

func IntPtr(params ...any) *ZodIntegerTyped[int, *int]

IntPtr creates a schema for *int.

func IntegerTyped added in v0.3.0

func IntegerTyped[T IntegerConstraint](params ...any) *ZodIntegerTyped[T, T]

IntegerTyped creates a generic integer schema with automatic type inference.

func Rune

func Rune(params ...any) *ZodIntegerTyped[int32, int32]

Rune creates an int32 schema (alias for rune).

func RunePtr added in v0.3.0

func RunePtr(params ...any) *ZodIntegerTyped[int32, *int32]

RunePtr creates a schema for *int32 (alias for *rune).

func Uint

func Uint(params ...any) *ZodIntegerTyped[uint, uint]

Uint creates a uint schema.

func Uint8

func Uint8(params ...any) *ZodIntegerTyped[uint8, uint8]

Uint8 creates a uint8 schema.

func Uint8Ptr added in v0.3.0

func Uint8Ptr(params ...any) *ZodIntegerTyped[uint8, *uint8]

Uint8Ptr creates a schema for *uint8.

func Uint16

func Uint16(params ...any) *ZodIntegerTyped[uint16, uint16]

Uint16 creates a uint16 schema.

func Uint16Ptr added in v0.3.0

func Uint16Ptr(params ...any) *ZodIntegerTyped[uint16, *uint16]

Uint16Ptr creates a schema for *uint16.

func Uint32

func Uint32(params ...any) *ZodIntegerTyped[uint32, uint32]

Uint32 creates a uint32 schema.

func Uint32Ptr added in v0.3.0

func Uint32Ptr(params ...any) *ZodIntegerTyped[uint32, *uint32]

Uint32Ptr creates a schema for *uint32.

func Uint64

func Uint64(params ...any) *ZodIntegerTyped[uint64, uint64]

Uint64 creates a uint64 schema.

func Uint64Ptr added in v0.3.0

func Uint64Ptr(params ...any) *ZodIntegerTyped[uint64, *uint64]

Uint64Ptr creates a schema for *uint64.

func UintPtr added in v0.3.0

func UintPtr(params ...any) *ZodIntegerTyped[uint, *uint]

UintPtr creates a schema for *uint.

func (*ZodIntegerTyped[T, R]) And added in v0.5.4

func (z *ZodIntegerTyped[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

Example:

schema := gozod.Int().Min(0).And(gozod.Int().Max(100))
result, _ := schema.Parse(50)

func (*ZodIntegerTyped[T, R]) Check added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodIntegerTyped[T, R]

Check adds a custom validation function that can push multiple issues.

func (*ZodIntegerTyped[T, R]) CloneFrom added in v0.3.0

func (z *ZodIntegerTyped[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodIntegerTyped[T, R]) Coerce added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Coerce(input any) (any, bool)

Coerce converts the input to the target integer type.

func (*ZodIntegerTyped[T, R]) Default added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Default(v int64) *ZodIntegerTyped[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodIntegerTyped[T, R]) DefaultFunc added in v0.3.0

func (z *ZodIntegerTyped[T, R]) DefaultFunc(fn func() int64) *ZodIntegerTyped[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodIntegerTyped[T, R]) Describe added in v0.5.4

func (z *ZodIntegerTyped[T, R]) Describe(
	description string,
) *ZodIntegerTyped[T, R]

Describe registers a description in the global registry.

func (*ZodIntegerTyped[T, R]) ExactOptional added in v0.5.4

func (z *ZodIntegerTyped[T, R]) ExactOptional() *ZodIntegerTyped[T, R]

ExactOptional accepts absent keys but rejects explicit nil values.

Unlike Optional, ExactOptional only accepts absent keys in object fields.

func (*ZodIntegerTyped[T, R]) Gt added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Gt(value int64, params ...any) *ZodIntegerTyped[T, R]

Gt adds greater-than validation (exclusive).

func (*ZodIntegerTyped[T, R]) Gte added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Gte(value int64, params ...any) *ZodIntegerTyped[T, R]

Gte adds greater-than-or-equal validation (inclusive).

func (*ZodIntegerTyped[T, R]) Internals added in v0.6.0

func (z *ZodIntegerTyped[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodIntegerTyped[T, R]) IsNilable added in v0.3.0

func (z *ZodIntegerTyped[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodIntegerTyped[T, R]) IsOptional added in v0.3.0

func (z *ZodIntegerTyped[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodIntegerTyped[T, R]) Lt added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Lt(value int64, params ...any) *ZodIntegerTyped[T, R]

Lt adds less-than validation (exclusive).

func (*ZodIntegerTyped[T, R]) Lte added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Lte(value int64, params ...any) *ZodIntegerTyped[T, R]

Lte adds less-than-or-equal validation (inclusive).

func (*ZodIntegerTyped[T, R]) Max added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Max(maximum int64, params ...any) *ZodIntegerTyped[T, R]

Max adds maximum value validation (alias for Lte).

func (*ZodIntegerTyped[T, R]) Meta added in v0.3.1

func (z *ZodIntegerTyped[T, R]) Meta(
	meta core.GlobalMeta,
) *ZodIntegerTyped[T, R]

Meta stores metadata for this integer schema in the global registry.

func (*ZodIntegerTyped[T, R]) Min added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Min(minimum int64, params ...any) *ZodIntegerTyped[T, R]

Min adds minimum value validation (alias for Gte).

func (*ZodIntegerTyped[T, R]) MultipleOf added in v0.3.0

func (z *ZodIntegerTyped[T, R]) MultipleOf(value int64, params ...any) *ZodIntegerTyped[T, R]

MultipleOf adds multiple-of validation.

func (*ZodIntegerTyped[T, R]) MustParse added in v0.3.0

func (z *ZodIntegerTyped[T, R]) MustParse(
	input any,
	ctx ...*core.ParseContext,
) R

MustParse panics if Parse returns an error.

func (*ZodIntegerTyped[T, R]) MustStrictParse added in v0.4.0

func (z *ZodIntegerTyped[T, R]) MustStrictParse(
	input R,
	ctx ...*core.ParseContext,
) R

MustStrictParse panics if StrictParse returns an error.

Example usage:

schema := gozod.Int().Min(0).Max(100)
result := schema.MustStrictParse(42)           // ✅ int → int
result := schema.MustStrictParse(&num)         // ❌ compile error

func (*ZodIntegerTyped[T, R]) Negative added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Negative(params ...any) *ZodIntegerTyped[T, R]

Negative adds negative number validation (< 0).

func (*ZodIntegerTyped[T, R]) Nilable added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Nilable() *ZodIntegerTyped[T, *T]

Nilable returns a schema that accepts T or nil, with constraint type *T.

func (*ZodIntegerTyped[T, R]) NonNegative added in v0.3.0

func (z *ZodIntegerTyped[T, R]) NonNegative(params ...any) *ZodIntegerTyped[T, R]

NonNegative adds non-negative number validation (>= 0).

func (*ZodIntegerTyped[T, R]) NonOptional added in v0.3.0

func (z *ZodIntegerTyped[T, R]) NonOptional() *ZodIntegerTyped[T, T]

NonOptional removes the optional flag and returns a value constraint (T).

func (*ZodIntegerTyped[T, R]) NonPositive added in v0.3.0

func (z *ZodIntegerTyped[T, R]) NonPositive(params ...any) *ZodIntegerTyped[T, R]

NonPositive adds non-positive number validation (<= 0).

func (*ZodIntegerTyped[T, R]) Nullish added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Nullish() *ZodIntegerTyped[T, *T]

Nullish combines optional and nilable modifiers.

func (*ZodIntegerTyped[T, R]) Optional added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Optional() *ZodIntegerTyped[T, *T]

Optional returns a schema that accepts T or nil, with constraint type *T.

func (*ZodIntegerTyped[T, R]) Or added in v0.5.4

func (z *ZodIntegerTyped[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

Example:

schema := gozod.Int().Or(gozod.String())
result, _ := schema.Parse(42)

func (*ZodIntegerTyped[T, R]) Overwrite added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Overwrite(
	transform func(T) T,
	params ...any,
) *ZodIntegerTyped[T, R]

Overwrite transforms the input value while preserving the original type.

func (*ZodIntegerTyped[T, R]) Parse added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Parse(
	input any,
	ctx ...*core.ParseContext,
) (R, error)

Parse validates input and returns a value matching the constraint type R.

func (*ZodIntegerTyped[T, R]) ParseAny added in v0.3.0

func (z *ZodIntegerTyped[T, R]) ParseAny(
	input any,
	ctx ...*core.ParseContext,
) (any, error)

ParseAny validates input and returns an untyped result for runtime scenarios.

func (*ZodIntegerTyped[T, R]) Pipe added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Pipe(
	target core.ZodType[any],
) *core.ZodPipe[R, any]

Pipe creates a validation pipeline to another schema.

func (*ZodIntegerTyped[T, R]) Positive added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Positive(params ...any) *ZodIntegerTyped[T, R]

Positive adds positive number validation (> 0).

func (*ZodIntegerTyped[T, R]) Prefault added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Prefault(v int64) *ZodIntegerTyped[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodIntegerTyped[T, R]) PrefaultFunc added in v0.3.0

func (z *ZodIntegerTyped[T, R]) PrefaultFunc(fn func() R) *ZodIntegerTyped[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodIntegerTyped[T, R]) Refine added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Refine(
	fn func(T) bool,
	params ...any,
) *ZodIntegerTyped[T, R]

Refine applies type-safe custom validation using the base type T.

func (*ZodIntegerTyped[T, R]) RefineAny added in v0.3.0

func (z *ZodIntegerTyped[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodIntegerTyped[T, R]

RefineAny adds flexible custom validation using an untyped function.

func (*ZodIntegerTyped[T, R]) Safe added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Safe(params ...any) *ZodIntegerTyped[T, R]

Safe adds safe integer validation (within JavaScript safe integer range).

func (*ZodIntegerTyped[T, R]) Step added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Step(step int64, params ...any) *ZodIntegerTyped[T, R]

Step adds step validation (alias for MultipleOf).

func (*ZodIntegerTyped[T, R]) StrictParse added in v0.4.0

func (z *ZodIntegerTyped[T, R]) StrictParse(
	input R,
	ctx ...*core.ParseContext,
) (R, error)

StrictParse validates input with compile-time type safety by requiring exact type matching.

func (*ZodIntegerTyped[T, R]) Transform added in v0.3.0

func (z *ZodIntegerTyped[T, R]) Transform(
	fn func(int64, *core.RefinementContext) (any, error),
) *core.ZodTransform[R, any]

Transform applies a transformation function that extracts int64 values.

func (*ZodIntegerTyped[T, R]) With added in v0.5.4

func (z *ZodIntegerTyped[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodIntegerTyped[T, R]

With is an alias for Check (Zod v4 API compatibility).

type ZodIntersection

type ZodIntersection[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodIntersection is an intersection validation schema with dual generic parameters. T is the base type (any) and R is the constraint type (any or *any).

func Intersection

func Intersection(left, right any, args ...any) *ZodIntersection[any, any]

Intersection creates an intersection schema with value constraint.

func IntersectionPtr added in v0.3.0

func IntersectionPtr(left, right any, args ...any) *ZodIntersection[any, *any]

IntersectionPtr creates an intersection schema with pointer constraint.

func IntersectionTyped added in v0.3.0

func IntersectionTyped[T any, R any](left, right any, args ...any) *ZodIntersection[T, R]

IntersectionTyped creates a typed intersection schema with generic constraints.

func (*ZodIntersection[T, R]) And added in v0.5.4

func (i *ZodIntersection[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

Example:

schema := gozod.String().Min(3).And(gozod.String().Max(10))
result, _ := schema.Parse("hello")

func (*ZodIntersection[T, R]) CloneFrom

func (i *ZodIntersection[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodIntersection[T, R]) Default

func (i *ZodIntersection[T, R]) Default(v T) *ZodIntersection[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodIntersection[T, R]) DefaultFunc

func (i *ZodIntersection[T, R]) DefaultFunc(fn func() T) *ZodIntersection[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodIntersection[T, R]) Describe added in v0.5.4

func (i *ZodIntersection[T, R]) Describe(description string) *ZodIntersection[T, R]

Describe registers a description in the global registry.

func (*ZodIntersection[T, R]) Internals added in v0.6.0

func (i *ZodIntersection[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodIntersection[T, R]) IsNilable added in v0.3.0

func (i *ZodIntersection[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodIntersection[T, R]) IsOptional added in v0.3.0

func (i *ZodIntersection[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodIntersection[T, R]) Left

func (i *ZodIntersection[T, R]) Left() core.ZodSchema

Left returns the left schema of the intersection.

func (*ZodIntersection[T, R]) Meta added in v0.3.1

func (i *ZodIntersection[T, R]) Meta(meta core.GlobalMeta) *ZodIntersection[T, R]

Meta stores metadata for this schema.

func (*ZodIntersection[T, R]) MustParse

func (i *ZodIntersection[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse panics if Parse returns an error.

func (*ZodIntersection[T, R]) MustStrictParse added in v0.4.0

func (i *ZodIntersection[T, R]) MustStrictParse(input T, ctx ...*core.ParseContext) R

MustStrictParse panics if StrictParse returns an error.

func (*ZodIntersection[T, R]) Nilable

func (i *ZodIntersection[T, R]) Nilable() *ZodIntersection[T, *T]

Nilable returns a schema that accepts T or nil, with constraint type *T.

func (*ZodIntersection[T, R]) NonOptional added in v0.3.0

func (i *ZodIntersection[T, R]) NonOptional() *ZodIntersection[T, T]

NonOptional removes the optional flag and returns a value constraint (T).

func (*ZodIntersection[T, R]) Nullish

func (i *ZodIntersection[T, R]) Nullish() *ZodIntersection[T, *T]

Nullish combines optional and nilable modifiers.

func (*ZodIntersection[T, R]) Optional

func (i *ZodIntersection[T, R]) Optional() *ZodIntersection[T, *T]

Optional returns a schema that accepts T or nil, with constraint type *T.

func (*ZodIntersection[T, R]) Or added in v0.5.4

func (i *ZodIntersection[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

Example:

schema := gozod.String().And(gozod.String().Min(3)).Or(gozod.Int())

func (*ZodIntersection[T, R]) Parse

func (i *ZodIntersection[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input using engine.ParseComplex for unified Default/Prefault handling.

func (*ZodIntersection[T, R]) ParseAny added in v0.3.0

func (i *ZodIntersection[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result for runtime scenarios.

func (*ZodIntersection[T, R]) Pipe

func (i *ZodIntersection[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a validation pipeline to another schema.

func (*ZodIntersection[T, R]) Prefault

func (i *ZodIntersection[T, R]) Prefault(v T) *ZodIntersection[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodIntersection[T, R]) PrefaultFunc

func (i *ZodIntersection[T, R]) PrefaultFunc(fn func() T) *ZodIntersection[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodIntersection[T, R]) Refine

func (i *ZodIntersection[T, R]) Refine(fn func(R) bool, params ...any) *ZodIntersection[T, R]

Refine applies type-safe validation with constraint type R.

func (*ZodIntersection[T, R]) RefineAny

func (i *ZodIntersection[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodIntersection[T, R]

RefineAny applies flexible validation without type conversion.

func (*ZodIntersection[T, R]) Right

func (i *ZodIntersection[T, R]) Right() core.ZodSchema

Right returns the right schema of the intersection.

func (*ZodIntersection[T, R]) StrictParse added in v0.4.0

func (i *ZodIntersection[T, R]) StrictParse(input T, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodIntersection[T, R]) Transform

func (i *ZodIntersection[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform creates a type-safe transformation pipeline.

type ZodIntersectionDef

type ZodIntersectionDef struct {
	core.ZodTypeDef
	Left  core.ZodSchema
	Right core.ZodSchema
}

ZodIntersectionDef is the configuration for intersection validation.

type ZodIntersectionInternals

type ZodIntersectionInternals struct {
	core.ZodTypeInternals
	Def   *ZodIntersectionDef
	Left  core.ZodSchema
	Right core.ZodSchema
}

ZodIntersectionInternals holds the internal state of an intersection validator.

type ZodIso added in v0.3.0

type ZodIso[T IsoConstraint] struct{ *ZodString[T] }

ZodIso validates ISO 8601 formatted strings (datetime, date, time, duration).

func Iso added in v0.3.0

func Iso(params ...any) *ZodIso[string]

Iso creates a base ISO string schema without format-specific validation.

func IsoDate added in v0.3.0

func IsoDate(params ...any) *ZodIso[string]

IsoDate creates a schema validating ISO 8601 date strings (YYYY-MM-DD).

func IsoDatePtr added in v0.3.0

func IsoDatePtr(params ...any) *ZodIso[*string]

IsoDatePtr creates a pointer ISO 8601 date schema.

func IsoDateTime added in v0.3.0

func IsoDateTime(params ...any) *ZodIso[string]

IsoDateTime creates a schema validating ISO 8601 datetime strings.

func IsoDateTimePtr added in v0.3.0

func IsoDateTimePtr(params ...any) *ZodIso[*string]

IsoDateTimePtr creates a pointer ISO 8601 datetime schema.

func IsoDateTimeTyped added in v0.3.0

func IsoDateTimeTyped[T IsoConstraint](params ...any) *ZodIso[T]

IsoDateTimeTyped creates a typed ISO 8601 datetime schema.

func IsoDateTyped added in v0.3.0

func IsoDateTyped[T IsoConstraint](params ...any) *ZodIso[T]

IsoDateTyped creates a typed ISO 8601 date schema.

func IsoDuration added in v0.3.0

func IsoDuration(params ...any) *ZodIso[string]

IsoDuration creates a schema validating ISO 8601 duration strings.

func IsoDurationPtr added in v0.3.0

func IsoDurationPtr(params ...any) *ZodIso[*string]

IsoDurationPtr creates a pointer ISO 8601 duration schema.

func IsoDurationTyped added in v0.3.0

func IsoDurationTyped[T IsoConstraint](params ...any) *ZodIso[T]

IsoDurationTyped creates a typed ISO 8601 duration schema.

func IsoPtr added in v0.3.0

func IsoPtr(params ...any) *ZodIso[*string]

IsoPtr creates a pointer ISO string schema.

func IsoTime added in v0.3.0

func IsoTime(params ...any) *ZodIso[string]

IsoTime creates a schema validating ISO 8601 time strings (HH:MM:SS).

func IsoTimePtr added in v0.3.0

func IsoTimePtr(params ...any) *ZodIso[*string]

IsoTimePtr creates a pointer ISO 8601 time schema.

func IsoTimeTyped added in v0.3.0

func IsoTimeTyped[T IsoConstraint](params ...any) *ZodIso[T]

IsoTimeTyped creates a typed ISO 8601 time schema.

func IsoTyped added in v0.3.0

func IsoTyped[T IsoConstraint](params ...any) *ZodIso[T]

IsoTyped creates a typed ISO string schema.

func (*ZodIso[T]) Date added in v0.3.0

func (z *ZodIso[T]) Date(params ...any) *ZodIso[T]

Date adds ISO 8601 date validation.

func (*ZodIso[T]) DateTime added in v0.3.0

func (z *ZodIso[T]) DateTime(opts ...IsoDatetimeOptions) *ZodIso[T]

DateTime adds ISO 8601 datetime validation.

func (*ZodIso[T]) Default added in v0.3.0

func (z *ZodIso[T]) Default(v string) *ZodIso[T]

Default uses v when input is nil, bypassing validation.

func (*ZodIso[T]) DefaultFunc added in v0.3.0

func (z *ZodIso[T]) DefaultFunc(fn func() string) *ZodIso[T]

DefaultFunc calls fn when input is nil, bypassing validation.

func (*ZodIso[T]) Describe added in v0.10.5

func (z *ZodIso[T]) Describe(description string) *ZodIso[T]

Describe attaches a description to this schema via the global registry.

func (*ZodIso[T]) Duration added in v0.3.0

func (z *ZodIso[T]) Duration(params ...any) *ZodIso[T]

Duration adds ISO 8601 duration validation.

func (*ZodIso[T]) Internals added in v0.6.0

func (z *ZodIso[T]) Internals() *core.ZodTypeInternals

Internals returns the schema's internal configuration.

func (*ZodIso[T]) Max added in v0.3.0

func (z *ZodIso[T]) Max(v string, params ...any) *ZodIso[T]

Max validates the ISO string is <= v using lexicographic comparison.

func (*ZodIso[T]) Meta added in v0.10.5

func (z *ZodIso[T]) Meta(meta core.GlobalMeta) *ZodIso[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodIso[T]) Min added in v0.3.0

func (z *ZodIso[T]) Min(v string, params ...any) *ZodIso[T]

Min validates the ISO string is >= v using lexicographic comparison.

func (*ZodIso[T]) MustStrictParse added in v0.4.0

func (z *ZodIso[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodIso[T]) Nilable added in v0.3.0

func (z *ZodIso[T]) Nilable() *ZodIso[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodIso[T]) Nullish added in v0.3.0

func (z *ZodIso[T]) Nullish() *ZodIso[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodIso[T]) Optional added in v0.3.0

func (z *ZodIso[T]) Optional() *ZodIso[*string]

Optional returns a new schema that accepts nil values.

func (*ZodIso[T]) Prefault added in v0.3.0

func (z *ZodIso[T]) Prefault(v string) *ZodIso[T]

Prefault uses v when input is nil, running through full validation.

func (*ZodIso[T]) PrefaultFunc added in v0.3.0

func (z *ZodIso[T]) PrefaultFunc(fn func() string) *ZodIso[T]

PrefaultFunc calls fn when input is nil, running through full validation.

func (*ZodIso[T]) RefineAny added in v0.10.5

func (z *ZodIso[T]) RefineAny(fn func(any) bool, params ...any) *ZodIso[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodIso[T]) StrictParse added in v0.4.0

func (z *ZodIso[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

func (*ZodIso[T]) Time added in v0.3.0

func (z *ZodIso[T]) Time(opts ...IsoTimeOptions) *ZodIso[T]

Time adds ISO 8601 time validation.

type ZodJWT added in v0.3.0

type ZodJWT[T StringConstraint] struct {
	*ZodString[T]
}

ZodJWT validates strings in JWT (JSON Web Token) format. String modifiers (Min, Max, StartsWith, etc.) are promoted from the embedded *ZodString[T].

func JWT added in v0.3.0

func JWT(params ...any) *ZodJWT[string]

JWT creates a JWT token validation schema.

JWT()                                                - basic structure validation
JWT("error message")                                 - with custom error message
JWT(JWTOptions{Algorithm: "HS256"})                  - with algorithm constraint
JWT(JWTOptions{Algorithm: "HS256"}, "error message") - options with error message

func JWTPtr added in v0.3.0

func JWTPtr(params ...any) *ZodJWT[*string]

JWTPtr creates a pointer JWT token validation schema.

func JWTTyped added in v0.3.0

func JWTTyped[T StringConstraint](params ...any) *ZodJWT[T]

JWTTyped creates a JWT token validation schema for a specific type.

func (*ZodJWT[T]) Default added in v0.10.5

func (z *ZodJWT[T]) Default(v string) *ZodJWT[T]

Default sets a fallback value returned when input is nil.

func (*ZodJWT[T]) DefaultFunc added in v0.10.5

func (z *ZodJWT[T]) DefaultFunc(fn func() string) *ZodJWT[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodJWT[T]) Describe added in v0.10.5

func (z *ZodJWT[T]) Describe(description string) *ZodJWT[T]

Describe attaches a description to this schema via the global registry.

func (*ZodJWT[T]) Meta added in v0.10.5

func (z *ZodJWT[T]) Meta(meta core.GlobalMeta) *ZodJWT[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodJWT[T]) MustStrictParse added in v0.4.0

func (z *ZodJWT[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodJWT[T]) Nilable added in v0.6.0

func (z *ZodJWT[T]) Nilable() *ZodJWT[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodJWT[T]) Nullish added in v0.6.0

func (z *ZodJWT[T]) Nullish() *ZodJWT[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodJWT[T]) Optional added in v0.6.0

func (z *ZodJWT[T]) Optional() *ZodJWT[*string]

Optional returns a new schema that accepts nil values.

func (*ZodJWT[T]) Prefault added in v0.10.5

func (z *ZodJWT[T]) Prefault(v string) *ZodJWT[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodJWT[T]) PrefaultFunc added in v0.10.5

func (z *ZodJWT[T]) PrefaultFunc(fn func() string) *ZodJWT[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodJWT[T]) RefineAny added in v0.10.5

func (z *ZodJWT[T]) RefineAny(fn func(any) bool, params ...any) *ZodJWT[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodJWT[T]) StrictParse added in v0.4.0

func (z *ZodJWT[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodKSUID added in v0.3.0

type ZodKSUID[T StringConstraint] struct{ *ZodString[T] }

ZodKSUID validates strings in KSUID format.

func KSUID added in v0.7.0

func KSUID(params ...any) *ZodKSUID[string]

KSUID creates a KSUID schema.

func KSUIDPtr added in v0.7.0

func KSUIDPtr(params ...any) *ZodKSUID[*string]

KSUIDPtr creates a pointer KSUID schema.

func (*ZodKSUID[T]) Default added in v0.10.5

func (z *ZodKSUID[T]) Default(v string) *ZodKSUID[T]

Default sets a fallback value returned when input is nil.

func (*ZodKSUID[T]) DefaultFunc added in v0.10.5

func (z *ZodKSUID[T]) DefaultFunc(fn func() string) *ZodKSUID[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodKSUID[T]) Describe added in v0.10.5

func (z *ZodKSUID[T]) Describe(description string) *ZodKSUID[T]

Describe attaches a description to this schema via the global registry.

func (*ZodKSUID[T]) Meta added in v0.10.5

func (z *ZodKSUID[T]) Meta(meta core.GlobalMeta) *ZodKSUID[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodKSUID[T]) MustStrictParse added in v0.4.0

func (z *ZodKSUID[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodKSUID[T]) Nilable added in v0.6.0

func (z *ZodKSUID[T]) Nilable() *ZodKSUID[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodKSUID[T]) Nullish added in v0.6.0

func (z *ZodKSUID[T]) Nullish() *ZodKSUID[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodKSUID[T]) Optional added in v0.6.0

func (z *ZodKSUID[T]) Optional() *ZodKSUID[*string]

Optional returns a new schema that accepts nil values.

func (*ZodKSUID[T]) Prefault added in v0.10.5

func (z *ZodKSUID[T]) Prefault(v string) *ZodKSUID[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodKSUID[T]) PrefaultFunc added in v0.10.5

func (z *ZodKSUID[T]) PrefaultFunc(fn func() string) *ZodKSUID[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodKSUID[T]) RefineAny added in v0.10.5

func (z *ZodKSUID[T]) RefineAny(fn func(any) bool, params ...any) *ZodKSUID[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodKSUID[T]) StrictParse added in v0.4.0

func (z *ZodKSUID[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodLazy

type ZodLazy[T LazyConstraint] struct {
	// contains filtered or unexported fields
}

ZodLazy is a lazy validation schema for recursive type definitions.

func LazyAny added in v0.3.0

func LazyAny(getter func() any, params ...any) *ZodLazy[any]

LazyAny creates a lazy schema that defers evaluation until needed.

func LazyPtr added in v0.3.0

func LazyPtr(getter func() any, params ...any) *ZodLazy[*any]

LazyPtr creates a lazy schema for *any type.

func LazyTyped added in v0.3.0

func LazyTyped[T LazyConstraint](getter func() any, params ...any) *ZodLazy[T]

LazyTyped is the underlying generic constructor for lazy schemas.

func (*ZodLazy[T]) CloneFrom

func (z *ZodLazy[T]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodLazy[T]) Coerce

func (z *ZodLazy[T]) Coerce(input any) (any, bool)

Coerce delegates coercion to the inner schema.

func (*ZodLazy[T]) Default

func (z *ZodLazy[T]) Default(v any) *ZodLazy[T]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodLazy[T]) DefaultFunc

func (z *ZodLazy[T]) DefaultFunc(fn func() any) *ZodLazy[T]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodLazy[T]) Describe added in v0.5.4

func (z *ZodLazy[T]) Describe(description string) *ZodLazy[T]

Describe registers a description in the global registry.

func (*ZodLazy[T]) Internals added in v0.6.0

func (z *ZodLazy[T]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodLazy[T]) IsNilable added in v0.3.0

func (z *ZodLazy[T]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodLazy[T]) IsOptional added in v0.3.0

func (z *ZodLazy[T]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodLazy[T]) Meta added in v0.3.1

func (z *ZodLazy[T]) Meta(meta core.GlobalMeta) *ZodLazy[T]

Meta stores metadata for this lazy schema.

func (*ZodLazy[T]) MustParse

func (z *ZodLazy[T]) MustParse(input any, ctx ...*core.ParseContext) T

MustParse validates input and panics on error.

func (*ZodLazy[T]) MustStrictParse added in v0.4.0

func (z *ZodLazy[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates with strict type matching and panics on error.

func (*ZodLazy[T]) Nilable

func (z *ZodLazy[T]) Nilable() *ZodLazy[*any]

Nilable returns a schema that accepts nil, with constraint type *any.

func (*ZodLazy[T]) NonOptional added in v0.3.0

func (z *ZodLazy[T]) NonOptional() *ZodLazy[any]

NonOptional removes the Optional flag and enforces non-nil value.

func (*ZodLazy[T]) Nullish

func (z *ZodLazy[T]) Nullish() *ZodLazy[*any]

Nullish combines optional and nilable modifiers.

func (*ZodLazy[T]) Optional

func (z *ZodLazy[T]) Optional() *ZodLazy[*any]

Optional returns a schema that accepts nil, with constraint type *any.

func (*ZodLazy[T]) Parse

func (z *ZodLazy[T]) Parse(input any, ctx ...*core.ParseContext) (T, error)

Parse validates and returns the parsed value using lazy evaluation.

func (*ZodLazy[T]) ParseAny added in v0.3.0

func (z *ZodLazy[T]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodLazy[T]) Pipe

func (z *ZodLazy[T]) Pipe(target core.ZodType[any]) *core.ZodPipe[T, any]

Pipe creates a validation pipeline to another schema.

func (*ZodLazy[T]) Prefault

func (z *ZodLazy[T]) Prefault(v any) *ZodLazy[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodLazy[T]) PrefaultFunc

func (z *ZodLazy[T]) PrefaultFunc(fn func() any) *ZodLazy[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodLazy[T]) Refine

func (z *ZodLazy[T]) Refine(fn func(T) bool, params ...any) *ZodLazy[T]

Refine adds a typed custom validation function.

func (*ZodLazy[T]) RefineAny

func (z *ZodLazy[T]) RefineAny(fn func(any) bool, params ...any) *ZodLazy[T]

RefineAny adds a custom validation function accepting any input.

func (*ZodLazy[T]) StrictParse added in v0.4.0

func (z *ZodLazy[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse requires exact type matching for compile-time safety.

func (*ZodLazy[T]) Transform

func (z *ZodLazy[T]) Transform(fn func(any, *core.RefinementContext) (any, error)) *core.ZodTransform[T, any]

Transform creates a type-safe transformation pipeline.

func (*ZodLazy[T]) Unwrap

func (z *ZodLazy[T]) Unwrap() core.ZodType[any]

Unwrap resolves and returns the inner schema.

type ZodLazyDef

type ZodLazyDef struct {
	core.ZodTypeDef
	Getter func() any
}

ZodLazyDef is the configuration for lazy validation.

type ZodLazyInternals

type ZodLazyInternals struct {
	core.ZodTypeInternals
	Def    *ZodLazyDef
	Getter func() any
	// contains filtered or unexported fields
}

ZodLazyInternals holds the internal state of a lazy validator.

type ZodLazyTyped added in v0.3.0

type ZodLazyTyped[S ZodSchemaType] struct {
	*ZodLazy[any]
	// contains filtered or unexported fields
}

ZodLazyTyped is a type-safe wrapper that preserves the inner schema type.

func Lazy

func Lazy[S ZodSchemaType](getter func() S, params ...any) *ZodLazyTyped[S]

Lazy creates a type-safe lazy schema with compile-time type checking.

func (*ZodLazyTyped[S]) Default added in v0.3.0

func (z *ZodLazyTyped[S]) Default(v any) *ZodLazyTyped[S]

Default sets a value returned when input is nil, bypassing validation.

func (*ZodLazyTyped[S]) InnerSchema added in v0.6.0

func (z *ZodLazyTyped[S]) InnerSchema() S

InnerSchema returns the inner schema with its original type.

func (*ZodLazyTyped[S]) MustParse added in v0.3.0

func (z *ZodLazyTyped[S]) MustParse(input any, ctx ...*core.ParseContext) any

MustParse validates input and panics on error.

func (*ZodLazyTyped[S]) Nilable added in v0.3.0

func (z *ZodLazyTyped[S]) Nilable() *ZodLazy[*any]

Nilable returns a schema that accepts nil.

func (*ZodLazyTyped[S]) NonOptional added in v0.3.0

func (z *ZodLazyTyped[S]) NonOptional() *ZodLazy[any]

NonOptional removes the Optional flag and enforces non-nil value.

func (*ZodLazyTyped[S]) Optional added in v0.3.0

func (z *ZodLazyTyped[S]) Optional() *ZodLazy[*any]

Optional returns a schema that accepts nil.

func (*ZodLazyTyped[S]) Parse added in v0.3.0

func (z *ZodLazyTyped[S]) Parse(input any, ctx ...*core.ParseContext) (any, error)

Parse validates and returns the parsed value with type safety.

func (*ZodLazyTyped[S]) Refine added in v0.3.0

func (z *ZodLazyTyped[S]) Refine(fn func(any) bool, params ...any) *ZodLazyTyped[S]

Refine adds a custom validation function.

type ZodLiteral

type ZodLiteral[T comparable, R any] struct {
	// contains filtered or unexported fields
}

ZodLiteral represents a literal validation schema for exact value matching.

func Literal

func Literal[T comparable](value T, params ...any) *ZodLiteral[T, T]

Literal creates a literal schema for a single value with type inference.

func LiteralOf added in v0.3.0

func LiteralOf[T comparable](values []T, params ...any) *ZodLiteral[T, T]

LiteralOf creates a multi-value literal schema with type inference.

func LiteralPtr added in v0.3.0

func LiteralPtr[T comparable](value T, params ...any) *ZodLiteral[T, *T]

LiteralPtr creates a literal schema for a single value with a pointer return type.

func LiteralPtrOf added in v0.3.0

func LiteralPtrOf[T comparable](values []T, params ...any) *ZodLiteral[T, *T]

LiteralPtrOf creates a multi-value literal schema with a pointer return type.

func LiteralTyped added in v0.3.0

func LiteralTyped[T comparable, R any](value T, params ...any) *ZodLiteral[T, R]

LiteralTyped creates a literal schema with explicit type parameters.

func (*ZodLiteral[T, R]) Contains added in v0.3.0

func (z *ZodLiteral[T, R]) Contains(v T) bool

Contains reports whether v is one of the allowed literal values.

func (*ZodLiteral[T, R]) Default

func (z *ZodLiteral[T, R]) Default(v T) *ZodLiteral[T, R]

Default sets a default value returned when input is nil, bypassing validation.

func (*ZodLiteral[T, R]) DefaultFunc

func (z *ZodLiteral[T, R]) DefaultFunc(fn func() T) *ZodLiteral[T, R]

DefaultFunc sets a factory function that provides the default value when input is nil.

func (*ZodLiteral[T, R]) Describe added in v0.6.0

func (z *ZodLiteral[T, R]) Describe(description string) *ZodLiteral[T, R]

Describe registers a description in the global registry.

func (*ZodLiteral[T, R]) Internals added in v0.6.0

func (z *ZodLiteral[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodLiteral[T, R]) IsNilable added in v0.3.0

func (z *ZodLiteral[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodLiteral[T, R]) IsOptional added in v0.3.0

func (z *ZodLiteral[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodLiteral[T, R]) Meta added in v0.6.0

func (z *ZodLiteral[T, R]) Meta(meta core.GlobalMeta) *ZodLiteral[T, R]

Meta stores metadata for this literal schema.

func (*ZodLiteral[T, R]) MustParse

func (z *ZodLiteral[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates input and panics on error.

func (*ZodLiteral[T, R]) MustParseAny added in v0.3.1

func (z *ZodLiteral[T, R]) MustParseAny(input any, ctx ...*core.ParseContext) any

MustParseAny validates input and panics on error, returning an untyped result.

func (*ZodLiteral[T, R]) MustStrictParse added in v0.4.0

func (z *ZodLiteral[T, R]) MustStrictParse(input R, ctx ...*core.ParseContext) R

MustStrictParse validates input with strict type matching and panics on error.

func (*ZodLiteral[T, R]) Nilable

func (z *ZodLiteral[T, R]) Nilable() *ZodLiteral[T, *T]

Nilable returns a schema that accepts nil, with constraint type *T.

func (*ZodLiteral[T, R]) Nullish

func (z *ZodLiteral[T, R]) Nullish() *ZodLiteral[T, *T]

Nullish combines optional and nilable modifiers for maximum flexibility.

func (*ZodLiteral[T, R]) Optional

func (z *ZodLiteral[T, R]) Optional() *ZodLiteral[T, *T]

Optional returns a schema that accepts nil, with constraint type *T.

func (*ZodLiteral[T, R]) Parse

func (z *ZodLiteral[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates the input value and returns a typed result.

func (*ZodLiteral[T, R]) ParseAny added in v0.3.0

func (z *ZodLiteral[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result for runtime scenarios.

func (*ZodLiteral[T, R]) Prefault

func (z *ZodLiteral[T, R]) Prefault(v T) *ZodLiteral[T, R]

Prefault sets a prefault value that goes through full parsing when input is nil.

func (*ZodLiteral[T, R]) PrefaultFunc

func (z *ZodLiteral[T, R]) PrefaultFunc(fn func() T) *ZodLiteral[T, R]

PrefaultFunc sets a factory function that provides the prefault value through full parsing.

func (*ZodLiteral[T, R]) Refine

func (z *ZodLiteral[T, R]) Refine(fn func(T) bool, params ...any) *ZodLiteral[T, R]

Refine adds a typed custom validation function.

func (*ZodLiteral[T, R]) RefineAny

func (z *ZodLiteral[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodLiteral[T, R]

RefineAny adds a flexible custom validation function accepting any input.

func (*ZodLiteral[T, R]) StrictParse added in v0.4.0

func (z *ZodLiteral[T, R]) StrictParse(input R, ctx ...*core.ParseContext) (R, error)

StrictParse provides compile-time type safety by requiring exact type matching.

func (*ZodLiteral[T, R]) Value

func (z *ZodLiteral[T, R]) Value() T

Value returns the single literal value. Panics if the schema has multiple values.

func (*ZodLiteral[T, R]) Values added in v0.3.0

func (z *ZodLiteral[T, R]) Values() []T

Values returns all literal values.

type ZodLiteralDef

type ZodLiteralDef[T comparable] struct {
	core.ZodTypeDef
	Values []T
}

ZodLiteralDef defines the configuration for a literal schema.

type ZodLiteralInternals

type ZodLiteralInternals[T comparable] struct {
	core.ZodTypeInternals
	Def *ZodLiteralDef[T]
}

ZodLiteralInternals contains literal validator internal state.

type ZodMAC added in v0.5.4

type ZodMAC[T StringConstraint] struct{ *ZodString[T] }

ZodMAC validates strings in MAC address format.

func CoercedMAC added in v0.6.0

func CoercedMAC(params ...any) *ZodMAC[string]

CoercedMAC creates a coerced MAC schema that attempts string conversion.

func MAC added in v0.5.4

func MAC(params ...any) *ZodMAC[string]

MAC creates a MAC address validation schema. Accepts optional delimiter string as first parameter (default: any standard delimiter).

func MACPtr added in v0.5.4

func MACPtr(params ...any) *ZodMAC[*string]

MACPtr creates a pointer MAC address validation schema. Accepts optional delimiter string as first parameter (default: any standard delimiter).

func MACTyped added in v0.5.4

func MACTyped[T StringConstraint](params ...any) *ZodMAC[T]

MACTyped creates a MAC address validation schema with the given type constraint. Accepts optional delimiter string as first parameter (default: any standard delimiter).

func MACWithDelimiter added in v0.5.4

func MACWithDelimiter(delimiter string, params ...any) *ZodMAC[string]

MACWithDelimiter creates a MAC address validation schema with a specific delimiter.

func (*ZodMAC[T]) Default added in v0.5.4

func (z *ZodMAC[T]) Default(v string) *ZodMAC[T]

Default sets a fallback value returned when input is nil.

func (*ZodMAC[T]) DefaultFunc added in v0.10.5

func (z *ZodMAC[T]) DefaultFunc(fn func() string) *ZodMAC[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodMAC[T]) Describe added in v0.5.4

func (z *ZodMAC[T]) Describe(description string) *ZodMAC[T]

Describe attaches a description to this schema via the global registry.

func (*ZodMAC[T]) Meta added in v0.10.5

func (z *ZodMAC[T]) Meta(meta core.GlobalMeta) *ZodMAC[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodMAC[T]) MustStrictParse added in v0.5.4

func (z *ZodMAC[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodMAC[T]) Nilable added in v0.5.4

func (z *ZodMAC[T]) Nilable() *ZodMAC[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodMAC[T]) Nullish added in v0.6.0

func (z *ZodMAC[T]) Nullish() *ZodMAC[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodMAC[T]) Optional added in v0.5.4

func (z *ZodMAC[T]) Optional() *ZodMAC[*string]

Optional returns a new schema that accepts nil values.

func (*ZodMAC[T]) Prefault added in v0.10.5

func (z *ZodMAC[T]) Prefault(v string) *ZodMAC[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodMAC[T]) PrefaultFunc added in v0.10.5

func (z *ZodMAC[T]) PrefaultFunc(fn func() string) *ZodMAC[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodMAC[T]) RefineAny added in v0.5.7

func (z *ZodMAC[T]) RefineAny(fn func(any) bool, params ...any) *ZodMAC[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodMAC[T]) StrictParse added in v0.5.4

func (z *ZodMAC[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodMap

type ZodMap[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodMap is a type-safe map validation schema. T is the base type, R is the constraint type (value or pointer).

func Map

func Map(keySchema, valueSchema any, paramArgs ...any) *ZodMap[map[any]any, map[any]any]

Map creates a map schema with key and value validation returning a value constraint.

func MapPtr added in v0.3.0

func MapPtr(keySchema, valueSchema any, paramArgs ...any) *ZodMap[map[any]any, *map[any]any]

MapPtr creates a map schema returning a pointer constraint.

func MapTyped added in v0.3.0

func MapTyped[T any, R any](keySchema, valueSchema any, paramArgs ...any) *ZodMap[T, R]

MapTyped creates a typed map schema with explicit generic constraints.

func (*ZodMap[T, R]) Check

func (z *ZodMap[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodMap[T, R]

Check adds a custom validation function that can report multiple issues.

func (*ZodMap[T, R]) CloneFrom

func (z *ZodMap[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema of the same type.

func (*ZodMap[T, R]) Default

func (z *ZodMap[T, R]) Default(v T) *ZodMap[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodMap[T, R]) DefaultFunc

func (z *ZodMap[T, R]) DefaultFunc(fn func() T) *ZodMap[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodMap[T, R]) Describe added in v0.5.4

func (z *ZodMap[T, R]) Describe(description string) *ZodMap[T, R]

Describe registers a description in the global registry.

func (*ZodMap[T, R]) Internals added in v0.6.0

func (z *ZodMap[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodMap[T, R]) IsNilable added in v0.3.0

func (z *ZodMap[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodMap[T, R]) IsOptional added in v0.3.0

func (z *ZodMap[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodMap[T, R]) KeyType added in v0.3.1

func (z *ZodMap[T, R]) KeyType() any

KeyType returns the key schema for this map.

func (*ZodMap[T, R]) Length

func (z *ZodMap[T, R]) Length(exactLen int, params ...any) *ZodMap[T, R]

Length sets the exact number of entries required.

func (*ZodMap[T, R]) Max

func (z *ZodMap[T, R]) Max(maxLen int, params ...any) *ZodMap[T, R]

Max sets the maximum number of entries.

func (*ZodMap[T, R]) Meta added in v0.3.1

func (z *ZodMap[T, R]) Meta(meta core.GlobalMeta) *ZodMap[T, R]

Meta stores metadata for this map schema.

func (*ZodMap[T, R]) Min

func (z *ZodMap[T, R]) Min(minLen int, params ...any) *ZodMap[T, R]

Min sets the minimum number of entries.

func (*ZodMap[T, R]) MustParse

func (z *ZodMap[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates input and panics on error.

func (*ZodMap[T, R]) MustStrictParse added in v0.4.0

func (z *ZodMap[T, R]) MustStrictParse(input T, ctx ...*core.ParseContext) R

MustStrictParse validates input with type safety and panics on error.

func (*ZodMap[T, R]) Nilable

func (z *ZodMap[T, R]) Nilable() *ZodMap[T, *T]

Nilable returns a schema that accepts nil, with constraint type *T.

func (*ZodMap[T, R]) NonEmpty added in v0.5.4

func (z *ZodMap[T, R]) NonEmpty(params ...any) *ZodMap[T, R]

NonEmpty ensures the map has at least one entry. Equivalent to Min(1).

func (*ZodMap[T, R]) NonOptional added in v0.3.0

func (z *ZodMap[T, R]) NonOptional() *ZodMap[T, T]

NonOptional removes the Optional flag and returns base constraint type.

func (*ZodMap[T, R]) Nullish

func (z *ZodMap[T, R]) Nullish() *ZodMap[T, *T]

Nullish combines optional and nilable modifiers.

func (*ZodMap[T, R]) Optional

func (z *ZodMap[T, R]) Optional() *ZodMap[T, *T]

Optional returns a schema that accepts nil, with constraint type *T.

func (*ZodMap[T, R]) Overwrite added in v0.3.0

func (z *ZodMap[T, R]) Overwrite(transform func(R) R, params ...any) *ZodMap[T, R]

Overwrite transforms the value while preserving the original type.

func (*ZodMap[T, R]) Parse

func (z *ZodMap[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input using map-specific parsing logic.

func (*ZodMap[T, R]) ParseAny added in v0.3.0

func (z *ZodMap[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodMap[T, R]) Pipe

func (z *ZodMap[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a pipeline that passes the parsed result to a target schema.

func (*ZodMap[T, R]) Prefault

func (z *ZodMap[T, R]) Prefault(v T) *ZodMap[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodMap[T, R]) PrefaultFunc

func (z *ZodMap[T, R]) PrefaultFunc(fn func() T) *ZodMap[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodMap[T, R]) Refine

func (z *ZodMap[T, R]) Refine(fn func(R) bool, params ...any) *ZodMap[T, R]

Refine adds a typed custom validation function.

func (*ZodMap[T, R]) RefineAny

func (z *ZodMap[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodMap[T, R]

RefineAny adds a custom validation function accepting any input.

func (*ZodMap[T, R]) StrictParse added in v0.4.0

func (z *ZodMap[T, R]) StrictParse(input T, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodMap[T, R]) Transform

func (z *ZodMap[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed map value.

func (*ZodMap[T, R]) ValueType added in v0.3.1

func (z *ZodMap[T, R]) ValueType() any

ValueType returns the value schema for this map.

func (*ZodMap[T, R]) With added in v0.5.4

func (z *ZodMap[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodMap[T, R]

With is an alias for Check.

type ZodMapDef

type ZodMapDef struct {
	core.ZodTypeDef
	KeyType   any
	ValueType any
}

ZodMapDef is the configuration for a map schema.

type ZodMapInternals

type ZodMapInternals struct {
	core.ZodTypeInternals
	Def       *ZodMapDef
	KeyType   any
	ValueType any
}

ZodMapInternals holds the internal state of a map validator.

type ZodNanoID added in v0.3.0

type ZodNanoID[T StringConstraint] struct{ *ZodString[T] }

ZodNanoID validates strings in NanoID format.

func NanoID added in v0.7.0

func NanoID(params ...any) *ZodNanoID[string]

NanoID creates a NanoID schema.

func NanoIDPtr added in v0.7.0

func NanoIDPtr(params ...any) *ZodNanoID[*string]

NanoIDPtr creates a pointer NanoID schema.

func (*ZodNanoID[T]) Default added in v0.10.5

func (z *ZodNanoID[T]) Default(v string) *ZodNanoID[T]

Default sets a fallback value returned when input is nil.

func (*ZodNanoID[T]) DefaultFunc added in v0.10.5

func (z *ZodNanoID[T]) DefaultFunc(fn func() string) *ZodNanoID[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodNanoID[T]) Describe added in v0.10.5

func (z *ZodNanoID[T]) Describe(description string) *ZodNanoID[T]

Describe attaches a description to this schema via the global registry.

func (*ZodNanoID[T]) Meta added in v0.10.5

func (z *ZodNanoID[T]) Meta(meta core.GlobalMeta) *ZodNanoID[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodNanoID[T]) MustStrictParse added in v0.4.0

func (z *ZodNanoID[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodNanoID[T]) Nilable added in v0.6.0

func (z *ZodNanoID[T]) Nilable() *ZodNanoID[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodNanoID[T]) Nullish added in v0.6.0

func (z *ZodNanoID[T]) Nullish() *ZodNanoID[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodNanoID[T]) Optional added in v0.6.0

func (z *ZodNanoID[T]) Optional() *ZodNanoID[*string]

Optional returns a new schema that accepts nil values.

func (*ZodNanoID[T]) Prefault added in v0.10.5

func (z *ZodNanoID[T]) Prefault(v string) *ZodNanoID[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodNanoID[T]) PrefaultFunc added in v0.10.5

func (z *ZodNanoID[T]) PrefaultFunc(fn func() string) *ZodNanoID[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodNanoID[T]) RefineAny added in v0.10.5

func (z *ZodNanoID[T]) RefineAny(fn func(any) bool, params ...any) *ZodNanoID[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodNanoID[T]) StrictParse added in v0.4.0

func (z *ZodNanoID[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodNever

type ZodNever[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodNever represents a validation schema that always rejects input. T is the base type and R is the constraint type (may be a pointer for modifiers like Optional/Nilable).

func Never

func Never(params ...any) *ZodNever[any, any]

Never creates a never schema that always rejects input.

Usage:

Never()                    // no parameters
Never("custom error")      // string shorthand
Never(SchemaParams{...})   // full parameters

func NeverPtr added in v0.3.0

func NeverPtr(params ...any) *ZodNever[any, *any]

NeverPtr creates a never schema with pointer constraint type.

func NeverTyped added in v0.3.0

func NeverTyped[T any, R any](params ...any) *ZodNever[T, R]

NeverTyped creates a typed never schema with explicit generic constraints.

func (*ZodNever[T, R]) CloneFrom

func (z *ZodNever[T, R]) CloneFrom(source any)

CloneFrom copies the configuration from another schema of the same type.

func (*ZodNever[T, R]) Default added in v0.3.0

func (z *ZodNever[T, R]) Default(v T) *ZodNever[T, R]

Default sets a default value that is returned when the input is nil. The default value bypasses validation (short-circuit behavior).

func (*ZodNever[T, R]) DefaultFunc added in v0.3.0

func (z *ZodNever[T, R]) DefaultFunc(fn func() T) *ZodNever[T, R]

DefaultFunc sets a function that provides the default value when the input is nil. The default value bypasses validation (short-circuit behavior).

func (*ZodNever[T, R]) Describe added in v0.5.4

func (z *ZodNever[T, R]) Describe(description string) *ZodNever[T, R]

Describe registers a description for this schema in the global registry.

func (*ZodNever[T, R]) Internals added in v0.6.0

func (z *ZodNever[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodNever[T, R]) IsNilable added in v0.3.0

func (z *ZodNever[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodNever[T, R]) IsOptional added in v0.3.0

func (z *ZodNever[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts missing values.

func (*ZodNever[T, R]) Meta added in v0.3.1

func (z *ZodNever[T, R]) Meta(meta core.GlobalMeta) *ZodNever[T, R]

Meta stores metadata for this schema in the global registry.

func (*ZodNever[T, R]) MustParse

func (z *ZodNever[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates the input and panics on failure.

func (*ZodNever[T, R]) MustParseAny added in v0.6.0

func (z *ZodNever[T, R]) MustParseAny(input any, ctx ...*core.ParseContext) any

MustParseAny validates the input and panics on failure.

func (*ZodNever[T, R]) MustStrictParse added in v0.4.0

func (z *ZodNever[T, R]) MustStrictParse(input R, ctx ...*core.ParseContext) R

MustStrictParse requires exact type matching and panics on failure.

func (*ZodNever[T, R]) Nilable

func (z *ZodNever[T, R]) Nilable() *ZodNever[T, *T]

Nilable returns a pointer constraint that accepts nil values.

func (*ZodNever[T, R]) Nullish

func (z *ZodNever[T, R]) Nullish() *ZodNever[T, *T]

Nullish returns a pointer constraint that accepts both nil and missing values.

func (*ZodNever[T, R]) Optional

func (z *ZodNever[T, R]) Optional() *ZodNever[T, *T]

Optional returns a pointer constraint that accepts missing values.

func (*ZodNever[T, R]) Parse

func (z *ZodNever[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates the input and always rejects non-nil values.

func (*ZodNever[T, R]) ParseAny added in v0.3.0

func (z *ZodNever[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates the input and returns any type.

func (*ZodNever[T, R]) Pipe

func (z *ZodNever[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a validation pipeline with the given target schema.

func (*ZodNever[T, R]) Prefault added in v0.3.0

func (z *ZodNever[T, R]) Prefault(v T) *ZodNever[T, R]

Prefault sets a fallback value that is used when the input is nil. Unlike Default, the prefault value goes through the full parsing pipeline.

func (*ZodNever[T, R]) PrefaultFunc added in v0.3.0

func (z *ZodNever[T, R]) PrefaultFunc(fn func() T) *ZodNever[T, R]

PrefaultFunc sets a function that provides the fallback value when the input is nil. Unlike DefaultFunc, the prefault value goes through the full parsing pipeline.

func (*ZodNever[T, R]) Refine

func (z *ZodNever[T, R]) Refine(fn func(R) bool, params ...any) *ZodNever[T, R]

Refine adds a custom validation function that operates on the constraint type R.

func (*ZodNever[T, R]) RefineAny

func (z *ZodNever[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodNever[T, R]

RefineAny adds a custom validation function that operates on any type.

func (*ZodNever[T, R]) StrictParse added in v0.4.0

func (z *ZodNever[T, R]) StrictParse(input R, ctx ...*core.ParseContext) (R, error)

StrictParse requires exact type matching for compile-time type safety.

func (*ZodNever[T, R]) Transform

func (z *ZodNever[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed value.

func (*ZodNever[T, R]) Unwrap

func (z *ZodNever[T, R]) Unwrap() *ZodNever[T, R]

Unwrap returns the schema itself (implements unwrapping interface).

type ZodNeverDef

type ZodNeverDef struct {
	core.ZodTypeDef
}

ZodNeverDef defines the configuration for never validation.

type ZodNeverInternals

type ZodNeverInternals struct {
	core.ZodTypeInternals
	Def *ZodNeverDef
}

ZodNeverInternals contains the internal state for never validators.

type ZodNil

type ZodNil[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodNil is a type-safe nil validation schema. T is the base type and R is the constraint type (may be a pointer for modifiers like Optional/Nilable).

func Nil

func Nil(params ...any) *ZodNil[any, any]

Nil creates a nil schema that only accepts nil values.

Usage:

Nil()                    // no parameters
Nil("custom error")      // string shorthand
Nil(SchemaParams{...})   // full parameters

func NilPtr added in v0.3.0

func NilPtr(params ...any) *ZodNil[any, *any]

NilPtr creates a nil schema with pointer constraint.

func NilTyped added in v0.3.0

func NilTyped[T any, R any](params ...any) *ZodNil[T, R]

NilTyped is the generic constructor for nil schemas.

func (*ZodNil[T, R]) And added in v0.6.0

func (z *ZodNil[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodNil[T, R]) Check

func (z *ZodNil[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodNil[T, R]

Check adds a custom validation function that can push multiple issues.

func (*ZodNil[T, R]) CloneFrom

func (z *ZodNil[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema of the same type.

func (*ZodNil[T, R]) Default

func (z *ZodNil[T, R]) Default(v T) *ZodNil[T, R]

Default sets a fallback value returned when input is nil (short-circuits).

func (*ZodNil[T, R]) DefaultFunc

func (z *ZodNil[T, R]) DefaultFunc(fn func() T) *ZodNil[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits).

func (*ZodNil[T, R]) Describe added in v0.5.4

func (z *ZodNil[T, R]) Describe(desc string) *ZodNil[T, R]

Describe registers a description in the global registry.

func (*ZodNil[T, R]) ExactOptional added in v0.6.0

func (z *ZodNil[T, R]) ExactOptional() *ZodNil[T, R]

ExactOptional accepts absent keys but rejects explicit nil values.

func (*ZodNil[T, R]) Internals added in v0.6.0

func (z *ZodNil[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodNil[T, R]) IsNilable added in v0.3.0

func (z *ZodNil[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodNil[T, R]) IsOptional added in v0.3.0

func (z *ZodNil[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts missing values.

func (*ZodNil[T, R]) Meta added in v0.3.1

func (z *ZodNil[T, R]) Meta(meta core.GlobalMeta) *ZodNil[T, R]

Meta stores metadata in the global registry.

func (*ZodNil[T, R]) MustParse

func (z *ZodNil[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse panics on validation failure.

func (*ZodNil[T, R]) MustStrictParse added in v0.4.0

func (z *ZodNil[T, R]) MustStrictParse(input R, ctx ...*core.ParseContext) R

MustStrictParse panics on validation failure with compile-time type safety.

func (*ZodNil[T, R]) Nilable

func (z *ZodNil[T, R]) Nilable() *ZodNil[T, *T]

Nilable returns a schema that accepts nil values with pointer constraint.

func (*ZodNil[T, R]) NonOptional added in v0.6.0

func (z *ZodNil[T, R]) NonOptional() *ZodNil[T, T]

NonOptional removes the optional flag, returning a base constraint.

func (*ZodNil[T, R]) Nullish

func (z *ZodNil[T, R]) Nullish() *ZodNil[T, *T]

Nullish combines optional and nilable modifiers.

func (*ZodNil[T, R]) Optional

func (z *ZodNil[T, R]) Optional() *ZodNil[T, *T]

Optional returns a schema that accepts nil values with pointer constraint.

func (*ZodNil[T, R]) Or added in v0.6.0

func (z *ZodNil[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodNil[T, R]) Overwrite added in v0.6.0

func (z *ZodNil[T, R]) Overwrite(transform func(R) R, params ...any) *ZodNil[T, R]

Overwrite transforms the input value while preserving the original type.

func (*ZodNil[T, R]) Parse

func (z *ZodNil[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input and returns a value matching the constraint type R.

func (*ZodNil[T, R]) ParseAny added in v0.3.0

func (z *ZodNil[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodNil[T, R]) Pipe

func (z *ZodNil[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a validation pipeline with another schema.

func (*ZodNil[T, R]) Prefault

func (z *ZodNil[T, R]) Prefault(v T) *ZodNil[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodNil[T, R]) PrefaultFunc

func (z *ZodNil[T, R]) PrefaultFunc(fn func() T) *ZodNil[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodNil[T, R]) Refine

func (z *ZodNil[T, R]) Refine(fn func(R) bool, params ...any) *ZodNil[T, R]

Refine applies a custom validation function matching the schema's output type R.

func (*ZodNil[T, R]) RefineAny

func (z *ZodNil[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodNil[T, R]

RefineAny applies a custom validation function that receives the raw value.

func (*ZodNil[T, R]) StrictParse added in v0.4.0

func (z *ZodNil[T, R]) StrictParse(input R, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodNil[T, R]) Transform

func (z *ZodNil[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed value.

func (*ZodNil[T, R]) With added in v0.6.0

func (z *ZodNil[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodNil[T, R]

With is an alias for Check (Zod v4 API compatibility).

type ZodNilDef

type ZodNilDef struct {
	core.ZodTypeDef
}

ZodNilDef holds the configuration for nil validation.

type ZodNilInternals

type ZodNilInternals struct {
	core.ZodTypeInternals
	Def *ZodNilDef
}

ZodNilInternals contains the internal state of a nil validator.

type ZodObject

type ZodObject[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodObject represents a type-safe object validation schema. T is the base type, R is the constraint type (value or pointer).

func LooseObject

func LooseObject(shape core.ObjectSchema, params ...any) *ZodObject[map[string]any, map[string]any]

LooseObject creates a loose object schema that allows unknown keys.

func LooseObjectPtr added in v0.3.0

func LooseObjectPtr(shape core.ObjectSchema, params ...any) *ZodObject[map[string]any, *map[string]any]

LooseObjectPtr creates a loose object schema with pointer constraint.

func Object

func Object(shape core.ObjectSchema, params ...any) *ZodObject[map[string]any, map[string]any]

Object creates an object schema with default types.

func ObjectPtr added in v0.3.0

func ObjectPtr(shape core.ObjectSchema, params ...any) *ZodObject[map[string]any, *map[string]any]

ObjectPtr creates an object schema with pointer constraint.

func ObjectTyped added in v0.3.0

func ObjectTyped[T any, R any](shape core.ObjectSchema, params ...any) *ZodObject[T, R]

ObjectTyped creates a typed object schema with explicit type parameters.

func StrictObject

func StrictObject(shape core.ObjectSchema, params ...any) *ZodObject[map[string]any, map[string]any]

StrictObject creates a strict object schema that rejects unknown keys.

func StrictObjectPtr added in v0.3.0

func StrictObjectPtr(shape core.ObjectSchema, params ...any) *ZodObject[map[string]any, *map[string]any]

StrictObjectPtr creates a strict object schema with pointer constraint.

func (*ZodObject[T, R]) And added in v0.5.4

func (z *ZodObject[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodObject[T, R]) Catchall

func (z *ZodObject[T, R]) Catchall() core.ZodSchema

Catchall returns the catchall schema for unknown fields.

func (*ZodObject[T, R]) Check

func (z *ZodObject[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodObject[T, R]

Check adds a custom validation function that can report multiple issues.

func (*ZodObject[T, R]) CloneFrom

func (z *ZodObject[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodObject[T, R]) Default

func (z *ZodObject[T, R]) Default(v T) *ZodObject[T, R]

Default sets a default value returned when input is nil, bypassing validation.

func (*ZodObject[T, R]) DefaultFunc

func (z *ZodObject[T, R]) DefaultFunc(fn func() T) *ZodObject[T, R]

DefaultFunc sets a factory function that provides the default value when input is nil.

func (*ZodObject[T, R]) Describe added in v0.5.4

func (z *ZodObject[T, R]) Describe(description string) *ZodObject[T, R]

Describe registers a description in the global registry.

func (*ZodObject[T, R]) Extend

func (z *ZodObject[T, R]) Extend(augmentation core.ObjectSchema, params ...any) (*ZodObject[T, R], error)

Extend creates a new object by extending with additional fields. Returns an error if the schema has refinements and augmentation overlaps existing keys.

func (*ZodObject[T, R]) Internals added in v0.6.0

func (z *ZodObject[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodObject[T, R]) IsNilable added in v0.3.0

func (z *ZodObject[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodObject[T, R]) IsOptional added in v0.3.0

func (z *ZodObject[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodObject[T, R]) Keyof

func (z *ZodObject[T, R]) Keyof() *ZodEnum[string, string]

Keyof returns a string enum schema of all keys.

func (*ZodObject[T, R]) Length added in v0.6.0

func (z *ZodObject[T, R]) Length(exactLen int, params ...any) *ZodObject[T, R]

Length sets the exact number of fields required.

func (*ZodObject[T, R]) Max added in v0.3.0

func (z *ZodObject[T, R]) Max(maxLen int, params ...any) *ZodObject[T, R]

Max sets the maximum number of fields.

func (*ZodObject[T, R]) Merge

func (z *ZodObject[T, R]) Merge(other *ZodObject[T, R], params ...any) *ZodObject[T, R]

Merge combines two object schemas, clearing all checks/refinements.

func (*ZodObject[T, R]) Meta added in v0.3.1

func (z *ZodObject[T, R]) Meta(meta core.GlobalMeta) *ZodObject[T, R]

Meta attaches GlobalMeta to this object schema via the global registry.

func (*ZodObject[T, R]) Min added in v0.3.0

func (z *ZodObject[T, R]) Min(minLen int, params ...any) *ZodObject[T, R]

Min sets the minimum number of fields.

func (*ZodObject[T, R]) MustOmit added in v0.5.4

func (z *ZodObject[T, R]) MustOmit(keys []string, params ...any) *ZodObject[T, R]

MustOmit is like Omit but panics on error.

func (*ZodObject[T, R]) MustParse

func (z *ZodObject[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates input and panics on error.

func (*ZodObject[T, R]) MustPick added in v0.5.4

func (z *ZodObject[T, R]) MustPick(keys []string, params ...any) *ZodObject[T, R]

MustPick is like Pick but panics on error.

func (*ZodObject[T, R]) MustStrictParse added in v0.4.0

func (z *ZodObject[T, R]) MustStrictParse(input T, ctx ...*core.ParseContext) R

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodObject[T, R]) Nilable

func (z *ZodObject[T, R]) Nilable() *ZodObject[T, *T]

Nilable returns a schema that accepts nil, with constraint type *T.

func (*ZodObject[T, R]) NonOptional added in v0.3.0

func (z *ZodObject[T, R]) NonOptional() *ZodObject[T, T]

NonOptional removes the optional flag and returns base constraint type.

func (*ZodObject[T, R]) Nullish added in v0.3.0

func (z *ZodObject[T, R]) Nullish() *ZodObject[T, *T]

Nullish combines optional and nilable modifiers.

func (*ZodObject[T, R]) Omit

func (z *ZodObject[T, R]) Omit(keys []string, params ...any) (*ZodObject[T, R], error)

Omit creates a new object excluding the specified keys. Returns an error if any key does not exist or the schema contains refinements.

func (*ZodObject[T, R]) Optional

func (z *ZodObject[T, R]) Optional() *ZodObject[T, *T]

Optional returns a schema that accepts nil, with constraint type *T.

func (*ZodObject[T, R]) Or added in v0.5.4

func (z *ZodObject[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodObject[T, R]) Overwrite added in v0.3.0

func (z *ZodObject[T, R]) Overwrite(transform func(R) R, params ...any) *ZodObject[T, R]

Overwrite transforms the value while preserving the original type.

func (*ZodObject[T, R]) Parse

func (z *ZodObject[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input using object-specific parsing logic with engine.ParseComplex.

func (*ZodObject[T, R]) ParseAny added in v0.3.0

func (z *ZodObject[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result for runtime scenarios.

func (*ZodObject[T, R]) Partial

func (z *ZodObject[T, R]) Partial(keys ...[]string) *ZodObject[T, R]

Partial makes all fields optional, or specific fields if keys are provided.

func (*ZodObject[T, R]) Passthrough

func (z *ZodObject[T, R]) Passthrough() *ZodObject[T, R]

Passthrough sets passthrough mode (allows unknown keys).

func (*ZodObject[T, R]) Pick

func (z *ZodObject[T, R]) Pick(keys []string, params ...any) (*ZodObject[T, R], error)

Pick creates a new object with only the specified keys. Returns an error if any key does not exist or the schema contains refinements.

func (*ZodObject[T, R]) Pipe

func (z *ZodObject[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a pipeline to another schema.

func (*ZodObject[T, R]) Prefault

func (z *ZodObject[T, R]) Prefault(v T) *ZodObject[T, R]

Prefault sets a prefault value that goes through the full parsing pipeline when input is nil.

func (*ZodObject[T, R]) PrefaultFunc

func (z *ZodObject[T, R]) PrefaultFunc(fn func() T) *ZodObject[T, R]

PrefaultFunc sets a factory function that provides the prefault value through the full parsing pipeline.

func (*ZodObject[T, R]) Property added in v0.3.0

func (z *ZodObject[T, R]) Property(key string, schema core.ZodSchema, params ...any) *ZodObject[T, R]

Property validates a specific property using the provided schema.

func (*ZodObject[T, R]) Refine

func (z *ZodObject[T, R]) Refine(fn func(R) bool, params ...any) *ZodObject[T, R]

Refine applies type-safe validation using constraint type. Schemas with refinements cannot use Pick/Omit.

func (*ZodObject[T, R]) RefineAny

func (z *ZodObject[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodObject[T, R]

RefineAny provides flexible validation without type conversion. Schemas with refinements cannot use Pick/Omit.

func (*ZodObject[T, R]) Required

func (z *ZodObject[T, R]) Required(fields ...[]string) *ZodObject[T, R]

Required makes all fields required, or specific fields if provided.

func (*ZodObject[T, R]) SafeExtend added in v0.5.4

func (z *ZodObject[T, R]) SafeExtend(augmentation core.ObjectSchema, params ...any) *ZodObject[T, R]

SafeExtend creates a new object by extending without checking refinements.

func (*ZodObject[T, R]) Shape

func (z *ZodObject[T, R]) Shape() core.ObjectSchema

Shape returns the object shape (field schemas).

func (*ZodObject[T, R]) Strict

func (z *ZodObject[T, R]) Strict() *ZodObject[T, R]

Strict sets strict mode (rejects unknown keys).

func (*ZodObject[T, R]) StrictParse added in v0.4.0

func (z *ZodObject[T, R]) StrictParse(input T, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodObject[T, R]) Strip

func (z *ZodObject[T, R]) Strip() *ZodObject[T, R]

Strip sets strip mode (removes unknown keys).

func (*ZodObject[T, R]) Transform

func (z *ZodObject[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed object value.

func (*ZodObject[T, R]) UnknownKeys added in v0.6.0

func (z *ZodObject[T, R]) UnknownKeys() ObjectMode

UnknownKeys returns the unknown keys handling mode.

func (*ZodObject[T, R]) With added in v0.5.4

func (z *ZodObject[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodObject[T, R]

With is an alias for Check.

func (*ZodObject[T, R]) WithCatchall added in v0.6.0

func (z *ZodObject[T, R]) WithCatchall(catchallSchema core.ZodSchema) *ZodObject[T, R]

WithCatchall sets a schema for validating unknown keys.

func (*ZodObject[T, R]) WithFieldNameTag added in v0.11.6

func (z *ZodObject[T, R]) WithFieldNameTag(fieldNameTag string) *ZodObject[T, R]

WithFieldNameTag returns a new schema that resolves struct field names using the named struct tag (e.g. "yaml", "toml") instead of the default "json" when a struct value is coerced to an object.

type ZodObjectDef

type ZodObjectDef struct {
	core.ZodTypeDef
	// Shape maps field names to field schemas.
	Shape core.ObjectSchema
	// Catchall validates unknown keys when passthrough behavior is enabled.
	Catchall core.ZodSchema
	// UnknownKeys controls how unknown keys are handled.
	UnknownKeys ObjectMode
}

ZodObjectDef defines the configuration for an object schema.

type ZodObjectInternals

type ZodObjectInternals struct {
	core.ZodTypeInternals
	// Def points to the schema definition.
	Def *ZodObjectDef
	// Shape maps field names to field schemas.
	Shape core.ObjectSchema
	// Catchall validates unknown keys when passthrough behavior is enabled.
	Catchall core.ZodSchema
	// UnknownKeys controls how unknown keys are handled.
	UnknownKeys ObjectMode
	// IsPartial reports whether omitted fields are allowed.
	IsPartial bool
	// PartialExceptions marks fields that remain required in partial mode.
	PartialExceptions map[string]bool
	// HasUserRefinements reports whether user-defined refinements are attached.
	HasUserRefinements bool
	// FieldNameTag is the struct tag used for field names (default "json").
	FieldNameTag string
}

ZodObjectInternals contains object validator internal state.

type ZodRecord

type ZodRecord[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodRecord represents a type-safe record validation schema. T is the base type, R is the constraint type (value or pointer).

func LooseRecord added in v0.5.4

func LooseRecord(keySchema, valueSchema any, paramArgs ...any) *ZodRecord[map[string]any, map[string]any]

LooseRecord creates a record schema that passes through non-matching keys unchanged. Unlike regular Record which errors on keys that don't match the key schema, LooseRecord preserves non-matching keys without validation.

This is particularly useful for pattern-based key validation where you want to: - Validate keys matching a specific pattern - Preserve all other keys unchanged

TypeScript Zod v4 equivalent: z.looseRecord(keySchema, valueSchema)

Example:

// Only validate keys starting with "S_"
schema := LooseRecord(String().Regex(`^S_`), String())
result, _ := schema.Parse(map[string]any{"S_name": "John", "other": 123})
// Result: {"S_name": "John", "other": 123} - "other" key is preserved

func LooseRecordPtr added in v0.5.4

func LooseRecordPtr(keySchema, valueSchema any, paramArgs ...any) *ZodRecord[map[string]any, *map[string]any]

LooseRecordPtr creates a loose record schema returning a pointer constraint.

func PartialRecord

func PartialRecord(keySchema, valueSchema any, paramArgs ...any) *ZodRecord[map[string]any, map[string]any]

PartialRecord creates a record schema that skips exhaustive key checks.

func PartialRecordPtr added in v0.3.1

func PartialRecordPtr(keySchema, valueSchema any, paramArgs ...any) *ZodRecord[map[string]any, *map[string]any]

PartialRecordPtr creates a partial record schema returning a pointer constraint.

func Record

func Record(keySchema, valueSchema any, paramArgs ...any) *ZodRecord[map[string]any, map[string]any]

Record creates a record schema with key and value schemas.

func RecordPtr added in v0.3.0

func RecordPtr(keySchema, valueSchema any, paramArgs ...any) *ZodRecord[map[string]any, *map[string]any]

RecordPtr creates a record schema returning a pointer constraint.

func RecordTyped added in v0.3.0

func RecordTyped[T any, R any](keySchema, valueSchema any, paramArgs ...any) *ZodRecord[T, R]

RecordTyped creates a typed record schema with generic constraints.

func (*ZodRecord[T, R]) Check added in v0.3.0

func (z *ZodRecord[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodRecord[T, R]

Check adds a custom validation function that can report multiple issues.

func (*ZodRecord[T, R]) CloneFrom

func (z *ZodRecord[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema

func (*ZodRecord[T, R]) Default

func (z *ZodRecord[T, R]) Default(v T) *ZodRecord[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodRecord[T, R]) DefaultFunc

func (z *ZodRecord[T, R]) DefaultFunc(fn func() T) *ZodRecord[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodRecord[T, R]) Describe added in v0.5.4

func (z *ZodRecord[T, R]) Describe(description string) *ZodRecord[T, R]

Describe registers a description in the global registry.

func (*ZodRecord[T, R]) Internals added in v0.6.0

func (z *ZodRecord[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodRecord[T, R]) IsLoose added in v0.5.4

func (z *ZodRecord[T, R]) IsLoose() bool

IsLoose reports whether non-matching keys pass through unchanged.

func (*ZodRecord[T, R]) IsNilable added in v0.3.0

func (z *ZodRecord[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodRecord[T, R]) IsOptional added in v0.3.0

func (z *ZodRecord[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodRecord[T, R]) KeyType added in v0.3.1

func (z *ZodRecord[T, R]) KeyType() any

KeyType returns the key schema for this record.

func (*ZodRecord[T, R]) Length added in v0.6.0

func (z *ZodRecord[T, R]) Length(exactLen int, params ...any) *ZodRecord[T, R]

Length sets the exact number of entries.

func (*ZodRecord[T, R]) Max added in v0.3.0

func (z *ZodRecord[T, R]) Max(maxLen int, params ...any) *ZodRecord[T, R]

Max sets the maximum number of entries.

func (*ZodRecord[T, R]) Meta added in v0.3.1

func (z *ZodRecord[T, R]) Meta(meta core.GlobalMeta) *ZodRecord[T, R]

Meta stores metadata for this record schema.

func (*ZodRecord[T, R]) Min added in v0.3.0

func (z *ZodRecord[T, R]) Min(minLen int, params ...any) *ZodRecord[T, R]

Min sets the minimum number of entries.

func (*ZodRecord[T, R]) MustParse

func (z *ZodRecord[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates input and panics on error.

func (*ZodRecord[T, R]) MustStrictParse added in v0.4.0

func (z *ZodRecord[T, R]) MustStrictParse(input T, ctx ...*core.ParseContext) R

MustStrictParse validates input with type safety and panics on error.

func (*ZodRecord[T, R]) Nilable

func (z *ZodRecord[T, R]) Nilable() *ZodRecord[T, *T]

Nilable allows nil values and returns a pointer constraint.

func (*ZodRecord[T, R]) NonOptional added in v0.3.0

func (z *ZodRecord[T, R]) NonOptional() *ZodRecord[T, T]

NonOptional removes Optional flag and enforces record presence.

func (*ZodRecord[T, R]) Nullish

func (z *ZodRecord[T, R]) Nullish() *ZodRecord[T, *T]

Nullish combines optional and nilable modifiers.

func (*ZodRecord[T, R]) Optional

func (z *ZodRecord[T, R]) Optional() *ZodRecord[T, *T]

Optional creates an optional record schema that returns a pointer constraint.

func (*ZodRecord[T, R]) Overwrite added in v0.3.0

func (z *ZodRecord[T, R]) Overwrite(transform func(R) R, params ...any) *ZodRecord[T, R]

Overwrite transforms the input value while preserving the original type.

func (*ZodRecord[T, R]) Parse

func (z *ZodRecord[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input using unified ParseComplex API.

func (*ZodRecord[T, R]) ParseAny added in v0.3.0

func (z *ZodRecord[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodRecord[T, R]) Partial added in v0.5.5

func (z *ZodRecord[T, R]) Partial() *ZodRecord[T, R]

Partial makes all record values optional by skipping exhaustive key checks. When a record has an exhaustive key schema (like Enum or Literal), Partial() allows missing keys instead of requiring all keys to be present.

TypeScript Zod v4 equivalent: z.partialRecord(keySchema, valueSchema)

Example:

keys := gozod.Enum([]string{"id", "name", "email"})
// Regular record requires all keys
schema := gozod.Record(keys, gozod.String())
_, err := schema.Parse(map[string]any{"id": "1"}) // Error: missing "name" and "email"

// Partial record allows missing keys
partialSchema := schema.Partial()
result, _ := partialSchema.Parse(map[string]any{"id": "1"}) // OK

func (*ZodRecord[T, R]) Pipe

func (z *ZodRecord[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a validation pipeline with a target schema.

func (*ZodRecord[T, R]) Prefault

func (z *ZodRecord[T, R]) Prefault(v T) *ZodRecord[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodRecord[T, R]) PrefaultFunc

func (z *ZodRecord[T, R]) PrefaultFunc(fn func() T) *ZodRecord[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodRecord[T, R]) Refine

func (z *ZodRecord[T, R]) Refine(fn func(R) bool, params ...any) *ZodRecord[T, R]

Refine applies type-safe validation with constraint type R.

func (*ZodRecord[T, R]) RefineAny

func (z *ZodRecord[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodRecord[T, R]

RefineAny provides flexible validation without type conversion.

func (*ZodRecord[T, R]) StrictParse added in v0.4.0

func (z *ZodRecord[T, R]) StrictParse(input T, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodRecord[T, R]) Transform

func (z *ZodRecord[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed record value.

func (*ZodRecord[T, R]) ValueType added in v0.3.1

func (z *ZodRecord[T, R]) ValueType() any

ValueType returns the value schema for this record.

func (*ZodRecord[T, R]) With added in v0.5.4

func (z *ZodRecord[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodRecord[T, R]

With is an alias for Check. TypeScript Zod v4 equivalent: schema.with(...)

type ZodRecordDef

type ZodRecordDef struct {
	core.ZodTypeDef
	KeyType   any
	ValueType any
}

ZodRecordDef defines the configuration for a record schema.

type ZodRecordInternals

type ZodRecordInternals struct {
	core.ZodTypeInternals
	Def       *ZodRecordDef
	KeyType   any
	ValueType any
	Loose     bool
}

ZodRecordInternals contains record validator internal state.

type ZodSchemaType added in v0.3.0

type ZodSchemaType interface {
	Internals() *core.ZodTypeInternals
}

ZodSchemaType represents any Zod schema type that implements the basic interface.

type ZodSet added in v0.5.5

type ZodSet[T comparable, R any] struct {
	// contains filtered or unexported fields
}

ZodSet is a type-safe set validation schema. T is the element type (must be comparable). R is the constraint type (value or pointer).

func Set added in v0.5.5

func Set[T comparable](valueSchema any, paramArgs ...any) *ZodSet[T, map[T]struct{}]

Set creates a set schema with element validation.

func SetPtr added in v0.5.5

func SetPtr[T comparable](valueSchema any, paramArgs ...any) *ZodSet[T, *map[T]struct{}]

SetPtr creates a set schema returning a pointer constraint.

func SetTyped added in v0.5.5

func SetTyped[T comparable, R any](valueSchema any, paramArgs ...any) *ZodSet[T, R]

SetTyped creates a typed set schema with explicit generic constraints.

func (*ZodSet[T, R]) And added in v0.5.5

func (z *ZodSet[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodSet[T, R]) Check added in v0.5.5

func (z *ZodSet[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodSet[T, R]

Check adds a custom validation function that can report multiple issues.

func (*ZodSet[T, R]) CloneFrom added in v0.5.5

func (z *ZodSet[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema of the same type.

func (*ZodSet[T, R]) Default added in v0.5.5

func (z *ZodSet[T, R]) Default(v map[T]struct{}) *ZodSet[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation). The default value bypasses validation.

func (*ZodSet[T, R]) DefaultFunc added in v0.5.5

func (z *ZodSet[T, R]) DefaultFunc(fn func() map[T]struct{}) *ZodSet[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodSet[T, R]) Describe added in v0.5.5

func (z *ZodSet[T, R]) Describe(description string) *ZodSet[T, R]

Describe registers a description in the global registry.

func (*ZodSet[T, R]) Internals added in v0.6.0

func (z *ZodSet[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodSet[T, R]) IsNilable added in v0.5.5

func (z *ZodSet[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodSet[T, R]) IsOptional added in v0.5.5

func (z *ZodSet[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined or missing values.

func (*ZodSet[T, R]) Length added in v0.6.0

func (z *ZodSet[T, R]) Length(exactLen int, params ...any) *ZodSet[T, R]

Length sets the exact number of elements required.

func (*ZodSet[T, R]) Max added in v0.5.5

func (z *ZodSet[T, R]) Max(maxLen int, params ...any) *ZodSet[T, R]

Max sets the maximum number of elements.

func (*ZodSet[T, R]) Meta added in v0.5.5

func (z *ZodSet[T, R]) Meta(meta core.GlobalMeta) *ZodSet[T, R]

Meta stores metadata for this set schema.

func (*ZodSet[T, R]) Min added in v0.5.5

func (z *ZodSet[T, R]) Min(minLen int, params ...any) *ZodSet[T, R]

Min sets the minimum number of elements.

func (*ZodSet[T, R]) MustParse added in v0.5.5

func (z *ZodSet[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates input and panics on error.

func (*ZodSet[T, R]) MustStrictParse added in v0.5.5

func (z *ZodSet[T, R]) MustStrictParse(input map[T]struct{}, ctx ...*core.ParseContext) R

MustStrictParse validates input with type safety and panics on error.

func (*ZodSet[T, R]) Nilable added in v0.5.5

func (z *ZodSet[T, R]) Nilable() *ZodSet[T, *map[T]struct{}]

Nilable returns a schema that accepts nil. The constraint type becomes *map[T]struct{}.

func (*ZodSet[T, R]) NonEmpty added in v0.5.5

func (z *ZodSet[T, R]) NonEmpty(params ...any) *ZodSet[T, R]

NonEmpty ensures the set has at least one element. This is equivalent to Min(1).

func (*ZodSet[T, R]) NonOptional added in v0.5.5

func (z *ZodSet[T, R]) NonOptional() *ZodSet[T, map[T]struct{}]

NonOptional removes the Optional flag and returns base constraint type.

func (*ZodSet[T, R]) Nullish added in v0.5.5

func (z *ZodSet[T, R]) Nullish() *ZodSet[T, *map[T]struct{}]

Nullish combines optional and nilable modifiers.

func (*ZodSet[T, R]) Optional added in v0.5.5

func (z *ZodSet[T, R]) Optional() *ZodSet[T, *map[T]struct{}]

Optional returns a schema that accepts nil. The constraint type becomes *map[T]struct{}.

func (*ZodSet[T, R]) Or added in v0.5.5

func (z *ZodSet[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodSet[T, R]) Overwrite added in v0.5.5

func (z *ZodSet[T, R]) Overwrite(transform func(R) R, params ...any) *ZodSet[T, R]

Overwrite transforms the value while preserving the original type.

func (*ZodSet[T, R]) Parse added in v0.5.5

func (z *ZodSet[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input using set-specific parsing logic.

func (*ZodSet[T, R]) ParseAny added in v0.5.5

func (z *ZodSet[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodSet[T, R]) Pipe added in v0.5.5

func (z *ZodSet[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a pipeline that passes the parsed result to a target schema.

func (*ZodSet[T, R]) Prefault added in v0.5.5

func (z *ZodSet[T, R]) Prefault(v map[T]struct{}) *ZodSet[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodSet[T, R]) PrefaultFunc added in v0.5.5

func (z *ZodSet[T, R]) PrefaultFunc(fn func() map[T]struct{}) *ZodSet[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline. The prefault value goes through full validation.

func (*ZodSet[T, R]) Refine added in v0.5.5

func (z *ZodSet[T, R]) Refine(fn func(R) bool, params ...any) *ZodSet[T, R]

Refine adds a typed custom validation function.

func (*ZodSet[T, R]) RefineAny added in v0.5.5

func (z *ZodSet[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodSet[T, R]

RefineAny adds a custom validation function accepting any input.

func (*ZodSet[T, R]) StrictParse added in v0.5.5

func (z *ZodSet[T, R]) StrictParse(input map[T]struct{}, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodSet[T, R]) Transform added in v0.5.5

func (z *ZodSet[T, R]) Transform(fn func(R, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed set value.

func (*ZodSet[T, R]) ValueType added in v0.5.5

func (z *ZodSet[T, R]) ValueType() any

ValueType returns the value schema for this set.

func (*ZodSet[T, R]) With added in v0.5.5

func (z *ZodSet[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodSet[T, R]

With is an alias for Check.

type ZodSetDef added in v0.5.5

type ZodSetDef struct {
	core.ZodTypeDef
	ValueType any
}

ZodSetDef defines the configuration for a set schema.

type ZodSetInternals added in v0.5.5

type ZodSetInternals[T comparable] struct {
	core.ZodTypeInternals
	Def       *ZodSetDef
	ValueType any
}

ZodSetInternals holds the internal state of a set validator.

type ZodSlice

type ZodSlice[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodSlice is a type-safe slice validation schema. T is the element type, R is the constraint type (value or pointer).

func Slice

func Slice[T any](elementSchema any, args ...any) *ZodSlice[T, []T]

Slice creates a slice schema with element validation.

func SlicePtr added in v0.3.0

func SlicePtr[T any](elementSchema any, args ...any) *ZodSlice[T, *[]T]

SlicePtr creates a slice schema with pointer constraint.

func SliceTyped added in v0.3.0

func SliceTyped[T any, R any](elementSchema any, args ...any) *ZodSlice[T, R]

SliceTyped creates a slice schema with an explicit constraint type.

func (*ZodSlice[T, R]) And added in v0.5.4

func (z *ZodSlice[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodSlice[T, R]) Check

func (z *ZodSlice[T, R]) Check(
	fn func(R, *core.ParsePayload),
	params ...any,
) *ZodSlice[T, R]

Check adds a custom validation function that can report multiple issues.

func (*ZodSlice[T, R]) CloneFrom

func (z *ZodSlice[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodSlice[T, R]) Default

func (z *ZodSlice[T, R]) Default(v []T) *ZodSlice[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation). Short-circuits validation and returns the default immediately.

func (*ZodSlice[T, R]) DefaultFunc

func (z *ZodSlice[T, R]) DefaultFunc(fn func() []T) *ZodSlice[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodSlice[T, R]) Describe added in v0.5.4

func (z *ZodSlice[T, R]) Describe(description string) *ZodSlice[T, R]

Describe sets a description for this schema in the global registry.

func (*ZodSlice[T, R]) Element

func (z *ZodSlice[T, R]) Element() core.ZodSchema

Element returns the element schema.

func (*ZodSlice[T, R]) ExactOptional added in v0.6.0

func (z *ZodSlice[T, R]) ExactOptional() *ZodSlice[T, R]

ExactOptional accepts absent keys but rejects explicit nil values.

func (*ZodSlice[T, R]) Internals added in v0.6.0

func (z *ZodSlice[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state for framework usage.

func (*ZodSlice[T, R]) IsNilable added in v0.3.0

func (z *ZodSlice[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodSlice[T, R]) IsOptional added in v0.3.0

func (z *ZodSlice[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodSlice[T, R]) Length

func (z *ZodSlice[T, R]) Length(n int, params ...any) *ZodSlice[T, R]

Length adds an exact element count constraint.

func (*ZodSlice[T, R]) Max

func (z *ZodSlice[T, R]) Max(n int, params ...any) *ZodSlice[T, R]

Max adds a maximum element count constraint.

func (*ZodSlice[T, R]) Meta added in v0.3.1

func (z *ZodSlice[T, R]) Meta(meta core.GlobalMeta) *ZodSlice[T, R]

Meta stores metadata for this slice schema in the global registry.

func (*ZodSlice[T, R]) Min

func (z *ZodSlice[T, R]) Min(n int, params ...any) *ZodSlice[T, R]

Min adds a minimum element count constraint.

func (*ZodSlice[T, R]) MustParse

func (z *ZodSlice[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates input and panics on error.

func (*ZodSlice[T, R]) MustStrictParse added in v0.4.0

func (z *ZodSlice[T, R]) MustStrictParse(input R, ctx ...*core.ParseContext) R

MustStrictParse validates input with type safety and panics on error.

func (*ZodSlice[T, R]) Nilable

func (z *ZodSlice[T, R]) Nilable() *ZodSlice[T, *[]T]

Nilable returns a schema that accepts nil values with pointer constraint.

func (*ZodSlice[T, R]) NonEmpty

func (z *ZodSlice[T, R]) NonEmpty(params ...any) *ZodSlice[T, R]

NonEmpty requires at least one element.

func (*ZodSlice[T, R]) NonOptional added in v0.3.0

func (z *ZodSlice[T, R]) NonOptional() *ZodSlice[T, []T]

NonOptional enforces non-nil value constraint.

func (*ZodSlice[T, R]) Nullish

func (z *ZodSlice[T, R]) Nullish() *ZodSlice[T, *[]T]

Nullish combines optional and nilable modifiers.

func (*ZodSlice[T, R]) Optional

func (z *ZodSlice[T, R]) Optional() *ZodSlice[T, *[]T]

Optional returns a schema that accepts nil values with pointer constraint.

func (*ZodSlice[T, R]) Or added in v0.5.4

func (z *ZodSlice[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodSlice[T, R]) Overwrite added in v0.3.0

func (z *ZodSlice[T, R]) Overwrite(fn func(R) R, params ...any) *ZodSlice[T, R]

Overwrite transforms the slice value while preserving the original type.

func (*ZodSlice[T, R]) Parse

func (z *ZodSlice[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input and returns the parsed slice value.

func (*ZodSlice[T, R]) ParseAny added in v0.3.0

func (z *ZodSlice[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodSlice[T, R]) Pipe

func (z *ZodSlice[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe passes the parsed value to a target schema.

func (*ZodSlice[T, R]) Prefault

func (z *ZodSlice[T, R]) Prefault(v []T) *ZodSlice[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodSlice[T, R]) PrefaultFunc

func (z *ZodSlice[T, R]) PrefaultFunc(fn func() []T) *ZodSlice[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodSlice[T, R]) Refine

func (z *ZodSlice[T, R]) Refine(fn func(R) bool, params ...any) *ZodSlice[T, R]

Refine adds type-safe custom validation.

func (*ZodSlice[T, R]) RefineAny

func (z *ZodSlice[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodSlice[T, R]

RefineAny adds custom validation without type conversion.

func (*ZodSlice[T, R]) StrictParse added in v0.4.0

func (z *ZodSlice[T, R]) StrictParse(input R, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodSlice[T, R]) Transform

func (z *ZodSlice[T, R]) Transform(
	fn func(R, *core.RefinementContext) (any, error),
) *core.ZodTransform[R, any]

Transform applies a transformation function to the parsed slice value.

func (*ZodSlice[T, R]) With added in v0.5.4

func (z *ZodSlice[T, R]) With(
	fn func(R, *core.ParsePayload),
	params ...any,
) *ZodSlice[T, R]

With is an alias for Check.

type ZodSliceDef

type ZodSliceDef struct {
	core.ZodTypeDef
	Element any
}

ZodSliceDef defines the configuration for a slice schema.

type ZodSliceInternals

type ZodSliceInternals[T any] struct {
	core.ZodTypeInternals
	Def     *ZodSliceDef
	Element any
}

ZodSliceInternals contains the internal state for a slice schema.

type ZodString

type ZodString[T StringConstraint] struct {
	// contains filtered or unexported fields
}

ZodString is a type-safe string validation schema.

func CoercedString added in v0.2.1

func CoercedString(params ...any) *ZodString[string]

CoercedString creates a new string schema with coercion enabled.

func CoercedStringPtr added in v0.3.0

func CoercedStringPtr(params ...any) *ZodString[*string]

CoercedStringPtr creates a new string schema with pointer type and coercion.

func String

func String(params ...any) *ZodString[string]

String creates a new string schema.

func StringPtr added in v0.3.0

func StringPtr(params ...any) *ZodString[*string]

StringPtr creates a new string schema with pointer type.

func StringTyped added in v0.3.0

func StringTyped[T StringConstraint](params ...any) *ZodString[T]

StringTyped creates a new string schema with a specific constraint type.

func (*ZodString[T]) And added in v0.5.4

func (z *ZodString[T]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodString[T]) Check added in v0.3.0

func (z *ZodString[T]) Check(fn func(value T, payload *core.ParsePayload), params ...any) *ZodString[T]

Check adds a custom validation function that can push multiple issues.

func (*ZodString[T]) CloneFrom

func (z *ZodString[T]) CloneFrom(source any)

CloneFrom copies the internal state from another schema.

func (*ZodString[T]) Coerce

func (z *ZodString[T]) Coerce(input any) (any, bool)

Coerce converts input to string.

func (*ZodString[T]) Default

func (z *ZodString[T]) Default(v string) *ZodString[T]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodString[T]) DefaultFunc

func (z *ZodString[T]) DefaultFunc(fn func() string) *ZodString[T]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodString[T]) Describe added in v0.5.3

func (z *ZodString[T]) Describe(description string) *ZodString[T]

Describe attaches a description to this schema via the global registry.

func (*ZodString[T]) Email

func (z *ZodString[T]) Email(params ...any) *ZodString[T]

Email adds email format validation.

func (*ZodString[T]) EndsWith

func (z *ZodString[T]) EndsWith(suffix string, params ...any) *ZodString[T]

EndsWith adds suffix validation.

func (*ZodString[T]) ExactOptional added in v0.5.4

func (z *ZodString[T]) ExactOptional() *ZodString[T]

ExactOptional returns a new schema that accepts absent keys but rejects explicit nil. Unlike Optional, it only accepts absent keys in object fields.

func (*ZodString[T]) Includes

func (z *ZodString[T]) Includes(substring string, params ...any) *ZodString[T]

Includes adds substring validation.

func (*ZodString[T]) Internals added in v0.6.0

func (z *ZodString[T]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodString[T]) IsNilable added in v0.3.0

func (z *ZodString[T]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodString[T]) IsOptional added in v0.3.0

func (z *ZodString[T]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodString[T]) JSON

func (z *ZodString[T]) JSON(params ...any) *ZodString[T]

JSON adds JSON format validation.

func (*ZodString[T]) JWT

func (z *ZodString[T]) JWT(params ...any) *ZodString[T]

JWT adds JWT token format validation.

Accepts an optional algorithm string ("HS256", "RS256", etc.) or validate.JWTOptions.

JWT()                                        // standard format
JWT("HS256")                                 // require specific algorithm
JWT(validate.JWTOptions{Algorithm: "RS256"}) // full options

func (*ZodString[T]) Length

func (z *ZodString[T]) Length(length int, params ...any) *ZodString[T]

Length adds exact length validation.

func (*ZodString[T]) Lowercase added in v0.5.5

func (z *ZodString[T]) Lowercase(params ...any) *ZodString[T]

Lowercase validates that the string contains no uppercase letters.

func (*ZodString[T]) MAC added in v0.5.3

func (z *ZodString[T]) MAC(params ...any) *ZodString[T]

MAC adds MAC address format validation.

Accepts an optional delimiter string (":", "-", ".") or validate.MACOptions. Without arguments, defaults to colon delimiter.

MAC()                                     // default ":"
MAC("-")                                  // dash delimiter
MAC(validate.MACOptions{Delimiter: "."})  // full options

func (*ZodString[T]) Max

func (z *ZodString[T]) Max(maxLen int, params ...any) *ZodString[T]

Max adds maximum length validation.

func (*ZodString[T]) Meta added in v0.3.1

func (z *ZodString[T]) Meta(meta core.GlobalMeta) *ZodString[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodString[T]) Min

func (z *ZodString[T]) Min(minLen int, params ...any) *ZodString[T]

Min adds minimum length validation.

func (*ZodString[T]) MustParse

func (z *ZodString[T]) MustParse(input any, ctx ...*core.ParseContext) T

MustParse validates input and panics on failure.

func (*ZodString[T]) MustParseAny added in v0.3.1

func (z *ZodString[T]) MustParseAny(input any, ctx ...*core.ParseContext) any

MustParseAny validates input and panics on failure.

func (*ZodString[T]) MustStrictParse added in v0.4.0

func (z *ZodString[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse requires exact type T and panics on failure.

func (*ZodString[T]) Nilable

func (z *ZodString[T]) Nilable() *ZodString[*string]

Nilable returns a new schema that accepts nil values, with *string constraint.

func (*ZodString[T]) NonOptional added in v0.3.0

func (z *ZodString[T]) NonOptional() *ZodString[string]

NonOptional removes the optional flag and returns a required string schema.

func (*ZodString[T]) Normalize added in v0.5.5

func (z *ZodString[T]) Normalize(form ...string) *ZodString[T]

Normalize transforms the string using Unicode normalization. Supported forms: "NFC" (default), "NFD", "NFKC", "NFKD".

func (*ZodString[T]) Nullish

func (z *ZodString[T]) Nullish() *ZodString[*string]

Nullish returns a new schema that combines optional and nilable modifiers.

func (*ZodString[T]) Optional

func (z *ZodString[T]) Optional() *ZodString[*string]

Optional returns a new schema that accepts nil, with *string output.

func (*ZodString[T]) Or added in v0.5.4

func (z *ZodString[T]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodString[T]) Overwrite added in v0.3.0

func (z *ZodString[T]) Overwrite(fn func(T) T, params ...any) *ZodString[T]

Overwrite applies a same-type transformation to the validated string.

func (*ZodString[T]) Parse

func (z *ZodString[T]) Parse(input any, ctx ...*core.ParseContext) (T, error)

Parse validates input and returns a value of type T.

func (*ZodString[T]) ParseAny added in v0.3.0

func (z *ZodString[T]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns any for runtime interface usage.

func (*ZodString[T]) Pipe

func (z *ZodString[T]) Pipe(target core.ZodType[any]) *core.ZodPipe[T, any]

Pipe creates a pipeline with another schema.

func (*ZodString[T]) Prefault

func (z *ZodString[T]) Prefault(v string) *ZodString[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodString[T]) PrefaultFunc

func (z *ZodString[T]) PrefaultFunc(fn func() string) *ZodString[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodString[T]) Refine

func (z *ZodString[T]) Refine(fn func(T) bool, params ...any) *ZodString[T]

Refine applies a custom validation function matching the schema's output type T.

func (*ZodString[T]) RefineAny

func (z *ZodString[T]) RefineAny(fn func(any) bool, params ...any) *ZodString[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodString[T]) Regex

func (z *ZodString[T]) Regex(pattern *regexp.Regexp, params ...any) *ZodString[T]

Regex adds custom regex validation.

func (*ZodString[T]) RegexString added in v0.3.0

func (z *ZodString[T]) RegexString(pattern string, params ...any) *ZodString[T]

RegexString adds custom regex validation using a string pattern.

func (*ZodString[T]) Slugify added in v0.5.3

func (z *ZodString[T]) Slugify(params ...any) *ZodString[T]

Slugify transforms the string to a URL-friendly slug.

func (*ZodString[T]) StartsWith

func (z *ZodString[T]) StartsWith(prefix string, params ...any) *ZodString[T]

StartsWith adds prefix validation.

func (*ZodString[T]) StrictParse added in v0.4.0

func (z *ZodString[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse requires exact type T for compile-time type safety.

func (*ZodString[T]) ToLowerCase

func (z *ZodString[T]) ToLowerCase(params ...any) *ZodString[T]

ToLowerCase transforms the string to lower case.

func (*ZodString[T]) ToUpperCase

func (z *ZodString[T]) ToUpperCase(params ...any) *ZodString[T]

ToUpperCase transforms the string to upper case.

func (*ZodString[T]) Transform

func (z *ZodString[T]) Transform(fn func(string, *core.RefinementContext) (any, error)) *core.ZodTransform[T, any]

Transform applies a transformation function to the validated string.

func (*ZodString[T]) Trim

func (z *ZodString[T]) Trim(params ...any) *ZodString[T]

Trim adds string trimming transformation.

func (*ZodString[T]) Uppercase added in v0.5.5

func (z *ZodString[T]) Uppercase(params ...any) *ZodString[T]

Uppercase validates that the string contains no lowercase letters.

func (*ZodString[T]) With added in v0.5.4

func (z *ZodString[T]) With(fn func(value T, payload *core.ParsePayload), params ...any) *ZodString[T]

With is an alias for Check (Zod v4 API compatibility).

type ZodStringBool

type ZodStringBool[T StringBoolConstraint] struct {
	// contains filtered or unexported fields
}

ZodStringBool is a type-safe string-to-boolean validation schema.

func CoercedStringBool added in v0.3.0

func CoercedStringBool(params ...any) *ZodStringBool[bool]

CoercedStringBool creates a coerced string-to-bool schema.

func CoercedStringBoolPtr added in v0.3.0

func CoercedStringBoolPtr(params ...any) *ZodStringBool[*bool]

CoercedStringBoolPtr creates a coerced string-to-*bool schema.

func StringBool

func StringBool(params ...any) *ZodStringBool[bool]

StringBool creates a string-to-bool validation schema.

func StringBoolPtr added in v0.3.0

func StringBoolPtr(params ...any) *ZodStringBool[*bool]

StringBoolPtr creates a string-to-*bool validation schema.

func StringBoolTyped added in v0.3.0

func StringBoolTyped[T StringBoolConstraint](params ...any) *ZodStringBool[T]

StringBoolTyped is the generic constructor for string-boolean schemas.

func (*ZodStringBool[T]) And added in v0.6.0

func (z *ZodStringBool[T]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodStringBool[T]) Check added in v0.6.0

func (z *ZodStringBool[T]) Check(fn func(value T, payload *core.ParsePayload), params ...any) *ZodStringBool[T]

Check adds a custom validation function that can push multiple issues.

func (*ZodStringBool[T]) CloneFrom added in v0.3.0

func (z *ZodStringBool[T]) CloneFrom(source any)

CloneFrom copies configuration from another schema of the same type.

func (*ZodStringBool[T]) Coerce

func (z *ZodStringBool[T]) Coerce(input any) (any, bool)

Coerce converts input to a recognized truthy/falsy string.

func (*ZodStringBool[T]) Default

func (z *ZodStringBool[T]) Default(v bool) *ZodStringBool[T]

Default sets a fallback value returned when input is nil (short-circuits).

func (*ZodStringBool[T]) DefaultFunc

func (z *ZodStringBool[T]) DefaultFunc(fn func() bool) *ZodStringBool[T]

DefaultFunc sets a fallback function called when input is nil (short-circuits).

func (*ZodStringBool[T]) Describe added in v0.5.4

func (z *ZodStringBool[T]) Describe(desc string) *ZodStringBool[T]

Describe registers a description in the global registry.

func (*ZodStringBool[T]) ExactOptional added in v0.6.0

func (z *ZodStringBool[T]) ExactOptional() *ZodStringBool[T]

ExactOptional accepts absent keys but rejects explicit nil values.

func (*ZodStringBool[T]) Internals added in v0.6.0

func (z *ZodStringBool[T]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodStringBool[T]) IsNilable added in v0.3.0

func (z *ZodStringBool[T]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodStringBool[T]) IsOptional added in v0.3.0

func (z *ZodStringBool[T]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodStringBool[T]) Meta added in v0.3.1

func (z *ZodStringBool[T]) Meta(meta core.GlobalMeta) *ZodStringBool[T]

Meta stores metadata in the global registry.

func (*ZodStringBool[T]) MustParse

func (z *ZodStringBool[T]) MustParse(input any, ctx ...*core.ParseContext) T

MustParse panics on validation failure.

func (*ZodStringBool[T]) MustStrictParse added in v0.4.0

func (z *ZodStringBool[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse panics on validation failure with compile-time type safety.

func (*ZodStringBool[T]) Nilable

func (z *ZodStringBool[T]) Nilable() *ZodStringBool[*bool]

Nilable returns a schema that accepts nil values with pointer constraint.

func (*ZodStringBool[T]) NonOptional added in v0.6.0

func (z *ZodStringBool[T]) NonOptional() *ZodStringBool[bool]

NonOptional removes the optional flag, returning a bool constraint.

func (*ZodStringBool[T]) Nullish

func (z *ZodStringBool[T]) Nullish() *ZodStringBool[*bool]

Nullish combines optional and nilable modifiers.

func (*ZodStringBool[T]) Optional

func (z *ZodStringBool[T]) Optional() *ZodStringBool[*bool]

Optional returns a schema that accepts nil values with pointer constraint.

func (*ZodStringBool[T]) Or added in v0.6.0

func (z *ZodStringBool[T]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodStringBool[T]) Overwrite added in v0.3.0

func (z *ZodStringBool[T]) Overwrite(transform func(T) T, params ...any) *ZodStringBool[T]

Overwrite transforms the input value while preserving the original type.

func (*ZodStringBool[T]) Parse

func (z *ZodStringBool[T]) Parse(input any, ctx ...*core.ParseContext) (T, error)

Parse validates input and returns a value matching the generic type T.

func (*ZodStringBool[T]) ParseAny added in v0.3.0

func (z *ZodStringBool[T]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodStringBool[T]) Pipe

func (z *ZodStringBool[T]) Pipe(target core.ZodType[any]) *core.ZodPipe[T, any]

Pipe creates a validation pipeline with another schema.

func (*ZodStringBool[T]) Prefault

func (z *ZodStringBool[T]) Prefault(v string) *ZodStringBool[T]

Prefault sets a fallback value that goes through the full validation pipeline. Accepts string input per Zod v4 semantics for StringBool.

func (*ZodStringBool[T]) PrefaultFunc

func (z *ZodStringBool[T]) PrefaultFunc(fn func() string) *ZodStringBool[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline. Returns string per Zod v4 semantics for StringBool.

func (*ZodStringBool[T]) Refine

func (z *ZodStringBool[T]) Refine(fn func(T) bool, params ...any) *ZodStringBool[T]

Refine applies a custom validation function matching the schema's output type T.

func (*ZodStringBool[T]) RefineAny

func (z *ZodStringBool[T]) RefineAny(fn func(any) bool, params ...any) *ZodStringBool[T]

RefineAny applies a custom validation function that receives the raw value.

func (*ZodStringBool[T]) StrictParse added in v0.4.0

func (z *ZodStringBool[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

func (*ZodStringBool[T]) Transform

func (z *ZodStringBool[T]) Transform(fn func(bool, *core.RefinementContext) (any, error)) *core.ZodTransform[T, any]

Transform applies a transformation function to the parsed value.

func (*ZodStringBool[T]) With added in v0.6.0

func (z *ZodStringBool[T]) With(fn func(value T, payload *core.ParsePayload), params ...any) *ZodStringBool[T]

With is an alias for Check (Zod v4 API compatibility).

type ZodStringBoolDef

type ZodStringBoolDef struct {
	core.ZodTypeDef
	Truthy []string
	Falsy  []string
	Case   string
	Custom bool
}

ZodStringBoolDef holds the configuration for string-boolean validation.

type ZodStringBoolInternals

type ZodStringBoolInternals struct {
	core.ZodTypeInternals
	Def    *ZodStringBoolDef
	Truthy map[string]struct{}
	Falsy  map[string]struct{}
}

ZodStringBoolInternals contains the internal state of a string-boolean validator.

type ZodStringDef

type ZodStringDef struct {
	core.ZodTypeDef
}

ZodStringDef holds the configuration for a string schema.

type ZodStringInternals

type ZodStringInternals struct {
	core.ZodTypeInternals
	Def *ZodStringDef
}

ZodStringInternals holds string validator internal state.

type ZodStruct

type ZodStruct[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodStruct represents a type-safe struct validation schema.

func FromStruct added in v0.5.0

func FromStruct[T any](opts ...FromStructOption) *ZodStruct[T, T]

FromStruct builds a struct schema from tags on T.

func FromStructPtr added in v0.5.0

func FromStructPtr[T any](opts ...FromStructOption) *ZodStruct[T, *T]

FromStructPtr builds a struct schema for *T from tags on T.

func Struct

func Struct[T any](params ...any) *ZodStruct[T, T]

Struct creates a struct schema for type T.

func StructPtr added in v0.3.0

func StructPtr[T any](params ...any) *ZodStruct[T, *T]

StructPtr creates a struct schema for *T.

func (*ZodStruct[T, R]) Catchall

func (z *ZodStruct[T, R]) Catchall() core.ZodSchema

Catchall returns nil because struct schemas are always strict.

func (*ZodStruct[T, R]) Check added in v0.3.0

func (z *ZodStruct[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodStruct[T, R]

Check adds a custom validation function that can report multiple issues for struct schema.

func (*ZodStruct[T, R]) CloneFrom

func (z *ZodStruct[T, R]) CloneFrom(source any)

CloneFrom copies configuration from a source.

func (*ZodStruct[T, R]) Default

func (z *ZodStruct[T, R]) Default(v T) *ZodStruct[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodStruct[T, R]) DefaultFunc

func (z *ZodStruct[T, R]) DefaultFunc(fn func() T) *ZodStruct[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodStruct[T, R]) Describe added in v0.5.4

func (z *ZodStruct[T, R]) Describe(description string) *ZodStruct[T, R]

Describe registers a description in the global registry.

func (*ZodStruct[T, R]) Extend

func (z *ZodStruct[T, R]) Extend(augmentation core.StructSchema, params ...any) *ZodStruct[T, R]

Extend returns a schema with additional field schemas.

func (*ZodStruct[T, R]) Internals added in v0.6.0

func (z *ZodStruct[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodStruct[T, R]) IsNilable added in v0.3.0

func (z *ZodStruct[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodStruct[T, R]) IsOptional added in v0.3.0

func (z *ZodStruct[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodStruct[T, R]) Meta added in v0.3.1

func (z *ZodStruct[T, R]) Meta(meta core.GlobalMeta) *ZodStruct[T, R]

Meta stores metadata.

func (*ZodStruct[T, R]) MustParse

func (z *ZodStruct[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse panics on validation failure.

func (*ZodStruct[T, R]) MustStrictParse added in v0.4.0

func (z *ZodStruct[T, R]) MustStrictParse(input T, ctx ...*core.ParseContext) R

MustStrictParse panics on validation failure with compile-time type safety.

func (*ZodStruct[T, R]) Nilable

func (z *ZodStruct[T, R]) Nilable() *ZodStruct[T, *T]

Nilable returns a schema that accepts nil values with pointer constraint.

func (*ZodStruct[T, R]) NonOptional added in v0.3.0

func (z *ZodStruct[T, R]) NonOptional() *ZodStruct[T, T]

NonOptional enforces non-nil struct value.

func (*ZodStruct[T, R]) Nullish

func (z *ZodStruct[T, R]) Nullish() *ZodStruct[T, *T]

Nullish combines optional and nilable modifiers.

func (*ZodStruct[T, R]) Optional

func (z *ZodStruct[T, R]) Optional() *ZodStruct[T, *T]

Optional returns a schema that accepts nil values with pointer constraint.

func (*ZodStruct[T, R]) Overwrite added in v0.3.0

func (z *ZodStruct[T, R]) Overwrite(transform func(R) R, params ...any) *ZodStruct[T, R]

Overwrite transforms the parsed value while preserving the original type.

func (*ZodStruct[T, R]) Parse

func (z *ZodStruct[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input and returns a value of type R.

func (*ZodStruct[T, R]) ParseAny added in v0.3.0

func (z *ZodStruct[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodStruct[T, R]) Partial

func (z *ZodStruct[T, R]) Partial(keys ...[]string) *ZodStruct[T, R]

Partial makes all fields optional.

func (*ZodStruct[T, R]) Pipe

func (z *ZodStruct[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a pipeline.

func (*ZodStruct[T, R]) Prefault

func (z *ZodStruct[T, R]) Prefault(v T) *ZodStruct[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodStruct[T, R]) PrefaultFunc

func (z *ZodStruct[T, R]) PrefaultFunc(fn func() T) *ZodStruct[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodStruct[T, R]) Refine

func (z *ZodStruct[T, R]) Refine(fn func(R) bool, params ...any) *ZodStruct[T, R]

Refine adds a custom validation function.

func (*ZodStruct[T, R]) RefineAny

func (z *ZodStruct[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodStruct[T, R]

RefineAny adds a custom validation function for any type.

func (*ZodStruct[T, R]) Required added in v0.4.0

func (z *ZodStruct[T, R]) Required(fields ...[]string) *ZodStruct[T, R]

Required makes all fields required.

func (*ZodStruct[T, R]) Shape

func (z *ZodStruct[T, R]) Shape() core.StructSchema

Shape returns the struct field schemas.

func (*ZodStruct[T, R]) StrictParse added in v0.4.0

func (z *ZodStruct[T, R]) StrictParse(input T, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodStruct[T, R]) Transform added in v0.3.0

func (z *ZodStruct[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation to the parsed struct value.

func (*ZodStruct[T, R]) UnknownKeys added in v0.6.0

func (z *ZodStruct[T, R]) UnknownKeys() ObjectMode

UnknownKeys returns the unknown keys handling mode.

func (*ZodStruct[T, R]) With added in v0.5.4

func (z *ZodStruct[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodStruct[T, R]

With is an alias for Check - adds a custom validation function. TypeScript Zod v4 equivalent: schema.with(...)

func (*ZodStruct[T, R]) WithFieldNameTag added in v0.11.6

func (z *ZodStruct[T, R]) WithFieldNameTag(fieldNameTag string) *ZodStruct[T, R]

WithFieldNameTag returns a schema that resolves struct field names using the named struct tag (for example "yaml" or "toml") instead of the default "json".

type ZodStructDef

type ZodStructDef struct {
	core.ZodTypeDef
	// Shape maps field names to field schemas.
	Shape core.StructSchema
}

ZodStructDef defines the configuration for struct validation.

type ZodStructInternals

type ZodStructInternals struct {
	core.ZodTypeInternals
	// Def points to the schema definition.
	Def *ZodStructDef
	// Shape maps field names to field schemas.
	Shape core.StructSchema
	// IsPartial reports whether omitted fields are allowed.
	IsPartial bool
	// PartialExceptions marks fields that remain required in partial mode.
	PartialExceptions map[string]bool
	// FieldNameTag is the struct tag used for field names (default "json").
	FieldNameTag string
}

ZodStructInternals contains the internal state for struct schemas.

type ZodTime added in v0.3.0

type ZodTime[T TimeConstraint] struct {
	// contains filtered or unexported fields
}

ZodTime is a type-safe time validation schema.

func CoercedTime added in v0.3.0

func CoercedTime(args ...any) *ZodTime[time.Time]

CoercedTime creates a time.Time schema with coercion enabled.

func CoercedTimePtr added in v0.3.0

func CoercedTimePtr(args ...any) *ZodTime[*time.Time]

CoercedTimePtr creates a *time.Time schema with coercion enabled.

func Time added in v0.3.0

func Time(params ...any) *ZodTime[time.Time]

Time creates a time.Time validation schema.

Time()                    // no parameters
Time("custom error")      // string shorthand
Time(SchemaParams{...})   // full parameters

func TimePtr added in v0.3.0

func TimePtr(params ...any) *ZodTime[*time.Time]

TimePtr creates a *time.Time validation schema.

func TimeTyped added in v0.3.0

func TimeTyped[T TimeConstraint](params ...any) *ZodTime[T]

TimeTyped creates a time schema with explicit type parameterization.

func (*ZodTime[T]) And added in v0.6.0

func (z *ZodTime[T]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodTime[T]) Check added in v0.6.0

func (z *ZodTime[T]) Check(fn func(value T, payload *core.ParsePayload), params ...any) *ZodTime[T]

Check applies a custom validation function with full payload access (Zod v4 API).

func (*ZodTime[T]) CloneFrom added in v0.3.0

func (z *ZodTime[T]) CloneFrom(source any)

CloneFrom copies configuration from another schema of the same type.

func (*ZodTime[T]) Coerce added in v0.3.0

func (z *ZodTime[T]) Coerce(input any) (any, bool)

Coerce converts input to time.Time.

func (*ZodTime[T]) Default added in v0.3.0

func (z *ZodTime[T]) Default(v time.Time) *ZodTime[T]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodTime[T]) DefaultFunc added in v0.3.0

func (z *ZodTime[T]) DefaultFunc(fn func() time.Time) *ZodTime[T]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodTime[T]) Describe added in v0.5.4

func (z *ZodTime[T]) Describe(desc string) *ZodTime[T]

Describe registers a description in the global registry.

func (*ZodTime[T]) ExactOptional added in v0.6.0

func (z *ZodTime[T]) ExactOptional() *ZodTime[T]

ExactOptional accepts absent keys but rejects explicit nil values. Unlike Optional, ExactOptional only accepts absent keys in object fields.

func (*ZodTime[T]) Internals added in v0.6.0

func (z *ZodTime[T]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodTime[T]) IsNilable added in v0.3.0

func (z *ZodTime[T]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodTime[T]) IsOptional added in v0.3.0

func (z *ZodTime[T]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodTime[T]) Meta added in v0.3.1

func (z *ZodTime[T]) Meta(meta core.GlobalMeta) *ZodTime[T]

Meta stores metadata for this time schema in the global registry.

func (*ZodTime[T]) MustParse added in v0.3.0

func (z *ZodTime[T]) MustParse(input any, ctx ...*core.ParseContext) T

MustParse validates input and panics on failure.

func (*ZodTime[T]) MustStrictParse added in v0.4.0

func (z *ZodTime[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse requires exact type T and panics on failure.

func (*ZodTime[T]) Nilable added in v0.3.0

func (z *ZodTime[T]) Nilable() *ZodTime[*time.Time]

Nilable returns a new schema that accepts nil values, with *time.Time constraint.

func (*ZodTime[T]) NonOptional added in v0.6.0

func (z *ZodTime[T]) NonOptional() *ZodTime[time.Time]

NonOptional removes the optional flag, returning a time.Time constraint.

func (*ZodTime[T]) Nullish added in v0.3.0

func (z *ZodTime[T]) Nullish() *ZodTime[*time.Time]

Nullish returns a new schema combining optional and nilable modifiers.

func (*ZodTime[T]) Optional added in v0.3.0

func (z *ZodTime[T]) Optional() *ZodTime[*time.Time]

Optional returns a new schema that accepts nil, with *time.Time constraint.

func (*ZodTime[T]) Or added in v0.6.0

func (z *ZodTime[T]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodTime[T]) Overwrite added in v0.3.0

func (z *ZodTime[T]) Overwrite(transform func(T) T, params ...any) *ZodTime[T]

Overwrite transforms the input value while preserving the original type.

func (*ZodTime[T]) Parse added in v0.3.0

func (z *ZodTime[T]) Parse(input any, ctx ...*core.ParseContext) (T, error)

Parse validates input and returns a value of type T.

func (*ZodTime[T]) ParseAny added in v0.3.0

func (z *ZodTime[T]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns any type for runtime interface usage.

func (*ZodTime[T]) Pipe added in v0.3.0

func (z *ZodTime[T]) Pipe(target core.ZodType[any]) *core.ZodPipe[T, any]

Pipe creates a validation pipeline with another schema.

func (*ZodTime[T]) Prefault added in v0.3.0

func (z *ZodTime[T]) Prefault(v time.Time) *ZodTime[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodTime[T]) PrefaultFunc added in v0.3.0

func (z *ZodTime[T]) PrefaultFunc(fn func() time.Time) *ZodTime[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodTime[T]) Refine added in v0.3.0

func (z *ZodTime[T]) Refine(fn func(T) bool, params ...any) *ZodTime[T]

Refine applies a custom validation function matching the schema's output type T.

func (*ZodTime[T]) RefineAny added in v0.3.0

func (z *ZodTime[T]) RefineAny(fn func(any) bool, params ...any) *ZodTime[T]

RefineAny applies a custom validation function that receives the raw value.

func (*ZodTime[T]) StrictParse added in v0.4.0

func (z *ZodTime[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse requires exact type T for compile-time type safety.

func (*ZodTime[T]) Transform added in v0.3.0

func (z *ZodTime[T]) Transform(fn func(time.Time, *core.RefinementContext) (any, error)) *core.ZodTransform[T, any]

Transform applies a transformation function to the parsed value.

func (*ZodTime[T]) With added in v0.6.0

func (z *ZodTime[T]) With(fn func(value T, payload *core.ParsePayload), params ...any) *ZodTime[T]

With is an alias for Check (Zod v4 API compatibility).

type ZodTimeDef added in v0.3.0

type ZodTimeDef struct {
	core.ZodTypeDef
}

ZodTimeDef holds the configuration for a time schema.

type ZodTimeInternals added in v0.3.0

type ZodTimeInternals struct {
	core.ZodTypeInternals
	Def *ZodTimeDef
}

ZodTimeInternals holds time validator internal state.

type ZodTuple added in v0.5.4

type ZodTuple[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodTuple represents a type-safe tuple validation schema. T is the base type ([]any), R is the constraint type ([]any or *[]any).

func Tuple added in v0.5.4

func Tuple(items ...core.ZodSchema) *ZodTuple[[]any, []any]

Tuple creates a tuple schema with fixed positional items.

func TuplePtr added in v0.5.4

func TuplePtr(items ...core.ZodSchema) *ZodTuple[[]any, *[]any]

TuplePtr creates an optional tuple schema that returns *[]any.

func TupleTyped added in v0.5.4

func TupleTyped[T any, R any](items []core.ZodSchema, rest core.ZodSchema, params ...any) *ZodTuple[T, R]

TupleTyped creates a tuple schema with explicit type parameters.

func TupleWithRest added in v0.5.4

func TupleWithRest(items []core.ZodSchema, rest core.ZodSchema, params ...any) *ZodTuple[[]any, []any]

TupleWithRest creates a tuple schema with fixed items and a rest element.

func (*ZodTuple[T, R]) Check added in v0.5.4

func (z *ZodTuple[T, R]) Check(check core.ZodCheck) *ZodTuple[T, R]

Check adds a custom validation check.

func (*ZodTuple[T, R]) Default added in v0.5.4

func (z *ZodTuple[T, R]) Default(v []any) *ZodTuple[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodTuple[T, R]) Describe added in v0.5.4

func (z *ZodTuple[T, R]) Describe(description string) *ZodTuple[T, R]

Describe registers a description in the global registry.

func (*ZodTuple[T, R]) ExactOptional added in v0.6.0

func (z *ZodTuple[T, R]) ExactOptional() *ZodTuple[T, R]

ExactOptional accepts absent keys but rejects explicit nil values.

func (*ZodTuple[T, R]) Internals added in v0.6.0

func (z *ZodTuple[T, R]) Internals() *core.ZodTypeInternals

Internals exposes the internal state for framework usage.

func (*ZodTuple[T, R]) IsNilable added in v0.5.4

func (z *ZodTuple[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodTuple[T, R]) IsOptional added in v0.5.4

func (z *ZodTuple[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined or missing values.

func (*ZodTuple[T, R]) Items added in v0.6.0

func (z *ZodTuple[T, R]) Items() []core.ZodSchema

Items returns the tuple item schemas.

func (*ZodTuple[T, R]) Length added in v0.5.4

func (z *ZodTuple[T, R]) Length(length int, params ...any) *ZodTuple[T, R]

Length sets the exact tuple length validation.

func (*ZodTuple[T, R]) Max added in v0.5.4

func (z *ZodTuple[T, R]) Max(maximum int, params ...any) *ZodTuple[T, R]

Max sets the maximum tuple length validation.

func (*ZodTuple[T, R]) Meta added in v0.5.4

func (z *ZodTuple[T, R]) Meta(meta core.GlobalMeta) *ZodTuple[T, R]

Meta stores metadata for this tuple schema.

func (*ZodTuple[T, R]) Min added in v0.5.4

func (z *ZodTuple[T, R]) Min(minimum int, params ...any) *ZodTuple[T, R]

Min sets the minimum tuple length validation.

func (*ZodTuple[T, R]) MustParse added in v0.5.4

func (z *ZodTuple[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse validates the input value and panics on failure.

func (*ZodTuple[T, R]) MustStrictParse added in v0.5.4

func (z *ZodTuple[T, R]) MustStrictParse(input T, ctx ...*core.ParseContext) R

MustStrictParse provides compile-time type safety and panics on failure.

func (*ZodTuple[T, R]) Nilable added in v0.5.4

func (z *ZodTuple[T, R]) Nilable() *ZodTuple[T, *[]any]

Nilable marks this tuple as nilable.

func (*ZodTuple[T, R]) NonEmpty added in v0.5.4

func (z *ZodTuple[T, R]) NonEmpty(params ...any) *ZodTuple[T, R]

NonEmpty ensures the tuple has at least one element.

func (*ZodTuple[T, R]) Nullish added in v0.5.4

func (z *ZodTuple[T, R]) Nullish() *ZodTuple[T, *[]any]

Nullish marks this tuple as nullish (both optional and nilable).

func (*ZodTuple[T, R]) Optional added in v0.5.4

func (z *ZodTuple[T, R]) Optional() *ZodTuple[T, *[]any]

Optional marks this tuple as optional.

func (*ZodTuple[T, R]) Parse added in v0.5.4

func (z *ZodTuple[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates the input and returns a value matching the constraint type R.

func (*ZodTuple[T, R]) ParseAny added in v0.5.4

func (z *ZodTuple[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates the input and returns any type for runtime interface usage.

func (*ZodTuple[T, R]) Refine added in v0.5.4

func (z *ZodTuple[T, R]) Refine(fn func([]any) bool, params ...any) *ZodTuple[T, R]

Refine adds a custom validation function.

func (*ZodTuple[T, R]) Rest added in v0.5.4

func (z *ZodTuple[T, R]) Rest() core.ZodSchema

Rest returns the rest element schema.

func (*ZodTuple[T, R]) StrictParse added in v0.5.4

func (z *ZodTuple[T, R]) StrictParse(input T, ctx ...*core.ParseContext) (R, error)

StrictParse provides compile-time type safety by requiring the exact type T.

func (*ZodTuple[T, R]) With added in v0.5.4

func (z *ZodTuple[T, R]) With(check core.ZodCheck) *ZodTuple[T, R]

With is an alias for Check, for Zod v4 compatibility.

func (*ZodTuple[T, R]) WithRest added in v0.6.0

func (z *ZodTuple[T, R]) WithRest(restSchema core.ZodSchema) *ZodTuple[T, R]

WithRest sets a rest element schema for additional elements beyond the fixed items.

type ZodTupleDef added in v0.5.4

type ZodTupleDef struct {
	core.ZodTypeDef
	Items []core.ZodSchema // Fixed positional item schemas.
	Rest  core.ZodSchema   // Rest element schema (optional, for variadic elements).
}

ZodTupleDef defines the schema definition for tuple validation.

type ZodTupleInternals added in v0.5.4

type ZodTupleInternals struct {
	core.ZodTypeInternals
	Def           *ZodTupleDef
	Items         []core.ZodSchema // Item schemas for runtime validation.
	Rest          core.ZodSchema   // Rest element schema.
	RequiredCount int              // Number of required items (up to first optional from end).
}

ZodTupleInternals contains the internal state for tuple schema.

type ZodULID added in v0.3.0

type ZodULID[T StringConstraint] struct{ *ZodString[T] }

ZodULID validates strings in ULID format.

func ULID added in v0.7.0

func ULID(params ...any) *ZodULID[string]

ULID creates a ULID schema.

func ULIDPtr added in v0.7.0

func ULIDPtr(params ...any) *ZodULID[*string]

ULIDPtr creates a pointer ULID schema.

func (*ZodULID[T]) Default added in v0.10.5

func (z *ZodULID[T]) Default(v string) *ZodULID[T]

Default sets a fallback value returned when input is nil.

func (*ZodULID[T]) DefaultFunc added in v0.10.5

func (z *ZodULID[T]) DefaultFunc(fn func() string) *ZodULID[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodULID[T]) Describe added in v0.10.5

func (z *ZodULID[T]) Describe(description string) *ZodULID[T]

Describe attaches a description to this schema via the global registry.

func (*ZodULID[T]) Meta added in v0.10.5

func (z *ZodULID[T]) Meta(meta core.GlobalMeta) *ZodULID[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodULID[T]) MustStrictParse added in v0.4.0

func (z *ZodULID[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodULID[T]) Nilable added in v0.6.0

func (z *ZodULID[T]) Nilable() *ZodULID[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodULID[T]) Nullish added in v0.6.0

func (z *ZodULID[T]) Nullish() *ZodULID[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodULID[T]) Optional added in v0.6.0

func (z *ZodULID[T]) Optional() *ZodULID[*string]

Optional returns a new schema that accepts nil values.

func (*ZodULID[T]) Prefault added in v0.10.5

func (z *ZodULID[T]) Prefault(v string) *ZodULID[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodULID[T]) PrefaultFunc added in v0.10.5

func (z *ZodULID[T]) PrefaultFunc(fn func() string) *ZodULID[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodULID[T]) RefineAny added in v0.10.5

func (z *ZodULID[T]) RefineAny(fn func(any) bool, params ...any) *ZodULID[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodULID[T]) StrictParse added in v0.4.0

func (z *ZodULID[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodURL added in v0.3.0

type ZodURL[T StringConstraint] struct{ *ZodString[T] }

ZodURL validates strings in URL format.

func CoercedURL added in v0.3.0

func CoercedURL(params ...any) *ZodURL[string]

CoercedURL creates a coerced URL schema that attempts string conversion.

func HTTPURL added in v0.6.0

func HTTPURL(params ...any) *ZodURL[string]

HTTPURL creates a URL validation schema that only accepts http:// or https:// protocols.

func HTTPURLPtr added in v0.6.0

func HTTPURLPtr(params ...any) *ZodURL[*string]

HTTPURLPtr creates a pointer URL validation schema that only accepts http:// or https:// protocols.

func HTTPURLTyped added in v0.6.0

func HTTPURLTyped[T StringConstraint](params ...any) *ZodURL[T]

HTTPURLTyped creates a URL validation schema with the given type constraint that only accepts http:// or https:// protocols.

func URL added in v0.3.0

func URL(params ...any) *ZodURL[string]

URL creates a URL validation schema. Accepts optional URLOptions as first parameter for custom validation.

func URLPtr added in v0.3.0

func URLPtr(params ...any) *ZodURL[*string]

URLPtr creates a pointer URL validation schema. Accepts optional URLOptions as first parameter for custom validation.

func URLTyped added in v0.3.0

func URLTyped[T StringConstraint](params ...any) *ZodURL[T]

URLTyped creates a URL validation schema with the given type constraint. Accepts optional URLOptions as first parameter for custom validation.

func (*ZodURL[T]) Default added in v0.3.0

func (z *ZodURL[T]) Default(v string) *ZodURL[T]

Default sets a fallback value returned when input is nil.

func (*ZodURL[T]) DefaultFunc added in v0.3.0

func (z *ZodURL[T]) DefaultFunc(fn func() string) *ZodURL[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodURL[T]) Describe added in v0.10.5

func (z *ZodURL[T]) Describe(description string) *ZodURL[T]

Describe attaches a description to this schema via the global registry.

func (*ZodURL[T]) Meta added in v0.10.5

func (z *ZodURL[T]) Meta(meta core.GlobalMeta) *ZodURL[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodURL[T]) MustStrictParse added in v0.4.0

func (z *ZodURL[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodURL[T]) Nilable added in v0.3.0

func (z *ZodURL[T]) Nilable() *ZodURL[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodURL[T]) Nullish added in v0.3.0

func (z *ZodURL[T]) Nullish() *ZodURL[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodURL[T]) Optional added in v0.3.0

func (z *ZodURL[T]) Optional() *ZodURL[*string]

Optional returns a new schema that accepts nil values.

func (*ZodURL[T]) Prefault added in v0.3.0

func (z *ZodURL[T]) Prefault(v string) *ZodURL[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodURL[T]) PrefaultFunc added in v0.3.0

func (z *ZodURL[T]) PrefaultFunc(fn func() string) *ZodURL[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodURL[T]) RefineAny added in v0.3.0

func (z *ZodURL[T]) RefineAny(fn func(any) bool, params ...any) *ZodURL[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodURL[T]) StrictParse added in v0.4.0

func (z *ZodURL[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodUUID added in v0.3.0

type ZodUUID[T StringConstraint] struct{ *ZodString[T] }

ZodUUID validates strings in UUID format.

func UUID added in v0.7.0

func UUID(params ...any) *ZodUUID[string]

UUID creates a UUID schema with optional version parameter: "v4", "v6", "v7".

func UUIDPtr added in v0.7.0

func UUIDPtr(params ...any) *ZodUUID[*string]

UUIDPtr creates a pointer UUID schema with optional version parameter.

func UUIDv4 added in v0.7.0

func UUIDv4(params ...any) *ZodUUID[string]

UUIDv4 creates a UUID v4 schema.

func UUIDv4Ptr added in v0.7.0

func UUIDv4Ptr(params ...any) *ZodUUID[*string]

UUIDv4Ptr creates a pointer UUID v4 schema.

func UUIDv6 added in v0.7.0

func UUIDv6(params ...any) *ZodUUID[string]

UUIDv6 creates a UUID v6 schema.

func UUIDv6Ptr added in v0.7.0

func UUIDv6Ptr(params ...any) *ZodUUID[*string]

UUIDv6Ptr creates a pointer UUID v6 schema.

func UUIDv7 added in v0.7.0

func UUIDv7(params ...any) *ZodUUID[string]

UUIDv7 creates a UUID v7 schema.

func UUIDv7Ptr added in v0.7.0

func UUIDv7Ptr(params ...any) *ZodUUID[*string]

UUIDv7Ptr creates a pointer UUID v7 schema.

func (*ZodUUID[T]) Default added in v0.10.5

func (z *ZodUUID[T]) Default(v string) *ZodUUID[T]

Default sets a fallback value returned when input is nil.

func (*ZodUUID[T]) DefaultFunc added in v0.10.5

func (z *ZodUUID[T]) DefaultFunc(fn func() string) *ZodUUID[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodUUID[T]) Describe added in v0.10.5

func (z *ZodUUID[T]) Describe(description string) *ZodUUID[T]

Describe attaches a description to this schema via the global registry.

func (*ZodUUID[T]) Meta added in v0.10.5

func (z *ZodUUID[T]) Meta(meta core.GlobalMeta) *ZodUUID[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodUUID[T]) MustStrictParse added in v0.4.0

func (z *ZodUUID[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodUUID[T]) Nilable added in v0.6.0

func (z *ZodUUID[T]) Nilable() *ZodUUID[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodUUID[T]) Nullish added in v0.6.0

func (z *ZodUUID[T]) Nullish() *ZodUUID[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodUUID[T]) Optional added in v0.6.0

func (z *ZodUUID[T]) Optional() *ZodUUID[*string]

Optional returns a new schema that accepts nil values.

func (*ZodUUID[T]) Prefault added in v0.10.5

func (z *ZodUUID[T]) Prefault(v string) *ZodUUID[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodUUID[T]) PrefaultFunc added in v0.10.5

func (z *ZodUUID[T]) PrefaultFunc(fn func() string) *ZodUUID[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodUUID[T]) RefineAny added in v0.10.5

func (z *ZodUUID[T]) RefineAny(fn func(any) bool, params ...any) *ZodUUID[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodUUID[T]) StrictParse added in v0.4.0

func (z *ZodUUID[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodUnion

type ZodUnion[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodUnion validates that input matches at least one member schema. T is the base type, R is the constraint type (T or *T for optional/nilable).

func Union

func Union(options []any, args ...any) *ZodUnion[any, any]

Union creates a union schema that accepts one of multiple types.

func UnionOf added in v0.3.0

func UnionOf(schemas ...any) *ZodUnion[any, any]

UnionOf creates a union schema from variadic arguments.

func UnionOfPtr added in v0.3.0

func UnionOfPtr(schemas ...any) *ZodUnion[any, *any]

UnionOfPtr creates a union schema from variadic arguments with pointer constraint.

func UnionPtr added in v0.3.0

func UnionPtr(options []any, args ...any) *ZodUnion[any, *any]

UnionPtr creates a union schema with pointer constraint type.

func UnionTyped added in v0.3.0

func UnionTyped[T any, R any](options []any, args ...any) *ZodUnion[T, R]

UnionTyped creates a typed union schema with generic constraints.

func (*ZodUnion[T, R]) And added in v0.5.4

func (z *ZodUnion[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection of this schema with another.

func (*ZodUnion[T, R]) CloneFrom

func (z *ZodUnion[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodUnion[T, R]) Default

func (z *ZodUnion[T, R]) Default(v T) *ZodUnion[T, R]

Default sets a value to use when input is nil, bypassing validation.

func (*ZodUnion[T, R]) DefaultFunc

func (z *ZodUnion[T, R]) DefaultFunc(fn func() T) *ZodUnion[T, R]

DefaultFunc sets a function to produce the default value when input is nil.

func (*ZodUnion[T, R]) Describe added in v0.5.4

func (z *ZodUnion[T, R]) Describe(desc string) *ZodUnion[T, R]

Describe sets a human-readable description for this schema.

func (*ZodUnion[T, R]) Internals added in v0.6.0

func (z *ZodUnion[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state for framework usage.

func (*ZodUnion[T, R]) IsNilable added in v0.3.0

func (z *ZodUnion[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodUnion[T, R]) IsOptional added in v0.3.0

func (z *ZodUnion[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodUnion[T, R]) Meta added in v0.3.1

func (z *ZodUnion[T, R]) Meta(meta core.GlobalMeta) *ZodUnion[T, R]

Meta attaches metadata to this schema.

func (*ZodUnion[T, R]) MustParse

func (z *ZodUnion[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse is like Parse but panics on validation failure.

func (*ZodUnion[T, R]) MustStrictParse added in v0.4.0

func (z *ZodUnion[T, R]) MustStrictParse(input T, ctx ...*core.ParseContext) R

MustStrictParse is like StrictParse but panics on validation failure.

func (*ZodUnion[T, R]) Nilable

func (z *ZodUnion[T, R]) Nilable() *ZodUnion[T, *T]

Nilable returns a new schema that accepts nil values.

func (*ZodUnion[T, R]) NonOptional added in v0.3.0

func (z *ZodUnion[T, R]) NonOptional() *ZodUnion[T, T]

NonOptional returns a new schema that enforces non-nil values.

func (*ZodUnion[T, R]) Nullish added in v0.3.0

func (z *ZodUnion[T, R]) Nullish() *ZodUnion[T, *T]

Nullish returns a new schema that accepts both undefined and nil values.

func (*ZodUnion[T, R]) Optional

func (z *ZodUnion[T, R]) Optional() *ZodUnion[T, *T]

Optional returns a new schema that accepts undefined/missing values.

func (*ZodUnion[T, R]) Options

func (z *ZodUnion[T, R]) Options() []core.ZodSchema

Options returns a copy of all union member schemas.

func (*ZodUnion[T, R]) Or added in v0.5.4

func (z *ZodUnion[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union of this schema with another.

func (*ZodUnion[T, R]) Parse

func (z *ZodUnion[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input against all union member schemas, returning the first match.

func (*ZodUnion[T, R]) ParseAny added in v0.3.0

func (z *ZodUnion[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodUnion[T, R]) Pipe

func (z *ZodUnion[T, R]) Pipe(
	target core.ZodType[any],
) *core.ZodPipe[R, any]

Pipe chains this schema's output into another schema for further validation.

func (*ZodUnion[T, R]) Prefault

func (z *ZodUnion[T, R]) Prefault(v T) *ZodUnion[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodUnion[T, R]) PrefaultFunc

func (z *ZodUnion[T, R]) PrefaultFunc(fn func() T) *ZodUnion[T, R]

PrefaultFunc sets a function to produce the prefault value.

func (*ZodUnion[T, R]) Refine

func (z *ZodUnion[T, R]) Refine(
	fn func(R) bool,
	params ...any,
) *ZodUnion[T, R]

Refine adds a custom validation check with type-safe access to the parsed value.

func (*ZodUnion[T, R]) RefineAny

func (z *ZodUnion[T, R]) RefineAny(
	fn func(any) bool,
	params ...any,
) *ZodUnion[T, R]

RefineAny adds a custom validation check operating on the raw value.

func (*ZodUnion[T, R]) StrictParse added in v0.4.0

func (z *ZodUnion[T, R]) StrictParse(input T, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety.

func (*ZodUnion[T, R]) Transform

func (z *ZodUnion[T, R]) Transform(
	fn func(T, *core.RefinementContext) (any, error),
) *core.ZodTransform[R, any]

Transform creates a type-safe transformation pipeline.

type ZodUnionDef

type ZodUnionDef struct {
	core.ZodTypeDef
	Options []core.ZodSchema
}

ZodUnionDef holds the configuration for union validation.

type ZodUnionInternals

type ZodUnionInternals struct {
	core.ZodTypeInternals
	Def     *ZodUnionDef
	Options []core.ZodSchema
}

ZodUnionInternals holds the internal state for a union schema.

type ZodUnknown

type ZodUnknown[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodUnknown validates unknown values with dual generic parameters. T is the base type, R is the constraint type (T or *T).

func Unknown

func Unknown(params ...any) *ZodUnknown[any, any]

Unknown creates a schema that accepts unknown values.

func UnknownPtr added in v0.3.0

func UnknownPtr(params ...any) *ZodUnknown[any, *any]

UnknownPtr creates a schema that accepts unknown values with pointer constraint.

func UnknownTyped added in v0.3.0

func UnknownTyped[T any, R any](params ...any) *ZodUnknown[T, R]

UnknownTyped creates a typed unknown schema with generic constraints.

func (*ZodUnknown[T, R]) And added in v0.6.0

func (z *ZodUnknown[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection with another schema.

func (*ZodUnknown[T, R]) Check

func (z *ZodUnknown[T, R]) Check(fn func(value R, payload *core.ParsePayload), params ...any) *ZodUnknown[T, R]

Check adds a custom validation function that can push multiple issues.

func (*ZodUnknown[T, R]) CloneFrom

func (z *ZodUnknown[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodUnknown[T, R]) Default

func (z *ZodUnknown[T, R]) Default(v T) *ZodUnknown[T, R]

Default sets a fallback value returned when input is nil (short-circuits validation).

func (*ZodUnknown[T, R]) DefaultFunc

func (z *ZodUnknown[T, R]) DefaultFunc(fn func() T) *ZodUnknown[T, R]

DefaultFunc sets a fallback function called when input is nil (short-circuits validation).

func (*ZodUnknown[T, R]) Describe added in v0.5.4

func (z *ZodUnknown[T, R]) Describe(desc string) *ZodUnknown[T, R]

Describe registers a description in the global registry.

func (*ZodUnknown[T, R]) ExactOptional added in v0.6.0

func (z *ZodUnknown[T, R]) ExactOptional() *ZodUnknown[T, R]

ExactOptional accepts absent keys but rejects explicit nil values.

func (*ZodUnknown[T, R]) Internals added in v0.6.0

func (z *ZodUnknown[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state of the schema.

func (*ZodUnknown[T, R]) IsNilable added in v0.3.0

func (z *ZodUnknown[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodUnknown[T, R]) IsOptional added in v0.3.0

func (z *ZodUnknown[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodUnknown[T, R]) Meta added in v0.3.1

func (z *ZodUnknown[T, R]) Meta(meta core.GlobalMeta) *ZodUnknown[T, R]

Meta stores metadata in the global registry.

func (*ZodUnknown[T, R]) MustParse

func (z *ZodUnknown[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse panics on validation error.

func (*ZodUnknown[T, R]) MustStrictParse added in v0.4.0

func (z *ZodUnknown[T, R]) MustStrictParse(input R, ctx ...*core.ParseContext) R

MustStrictParse panics on validation error with compile-time type safety.

func (*ZodUnknown[T, R]) Nilable

func (z *ZodUnknown[T, R]) Nilable() *ZodUnknown[T, *T]

Nilable returns a pointer-typed schema that accepts nil values.

func (*ZodUnknown[T, R]) NonOptional added in v0.3.0

func (z *ZodUnknown[T, R]) NonOptional() *ZodUnknown[T, T]

NonOptional removes the optional flag and forces return type to T.

func (*ZodUnknown[T, R]) Nullish

func (z *ZodUnknown[T, R]) Nullish() *ZodUnknown[T, *T]

Nullish combines optional and nilable modifiers.

func (*ZodUnknown[T, R]) Optional

func (z *ZodUnknown[T, R]) Optional() *ZodUnknown[T, *T]

Optional returns a pointer-typed schema that accepts missing values.

func (*ZodUnknown[T, R]) Or added in v0.6.0

func (z *ZodUnknown[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union with another schema.

func (*ZodUnknown[T, R]) Overwrite added in v0.3.0

func (z *ZodUnknown[T, R]) Overwrite(transform func(T) T, params ...any) *ZodUnknown[T, R]

Overwrite applies data transformation while preserving type structure.

func (*ZodUnknown[T, R]) Parse

func (z *ZodUnknown[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input and returns a value matching the generic type R.

func (*ZodUnknown[T, R]) ParseAny added in v0.3.0

func (z *ZodUnknown[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result.

func (*ZodUnknown[T, R]) Pipe

func (z *ZodUnknown[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe creates a pipeline to another schema.

func (*ZodUnknown[T, R]) Prefault

func (z *ZodUnknown[T, R]) Prefault(v T) *ZodUnknown[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodUnknown[T, R]) PrefaultFunc

func (z *ZodUnknown[T, R]) PrefaultFunc(fn func() T) *ZodUnknown[T, R]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodUnknown[T, R]) Refine

func (z *ZodUnknown[T, R]) Refine(fn func(R) bool, params ...any) *ZodUnknown[T, R]

Refine applies a custom validation function matching the schema's output type R.

func (*ZodUnknown[T, R]) RefineAny

func (z *ZodUnknown[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodUnknown[T, R]

RefineAny provides flexible validation without type conversion.

func (*ZodUnknown[T, R]) StrictParse added in v0.4.0

func (z *ZodUnknown[T, R]) StrictParse(input R, ctx ...*core.ParseContext) (R, error)

StrictParse provides type-safe parsing with compile-time guarantees.

func (*ZodUnknown[T, R]) Transform

func (z *ZodUnknown[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform applies a transformation function.

func (*ZodUnknown[T, R]) With added in v0.6.0

func (z *ZodUnknown[T, R]) With(fn func(value R, payload *core.ParsePayload), params ...any) *ZodUnknown[T, R]

With is an alias for Check for Zod v4 API compatibility.

type ZodUnknownDef

type ZodUnknownDef struct {
	core.ZodTypeDef
}

ZodUnknownDef holds the configuration for unknown value validation.

type ZodUnknownInternals

type ZodUnknownInternals struct {
	core.ZodTypeInternals
	Def *ZodUnknownDef
}

ZodUnknownInternals contains the internal state of an unknown validator.

type ZodXID added in v0.3.0

type ZodXID[T StringConstraint] struct{ *ZodString[T] }

ZodXID validates strings in XID format.

func XID added in v0.7.0

func XID(params ...any) *ZodXID[string]

XID creates an XID schema.

func XIDPtr added in v0.7.0

func XIDPtr(params ...any) *ZodXID[*string]

XIDPtr creates a pointer XID schema.

func (*ZodXID[T]) Default added in v0.10.5

func (z *ZodXID[T]) Default(v string) *ZodXID[T]

Default sets a fallback value returned when input is nil.

func (*ZodXID[T]) DefaultFunc added in v0.10.5

func (z *ZodXID[T]) DefaultFunc(fn func() string) *ZodXID[T]

DefaultFunc sets a fallback function called when input is nil.

func (*ZodXID[T]) Describe added in v0.10.5

func (z *ZodXID[T]) Describe(description string) *ZodXID[T]

Describe attaches a description to this schema via the global registry.

func (*ZodXID[T]) Meta added in v0.10.5

func (z *ZodXID[T]) Meta(meta core.GlobalMeta) *ZodXID[T]

Meta attaches metadata to this schema via the global registry.

func (*ZodXID[T]) MustStrictParse added in v0.4.0

func (z *ZodXID[T]) MustStrictParse(input T, ctx ...*core.ParseContext) T

MustStrictParse validates input with compile-time type safety and panics on error.

func (*ZodXID[T]) Nilable added in v0.6.0

func (z *ZodXID[T]) Nilable() *ZodXID[*string]

Nilable returns a new schema that accepts nil values.

func (*ZodXID[T]) Nullish added in v0.6.0

func (z *ZodXID[T]) Nullish() *ZodXID[*string]

Nullish returns a new schema combining optional and nilable.

func (*ZodXID[T]) Optional added in v0.6.0

func (z *ZodXID[T]) Optional() *ZodXID[*string]

Optional returns a new schema that accepts nil values.

func (*ZodXID[T]) Prefault added in v0.10.5

func (z *ZodXID[T]) Prefault(v string) *ZodXID[T]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodXID[T]) PrefaultFunc added in v0.10.5

func (z *ZodXID[T]) PrefaultFunc(fn func() string) *ZodXID[T]

PrefaultFunc sets a fallback function that goes through the full validation pipeline.

func (*ZodXID[T]) RefineAny added in v0.10.5

func (z *ZodXID[T]) RefineAny(fn func(any) bool, params ...any) *ZodXID[T]

RefineAny adds custom validation that receives the raw value as any.

func (*ZodXID[T]) StrictParse added in v0.4.0

func (z *ZodXID[T]) StrictParse(input T, ctx ...*core.ParseContext) (T, error)

StrictParse validates input with compile-time type safety.

type ZodXor added in v0.5.4

type ZodXor[T any, R any] struct {
	// contains filtered or unexported fields
}

ZodXor validates that input matches exactly one member schema. T is the base type, R is the constraint type (T or *T for optional/nilable).

func Xor added in v0.5.4

func Xor(options []any, args ...any) *ZodXor[any, any]

Xor creates an exclusive union schema that requires exactly one option to match. Unlike Union which succeeds when any option matches, Xor fails if zero or multiple match.

func XorOf added in v0.5.4

func XorOf(schemas ...any) *ZodXor[any, any]

XorOf creates an exclusive union schema from variadic arguments.

func XorOfPtr added in v0.5.4

func XorOfPtr(schemas ...any) *ZodXor[any, *any]

XorOfPtr creates an exclusive union schema from variadic arguments with pointer constraint.

func XorPtr added in v0.5.4

func XorPtr(options []any, args ...any) *ZodXor[any, *any]

XorPtr creates an exclusive union schema with pointer constraint type.

func XorTyped added in v0.5.4

func XorTyped[T any, R any](options []any, args ...any) *ZodXor[T, R]

XorTyped creates a typed exclusive union schema with generic constraints.

func (*ZodXor[T, R]) And added in v0.6.0

func (z *ZodXor[T, R]) And(other any) *ZodIntersection[any, any]

And creates an intersection of this schema with another.

func (*ZodXor[T, R]) CloneFrom added in v0.6.0

func (z *ZodXor[T, R]) CloneFrom(source any)

CloneFrom copies configuration from another schema.

func (*ZodXor[T, R]) Default added in v0.6.0

func (z *ZodXor[T, R]) Default(v T) *ZodXor[T, R]

Default sets a value to use when input is nil, bypassing validation.

func (*ZodXor[T, R]) DefaultFunc added in v0.6.0

func (z *ZodXor[T, R]) DefaultFunc(fn func() T) *ZodXor[T, R]

DefaultFunc sets a function to produce the default value when input is nil.

func (*ZodXor[T, R]) Describe added in v0.5.4

func (z *ZodXor[T, R]) Describe(description string) *ZodXor[T, R]

Describe sets a human-readable description for this schema.

func (*ZodXor[T, R]) Internals added in v0.6.0

func (z *ZodXor[T, R]) Internals() *core.ZodTypeInternals

Internals returns the internal state for framework usage.

func (*ZodXor[T, R]) IsNilable added in v0.5.4

func (z *ZodXor[T, R]) IsNilable() bool

IsNilable reports whether this schema accepts nil values.

func (*ZodXor[T, R]) IsOptional added in v0.5.4

func (z *ZodXor[T, R]) IsOptional() bool

IsOptional reports whether this schema accepts undefined/missing values.

func (*ZodXor[T, R]) Meta added in v0.5.4

func (z *ZodXor[T, R]) Meta(meta core.GlobalMeta) *ZodXor[T, R]

Meta attaches metadata to this schema.

func (*ZodXor[T, R]) MustParse added in v0.5.4

func (z *ZodXor[T, R]) MustParse(input any, ctx ...*core.ParseContext) R

MustParse is like Parse but panics on validation failure.

func (*ZodXor[T, R]) MustStrictParse added in v0.5.4

func (z *ZodXor[T, R]) MustStrictParse(input T, ctx ...*core.ParseContext) R

MustStrictParse is like StrictParse but panics on validation failure.

func (*ZodXor[T, R]) Nilable added in v0.6.0

func (z *ZodXor[T, R]) Nilable() *ZodXor[T, *T]

Nilable returns a new schema that accepts nil values.

func (*ZodXor[T, R]) NonOptional added in v0.6.0

func (z *ZodXor[T, R]) NonOptional() *ZodXor[T, T]

NonOptional returns a new schema that enforces non-nil values.

func (*ZodXor[T, R]) Nullish added in v0.6.0

func (z *ZodXor[T, R]) Nullish() *ZodXor[T, *T]

Nullish returns a new schema that accepts both undefined and nil values.

func (*ZodXor[T, R]) Optional added in v0.6.0

func (z *ZodXor[T, R]) Optional() *ZodXor[T, *T]

Optional returns a new schema that accepts undefined/missing values.

func (*ZodXor[T, R]) Options added in v0.5.4

func (z *ZodXor[T, R]) Options() []core.ZodSchema

Options returns a copy of all exclusive union member schemas.

func (*ZodXor[T, R]) Or added in v0.6.0

func (z *ZodXor[T, R]) Or(other any) *ZodUnion[any, any]

Or creates a union of this schema with another, enabling chaining.

func (*ZodXor[T, R]) Parse added in v0.5.4

func (z *ZodXor[T, R]) Parse(input any, ctx ...*core.ParseContext) (R, error)

Parse validates input ensuring exactly one option matches.

func (*ZodXor[T, R]) ParseAny added in v0.5.4

func (z *ZodXor[T, R]) ParseAny(input any, ctx ...*core.ParseContext) (any, error)

ParseAny validates input and returns an untyped result for runtime scenarios.

func (*ZodXor[T, R]) Pipe added in v0.6.0

func (z *ZodXor[T, R]) Pipe(target core.ZodType[any]) *core.ZodPipe[R, any]

Pipe chains this schema's output into another schema for further validation.

func (*ZodXor[T, R]) Prefault added in v0.6.0

func (z *ZodXor[T, R]) Prefault(v T) *ZodXor[T, R]

Prefault sets a fallback value that goes through the full validation pipeline.

func (*ZodXor[T, R]) PrefaultFunc added in v0.6.0

func (z *ZodXor[T, R]) PrefaultFunc(fn func() T) *ZodXor[T, R]

PrefaultFunc sets a function to produce the prefault value.

func (*ZodXor[T, R]) Refine added in v0.6.0

func (z *ZodXor[T, R]) Refine(fn func(R) bool, params ...any) *ZodXor[T, R]

Refine adds a custom validation check with type-safe access to the parsed value.

func (*ZodXor[T, R]) RefineAny added in v0.6.0

func (z *ZodXor[T, R]) RefineAny(fn func(any) bool, params ...any) *ZodXor[T, R]

RefineAny adds a custom validation check operating on the raw value.

func (*ZodXor[T, R]) StrictParse added in v0.5.4

func (z *ZodXor[T, R]) StrictParse(input T, ctx ...*core.ParseContext) (R, error)

StrictParse validates input with compile-time type safety. The input must exactly match the schema's base type T.

func (*ZodXor[T, R]) Transform added in v0.6.0

func (z *ZodXor[T, R]) Transform(fn func(T, *core.RefinementContext) (any, error)) *core.ZodTransform[R, any]

Transform creates a type-safe transformation pipeline.

type ZodXorDef added in v0.5.4

type ZodXorDef struct {
	core.ZodTypeDef
	Options []core.ZodSchema
}

ZodXorDef defines the schema definition for exclusive union validation.

type ZodXorInternals added in v0.5.4

type ZodXorInternals struct {
	core.ZodTypeInternals
	Def     *ZodXorDef
	Options []core.ZodSchema
}

ZodXorInternals contains the internal state for exclusive union schema.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL