Documentation
¶
Index ¶
- Constants
- Variables
- func ConvertRawIssuesToIssues(rawIssues []core.ZodRawIssue, ctx *core.ParseContext) []core.ZodIssue
- func ConvertZodIssueToRaw(issue core.ZodIssue) core.ZodRawIssue
- func ConvertZodIssueToRawWithPrependedPath(issue core.ZodIssue, pathPrefix []any) core.ZodRawIssue
- func ConvertZodIssueToRawWithProperties(issue core.ZodIssue, pathPrefix []any) core.ZodRawIssue
- func CopyRawIssueProperties(rawIssue core.ZodRawIssue) map[string]any
- func CreateArrayValidationIssues(issues []core.ZodRawIssue) error
- func CreateCustomError(message string, properties map[string]any, input any, ctx *core.ParseContext) error
- func CreateCustomIssue(message string, properties map[string]any, input any) core.ZodRawIssue
- func CreateElementValidationIssue(index int, origin string, element any, elementError error) core.ZodRawIssue
- func CreateErrorMap(errorInput any) *core.ZodErrorMap
- func CreateFinalError(code core.IssueCode, message string, properties map[string]any, input any, ...) error
- func CreateFixedLengthArrayError(expectedLength any, actualLength int, input any, isTooSmall bool, ...) error
- func CreateFixedLengthArrayIssue(expectedLength any, actualLength int, input any, isTooSmall bool) core.ZodRawIssue
- func CreateIncompatibleTypesError(conflictType string, value1, value2 any, input any, ctx *core.ParseContext) error
- func CreateIncompatibleTypesIssue(conflictType string, value1, value2 any, input any) core.ZodRawIssue
- func CreateInvalidElementError(index int, origin string, input any, elementError error, ...) error
- func CreateInvalidElementIssue(index int, origin string, input any, elementError core.ZodRawIssue) core.ZodRawIssue
- func CreateInvalidFormatError(format string, input any, ctx *core.ParseContext, ...) error
- func CreateInvalidFormatIssue(format string, input any, additionalProps map[string]any) core.ZodRawIssue
- func CreateInvalidKeyError(key string, origin string, input any, ctx *core.ParseContext) error
- func CreateInvalidKeyIssue(key string, origin string, input any) core.ZodRawIssue
- func CreateInvalidSchemaError(reason string, input any, ctx *core.ParseContext, ...) error
- func CreateInvalidSchemaIssue(reason string, input any, additionalProps ...map[string]any) core.ZodRawIssue
- func CreateInvalidTypeError(expectedType core.ZodTypeCode, input any, ctx *core.ParseContext) error
- func CreateInvalidTypeErrorWithInst(expectedType core.ZodTypeCode, input any, ctx *core.ParseContext, inst any) error
- func CreateInvalidTypeIssue(expected core.ZodTypeCode, input any) core.ZodRawIssue
- func CreateInvalidTypeWithMsg(expected core.ZodTypeCode, message string, input any) core.ZodRawIssue
- func CreateInvalidUnionError(unionErrors []error, input any, ctx *core.ParseContext) error
- func CreateInvalidUnionIssue(unionErrors []core.ZodRawIssue, input any) core.ZodRawIssue
- func CreateInvalidUnionIssueWithResults(unionErrors []core.ZodRawIssue, input any, continueOnError ...bool) core.ZodRawIssue
- func CreateInvalidValueError(validValues []any, input any, ctx *core.ParseContext) error
- func CreateInvalidValueIssue(validValues []any, input any) core.ZodRawIssue
- func CreateInvalidXorError(matchCount int, input any, ctx *core.ParseContext) error
- func CreateIssue(code core.IssueCode, message string, properties map[string]any, input any) core.ZodRawIssue
- func CreateMissingKeyIssue(key string, options ...func(*core.ZodRawIssue)) core.ZodRawIssue
- func CreateMissingRequiredError(fieldName string, fieldType string, input any, ctx *core.ParseContext) error
- func CreateMissingRequiredIssue(fieldName string, fieldType string) core.ZodRawIssue
- func CreateNonOptionalError(ctx *core.ParseContext) error
- func CreateNonOptionalIssue(input any) core.ZodRawIssue
- func CreateNotMultipleOfError(divisor any, origin string, input any, ctx *core.ParseContext) error
- func CreateNotMultipleOfIssue(divisor any, origin string, input any) core.ZodRawIssue
- func CreateRestParameterTooSmallError(minimum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error
- func CreateTooBigError(maximum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error
- func CreateTooBigIssue(maximum any, inclusive bool, origin string, input any) core.ZodRawIssue
- func CreateTooSmallError(minimum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error
- func CreateTooSmallIssue(minimum any, inclusive bool, origin string, input any) core.ZodRawIssue
- func CreateTypeConversionError(fromType, toType string, input any, ctx *core.ParseContext) error
- func CreateTypeConversionIssue(fromType, toType string, input any) core.ZodRawIssue
- func CreateUnrecognizedKeysError(keys []string, input any, ctx *core.ParseContext) error
- func CreateUnrecognizedKeysIssue(keys []string, input any) core.ZodRawIssue
- func ExtractConfigLevelError(iss core.ZodRawIssue, config *core.ZodConfig) string
- func ExtractSchemaLevelError(iss core.ZodRawIssue) string
- func FinalizeIssue(iss core.ZodRawIssue, ctx *core.ParseContext, config *core.ZodConfig) core.ZodIssue
- func FormatMessage(raw core.ZodRawIssue) string
- func FormatMessageWithFormatter(raw core.ZodRawIssue, formatter MessageFormatter) string
- func FormatThreshold(threshold any) string
- func GenerateDefaultMessage(raw core.ZodRawIssue) string
- func GetComparisonOperator(isInclusive bool, isGreaterThan bool) string
- func GetCustomError(config *core.ZodConfig) core.ZodErrorMap
- func GetFormatNoun(format string) string
- func GetFriendlyComparisonText(isInclusive bool, isTooSmall bool) string
- func GetIssueDivisor(i core.ZodIssue) (any, bool)
- func GetIssueExpected(i core.ZodIssue) (core.ZodTypeCode, bool)
- func GetIssueFormat(i core.ZodIssue) (string, bool)
- func GetIssueMaximum(i core.ZodIssue) (any, bool)
- func GetIssueMinimum(i core.ZodIssue) (any, bool)
- func GetIssueReceived(i core.ZodIssue) (core.ZodTypeCode, bool)
- func GetLocaleError(config *core.ZodConfig) core.ZodErrorMap
- func GetRawIssueBoolProperty(r core.ZodRawIssue, key string) bool
- func GetRawIssueDivisor(r core.ZodRawIssue) any
- func GetRawIssueExpected(r core.ZodRawIssue) string
- func GetRawIssueFormat(r core.ZodRawIssue) string
- func GetRawIssueIncludes(r core.ZodRawIssue) string
- func GetRawIssueInclusive(r core.ZodRawIssue) bool
- func GetRawIssueKeys(r core.ZodRawIssue) []string
- func GetRawIssueMaximum(r core.ZodRawIssue) any
- func GetRawIssueMinimum(r core.ZodRawIssue) any
- func GetRawIssueOrigin(r core.ZodRawIssue) string
- func GetRawIssuePattern(r core.ZodRawIssue) string
- func GetRawIssuePrefix(r core.ZodRawIssue) string
- func GetRawIssueProperty(r core.ZodRawIssue, key string) any
- func GetRawIssueReceived(r core.ZodRawIssue) string
- func GetRawIssueStringProperty(r core.ZodRawIssue, key string) string
- func GetRawIssueSuffix(r core.ZodRawIssue) string
- func GetRawIssueValues(r core.ZodRawIssue) []any
- func HasRawIssueProperty(r core.ZodRawIssue, key string) bool
- func IsZodError(err error, target **ZodError) bool
- func JoinValuesWithSeparator(values []any, separator string) string
- func MapPropertiesToIssue(issue *core.ZodIssue, properties map[string]any)
- func MergeRawIssueProperties(rawIssue *core.ZodRawIssue, newProperties map[string]any)
- func NewRawIssue(code core.IssueCode, input any, options ...func(*core.ZodRawIssue)) core.ZodRawIssue
- func NewRawIssueFromMessage(message string, input any, inst any) core.ZodRawIssue
- func ParsedTypeToString(input any) string
- func PrettifyError(error *ZodError) string
- func PrettifyErrorWithFormatter(error *ZodError, formatter MessageFormatter) string
- func StringifyPrimitive(value any) string
- func ToDotPath(path []any) string
- func WithAlgorithm(algorithm string) func(*core.ZodRawIssue)
- func WithContinue(cont bool) func(*core.ZodRawIssue)
- func WithDivisor(divisor any) func(*core.ZodRawIssue)
- func WithExpected(expected string) func(*core.ZodRawIssue)
- func WithFormat(format string) func(*core.ZodRawIssue)
- func WithIncludes(includes string) func(*core.ZodRawIssue)
- func WithInclusive(inclusive bool) func(*core.ZodRawIssue)
- func WithInst(inst any) func(*core.ZodRawIssue)
- func WithKeys(keys []string) func(*core.ZodRawIssue)
- func WithMaximum(maximum any) func(*core.ZodRawIssue)
- func WithMessage(message string) func(*core.ZodRawIssue)
- func WithMinimum(minimum any) func(*core.ZodRawIssue)
- func WithOrigin(origin string) func(*core.ZodRawIssue)
- func WithParams(params map[string]any) func(*core.ZodRawIssue)
- func WithPath(path []any) func(*core.ZodRawIssue)
- func WithPattern(pattern string) func(*core.ZodRawIssue)
- func WithPrefix(prefix string) func(*core.ZodRawIssue)
- func WithProperties(properties map[string]any) func(*core.ZodRawIssue)
- func WithProperty(key string, value any) func(*core.ZodRawIssue)
- func WithReceived(received string) func(*core.ZodRawIssue)
- func WithSuffix(suffix string) func(*core.ZodRawIssue)
- func WithValues(values []any) func(*core.ZodRawIssue)
- type DefaultMessageFormatter
- type FlattenedError
- type IssueCode
- type MessageFormatter
- type ParseParams
- type SizingInfo
- type ZodError
- type ZodErrorMap
- type ZodErrorTree
- type ZodFormattedError
- type ZodIssue
- type ZodIssueBase
- type ZodIssueCustom
- type ZodIssueInvalidElement
- type ZodIssueInvalidKey
- type ZodIssueInvalidStringFormat
- type ZodIssueInvalidType
- type ZodIssueInvalidUnion
- type ZodIssueInvalidValue
- type ZodIssueNotMultipleOf
- type ZodIssueStringCommonFormats
- type ZodIssueStringEndsWith
- type ZodIssueStringIncludes
- type ZodIssueStringInvalidJWT
- type ZodIssueStringInvalidRegex
- type ZodIssueStringStartsWith
- type ZodIssueTooBig
- type ZodIssueTooSmall
- type ZodIssueUnrecognizedKeys
- type ZodRawIssue
Constants ¶
const ( InvalidType = core.InvalidType InvalidValue = core.InvalidValue InvalidFormat = core.InvalidFormat InvalidUnion = core.InvalidUnion InvalidKey = core.InvalidKey InvalidElement = core.InvalidElement TooBig = core.TooBig TooSmall = core.TooSmall NotMultipleOf = core.NotMultipleOf UnrecognizedKeys = core.UnrecognizedKeys Custom = core.Custom )
Re-export issue code constants for convenient access
Variables ¶
var FormatNouns = func() map[string]string { return map[string]string{ "regex": "input", "email": "email address", "url": "URL", "emoji": "emoji", "uuid": "uuid", "uuidv4": "uuid", "uuidv6": "uuid", "nanoid": "nanoid", "guid": "guid", "cuid": "cuid", "cuid2": "cuid2", "ulid": "ulid", "xid": "XID", "ksuid": "KSUID", "datetime": "ISO datetime", "date": "ISO date", "time": "ISO time", "duration": "ISO duration", "ipv4": "IPv4 address", "ipv6": "IPv6 address", "cidrv4": "IPv4 range", "cidrv6": "IPv6 range", "base64": "base64-encoded string", "base64url": "base64url-encoded string", "json_string": "JSON string", "e164": "E.164 number", "jwt": "JWT", "template_literal": "input", "iso_date": "ISO date format", "iso_time": "ISO time format", "iso_datetime": "ISO datetime format", "iso_duration": "ISO duration", "int8": "8-bit integer", "int16": "16-bit integer", "int32": "32-bit integer", "int64": "64-bit integer", "uint8": "8-bit unsigned integer", "uint16": "16-bit unsigned integer", "uint32": "32-bit unsigned integer", "uint64": "64-bit unsigned integer", "float32": "32-bit float", "float64": "64-bit float", "complex64": "64-bit complex number", "complex128": "128-bit complex number", } }()
FormatNouns maps format names to human-readable descriptions Enhanced initialization using modern Go patterns
var Sizable = map[string]SizingInfo{
"string": {Unit: "characters", Verb: "to have"},
"file": {Unit: "bytes", Verb: "to have"},
"array": {Unit: "items", Verb: "to have"},
"slice": {Unit: "items", Verb: "to have"},
"set": {Unit: "items", Verb: "to have"},
"object": {Unit: "keys", Verb: "to have"},
"map": {Unit: "keys", Verb: "to have"},
}
Sizable maps type names to their sizing terminology
Functions ¶
func ConvertRawIssuesToIssues ¶
func ConvertRawIssuesToIssues(rawIssues []core.ZodRawIssue, ctx *core.ParseContext) []core.ZodIssue
ConvertRawIssuesToIssues converts a slice of raw issues to a slice of finalized issues Uses precise pre-allocation and batch processing for optimal performance
func ConvertZodIssueToRaw ¶ added in v0.2.4
func ConvertZodIssueToRaw(issue core.ZodIssue) core.ZodRawIssue
ConvertZodIssueToRaw converts a ZodIssue to ZodRawIssue efficiently This is a helper for common ZodError -> RawIssue conversion patterns
func ConvertZodIssueToRawWithPrependedPath ¶ added in v0.5.6
func ConvertZodIssueToRawWithPrependedPath(issue core.ZodIssue, pathPrefix []any) core.ZodRawIssue
ConvertZodIssueToRawWithPrependedPath converts a ZodIssue to ZodRawIssue and prepends pathPrefix to the issue's existing path. This is used for map types where the key path is prepended to nested issue paths.
func ConvertZodIssueToRawWithProperties ¶ added in v0.5.6
func ConvertZodIssueToRawWithProperties(issue core.ZodIssue, pathPrefix []any) core.ZodRawIssue
ConvertZodIssueToRawWithProperties converts a ZodIssue to ZodRawIssue and copies essential properties (minimum, maximum, expected, received, inclusive). This is used by collection types (slice, set, map, object, struct) for element validation. The pathPrefix is set directly as the path (for slice/set where elements have simple index paths).
func CopyRawIssueProperties ¶
func CopyRawIssueProperties(rawIssue core.ZodRawIssue) map[string]any
CopyRawIssueProperties creates a copy of raw issue properties using mapx
func CreateArrayValidationIssues ¶ added in v0.4.0
func CreateArrayValidationIssues(issues []core.ZodRawIssue) error
CreateArrayValidationIssues creates multiple issues for array validation, collecting all validation errors
func CreateCustomError ¶ added in v0.4.0
func CreateCustomError(message string, properties map[string]any, input any, ctx *core.ParseContext) error
CreateCustomError creates a standardized custom error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateCustomIssue ¶
CreateCustomIssue creates a custom issue
func CreateElementValidationIssue ¶ added in v0.4.0
func CreateElementValidationIssue(index int, origin string, element any, elementError error) core.ZodRawIssue
CreateElementValidationIssue creates a raw issue for invalid element validation
func CreateErrorMap ¶
func CreateErrorMap(errorInput any) *core.ZodErrorMap
CreateErrorMap creates an error map from various input types
func CreateFinalError ¶ added in v0.4.0
func CreateFinalError(code core.IssueCode, message string, properties map[string]any, input any, ctx *core.ParseContext, config *core.ZodConfig) error
CreateFinalError directly creates a final ZodError, skipping intermediate steps This is the recommended way to create errors in most cases
func CreateFixedLengthArrayError ¶ added in v0.4.0
func CreateFixedLengthArrayError(expectedLength any, actualLength int, input any, isTooSmall bool, ctx *core.ParseContext) error
CreateFixedLengthArrayError creates an error for fixed-length array validation
func CreateFixedLengthArrayIssue ¶ added in v0.4.0
func CreateFixedLengthArrayIssue(expectedLength any, actualLength int, input any, isTooSmall bool) core.ZodRawIssue
CreateFixedLengthArrayIssue creates a size constraint issue for fixed-length arrays This function sets both minimum and maximum properties to enable "expected exactly N" formatting
func CreateIncompatibleTypesError ¶ added in v0.4.0
func CreateIncompatibleTypesError(conflictType string, value1, value2 any, input any, ctx *core.ParseContext) error
CreateIncompatibleTypesError creates a standardized incompatible types error with proper context
func CreateIncompatibleTypesIssue ¶ added in v0.4.0
func CreateIncompatibleTypesIssue(conflictType string, value1, value2 any, input any) core.ZodRawIssue
CreateIncompatibleTypesIssue creates an incompatible types issue
func CreateInvalidElementError ¶ added in v0.4.0
func CreateInvalidElementError(index int, origin string, input any, elementError error, ctx *core.ParseContext) error
CreateInvalidElementError creates a standardized invalid element error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateInvalidElementIssue ¶
func CreateInvalidElementIssue(index int, origin string, input any, elementError core.ZodRawIssue) core.ZodRawIssue
CreateInvalidElementIssue creates an invalid element issue with proper path
func CreateInvalidFormatError ¶ added in v0.4.0
func CreateInvalidFormatError(format string, input any, ctx *core.ParseContext, additionalProps ...map[string]any) error
CreateInvalidFormatError creates a standardized invalid format error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateInvalidFormatIssue ¶
func CreateInvalidFormatIssue(format string, input any, additionalProps map[string]any) core.ZodRawIssue
CreateInvalidFormatIssue creates an invalid format issue
func CreateInvalidKeyError ¶ added in v0.4.0
CreateInvalidKeyError creates a standardized invalid key error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateInvalidKeyIssue ¶
func CreateInvalidKeyIssue(key string, origin string, input any) core.ZodRawIssue
CreateInvalidKeyIssue creates an invalid key issue
func CreateInvalidSchemaError ¶ added in v0.4.0
func CreateInvalidSchemaError(reason string, input any, ctx *core.ParseContext, additionalProps ...map[string]any) error
CreateInvalidSchemaError creates an invalid schema error
func CreateInvalidSchemaIssue ¶ added in v0.4.0
func CreateInvalidSchemaIssue(reason string, input any, additionalProps ...map[string]any) core.ZodRawIssue
CreateInvalidSchemaIssue creates an invalid schema issue
func CreateInvalidTypeError ¶ added in v0.4.0
func CreateInvalidTypeError(expectedType core.ZodTypeCode, input any, ctx *core.ParseContext) error
CreateInvalidTypeError creates a standardized invalid type error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateInvalidTypeErrorWithInst ¶ added in v0.4.0
func CreateInvalidTypeErrorWithInst(expectedType core.ZodTypeCode, input any, ctx *core.ParseContext, inst any) error
CreateInvalidTypeErrorWithInst creates an invalid type error with schema internals
func CreateInvalidTypeIssue ¶
func CreateInvalidTypeIssue(expected core.ZodTypeCode, input any) core.ZodRawIssue
CreateInvalidTypeIssue creates an invalid type issue
func CreateInvalidTypeWithMsg ¶ added in v0.2.4
func CreateInvalidTypeWithMsg(expected core.ZodTypeCode, message string, input any) core.ZodRawIssue
CreateInvalidTypeWithMsg creates an invalid type issue with custom message This function supports type-safe expected types using core.ZodTypeCode
func CreateInvalidUnionError ¶ added in v0.4.0
func CreateInvalidUnionError(unionErrors []error, input any, ctx *core.ParseContext) error
CreateInvalidUnionError creates a standardized invalid union error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateInvalidUnionIssue ¶
func CreateInvalidUnionIssue(unionErrors []core.ZodRawIssue, input any) core.ZodRawIssue
CreateInvalidUnionIssue creates an invalid union issue
func CreateInvalidUnionIssueWithResults ¶ added in v0.2.4
func CreateInvalidUnionIssueWithResults(unionErrors []core.ZodRawIssue, input any, continueOnError ...bool) core.ZodRawIssue
CreateInvalidUnionIssueWithResults creates an invalid union issue with results array This maintains TypeScript-compatible structure with "errors" property for union validation
func CreateInvalidValueError ¶ added in v0.4.0
func CreateInvalidValueError(validValues []any, input any, ctx *core.ParseContext) error
CreateInvalidValueError creates a standardized invalid value error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateInvalidValueIssue ¶
func CreateInvalidValueIssue(validValues []any, input any) core.ZodRawIssue
CreateInvalidValueIssue creates an invalid value issue
func CreateInvalidXorError ¶ added in v0.5.4
func CreateInvalidXorError(matchCount int, input any, ctx *core.ParseContext) error
CreateInvalidXorError creates a standardized exclusive union error when multiple options match Zod v4 xor semantics: exactly one option must match Uses InvalidUnion code with inclusive=false to indicate exclusive union (xor) failure See: .reference/zod/packages/zod/src/v4/core/schemas.ts:2185-2192
func CreateIssue ¶
func CreateIssue(code core.IssueCode, message string, properties map[string]any, input any) core.ZodRawIssue
CreateIssue creates a new ZodRawIssue with mapx for safer property handling
func CreateMissingKeyIssue ¶
func CreateMissingKeyIssue(key string, options ...func(*core.ZodRawIssue)) core.ZodRawIssue
CreateMissingKeyIssue creates a missing key issue
func CreateMissingRequiredError ¶ added in v0.4.0
func CreateMissingRequiredError(fieldName string, fieldType string, input any, ctx *core.ParseContext) error
CreateMissingRequiredError creates a standardized missing required field error with proper context
func CreateMissingRequiredIssue ¶ added in v0.4.0
func CreateMissingRequiredIssue(fieldName string, fieldType string) core.ZodRawIssue
CreateMissingRequiredIssue creates a missing required field issue
func CreateNonOptionalError ¶ added in v0.4.0
func CreateNonOptionalError(ctx *core.ParseContext) error
CreateNonOptionalError creates a standardized non-optional error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateNonOptionalIssue ¶ added in v0.3.0
func CreateNonOptionalIssue(input any) core.ZodRawIssue
CreateNonOptionalIssue returns invalid_type issue with expected "nonoptional" – used by .NonOptional()
func CreateNotMultipleOfError ¶ added in v0.4.0
CreateNotMultipleOfError creates a standardized "not multiple of" error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateNotMultipleOfIssue ¶
func CreateNotMultipleOfIssue(divisor any, origin string, input any) core.ZodRawIssue
CreateNotMultipleOfIssue creates a "not multiple of" issue
func CreateRestParameterTooSmallError ¶ added in v0.4.0
func CreateRestParameterTooSmallError(minimum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error
CreateRestParameterTooSmallError creates a TooSmall error specifically for rest parameter arrays
func CreateTooBigError ¶ added in v0.4.0
func CreateTooBigError(maximum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error
CreateTooBigError creates a standardized "too big" error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateTooBigIssue ¶
CreateTooBigIssue creates a "too big" issue
func CreateTooSmallError ¶ added in v0.4.0
func CreateTooSmallError(minimum any, inclusive bool, origin string, input any, ctx *core.ParseContext) error
CreateTooSmallError creates a standardized "too small" error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateTooSmallIssue ¶
CreateTooSmallIssue creates a "too small" issue
func CreateTypeConversionError ¶ added in v0.4.0
func CreateTypeConversionError(fromType, toType string, input any, ctx *core.ParseContext) error
CreateTypeConversionError creates a standardized type conversion error with proper context
func CreateTypeConversionIssue ¶ added in v0.4.0
func CreateTypeConversionIssue(fromType, toType string, input any) core.ZodRawIssue
CreateTypeConversionIssue creates a type conversion failure issue
func CreateUnrecognizedKeysError ¶ added in v0.4.0
func CreateUnrecognizedKeysError(keys []string, input any, ctx *core.ParseContext) error
CreateUnrecognizedKeysError creates a standardized unrecognized keys error with proper context Simplified version that directly returns error instead of requiring multiple steps
func CreateUnrecognizedKeysIssue ¶
func CreateUnrecognizedKeysIssue(keys []string, input any) core.ZodRawIssue
CreateUnrecognizedKeysIssue creates an unrecognized keys issue
func ExtractConfigLevelError ¶
func ExtractConfigLevelError(iss core.ZodRawIssue, config *core.ZodConfig) string
ExtractConfigLevelError extracts error message from config
func ExtractSchemaLevelError ¶
func ExtractSchemaLevelError(iss core.ZodRawIssue) string
ExtractSchemaLevelError extracts error message from schema instance
func FinalizeIssue ¶
func FinalizeIssue(iss core.ZodRawIssue, ctx *core.ParseContext, config *core.ZodConfig) core.ZodIssue
FinalizeIssue creates a finalized ZodIssue from a ZodRawIssue Handles error message resolution chain and property mapping
func FormatMessage ¶
func FormatMessage(raw core.ZodRawIssue) string
FormatMessage formats a single issue using the default formatter
func FormatMessageWithFormatter ¶
func FormatMessageWithFormatter(raw core.ZodRawIssue, formatter MessageFormatter) string
FormatMessageWithFormatter formats a message using a custom formatter
func FormatThreshold ¶
FormatThreshold converts a threshold value to string for consistent formatting
func GenerateDefaultMessage ¶
func GenerateDefaultMessage(raw core.ZodRawIssue) string
GenerateDefaultMessage generates a default error message for an issue using enhanced utilities
func GetComparisonOperator ¶
GetComparisonOperator returns the comparison operator string based on inclusivity
func GetCustomError ¶
func GetCustomError(config *core.ZodConfig) core.ZodErrorMap
GetCustomError safely extracts custom error from config
func GetFormatNoun ¶
GetFormatNoun returns the human-readable noun for a format name Enhanced with mapx for safer access
func GetFriendlyComparisonText ¶ added in v0.4.0
GetFriendlyComparisonText returns user-friendly comparison text instead of mathematical operators
func GetIssueDivisor ¶
GetIssueDivisor returns the divisor for not_multiple_of issues
func GetIssueExpected ¶
func GetIssueExpected(i core.ZodIssue) (core.ZodTypeCode, bool)
GetIssueExpected returns the expected type for invalid_type issues
func GetIssueFormat ¶
GetIssueFormat returns the format for invalid_format issues
func GetIssueMaximum ¶
GetIssueMaximum returns the maximum value for too_big issues
func GetIssueMinimum ¶
GetIssueMinimum returns the minimum value for too_small issues
func GetIssueReceived ¶
func GetIssueReceived(i core.ZodIssue) (core.ZodTypeCode, bool)
GetIssueReceived returns the received type for invalid_type issues
func GetLocaleError ¶
func GetLocaleError(config *core.ZodConfig) core.ZodErrorMap
GetLocaleError safely extracts locale error from config
func GetRawIssueBoolProperty ¶
func GetRawIssueBoolProperty(r core.ZodRawIssue, key string) bool
GetRawIssueBoolProperty returns a bool property
func GetRawIssueDivisor ¶
func GetRawIssueDivisor(r core.ZodRawIssue) any
GetRawIssueDivisor returns the divisor value
func GetRawIssueExpected ¶
func GetRawIssueExpected(r core.ZodRawIssue) string
GetRawIssueExpected returns the expected value
func GetRawIssueFormat ¶
func GetRawIssueFormat(r core.ZodRawIssue) string
GetRawIssueFormat returns the format value
func GetRawIssueIncludes ¶
func GetRawIssueIncludes(r core.ZodRawIssue) string
GetRawIssueIncludes returns the includes value
func GetRawIssueInclusive ¶
func GetRawIssueInclusive(r core.ZodRawIssue) bool
GetRawIssueInclusive returns the inclusive value
func GetRawIssueKeys ¶
func GetRawIssueKeys(r core.ZodRawIssue) []string
GetRawIssueKeys returns the keys value
func GetRawIssueMaximum ¶
func GetRawIssueMaximum(r core.ZodRawIssue) any
GetRawIssueMaximum returns the maximum value
func GetRawIssueMinimum ¶
func GetRawIssueMinimum(r core.ZodRawIssue) any
GetRawIssueMinimum returns the minimum value
func GetRawIssueOrigin ¶
func GetRawIssueOrigin(r core.ZodRawIssue) string
GetRawIssueOrigin returns the origin value
func GetRawIssuePattern ¶
func GetRawIssuePattern(r core.ZodRawIssue) string
GetRawIssuePattern returns the pattern value
func GetRawIssuePrefix ¶
func GetRawIssuePrefix(r core.ZodRawIssue) string
GetRawIssuePrefix returns the prefix value
func GetRawIssueProperty ¶
func GetRawIssueProperty(r core.ZodRawIssue, key string) any
GetRawIssueProperty returns any property value
func GetRawIssueReceived ¶
func GetRawIssueReceived(r core.ZodRawIssue) string
GetRawIssueReceived returns the received value
func GetRawIssueStringProperty ¶
func GetRawIssueStringProperty(r core.ZodRawIssue, key string) string
GetRawIssueStringProperty returns a string property
func GetRawIssueSuffix ¶
func GetRawIssueSuffix(r core.ZodRawIssue) string
GetRawIssueSuffix returns the suffix value
func GetRawIssueValues ¶
func GetRawIssueValues(r core.ZodRawIssue) []any
GetRawIssueValues returns the values from properties map
func HasRawIssueProperty ¶
func HasRawIssueProperty(r core.ZodRawIssue, key string) bool
HasRawIssueProperty checks if a property exists
func IsZodError ¶
IsZodError checks if an error is a ZodError and extracts it This function provides similar functionality to errors.As for ZodError specifically
func JoinValuesWithSeparator ¶
JoinValuesWithSeparator formats an array of values with a custom separator using slicex Enhanced with slicex for better slice handling and type safety
func MapPropertiesToIssue ¶
MapPropertiesToIssue maps properties to ZodIssue fields using mapx
func MergeRawIssueProperties ¶
func MergeRawIssueProperties(rawIssue *core.ZodRawIssue, newProperties map[string]any)
MergeRawIssueProperties merges new properties into raw issue using mapx
func NewRawIssue ¶
func NewRawIssue(code core.IssueCode, input any, options ...func(*core.ZodRawIssue)) core.ZodRawIssue
NewRawIssue creates a new raw issue with options pattern
func NewRawIssueFromMessage ¶
func NewRawIssueFromMessage(message string, input any, inst any) core.ZodRawIssue
NewRawIssueFromMessage creates a ZodRawIssue with custom message
func ParsedTypeToString ¶
ParsedTypeToString converts input to parsed type string Enhanced with better float handling for NaN and Infinity Matches TypeScript Zod v4 reference implementation behavior
func PrettifyError ¶
PrettifyError formats a ZodError into a readable string using its formatter
func PrettifyErrorWithFormatter ¶
func PrettifyErrorWithFormatter(error *ZodError, formatter MessageFormatter) string
PrettifyErrorWithFormatter formats a ZodError into a readable string with custom formatter
func StringifyPrimitive ¶
StringifyPrimitive converts a primitive value to its string representation with quotes Enhanced with better type handling using modern Go practices
func WithAlgorithm ¶
func WithAlgorithm(algorithm string) func(*core.ZodRawIssue)
WithAlgorithm sets the algorithm field
func WithContinue ¶
func WithContinue(cont bool) func(*core.ZodRawIssue)
WithContinue sets the continue field
func WithDivisor ¶
func WithDivisor(divisor any) func(*core.ZodRawIssue)
WithDivisor sets the divisor field
func WithExpected ¶
func WithExpected(expected string) func(*core.ZodRawIssue)
WithExpected sets the expected field
func WithFormat ¶
func WithFormat(format string) func(*core.ZodRawIssue)
WithFormat sets the format field
func WithIncludes ¶
func WithIncludes(includes string) func(*core.ZodRawIssue)
WithIncludes sets the includes field
func WithInclusive ¶
func WithInclusive(inclusive bool) func(*core.ZodRawIssue)
WithInclusive sets the inclusive field
func WithMaximum ¶
func WithMaximum(maximum any) func(*core.ZodRawIssue)
WithMaximum sets the maximum field
func WithMessage ¶
func WithMessage(message string) func(*core.ZodRawIssue)
WithMessage sets the message field
func WithMinimum ¶
func WithMinimum(minimum any) func(*core.ZodRawIssue)
WithMinimum sets the minimum field
func WithOrigin ¶
func WithOrigin(origin string) func(*core.ZodRawIssue)
WithOrigin sets the origin field
func WithParams ¶
func WithParams(params map[string]any) func(*core.ZodRawIssue)
WithParams sets the params field
func WithPattern ¶
func WithPattern(pattern string) func(*core.ZodRawIssue)
WithPattern sets the pattern field
func WithPrefix ¶
func WithPrefix(prefix string) func(*core.ZodRawIssue)
WithPrefix sets the prefix field
func WithProperties ¶
func WithProperties(properties map[string]any) func(*core.ZodRawIssue)
WithProperties merges multiple properties
func WithProperty ¶
func WithProperty(key string, value any) func(*core.ZodRawIssue)
WithProperty sets a generic property
func WithReceived ¶
func WithReceived(received string) func(*core.ZodRawIssue)
WithReceived sets the received field
func WithSuffix ¶
func WithSuffix(suffix string) func(*core.ZodRawIssue)
WithSuffix sets the suffix field
func WithValues ¶
func WithValues(values []any) func(*core.ZodRawIssue)
WithValues sets the values field
Types ¶
type DefaultMessageFormatter ¶
type DefaultMessageFormatter struct{}
DefaultMessageFormatter implements the default English message formatting
func (*DefaultMessageFormatter) FormatMessage ¶
func (f *DefaultMessageFormatter) FormatMessage(raw core.ZodRawIssue) string
FormatMessage generates error messages using enhanced utilities
type FlattenedError ¶
type FlattenedError struct {
FormErrors []string `json:"formErrors"` // Top-level errors (path is empty)
FieldErrors map[string][]string `json:"fieldErrors"` // Field-level errors by field name
}
FlattenedError represents a flattened error structure for simple form validation Separates top-level form errors from field-specific errors
func FlattenError ¶
func FlattenError(error *ZodError) *FlattenedError
FlattenError flattens a ZodError into form and field errors Separates top-level form errors from field-specific errors
func FlattenErrorWithFormatter ¶
func FlattenErrorWithFormatter(error *ZodError, formatter MessageFormatter) *FlattenedError
FlattenErrorWithFormatter flattens a ZodError into form and field errors with custom formatter
func FlattenErrorWithMapper ¶
func FlattenErrorWithMapper(error *ZodError, mapper func(ZodIssue) string) *FlattenedError
FlattenErrorWithMapper flattens a ZodError into form and field errors with custom message mapping Uses precise pre-allocation and efficient batch processing
type MessageFormatter ¶
type MessageFormatter interface {
FormatMessage(raw core.ZodRawIssue) string
}
MessageFormatter provides a unified interface for formatting validation error messages Compatible with TypeScript Zod v4 error formatting patterns
Note: Error structure formatting (tree, flat, pretty) is handled by standalone functions in the errors.go file, following TypeScript Zod v4's functional approach: - TreeifyError() / TreeifyErrorWithMapper() - FlattenError() / FlattenErrorWithMapper() - PrettifyError() / PrettifyErrorWithFormatter() - FormatError() / FormatErrorWithMapper()
type SizingInfo ¶
type SizingInfo struct {
Unit string // The unit name (e.g., "characters", "items")
Verb string // The verb to use (e.g., "to have")
}
SizingInfo represents sizing terminology for different types
func GetSizing ¶
func GetSizing(origin string) *SizingInfo
GetSizing returns the appropriate sizing information for a given type
type ZodError ¶
type ZodError struct {
Type any `json:"type"` // The expected type that failed validation
Issues []ZodIssue `json:"issues"` // Collection of validation issues
Zod struct {
Output any `json:"output"` // The output value (if any)
Def []ZodIssue `json:"def"` // Issue definitions
} `json:"_zod"`
Stack string `json:"stack,omitempty"` // Stack trace for debugging
Name string `json:"name"` // Error name identifier
// contains filtered or unexported fields
}
ZodError represents a validation error with a collection of issues Implements TypeScript Zod v4 compatible error structure and behavior
func NewZodError ¶
NewZodError creates a new validation error with the given issues Uses the default message formatter for error formatting Uses Go 1.22+ slices.Clone for efficient issue copying
func NewZodErrorWithFormatter ¶
func NewZodErrorWithFormatter(issues []ZodIssue, formatter MessageFormatter) *ZodError
NewZodErrorWithFormatter creates a new validation error with a custom formatter Allows for localized or customized error message generation
func (*ZodError) Error ¶
Error implements the error interface using the configured formatter Returns a prettified string representation of all validation issues
func (*ZodError) GetFormatter ¶
func (e *ZodError) GetFormatter() MessageFormatter
GetFormatter returns the current message formatter
func (*ZodError) SetFormatter ¶
func (e *ZodError) SetFormatter(formatter MessageFormatter)
SetFormatter sets a new message formatter for this error Allows dynamic switching of error message formats
type ZodErrorMap ¶
type ZodErrorMap = core.ZodErrorMap
type ZodErrorTree ¶
type ZodErrorTree struct {
Errors []string `json:"errors"` // Errors at this level
Properties map[string]*ZodErrorTree `json:"properties,omitempty"` // Object property errors
Items [](*ZodErrorTree) `json:"items,omitempty"` // Array/slice item errors
}
ZodErrorTree represents a tree-structured error following TypeScript Zod patterns Provides a hierarchical view of validation errors for complex data structures
func TreeifyError ¶
func TreeifyError(error *ZodError) *ZodErrorTree
TreeifyError formats a ZodError into a tree structure Provides hierarchical error representation for complex data structures
func TreeifyErrorWithMapper ¶
func TreeifyErrorWithMapper(error *ZodError, mapper func(ZodIssue) string) *ZodErrorTree
TreeifyErrorWithMapper converts a ZodError into a tree structure with custom message mapping Uses precise pre-allocation based on issue count for optimal performance
type ZodFormattedError ¶
ZodFormattedError represents a formatted error structure following TypeScript patterns Provides hierarchical error representation with field-level error grouping
func FormatError ¶
func FormatError(error *ZodError) ZodFormattedError
FormatError formats a ZodError into a structured error object Creates a hierarchical representation matching TypeScript Zod v4 format
func FormatErrorWithMapper ¶
func FormatErrorWithMapper(error *ZodError, mapper func(ZodIssue) string) ZodFormattedError
FormatErrorWithMapper formats a ZodError with custom message mapping Allows for custom message generation while maintaining structure
type ZodIssueBase ¶
type ZodIssueBase = core.ZodIssueBase
type ZodIssueCustom ¶
type ZodIssueCustom struct {
ZodIssueBase
Params map[string]any `json:"params,omitempty"`
}
ZodIssueCustom represents a custom validation error
type ZodIssueInvalidElement ¶
type ZodIssueInvalidElement struct {
ZodIssueBase
Origin string `json:"origin"`
Key any `json:"key"`
Issues []ZodIssue `json:"issues"`
}
ZodIssueInvalidElement represents invalid element in a collection
type ZodIssueInvalidKey ¶
type ZodIssueInvalidKey struct {
ZodIssueBase
Origin string `json:"origin"`
Issues []ZodIssue `json:"issues"`
}
ZodIssueInvalidKey represents invalid key in a map or record
type ZodIssueInvalidStringFormat ¶
type ZodIssueInvalidStringFormat struct {
ZodIssueBase
Format string `json:"format"`
Pattern string `json:"pattern,omitempty"`
}
ZodIssueInvalidStringFormat represents an invalid string format error
type ZodIssueInvalidType ¶
type ZodIssueInvalidType struct {
ZodIssueBase
Expected core.ZodTypeCode `json:"expected"` // Schema type that was expected
Received core.ParsedType `json:"received"` // Runtime type that was received
}
ZodIssueInvalidType represents a type validation error Corresponds to Zod v4's $ZodIssueInvalidType See: .reference/zod/packages/zod/src/v4/core/errors.ts:20-24
type ZodIssueInvalidUnion ¶
type ZodIssueInvalidUnion struct {
ZodIssueBase
Errors [][]ZodIssue `json:"errors"`
}
ZodIssueInvalidUnion represents failure to match any union schemas
type ZodIssueInvalidValue ¶
type ZodIssueInvalidValue struct {
ZodIssueBase
Values []any `json:"values"`
}
ZodIssueInvalidValue represents a value not matching expected values
type ZodIssueNotMultipleOf ¶
type ZodIssueNotMultipleOf struct {
ZodIssueBase
Divisor any `json:"divisor"`
}
ZodIssueNotMultipleOf represents a value not being a multiple of expected divisor
type ZodIssueStringCommonFormats ¶
type ZodIssueStringCommonFormats struct {
ZodIssueInvalidStringFormat
}
ZodIssueStringCommonFormats represents common string format validation errors
type ZodIssueStringEndsWith ¶
type ZodIssueStringEndsWith struct {
ZodIssueInvalidStringFormat
Suffix string `json:"suffix"`
}
ZodIssueStringEndsWith represents string suffix validation error
type ZodIssueStringIncludes ¶
type ZodIssueStringIncludes struct {
ZodIssueInvalidStringFormat
Includes string `json:"includes"`
}
ZodIssueStringIncludes represents string inclusion validation error
type ZodIssueStringInvalidJWT ¶
type ZodIssueStringInvalidJWT struct {
ZodIssueInvalidStringFormat
Algorithm string `json:"algorithm,omitempty"`
}
ZodIssueStringInvalidJWT represents JWT validation error
type ZodIssueStringInvalidRegex ¶
type ZodIssueStringInvalidRegex struct {
ZodIssueInvalidStringFormat
Pattern string `json:"pattern"`
}
ZodIssueStringInvalidRegex represents regex pattern validation error
type ZodIssueStringStartsWith ¶
type ZodIssueStringStartsWith struct {
ZodIssueInvalidStringFormat
Prefix string `json:"prefix"`
}
ZodIssueStringStartsWith represents string prefix validation error
type ZodIssueTooBig ¶
type ZodIssueTooBig struct {
ZodIssueBase
Origin string `json:"origin"`
Maximum any `json:"maximum"`
Inclusive bool `json:"inclusive,omitempty"`
}
ZodIssueTooBig represents a value exceeding maximum constraint error
type ZodIssueTooSmall ¶
type ZodIssueTooSmall struct {
ZodIssueBase
Origin string `json:"origin"`
Minimum any `json:"minimum"`
Inclusive bool `json:"inclusive,omitempty"`
}
ZodIssueTooSmall represents a value below minimum constraint error
type ZodIssueUnrecognizedKeys ¶
type ZodIssueUnrecognizedKeys struct {
ZodIssueBase
Keys []string `json:"keys"`
}
ZodIssueUnrecognizedKeys represents unrecognized object keys error
type ZodRawIssue ¶
type ZodRawIssue = core.ZodRawIssue