yamlschema

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package yamlschema validates YAML documents against a JSON Schema and reports each problem with its file:line:column.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NodeAt

func NodeAt(root *yaml.Node, loc []string, keyNode bool) *yaml.Node

NodeAt returns the YAML node at loc, or the deepest node that exists. With keyNode, a mapping entry's key node is returned instead of its value.

func SortProblems

func SortProblems(problems []Problem)

SortProblems orders problems by line, then column, keeping the order of equal positions.

func ToJSONValue

func ToJSONValue(v any) (any, error)

ToJSONValue converts a decoded YAML value into the form the validator expects.

Types

type Document

type Document struct {
	Data any        // decoded value; an empty file decodes to an empty map
	Root *yaml.Node // for positions, see [NodeAt]
}

Document is a parsed YAML file.

type Leaf

type Leaf struct {
	Loc     []string
	Message string
	KeyNode bool // report the key's position, not the value's
}

Leaf is one schema violation at an instance location.

type Problem

type Problem struct {
	Origin  string // file path, "env NAME" or "flag --x"
	Line    int    // 0 when there is no position
	Column  int
	Key     string
	Message string
}

Problem is one validation error and where it is.

func (Problem) String

func (p Problem) String() string

type Schema

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

Schema is a compiled JSON Schema that keeps its raw form for type lookups.

func Compile

func Compile(url string, b []byte) (*Schema, error)

Compile parses and compiles the schema in b, registered under url.

func (*Schema) Parse

func (s *Schema) Parse(origin string, b []byte) (*Document, []Problem, error)

Parse decodes the YAML in b and validates it. Syntax errors and schema violations come back as problems with origin and position; the error is only for failures of the validator itself.

func (*Schema) Raw

func (s *Schema) Raw() map[string]any

Raw returns the schema document as decoded JSON.

func (*Schema) TypeAt

func (s *Schema) TypeAt(path []string) string

TypeAt returns the "type" of the property at path, following nested "properties", or "".

func (*Schema) Validate

func (s *Schema) Validate(inst any) ([]Leaf, error)

Validate checks a JSON value (see ToJSONValue) and returns its violations sorted by location.

Jump to

Keyboard shortcuts

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