validation

package
v1.16.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// Spec Validation Rules
	RuleValidationRequiredField           = "validation-required-field"
	RuleValidationTypeMismatch            = "validation-type-mismatch"
	RuleValidationDuplicateKey            = "validation-duplicate-key"
	RuleValidationInvalidFormat           = "validation-invalid-format"
	RuleValidationEmptyValue              = "validation-empty-value"
	RuleValidationInvalidReference        = "validation-invalid-reference"
	RuleValidationInvalidSyntax           = "validation-invalid-syntax"
	RuleValidationInvalidSchema           = "validation-invalid-schema"
	RuleValidationInvalidTarget           = "validation-invalid-target"
	RuleValidationAllowedValues           = "validation-allowed-values"
	RuleValidationMutuallyExclusiveFields = "validation-mutually-exclusive-fields"
	RuleValidationOperationNotFound       = "validation-operation-not-found"
	RuleValidationOperationIdUnique       = "validation-operation-id-unique"
	RuleValidationOperationParameters     = "validation-operation-parameters"
	RuleValidationSchemeNotFound          = "validation-scheme-not-found"
	RuleValidationTagNotFound             = "validation-tag-not-found"
	RuleValidationSupportedVersion        = "validation-supported-version"
	RuleValidationCircularReference       = "validation-circular-reference"
)

Variables

This section is empty.

Functions

func GetContextObject

func GetContextObject[T any](o *Options) *T

func NewMapKeyError added in v0.2.1

func NewMapKeyError(severity Severity, rule string, err error, core CoreModeler, node MapKeyNodeGetter, key string) error

func NewMapValueError added in v0.2.1

func NewMapValueError(severity Severity, rule string, err error, core CoreModeler, node MapValueNodeGetter, key string) error

func NewSliceError added in v0.2.1

func NewSliceError(severity Severity, rule string, err error, core CoreModeler, node SliceNodeGetter, index int) error

func NewValidationError added in v1.0.0

func NewValidationError(severity Severity, rule string, err error, node *yaml.Node) error

func NewValidationErrorWithDocumentLocation added in v1.16.0

func NewValidationErrorWithDocumentLocation(severity Severity, rule string, err error, node *yaml.Node, documentLocation string) error

NewValidationErrorWithDocumentLocation creates a validation error with document location metadata.

func NewValueError added in v0.2.1

func NewValueError(severity Severity, rule string, err error, core CoreModeler, node ValueNodeGetter) error

func RuleDescription added in v1.16.0

func RuleDescription(ruleID string) string

func RuleHowToFix added in v1.16.0

func RuleHowToFix(ruleID string) string

func RuleSummary added in v1.16.0

func RuleSummary(ruleID string) string

func SortValidationErrors added in v1.0.0

func SortValidationErrors(allErrors []error)

SortValidationErrors sorts the provided validation errors by line and column number lowest to highest.

Types

type CoreModeler added in v0.2.1

type CoreModeler interface {
	GetRootNode() *yaml.Node
}

type Error

type Error struct {
	UnderlyingError error
	Node            *yaml.Node
	Severity        Severity
	Rule            string
	Fix             Fix
	// DocumentLocation is the absolute location (URL or file path) of the document
	// where the error originated. Empty means the main document.
	DocumentLocation string
}

Error represents a validation error and the line and column where it occurred TODO allow getting the JSON path for line/column for validation errors

func (Error) Error

func (e Error) Error() string

func (Error) GetColumnNumber added in v1.0.0

func (e Error) GetColumnNumber() int

func (Error) GetDocumentLocation added in v1.16.0

func (e Error) GetDocumentLocation() string

GetDocumentLocation returns the document location where the error originated.

func (Error) GetLineNumber added in v1.0.0

func (e Error) GetLineNumber() int

func (Error) GetNode added in v1.16.0

func (e Error) GetNode() *yaml.Node

func (Error) GetSeverity added in v1.16.0

func (e Error) GetSeverity() Severity

func (Error) Unwrap added in v0.2.2

func (e Error) Unwrap() error

type Fix added in v1.16.0

type Fix interface {
	Apply(doc any) error
	FixDescription() string
}

Fix represents a suggested fix for a error finding

type MapKeyNodeGetter added in v1.7.12

type MapKeyNodeGetter interface {
	GetMapKeyNodeOrRoot(key string, root *yaml.Node) *yaml.Node
}

MapKeyNodeGetter provides access to map key nodes for error reporting.

type MapValueNodeGetter added in v1.7.12

type MapValueNodeGetter interface {
	GetMapValueNodeOrRoot(key string, root *yaml.Node) *yaml.Node
}

MapValueNodeGetter provides access to map value nodes for error reporting.

type Option

type Option func(o *Options)

func WithContextObject

func WithContextObject[T any](obj *T) Option

type Options

type Options struct {
	ContextObjects map[reflect.Type]any
}

func NewOptions

func NewOptions(opts ...Option) *Options

type RuleInfo added in v1.16.0

type RuleInfo struct {
	Summary     string
	Description string
	HowToFix    string
}

func RuleInfoForID added in v1.16.0

func RuleInfoForID(ruleID string) (RuleInfo, bool)

type Severity added in v1.16.0

type Severity string
const (
	SeverityError   Severity = "error"
	SeverityWarning Severity = "warning"
	SeverityHint    Severity = "hint"
)

func (Severity) Rank added in v1.16.0

func (s Severity) Rank() int

Rank returns a numeric rank for severity comparison. Higher rank means worse severity. SeverityError = 2, SeverityWarning = 1, SeverityHint = 0. Unknown severities are treated as SeverityError.

func (Severity) String added in v1.16.0

func (s Severity) String() string

type SliceNodeGetter added in v1.7.12

type SliceNodeGetter interface {
	GetSliceValueNodeOrRoot(index int, root *yaml.Node) *yaml.Node
}

SliceNodeGetter provides access to slice element nodes for error reporting.

type TypeMismatchError added in v0.2.2

type TypeMismatchError struct {
	Msg        string
	ParentName string
}

func NewTypeMismatchError added in v0.2.2

func NewTypeMismatchError(parentName, msg string, args ...any) *TypeMismatchError

func (TypeMismatchError) Error added in v0.2.2

func (e TypeMismatchError) Error() string

type ValueNodeGetter added in v1.7.12

type ValueNodeGetter interface {
	GetValueNodeOrRoot(root *yaml.Node) *yaml.Node
}

ValueNodeGetter provides access to value nodes for error reporting.

Jump to

Keyboard shortcuts

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