gozod

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 9 Imported by: 1

README

GoZod 🔷

GoZod is a TypeScript Zod-inspired validation library for Go, providing strongly-typed, zero-dependency data validation with intelligent type inference.

Go Version License Test Status

✨ Key Features

  • TypeScript Zod v4 Compatible API - Familiar syntax with Go-native optimizations
  • Intelligent Type Inference - Input types preserved in output with smart pointer handling
  • Zero Dependencies - Pure Go implementation, no external libraries
  • Optimized Performance - Efficient discriminated unions, optimized validation algorithms
  • Rich Validation Methods - Comprehensive built-in validators for all Go types
  • Type-Safe Method Chaining - Fluent API with compile-time type safety

📦 Quick Start

Installation
go get github.com/kaptinlin/gozod
Basic Usage
package main

import (
    "fmt"
    "github.com/kaptinlin/gozod"
)

func main() {
    // String validation with chaining
    nameSchema := gozod.String().Min(2).Max(50)
    result, err := nameSchema.Parse("Alice")
    if err == nil {
        fmt.Println("Valid name:", result) // "Alice"
    }

    // Email validation
    emailSchema := gozod.String().Email()
    result, err = emailSchema.Parse("user@example.com")
    // result: "user@example.com", err: nil
}
Object Schema Validation
// Define schema for structured data
userSchema := gozod.Object(gozod.ObjectSchema{
    "name":  gozod.String().Min(2).Max(50),
    "age":   gozod.Int().Min(0).Max(120),
    "email": gozod.String().Email().Optional(),
})

// Validate JSON-like data
userData := map[string]any{
    "name": "Alice",
    "age":  25,
    "email": "alice@example.com",
}

result, err := userSchema.Parse(userData)
if err != nil {
    fmt.Printf("Validation failed: %v\n", err)
    return
}

fmt.Printf("Valid user: %+v\n", result)
Type Coercion
// Automatic type conversion
stringSchema := gozod.Coerce.String()
result, _ := stringSchema.Parse(123)    // "123"

numberSchema := gozod.Coerce.Number()
result, _ = numberSchema.Parse("42")    // 42.0

// Schema-level coercion
coerceSchema := gozod.Int(gozod.SchemaParams{Coerce: true})
result, _ = coerceSchema.Parse("25")    // 25
Error Handling
schema := gozod.String().Min(5).Email()
_, err := schema.Parse("hi")

if err != nil {
    var zodErr *gozod.ZodError
    if gozod.IsZodError(err, &zodErr) {
        for _, issue := range zodErr.Issues {
            fmt.Printf("Error: %s at %v\n", issue.Message, issue.Path)
        }
    }
}

🔧 Core Concepts

Validation Methods
// String validation
gozod.String().Min(3).Max(100).Email().StartsWith("user")

// Number validation  
gozod.Int().Min(0).Max(120).Positive()

// Array validation
gozod.Slice(gozod.String()).Min(1).Max(10).NonEmpty()
Modifiers and Wrappers
// Optional (allows nil/missing)
gozod.String().Email().Optional()

// Nilable (handles explicit null values)
gozod.String().Nilable()  // Returns a typed nil (*string)(nil) for nil input

// Default values
gozod.String().Default("anonymous")

// Fallback on validation failure
gozod.String().Min(5).Prefault("fallback")
Advanced Types
// Enum types
colorEnum := gozod.Enum("red", "green", "blue")
statusMap := gozod.EnumMap(map[string]string{
	"ACTIVE": "active", 
	"INACTIVE": "inactive"
})

// Go native enum support
type Status int
const (
    Active Status = iota
    Inactive
)
statusEnum := gozod.Enum(Active, Inactive)

// Union types (OR logic)
gozod.Union([]gozod.ZodType[any, any]{gozod.String(), gozod.Int()})

// Discriminated unions (efficient lookup)
gozod.DiscriminatedUnion("type", schemas)

// Recursive types
var TreeNode gozod.ZodType[any, any]
TreeNode = gozod.Lazy(func() gozod.ZodType[any, any] {
    return gozod.Object(gozod.ObjectSchema{
        "value":    gozod.String(),
        "children": gozod.Slice(TreeNode),
    })
})

📚 Documentation

🔗 TypeScript Zod v4 Compatibility

GoZod provides comprehensive compatibility with TypeScript Zod v4 while adding Go-specific enhancements:

Core Type Support
  • Basic Types: string, number, boolean, bigint with Go-native type variants
  • Collections: array, object, record, map with smart type inference
  • Advanced Types: union, intersection, discriminated union, literal, enum
  • Modifiers: optional, nilable, default with Go semantics
Key Enhancements
  • Pointer Identity Preservation: Input pointer addresses maintained in output
  • Go-Specific Types: Support for all Go numeric types (int8-int64, uint8-uint64, float32/64, complex64/128)
  • Smart Nil Handling: Distinction between "missing field" (Optional) and "null value" (Nilable) semantics with simplified zero-value returns
  • Enhanced Error System: Structured error handling with custom formatting and internationalization
Compatibility Status

Fully Compatible: All major TypeScript Zod v4 features implemented
Go-Enhanced: Additional features leveraging Go's type system
Performance Optimized: Efficient validation algorithms and discriminated unions

For detailed feature mapping, migration guide, and compatibility matrix, see Feature Mapping Documentation.

🤝 Contributing

Contributions welcome! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

This project is a Go port inspired by the excellent TypeScript Zod implementation. We have adapted the core API design and added Go-specific optimizations while maintaining full compatibility with TypeScript Zod v4.

Special thanks to the original Zod project for providing a solid foundation and comprehensive test cases, which enabled this high-quality Go implementation.

Documentation

Index

Constants

View Source
const (
	IssueInvalidType      = core.InvalidType
	IssueInvalidValue     = core.InvalidValue
	IssueInvalidFormat    = core.InvalidFormat
	IssueInvalidUnion     = core.InvalidUnion
	IssueInvalidKey       = core.InvalidKey
	IssueInvalidElement   = core.InvalidElement
	IssueTooBig           = core.TooBig
	IssueTooSmall         = core.TooSmall
	IssueNotMultipleOf    = core.NotMultipleOf
	IssueUnrecognizedKeys = core.UnrecognizedKeys
	IssueCustom           = core.Custom
)

Issue code constants

Variables

View Source
var (
	Config    = core.Config
	GetConfig = core.GetConfig
)

Global configuration functions

View Source
var (
	String       = types.String
	StringPtr    = types.StringPtr
	Email        = types.Email
	EmailPtr     = types.EmailPtr
	Emoji        = types.Emoji
	EmojiPtr     = types.EmojiPtr
	Base64       = types.Base64
	Base64Ptr    = types.Base64Ptr
	Base64URL    = types.Base64URL
	Base64URLPtr = types.Base64URLPtr
)

String constructors

View Source
var (
	Bool    = types.Bool
	BoolPtr = types.BoolPtr
)

Boolean constructors

View Source
var (
	Int      = types.Int
	IntPtr   = types.IntPtr
	Int8     = types.Int8
	Int8Ptr  = types.Int8Ptr
	Int16    = types.Int16
	Int16Ptr = types.Int16Ptr
	Int32    = types.Int32
	Int32Ptr = types.Int32Ptr
	Int64    = types.Int64
	Int64Ptr = types.Int64Ptr
)

Integer constructors

View Source
var (
	Uint      = types.Uint
	UintPtr   = types.UintPtr
	Uint8     = types.Uint8
	Uint8Ptr  = types.Uint8Ptr
	Uint16    = types.Uint16
	Uint16Ptr = types.Uint16Ptr
	Uint32    = types.Uint32
	Uint32Ptr = types.Uint32Ptr
	Uint64    = types.Uint64
	Uint64Ptr = types.Uint64Ptr
)

Unsigned integer constructors

View Source
var (
	Float      = types.Float
	FloatPtr   = types.FloatPtr
	Float32    = types.Float32
	Float32Ptr = types.Float32Ptr
	Float64    = types.Float64
	Float64Ptr = types.Float64Ptr
	Number     = types.Number
	NumberPtr  = types.NumberPtr
)

Float constructors

View Source
var (
	BigInt    = types.BigInt
	BigIntPtr = types.BigIntPtr
)

BigInt constructors

View Source
var (
	Complex       = types.Complex
	ComplexPtr    = types.ComplexPtr
	Complex64     = types.Complex64
	Complex64Ptr  = types.Complex64Ptr
	Complex128    = types.Complex128
	Complex128Ptr = types.Complex128Ptr
)

Complex number constructors

View Source
var (
	Time    = types.Time
	TimePtr = types.TimePtr
)

Time constructors

View Source
var (
	IPv4      = types.IPv4
	IPv4Ptr   = types.IPv4Ptr
	IPv6      = types.IPv6
	IPv6Ptr   = types.IPv6Ptr
	CIDRv4    = types.CIDRv4
	CIDRv4Ptr = types.CIDRv4Ptr
	CIDRv6    = types.CIDRv6
	CIDRv6Ptr = types.CIDRv6Ptr
	URL       = types.URL
	URLPtr    = types.URLPtr
)

Network type constructors

View Source
var (
	Iso            = types.Iso
	IsoPtr         = types.IsoPtr
	IsoDateTime    = types.IsoDateTime
	IsoDateTimePtr = types.IsoDateTimePtr
	IsoDate        = types.IsoDate
	IsoDatePtr     = types.IsoDatePtr
	IsoTime        = types.IsoTime
	IsoTimePtr     = types.IsoTimePtr
	IsoDuration    = types.IsoDuration
	IsoDurationPtr = types.IsoDurationPtr
)

ISO 8601 format constructors

View Source
var (
	PrecisionMinute      = types.PrecisionMinute
	PrecisionSecond      = types.PrecisionSecond
	PrecisionDecisecond  = types.PrecisionDecisecond
	PrecisionCentisecond = types.PrecisionCentisecond
	PrecisionMillisecond = types.PrecisionMillisecond
	PrecisionMicrosecond = types.PrecisionMicrosecond
	PrecisionNanosecond  = types.PrecisionNanosecond
)

ISO precision constants

View Source
var (
	Cuid      = types.Cuid
	CuidPtr   = types.CuidPtr
	Cuid2     = types.Cuid2
	Cuid2Ptr  = types.Cuid2Ptr
	Ulid      = types.Ulid
	UlidPtr   = types.UlidPtr
	Xid       = types.Xid
	XidPtr    = types.XidPtr
	Ksuid     = types.Ksuid
	KsuidPtr  = types.KsuidPtr
	Nanoid    = types.Nanoid
	NanoidPtr = types.NanoidPtr
	Uuid      = types.Uuid
	UuidPtr   = types.UuidPtr
	Uuidv4    = types.Uuidv4
	Uuidv4Ptr = types.Uuidv4Ptr
	Uuidv6    = types.Uuidv6
	Uuidv6Ptr = types.Uuidv6Ptr
	Uuidv7    = types.Uuidv7
	Uuidv7Ptr = types.Uuidv7Ptr
	JWT       = types.JWT
	JWTPtr    = types.JWTPtr
)

Unique identifier constructors

View Source
var (
	Array    = types.Array
	ArrayPtr = types.ArrayPtr
	Map      = types.Map
	MapPtr   = types.MapPtr
)
View Source
var (
	Object          = types.Object
	ObjectPtr       = types.ObjectPtr
	StrictObject    = types.StrictObject
	StrictObjectPtr = types.StrictObjectPtr
	LooseObject     = types.LooseObject
	LooseObjectPtr  = types.LooseObjectPtr
)
View Source
var (
	Union                 = types.Union
	UnionPtr              = types.UnionPtr
	Intersection          = types.Intersection
	IntersectionPtr       = types.IntersectionPtr
	DiscriminatedUnion    = types.DiscriminatedUnion
	DiscriminatedUnionPtr = types.DiscriminatedUnionPtr
)

----------------------------------------------------------------------------- Composite Type Constructors -----------------------------------------------------------------------------

View Source
var (
	Any           = types.Any
	AnyPtr        = types.AnyPtr
	Unknown       = types.Unknown
	UnknownPtr    = types.UnknownPtr
	Never         = types.Never
	NeverPtr      = types.NeverPtr
	Nil           = types.Nil
	NilPtr        = types.NilPtr
	File          = types.File
	FilePtr       = types.FilePtr
	Function      = types.Function
	FunctionPtr   = types.FunctionPtr
	StringBool    = types.StringBool
	StringBoolPtr = types.StringBoolPtr
)

----------------------------------------------------------------------------- Special Type Constructors -----------------------------------------------------------------------------

View Source
var (
	LazyAny = types.LazyAny
	LazyPtr = types.LazyPtr
)
View Source
var (
	PrettifyError              = issues.PrettifyError
	PrettifyErrorWithFormatter = issues.PrettifyErrorWithFormatter
	FlattenErrorWithFormatter  = issues.FlattenErrorWithFormatter
	FlattenError               = issues.FlattenError
	FormatError                = issues.FormatError
	TreeifyError               = issues.TreeifyError
)

Re-export frequently used helper functions that operate on *ZodError so that callers can perform common error transformations without depending on the internal package path.

View Source
var (
	ErrUnsupportedInputType          = errors.New("unsupported input type")
	ErrCircularReference             = errors.New("circular reference detected")
	ErrUnrepresentableType           = errors.New("unrepresentable type")
	ErrSchemaNotObjectOrStruct       = errors.New("schema is not a ZodObject or ZodStruct")
	ErrSliceElementNotSchema         = errors.New("slice element is not a ZodSchema")
	ErrArrayItemNotSchema            = errors.New("array item is not a ZodSchema")
	ErrUnhandledArrayLike            = errors.New("unhandled array-like type")
	ErrUnionInvalid                  = errors.New("schema is not a union type with Options method")
	ErrUnionNoMembers                = errors.New("union has no member schemas")
	ErrIntersectionInvalid           = errors.New("schema is not an intersection type")
	ErrInvalidEnumSchema             = errors.New("invalid enum schema")
	ErrEnumExtractValues             = errors.New("unable to extract enum values")
	ErrLiteralNoValuesMethod         = errors.New("schema does not have a Values method")
	ErrLiteralUnexpectedReturnValues = errors.New("unexpected number of return values from Values method")
	ErrExpectedDiscriminatedUnion    = errors.New("expected a discriminated union schema")
	ErrExpectedRecord                = errors.New("expected a record schema with ValueType()")
	ErrRecordValueNotSchema          = errors.New("record value type is not a valid schema")
	ErrMapNoMethods                  = errors.New("schema does not implement KeyType() and ValueType() methods for map conversion")
	ErrMapKeyNotSchema               = errors.New("map key type is not a valid schema")
	ErrMapValueNotSchema             = errors.New("map value type is not a valid schema")
)

Sentinel errors reused across this package for consistent error handling.

View Source
var GlobalRegistry = core.GlobalRegistry

GlobalRegistry is the framework-provided, process-wide registry instance. Use it to store shared metadata that should be accessible throughout your application.

View Source
var IsZodError = issues.IsZodError

Error utility function

Functions

func Lazy

func Lazy[S types.ZodSchemaType](getter func() S, params ...any) *types.ZodLazyTyped[S]

func ToJSONSchema added in v0.3.1

func ToJSONSchema(input any, opts ...JSONSchemaOptions) (*lib.Schema, error)

ToJSONSchema converts a GoZod schema or registry into a JSON Schema instance.

Types

type CheckParams added in v0.3.0

type CheckParams = core.CheckParams

Validation check aliases

type CustomParams added in v0.3.1

type CustomParams = core.CustomParams

Validation check aliases

type FlattenedError

type FlattenedError = issues.FlattenedError

type GlobalMeta added in v0.3.1

type GlobalMeta = core.GlobalMeta

GlobalMeta mirrors common JSON-Schema keys and serves as a convenient default metadata structure. Alias to core.GlobalMeta so callers don't need to import the core package.

type IsoDatetimeOptions added in v0.3.0

type IsoDatetimeOptions = types.IsoDatetimeOptions

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type IsoTimeOptions added in v0.3.0

type IsoTimeOptions = types.IsoTimeOptions

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type IssueCode

type IssueCode = core.IssueCode

Validation payload and issue code aliases

type JSONSchemaOptions added in v0.3.1

type JSONSchemaOptions struct {
	// A registry used to look up metadata for each schema.
	// Any schema with an ID property will be extracted as a $def.
	Metadata *core.Registry[core.GlobalMeta]

	// How to handle unrepresentable types:
	// "throw" (default) - Unrepresentable types throw an error.
	// "any" - Unrepresentable types become {}.
	Unrepresentable string

	// How to handle cycles:
	// "ref" (default) - Cycles will be broken using $defs.
	// "throw" - Cycles will throw an error if encountered.
	Cycles string

	// How to handle reused schemas:
	// "inline" (default) - Reused schemas will be inlined.
	// "ref" - Reused schemas will be extracted as $defs.
	Reused string

	// A function used to convert ID values to URIs for external $refs.
	URI func(id string) string

	// Target specifies the JSON Schema version.
	// "draft-2020-12" (default) or "draft-07".
	Target string

	// Override is a custom logic to modify the schema after generation.
	Override func(ctx OverrideContext)

	// IO specifies whether to convert the "input" or "output" schema.
	// "output" (default) or "input".
	IO string
}

JSONSchemaOptions defines the configuration options for JSON schema conversion.

type JWTOptions added in v0.3.0

type JWTOptions = types.JWTOptions

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type MessageFormatter added in v0.3.0

type MessageFormatter = issues.MessageFormatter

type ObjectSchema

type ObjectSchema = core.ObjectSchema

Schema and configuration aliases

type OverrideContext added in v0.3.1

type OverrideContext struct {
	ZodSchema  core.ZodSchema
	JSONSchema *lib.Schema
}

OverrideContext provides context for the Override function.

type ParsePayload

type ParsePayload = core.ParsePayload

Validation payload and issue code aliases

type Registry added in v0.3.1

type Registry[M any] = core.Registry[M]

Registry provides a lightweight, type-safe store for attaching metadata to any Schema. This is an alias to core.Registry to make the API available via the primary gozod package.

Example:

fieldReg := gozod.NewRegistry[FieldMeta]()
fieldReg.Add(nameSchema, FieldMeta{Title: "User Name"})

See docs/metadata.md for usage patterns and best practices.

func NewRegistry added in v0.3.1

func NewRegistry[M any]() *Registry[M]

NewRegistry creates an empty Registry. It's a thin wrapper around core.NewRegistry to expose the constructor at the root package level.

type SchemaParams

type SchemaParams = core.SchemaParams

Schema and configuration aliases

type StructSchema added in v0.2.0

type StructSchema = core.StructSchema

Schema and configuration aliases

type URLOptions added in v0.3.0

type URLOptions = types.URLOptions

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodAny

type ZodAny[T any, R any] = types.ZodAny[T, R]

----------------------------------------------------------------------------- Special Types -----------------------------------------------------------------------------

type ZodArray

type ZodArray[T any, R any] = types.ZodArray[T, R]

----------------------------------------------------------------------------- Collection Types -----------------------------------------------------------------------------

type ZodBase64 added in v0.3.0

type ZodBase64[T types.StringConstraint] = types.ZodBase64[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodBase64URL added in v0.3.0

type ZodBase64URL[T types.StringConstraint] = types.ZodBase64URL[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodBool

type ZodBool[T types.BoolConstraint] = types.ZodBool[T]

----------------------------------------------------------------------------- Primitive Types -----------------------------------------------------------------------------

type ZodCIDRv4

type ZodCIDRv4[T types.NetworkConstraint] = types.ZodCIDRv4[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodCIDRv6

type ZodCIDRv6[T types.NetworkConstraint] = types.ZodCIDRv6[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodCUID added in v0.3.0

type ZodCUID[T types.StringConstraint] = types.ZodCUID[T]

Unique identifier formats

type ZodCUID2 added in v0.3.0

type ZodCUID2[T types.StringConstraint] = types.ZodCUID2[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodCheck

type ZodCheck = core.ZodCheck

Validation check aliases

type ZodCheckDef

type ZodCheckDef = core.ZodCheckDef

Validation check aliases

type ZodCheckFn

type ZodCheckFn = core.ZodCheckFn

Validation check aliases

type ZodCheckInternals

type ZodCheckInternals = core.ZodCheckInternals

Validation check aliases

type ZodComplex

type ZodComplex[T types.ComplexConstraint] = types.ZodComplex[T]

----------------------------------------------------------------------------- Primitive Types -----------------------------------------------------------------------------

type ZodConfig

type ZodConfig = core.ZodConfig

Schema and configuration aliases

type ZodDiscriminatedUnion

type ZodDiscriminatedUnion[T any, R any] = types.ZodDiscriminatedUnion[T, R]

----------------------------------------------------------------------------- Composite Types -----------------------------------------------------------------------------

type ZodEmail added in v0.3.0

type ZodEmail[T types.EmailConstraint] = types.ZodEmail[T]

Standard formats

type ZodEmoji added in v0.3.0

type ZodEmoji[T types.StringConstraint] = types.ZodEmoji[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodEnum

type ZodEnum[T comparable, R any] = types.ZodEnum[T, R]

----------------------------------------------------------------------------- Special Types -----------------------------------------------------------------------------

func Enum

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

func EnumMap

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

func EnumMapPtr added in v0.3.0

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

func EnumPtr added in v0.3.0

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

func EnumSlice

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

func EnumSlicePtr added in v0.3.0

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

type ZodError

type ZodError = issues.ZodError

Error type aliases

type ZodErrorTree

type ZodErrorTree = issues.ZodErrorTree

type ZodFile

type ZodFile[T any, R any] = types.ZodFile[T, R]

----------------------------------------------------------------------------- Special Types -----------------------------------------------------------------------------

type ZodFloat

type ZodFloat[T types.FloatConstraint, R any] = types.ZodFloat[T, R]

----------------------------------------------------------------------------- Primitive Types -----------------------------------------------------------------------------

type ZodFormattedError

type ZodFormattedError = issues.ZodFormattedError

type ZodFunction

type ZodFunction[T types.FunctionConstraint] = types.ZodFunction[T]

----------------------------------------------------------------------------- Special Types -----------------------------------------------------------------------------

type ZodIPv4

type ZodIPv4[T types.NetworkConstraint] = types.ZodIPv4[T]

Network formats

type ZodIPv6

type ZodIPv6[T types.NetworkConstraint] = types.ZodIPv6[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodInteger

type ZodInteger[T types.IntegerConstraint, R any] = types.ZodInteger[T, R]

----------------------------------------------------------------------------- Primitive Types -----------------------------------------------------------------------------

type ZodIntersection

type ZodIntersection[T any, R any] = types.ZodIntersection[T, R]

----------------------------------------------------------------------------- Composite Types -----------------------------------------------------------------------------

type ZodIso added in v0.3.0

type ZodIso[T types.IsoConstraint] = types.ZodIso[T]

ISO 8601 formats

type ZodIssue

type ZodIssue = core.ZodIssue

Error type aliases

type ZodJWT added in v0.3.0

type ZodJWT[T types.StringConstraint] = types.ZodJWT[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodKSUID added in v0.3.0

type ZodKSUID[T types.StringConstraint] = types.ZodKSUID[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodLazy

type ZodLazy[T types.LazyConstraint] = types.ZodLazy[T]

----------------------------------------------------------------------------- Special Types -----------------------------------------------------------------------------

type ZodLiteral

type ZodLiteral[T comparable, R any] = types.ZodLiteral[T, R]

----------------------------------------------------------------------------- Special Types -----------------------------------------------------------------------------

func Literal

func Literal[T comparable](value T, params ...any) *ZodLiteral[T, T]

func LiteralOf added in v0.3.0

func LiteralOf[T comparable](values []T, params ...any) *ZodLiteral[T, T]

func LiteralPtr added in v0.3.0

func LiteralPtr[T comparable](value T, params ...any) *ZodLiteral[T, *T]

func LiteralPtrOf added in v0.3.0

func LiteralPtrOf[T comparable](values []T, params ...any) *ZodLiteral[T, *T]

type ZodMap

type ZodMap[T any, R any] = types.ZodMap[T, R]

----------------------------------------------------------------------------- Collection Types -----------------------------------------------------------------------------

type ZodNanoID added in v0.3.0

type ZodNanoID[T types.StringConstraint] = types.ZodNanoID[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodNever

type ZodNever[T any, R any] = types.ZodNever[T, R]

----------------------------------------------------------------------------- Special Types -----------------------------------------------------------------------------

type ZodNil

type ZodNil[T any] = types.ZodNil[T]

----------------------------------------------------------------------------- Special Types -----------------------------------------------------------------------------

type ZodObject

type ZodObject[T any, R any] = types.ZodObject[T, R]

----------------------------------------------------------------------------- Collection Types -----------------------------------------------------------------------------

type ZodRawIssue

type ZodRawIssue = core.ZodRawIssue

Error type aliases

type ZodRecord

type ZodRecord[T any, R any] = types.ZodRecord[T, R]

----------------------------------------------------------------------------- Collection Types -----------------------------------------------------------------------------

func Record

func Record[K any, V any](keySchema any, valueSchema core.ZodType[V], paramArgs ...any) *ZodRecord[map[string]V, map[string]V]

Record creates a record schema with the specified key schema and value schema. Example: Record(String(), Int()) parses map[string]int.

func RecordPtr added in v0.3.0

func RecordPtr[K any, V any](keySchema any, valueSchema core.ZodType[V], paramArgs ...any) *ZodRecord[map[string]V, *map[string]V]

RecordPtr is the pointer-returning counterpart of Record.

type ZodRefineFn added in v0.3.0

type ZodRefineFn[T any] = core.ZodRefineFn[T]

Validation check aliases

type ZodSlice

type ZodSlice[T any, R any] = types.ZodSlice[T, R]

----------------------------------------------------------------------------- Collection Types -----------------------------------------------------------------------------

func Slice

func Slice[T any](elementSchema any, paramArgs ...any) *ZodSlice[T, []T]

func SlicePtr added in v0.3.0

func SlicePtr[T any](elementSchema any, paramArgs ...any) *ZodSlice[T, *[]T]

type ZodString

type ZodString[T types.StringConstraint] = types.ZodString[T]

----------------------------------------------------------------------------- Primitive Types -----------------------------------------------------------------------------

type ZodStringBool

type ZodStringBool[T types.StringBoolConstraint] = types.ZodStringBool[T]

----------------------------------------------------------------------------- Special Types -----------------------------------------------------------------------------

type ZodStruct

type ZodStruct[T any, R any] = types.ZodStruct[T, R]

----------------------------------------------------------------------------- Collection Types -----------------------------------------------------------------------------

func Struct

func Struct[T any](params ...any) *ZodStruct[T, T]

func StructPtr added in v0.3.0

func StructPtr[T any](params ...any) *ZodStruct[T, *T]

type ZodTime added in v0.3.0

type ZodTime[T types.TimeConstraint] = types.ZodTime[T]

----------------------------------------------------------------------------- Primitive Types -----------------------------------------------------------------------------

type ZodType

type ZodType[T any] = core.ZodType[T]

Generic ZodType alias for ergonomic use

type ZodULID added in v0.3.0

type ZodULID[T types.StringConstraint] = types.ZodULID[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodURL added in v0.3.0

type ZodURL[T types.NetworkConstraint] = types.ZodURL[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodUUID added in v0.3.0

type ZodUUID[T types.StringConstraint] = types.ZodUUID[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

type ZodUnion

type ZodUnion[T any, R any] = types.ZodUnion[T, R]

----------------------------------------------------------------------------- Composite Types -----------------------------------------------------------------------------

type ZodUnknown

type ZodUnknown[T any, R any] = types.ZodUnknown[T, R]

----------------------------------------------------------------------------- Special Types -----------------------------------------------------------------------------

type ZodWhenFn

type ZodWhenFn = core.ZodWhenFn

Validation check aliases

type ZodXID added in v0.3.0

type ZodXID[T types.StringConstraint] = types.ZodXID[T]

----------------------------------------------------------------------------- String Format Types -----------------------------------------------------------------------------

Directories

Path Synopsis
Package core contains the low-level building blocks shared by every schema implementation.
Package core contains the low-level building blocks shared by every schema implementation.
examples
advanced_lazy command
coerce command
config command
error_handling command
format command
i18n command
intersection command
object command
primitive command
quickstart command
union command
internal
checks
Package checks provides validation checks for schema validation
Package checks provides validation checks for schema validation
Package locales provides pre-configured error message formatters for different languages.
Package locales provides pre-configured error message formatters for different languages.
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL