validation

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package validation collects constraint failures from generated schema validators.

Design

Generated Validate methods report presence, range, format, value and repetition checks to Collector. A supplied support.Target also enables platform and enrollment-context checks for populated fields. Aggregating errors lets callers inspect multiple invalid values in one pass.

This package defines the result types and accumulation behavior. The generator defines schema-specific rules, and schema/support holds availability metadata. Successful structural validation does not prove a payload will install on a physical device.

References

Index

Constants

View Source
const (
	RuleRequired   = "required"
	RuleEnum       = "rangelist"
	RuleRange      = "range"
	RuleFormat     = "format"
	RuleRepetition = "repetition"
	RuleSupport    = "support"
)

Rule names used in Error.Rule.

Variables

View Source
var ErrValidation = errors.New("schema validation failed")

ErrValidation is the sentinel every Errors value unwraps to.

Functions

func Index

func Index(prefix string, i int) string

Index formats an array element path.

func Join

func Join(prefix, key string) string

Join concatenates key paths.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector accumulates errors and deprecation warnings.

func New

func New(t support.Target) *Collector

New starts a collector for a target. The zero Target skips support checks.

func (*Collector) Enum

func (c *Collector) Enum(path string, present bool, v any, allowed []any)

Enum records an error when a present value is not in the allowed list. Values are compared as strings, or numerically when both sides are numbers.

func (*Collector) Err

func (c *Collector) Err() error

Err returns the collected errors, or nil when there are none.

func (*Collector) Pattern

func (c *Collector) Pattern(path string, present bool, v string, re *regexp.Regexp)

Pattern records an error when a present string does not match re.

func (*Collector) Range

func (c *Collector) Range(path string, present bool, v float64, minValue, maxValue *float64)

Range records an error when a present number is outside [min, max].

func (*Collector) Repetition

func (c *Collector) Repetition(path string, present bool, n, minLen, maxLen int)

Repetition records an error when a present array's length is outside [min, max]. A max of 0 means unbounded.

func (*Collector) Required

func (c *Collector) Required(path string, present bool)

Required records an error when a required key is absent.

func (*Collector) Support

func (c *Collector) Support(path string, present bool, e *support.Entry)

Support records an error when a present key is not supported by the target, and a warning when it is deprecated there.

func (*Collector) Target

func (c *Collector) Target() support.Target

Target returns the collector's target.

func (*Collector) Warnings

func (c *Collector) Warnings() Errors

Warnings returns deprecation warnings collected so far.

type Error

type Error struct {
	Path    string // dotted wire-key path from the top-level type
	Rule    string
	Message string
}

Error is one validation failure.

func (*Error) Error

func (e *Error) Error() string

Error implements error.

type Errors

type Errors []*Error

Errors is every failure found. It implements error.

func (Errors) Error

func (es Errors) Error() string

Error implements error.

func (Errors) Unwrap

func (es Errors) Unwrap() error

Unwrap lets errors.Is(err, ErrValidation) succeed.

Jump to

Keyboard shortcuts

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