Versions in this module Expand all Collapse all v0 v0.1.0 Apr 6, 2025 Changes in this version + var ErrJSONTooLarge = errors.New("shape: JSON input too large") + func BindJSONContext[T any](ctx context.Context, target *T, source []byte, options ...JSONOptions) error + func BindJSONReaderContext[T any](ctx context.Context, target *T, reader io.Reader, options ...JSONOptions) error + func BindJSONReader[T any](target *T, reader io.Reader, options ...JSONOptions) error + func BindJSON[T any](target *T, source []byte, options ...JSONOptions) error + func ExportDocument[T any](schema Schema[T]) (map[string]any, error) + func ParseJSONContext[T any](ctx context.Context, schema Schema[T], source []byte, options ...JSONOptions) (T, error) + func ParseJSONReaderContext[T any](ctx context.Context, schema Schema[T], reader io.Reader, ...) (T, error) + func ParseJSONReader[T any](schema Schema[T], reader io.Reader, options ...JSONOptions) (T, error) + func ParseJSON[T any](schema Schema[T], source []byte, options ...JSONOptions) (T, error) + type FieldSpec interface + func Field[T any](name string, schema Schema[T]) FieldSpec + type JSONOptions struct + DisallowUnknownFields bool + MaxBytes int64 + type JSONSchema interface + ParseJSON func([]byte, ...JSONOptions) (T, error) + ParseJSONContext func(context.Context, []byte, ...JSONOptions) (T, error) + ParseJSONReader func(io.Reader, ...JSONOptions) (T, error) + ParseJSONReaderContext func(context.Context, io.Reader, ...JSONOptions) (T, error) + type MapKey interface + type MapSpec struct + func Map[K MapKey, V any](name string, key Schema[K], value Schema[V]) MapSpec[K, V] + func (f MapSpec[K, V]) Apply(values ...func(map[K]V) (map[K]V, error)) MapSpec[K, V] + func (f MapSpec[K, V]) ApplyContext(values ...func(context.Context, map[K]V) (map[K]V, error)) MapSpec[K, V] + func (f MapSpec[K, V]) IfNull(v map[K]V) MapSpec[K, V] + func (f MapSpec[K, V]) Label(label string) MapSpec[K, V] + func (f MapSpec[K, V]) Len(n int) MapSpec[K, V] + func (f MapSpec[K, V]) Max(n int) MapSpec[K, V] + func (f MapSpec[K, V]) Min(n int) MapSpec[K, V] + func (f MapSpec[K, V]) NotEmpty() MapSpec[K, V] + func (f MapSpec[K, V]) NotNull() MapSpec[K, V] + func (f MapSpec[K, V]) Refine(values ...func(map[K]V) error) MapSpec[K, V] + func (f MapSpec[K, V]) RefineContext(values ...func(context.Context, map[K]V) error) MapSpec[K, V] + func (f MapSpec[K, V]) Transform(v map[K]V) (map[K]V, error) + func (f MapSpec[K, V]) TransformContext(ctx context.Context, v map[K]V) (map[K]V, error) + func (f MapSpec[K, V]) Validate(v map[K]V) error + func (f MapSpec[K, V]) ValidateContext(ctx context.Context, v map[K]V) error + func (f MapSpec[K, V]) ValidateFirst(v map[K]V) error + func (f MapSpec[K, V]) ValidateFirstContext(ctx context.Context, v map[K]V) error + type NumberSpec struct + func Duration(name ...string) NumberSpec[types.Duration] + func Float64(name ...string) NumberSpec[float64] + func Int(name ...string) NumberSpec[int] + func Int64(name ...string) NumberSpec[int64] + func Number[N Numeric](name ...string) NumberSpec[N] + func (f NumberSpec[N]) Apply(values ...func(N) (N, error)) NumberSpec[N] + func (f NumberSpec[N]) ApplyContext(values ...func(context.Context, N) (N, error)) NumberSpec[N] + func (f NumberSpec[N]) Between(a, b N) NumberSpec[N] + func (f NumberSpec[N]) Gt(v N) NumberSpec[N] + func (f NumberSpec[N]) Gte(v N) NumberSpec[N] + func (f NumberSpec[N]) IfZero(v N) NumberSpec[N] + func (f NumberSpec[N]) Label(label string) NumberSpec[N] + func (f NumberSpec[N]) Lt(v N) NumberSpec[N] + func (f NumberSpec[N]) Lte(v N) NumberSpec[N] + func (f NumberSpec[N]) Max(v N) NumberSpec[N] + func (f NumberSpec[N]) Min(v N) NumberSpec[N] + func (f NumberSpec[N]) Negative() NumberSpec[N] + func (f NumberSpec[N]) NonNegative() NumberSpec[N] + func (f NumberSpec[N]) OneOf(values ...N) NumberSpec[N] + func (f NumberSpec[N]) Pointer() PointerSpec[N] + func (f NumberSpec[N]) Positive() NumberSpec[N] + func (f NumberSpec[N]) Refine(values ...func(N) error) NumberSpec[N] + func (f NumberSpec[N]) RefineContext(values ...func(context.Context, N) error) NumberSpec[N] + func (f NumberSpec[N]) Slice() SliceSpec[N] + func (f NumberSpec[N]) Transform(v N) (N, error) + func (f NumberSpec[N]) TransformContext(ctx context.Context, v N) (N, error) + func (f NumberSpec[N]) Validate(v N) error + func (f NumberSpec[N]) ValidateContext(ctx context.Context, v N) error + func (f NumberSpec[N]) ValidateFirst(v N) error + func (f NumberSpec[N]) ValidateFirstContext(ctx context.Context, v N) error + type Numeric interface + type PointerSpec struct + func Pointer[T any](name string, inner Schema[T]) PointerSpec[T] + func (f PointerSpec[T]) Apply(values ...func(*T) (*T, error)) PointerSpec[T] + func (f PointerSpec[T]) ApplyContext(values ...func(context.Context, *T) (*T, error)) PointerSpec[T] + func (f PointerSpec[T]) IfNull(v *T) PointerSpec[T] + func (f PointerSpec[T]) Label(label string) PointerSpec[T] + func (f PointerSpec[T]) NotEmpty() PointerSpec[T] + func (f PointerSpec[T]) NotNull() PointerSpec[T] + func (f PointerSpec[T]) Refine(values ...func(*T) error) PointerSpec[T] + func (f PointerSpec[T]) RefineContext(values ...func(context.Context, *T) error) PointerSpec[T] + func (f PointerSpec[T]) Transform(v *T) (*T, error) + func (f PointerSpec[T]) TransformContext(ctx context.Context, v *T) (*T, error) + func (f PointerSpec[T]) Validate(v *T) error + func (f PointerSpec[T]) ValidateContext(ctx context.Context, v *T) error + func (f PointerSpec[T]) ValidateFirst(v *T) error + func (f PointerSpec[T]) ValidateFirstContext(ctx context.Context, v *T) error + type Schema interface + Transform func(T) (T, error) + TransformContext func(context.Context, T) (T, error) + Validate func(T) error + ValidateContext func(context.Context, T) error + ValidateFirst func(T) error + ValidateFirstContext func(context.Context, T) error + type SliceSpec struct + func Slice[T any](name string, inner Schema[T]) SliceSpec[T] + func (f SliceSpec[T]) Apply(values ...func([]T) ([]T, error)) SliceSpec[T] + func (f SliceSpec[T]) ApplyContext(values ...func(context.Context, []T) ([]T, error)) SliceSpec[T] + func (f SliceSpec[T]) IfNull(v []T) SliceSpec[T] + func (f SliceSpec[T]) Label(label string) SliceSpec[T] + func (f SliceSpec[T]) Len(n int) SliceSpec[T] + func (f SliceSpec[T]) Max(n int) SliceSpec[T] + func (f SliceSpec[T]) Min(n int) SliceSpec[T] + func (f SliceSpec[T]) NotEmpty() SliceSpec[T] + func (f SliceSpec[T]) NotNull() SliceSpec[T] + func (f SliceSpec[T]) Refine(values ...func([]T) error) SliceSpec[T] + func (f SliceSpec[T]) RefineContext(values ...func(context.Context, []T) error) SliceSpec[T] + func (f SliceSpec[T]) Transform(v []T) ([]T, error) + func (f SliceSpec[T]) TransformContext(ctx context.Context, v []T) ([]T, error) + func (f SliceSpec[T]) Unique() SliceSpec[T] + func (f SliceSpec[T]) Validate(v []T) error + func (f SliceSpec[T]) ValidateContext(ctx context.Context, v []T) error + func (f SliceSpec[T]) ValidateFirst(v []T) error + func (f SliceSpec[T]) ValidateFirstContext(ctx context.Context, v []T) error + type StringSpec struct + func String(name ...string) StringSpec + func (f StringSpec) Apply(values ...func(string) (string, error)) StringSpec + func (f StringSpec) ApplyContext(values ...func(context.Context, string) (string, error)) StringSpec + func (f StringSpec) Contains(v string) StringSpec + func (f StringSpec) Email() StringSpec + func (f StringSpec) EndsWith(v string) StringSpec + func (f StringSpec) IP() StringSpec + func (f StringSpec) IfZero(v string) StringSpec + func (f StringSpec) LTrim(chars ...string) StringSpec + func (f StringSpec) Label(label string) StringSpec + func (f StringSpec) Len(n int) StringSpec + func (f StringSpec) MaxLength(n int) StringSpec + func (f StringSpec) MinLength(n int) StringSpec + func (f StringSpec) NotEmpty() StringSpec + func (f StringSpec) OneOf(values ...string) StringSpec + func (f StringSpec) Pattern(expr string) StringSpec + func (f StringSpec) Pointer() PointerSpec[string] + func (f StringSpec) RTrim(chars ...string) StringSpec + func (f StringSpec) Refine(values ...func(string) error) StringSpec + func (f StringSpec) RefineContext(values ...func(context.Context, string) error) StringSpec + func (f StringSpec) Slice() SliceSpec[string] + func (f StringSpec) StartsWith(v string) StringSpec + func (f StringSpec) ToLower() StringSpec + func (f StringSpec) ToUpper() StringSpec + func (f StringSpec) Transform(v string) (string, error) + func (f StringSpec) TransformContext(ctx context.Context, v string) (string, error) + func (f StringSpec) Trim(chars ...string) StringSpec + func (f StringSpec) URL() StringSpec + func (f StringSpec) UUID() StringSpec + func (f StringSpec) Validate(v string) error + func (f StringSpec) ValidateContext(ctx context.Context, v string) error + func (f StringSpec) ValidateFirst(v string) error + func (f StringSpec) ValidateFirstContext(ctx context.Context, v string) error + type StructSpec struct + func New[T any](fields ...FieldSpec) StructSpec[T] + func (s StructSpec[T]) Apply(steps ...func(T) (T, error)) StructSpec[T] + func (s StructSpec[T]) ApplyContext(steps ...func(context.Context, T) (T, error)) StructSpec[T] + func (s StructSpec[T]) ParseJSON(source []byte, options ...JSONOptions) (T, error) + func (s StructSpec[T]) ParseJSONContext(ctx context.Context, source []byte, options ...JSONOptions) (T, error) + func (s StructSpec[T]) ParseJSONReader(reader io.Reader, options ...JSONOptions) (T, error) + func (s StructSpec[T]) ParseJSONReaderContext(ctx context.Context, reader io.Reader, options ...JSONOptions) (T, error) + func (s StructSpec[T]) Refine(rules ...func(T) error) StructSpec[T] + func (s StructSpec[T]) RefineContext(rules ...func(context.Context, T) error) StructSpec[T] + func (s StructSpec[T]) Transform(value T) (T, error) + func (s StructSpec[T]) TransformContext(ctx context.Context, value T) (T, error) + func (s StructSpec[T]) Validate(value T) error + func (s StructSpec[T]) ValidateContext(ctx context.Context, value T) error + func (s StructSpec[T]) ValidateFirst(value T) error + func (s StructSpec[T]) ValidateFirstContext(ctx context.Context, value T) error + type TaggedSpec struct + func Struct[T any]() TaggedSpec[T] + func (s TaggedSpec[T]) Apply(steps ...func(T) (T, error)) TaggedSpec[T] + func (s TaggedSpec[T]) ApplyContext(steps ...func(context.Context, T) (T, error)) TaggedSpec[T] + func (s TaggedSpec[T]) ParseJSON(source []byte, options ...JSONOptions) (T, error) + func (s TaggedSpec[T]) ParseJSONContext(ctx context.Context, source []byte, options ...JSONOptions) (T, error) + func (s TaggedSpec[T]) ParseJSONReader(reader io.Reader, options ...JSONOptions) (T, error) + func (s TaggedSpec[T]) ParseJSONReaderContext(ctx context.Context, reader io.Reader, options ...JSONOptions) (T, error) + func (s TaggedSpec[T]) Refine(rules ...func(T) error) TaggedSpec[T] + func (s TaggedSpec[T]) RefineContext(rules ...func(context.Context, T) error) TaggedSpec[T] + func (s TaggedSpec[T]) Transform(value T) (T, error) + func (s TaggedSpec[T]) TransformContext(ctx context.Context, value T) (T, error) + func (s TaggedSpec[T]) Validate(value T) error + func (s TaggedSpec[T]) ValidateContext(ctx context.Context, value T) error + func (s TaggedSpec[T]) ValidateFirst(value T) error + func (s TaggedSpec[T]) ValidateFirstContext(ctx context.Context, value T) error + type TransformError struct + Err error + Path validate.Path + func (e *TransformError) Error() string + func (e *TransformError) Unwrap() error + type UnsupportedSchemaError struct + Feature string + func (e *UnsupportedSchemaError) Error() string + type ValueSpec struct + func Bool(name ...string) ValueSpec[bool] + func Time(name ...string) ValueSpec[time.Time] + func Value[T any](name ...string) ValueSpec[T] + func (f ValueSpec[T]) Apply(values ...func(T) (T, error)) ValueSpec[T] + func (f ValueSpec[T]) ApplyContext(values ...func(context.Context, T) (T, error)) ValueSpec[T] + func (f ValueSpec[T]) IfZero(v T) ValueSpec[T] + func (f ValueSpec[T]) Label(label string) ValueSpec[T] + func (f ValueSpec[T]) Pointer() PointerSpec[T] + func (f ValueSpec[T]) Refine(values ...func(T) error) ValueSpec[T] + func (f ValueSpec[T]) RefineContext(values ...func(context.Context, T) error) ValueSpec[T] + func (f ValueSpec[T]) Slice() SliceSpec[T] + func (f ValueSpec[T]) Transform(v T) (T, error) + func (f ValueSpec[T]) TransformContext(ctx context.Context, v T) (T, error) + func (f ValueSpec[T]) Validate(v T) error + func (f ValueSpec[T]) ValidateContext(ctx context.Context, v T) error + func (f ValueSpec[T]) ValidateFirst(v T) error + func (f ValueSpec[T]) ValidateFirstContext(ctx context.Context, v T) error