validation

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package validation collects schema validation results for generated types: a Collector the generated Validate methods report into and the Error and Errors types callers inspect.

Why

Apple's schema declares, per key, presence, allowed values, numeric ranges, formats, and repetition limits. Phase 1 of the plan of record generates a Validate method from those constraints (decision record 0003), and the value of that method is in reporting everything wrong with a value in one pass rather than stopping at the first fault, so an operator fixing a profile or a declaration sees the whole list. Generated methods call the Collector for every key with the rule and the key's support entry; given a Target, the Collector also records whether the target OS version and enrollment context accept each key.

The package defines the vocabulary and the accumulator only. The rules are generated, and the support tables live in schema/support.

References

  • Decision record 0003: docs/research/decisions/0003-schema-generator.md
  • Decision record 0004: docs/research/decisions/0004-checkin-and-command-core.md (validated command payloads)
  • Decision record 0009: docs/research/decisions/0009-enrollment-profiles.md (validated profiles)
  • Plan of record: docs/research/implementation_plan.md (section 2, the generator; phase 1)
  • Apple: https://github.com/apple/device-management/blob/release/docs/schema.md
  • Schema: third_party/device-management/docs/schema.yaml (meta-schema)

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