{"modulePath":"github.com/mockzilla/mockzilla-codegen","version":"v1.0.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package validation\n\nPackage validation checks values against the constraints of a spec and collects what fails.\n\n## Functions\n\n```go\nfunc AnyValid(variants ...VariantErrors) error\n```\nAnyValid is the check of an anyOf union: nil when a set variant passes, else all their errors.\n\n```go\nfunc AtLeastOne(set ...bool) error\n```\nAtLeastOne is the check of an anyOf union.\n\n```go\nfunc AtLeastOneOf(members string, has ...bool) error\n```\nAtLeastOneOf is the check of an anyOf of required lists: the value has one or more of them.\n\n```go\nfunc AtMostOne(set ...bool) error\n```\nAtMostOne is the check of a nullable oneOf union, where nothing set is null.\n\n```go\nfunc Base64(b []byte) string\n```\nBase64 is the text encoding/json writes for b, which the length and pattern of format byte count.\n\n```go\nfunc Const[T comparable](v, want T) error\n```\nConst checks that v is want.\n\n```go\nfunc Enum[T comparable](v T, values ...T) error\n```\nEnum checks that v is one of values.\n\n```go\nfunc EnumJSON[T any](v T, values ...string) error\n```\nEnumJSON checks that v is one of values, each read into a T, by comparing both written as JSON.\n\n```go\nfunc ExactlyOne(set ...bool) error\n```\nExactlyOne is the check of a oneOf union: one variant set.\n\n```go\nfunc ExactlyOneOf(members string, has ...bool) error\n```\nExactlyOneOf is the check of a oneOf of required lists: the value has exactly one of them.\n\n```go\nfunc Failed(err error) bool\n```\nFailed reports whether err holds Errors.\n\n```go\nfunc Format[S ~string](s S, format string) error\n```\nFormat checks that s is written in format. Formats it does not know pass.\n\n```go\nfunc Index(path string, i int) string\n```\nIndex is the path of item i under path: items\\[2].\n\n```go\nfunc IsZero(v any) bool\n```\nIsZero reports whether v is nil or its zero value, by its own IsZero method too, as omitzero sees it.\n\n```go\nfunc Join(prefix, field string) string\n```\nJoin is the path of field under prefix: pet.name, or pet\\[0] for an index.\n\n```go\nfunc Key(path, key string) string\n```\nKey is the path of the value under key: labels\\[\"team\"], or team at the top.\n\n```go\nfunc MaxItems[T any](s []T, n int) error\n```\nMaxItems checks that s has at most n items.\n\n```go\nfunc MaxLength[S ~string](s S, n int) error\n```\nMaxLength checks that s has at most n characters.\n\n```go\nfunc MaxProperties[V any](m map[string]V, n int) error\n```\nMaxProperties checks that m has at most n keys.\n\n```go\nfunc Maximum[T Number](v T, bound float64, isExclusive bool) error\n```\nMaximum checks that v is at most bound, or below it when isExclusive.\n\n```go\nfunc MinItems[T any](s []T, n int) error\n```\nMinItems checks that s has at least n items.\n\n```go\nfunc MinLength[S ~string](s S, n int) error\n```\nMinLength checks that s has at least n characters.\n\n```go\nfunc MinProperties[V any](m map[string]V, n int) error\n```\nMinProperties checks that m has at least n keys.\n\n```go\nfunc Minimum[T Number](v T, bound float64, isExclusive bool) error\n```\nMinimum checks that v is at least bound, or above it when isExclusive.\n\n```go\nfunc MultipleOf[T Number](v T, factor float64) error\n```\nMultipleOf checks that v, as the decimal JSON carries, is a whole multiple of a positive factor.\n\n```go\nfunc NotNull[N interface{ IsNull() bool }](n N) error\n```\nNotNull checks that n, a value the spec does not let be null, is not null.\n\n```go\nfunc OneValid(members ...VariantErrors) error\n```\nOneValid is the check of oneOf members that share a variant: nil when exactly one passes.\n\n```go\nfunc Pattern[S ~string](s S, re *regexp.Regexp, pattern string) error\n```\nPattern checks that re, compiled from the spec's pattern, matches s.\n\n```go\nfunc SortedKeys[V any](m map[string]V) []string\n```\nSortedKeys returns the keys of m in order, so errors come out the same on every run.\n\n```go\nfunc Unique[T comparable](s []T) error\n```\nUnique checks that no two items of s are equal.\n\n```go\nfunc UniqueJSON[T any](s []T) error\n```\nUniqueJSON checks that no two items of s have the same JSON, for items Go cannot compare.\n\n## Types\n\n```go\ntype Error struct {\n\tField   string\n\tMessage string\n\tRule    Rule\n\tLimit   any\n}\n```\nError is one failed check. Field is a path like items\\[2].name, empty for the value itself. Limit is the value of Rule in the spec, nil when the rule has none.\n\n```go\nfunc (e Error) Error() string\n```\n\n```go\ntype Errors []Error\n```\nErrors collects failed checks. errors.As finds it as a \\*Errors, and each Error in it.\n\n```go\nfunc (es *Errors) Add(field, message string)\n```\nAdd adds a failed check that names no rule.\n\n```go\nfunc (es *Errors) Append(prefix string, err error)\n```\nAppend adds err under prefix. Nested validation errors are flattened with their paths joined.\n\n```go\nfunc (es *Errors) Err() error\n```\nErr returns nil when nothing failed, so a Validate method can end with return errs.Err().\n\n```go\nfunc (es *Errors) Error() string\n```\n\n```go\nfunc (es *Errors) Required(field string)\n```\nRequired adds a required field that is not set.\n\n```go\nfunc (es *Errors) Unwrap() []error\n```\n\n```go\ntype Number interface {\n\t~int | ~int8 | ~int16 | ~int32 | ~int64 |\n\t\t~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |\n\t\t~float32 | ~float64\n}\n```\nNumber is every Go number type.\n\n```go\ntype Rule string\n```\nRule is the keyword of the spec a value fails, as JSON Schema names it.\n\n```go\nconst (\n\tRuleRequired             Rule = \"required\"\n\tRuleType                 Rule = \"type\"\n\tRuleAdditionalProperties Rule = \"additionalProperties\"\n\tRuleMinLength            Rule = \"minLength\"\n\tRuleMaxLength            Rule = \"maxLength\"\n\tRulePattern              Rule = \"pattern\"\n\tRuleFormat               Rule = \"format\"\n\tRuleMinimum              Rule = \"minimum\"\n\tRuleExclusiveMinimum     Rule = \"exclusiveMinimum\"\n\tRuleMaximum              Rule = \"maximum\"\n\tRuleExclusiveMaximum     Rule = \"exclusiveMaximum\"\n\tRuleMultipleOf           Rule = \"multipleOf\"\n\tRuleMinItems             Rule = \"minItems\"\n\tRuleMaxItems             Rule = \"maxItems\"\n\tRuleUniqueItems          Rule = \"uniqueItems\"\n\tRuleMinProperties        Rule = \"minProperties\"\n\tRuleMaxProperties        Rule = \"maxProperties\"\n\tRuleConst                Rule = \"const\"\n\tRuleEnum                 Rule = \"enum\"\n\tRuleOneOf                Rule = \"oneOf\"\n\tRuleAnyOf                Rule = \"anyOf\"\n\tRuleDiscriminator        Rule = \"discriminator\"\n)\n```\nThe rules of Error.\n\n```go\ntype VariantErrors struct {\n\tIsSet bool\n\tErrs  Errors\n}\n```\nVariantErrors are the failed checks of one union member, and whether its variant is set.\n\n","path":"github.com/mockzilla/mockzilla-codegen/pkg/runtime/validation","name":"validation","synopsis":"Package validation checks values against the constraints of a spec and collects what fails.","isRedistributable":true}
