validator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package validator defines interfaces and types for configuration validation.

This package provides the contract layer for validation. Concrete implementations live in subpackages (e.g., validators/jsonschema).

Key Types

  • Validator validates a tree.Node and returns a slice of ValidationError. It also reports its [Validator.SchemaType].
  • ValidationError describes a single validation failure with Path (keypath.KeyPath), Range (source position), Code (machine-readable), and Message (human-readable).
  • Position represents a line/column in a source file (1-based, 0 if unknown).
  • Range is a start/end Position pair used for source highlighting.

Helpers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Position

type Position struct {
	Line   int // Line number (1-based), 0 if unknown.
	Column int // Column number (1-based), 0 if unknown.
}

Position describes a position in source file (for LSP integration). Currently placeholder - will be populated when position tracking is implemented.

type Range

type Range struct {
	Start Position
	End   Position
}

Range describes a range in source file for highlighting.

func NewEmptyRange

func NewEmptyRange() Range

NewEmptyRange creates a placeholder Range.

func RangeFromTree

func RangeFromTree(r tree.Range) Range

RangeFromTree converts a tree.Range to a validator.Range.

type ValidationError

type ValidationError struct {
	Path    keypath.KeyPath // Logical path to the field.
	Range   Range           // Physical range (populated when position tracking available).
	Code    string          // Machine-readable code (e.g., "type", "required", "minimum").
	Message string          // Human-readable description.
}

ValidationError describes a single validation error.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error returns a string representation of the validation error.

type Validator

type Validator interface {
	// Validate checks the tree and returns all errors found.
	// Returns nil if validation succeeds.
	Validate(root *tree.Node) []ValidationError

	// SchemaType returns the type identifier (e.g., "json-schema").
	SchemaType() string
}

Validator validates configuration against a schema.

Jump to

Keyboard shortcuts

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