yamlschema

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 14 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 parses single-document YAML files and validates them against a JSON Schema, reporting every problem as "file:line: field: message". The messages are written here; they never contain the schema library's or the parser's text, nor the values being validated, so they are safe to print (AD-3). The provider registry and the tokenhound.yaml config loader share it.

Index

Constants

View Source
const MaxFileSize = 1 << 20

MaxFileSize bounds one YAML file read by a loader (1 MiB).

View Source
const RootField = "(root)"

RootField names the document itself in an issue.

Variables

This section is empty.

Functions

func Collect

func Collect(ve *jsonschema.ValidationError, report func(loc []string, msg string))

Collect walks a validation error tree and reports each leaf as an instance location plus a message written here (never the library's text).

func Compile

func Compile(url string, data []byte) (*jsonschema.Schema, error)

Compile compiles a Draft 2020-12 JSON Schema with format assertions on.

func FieldPath

func FieldPath(v any, loc []string) string

FieldPath formats an instance location as patterns[0].confidence, using the value to tell array indexes from object keys.

func Locate

func Locate(body ast.Node, loc []string) int

Locate returns the line of the deepest node along loc that exists in the AST: the key line for object fields and the item line for array items.

func Message

func Message(k jsonschema.ErrorKind) string

Message is the issue message for one validation error kind. Enum and const messages name the allowed values from the schema, never the rejected value.

func NodeLine

func NodeLine(n ast.Node) int

NodeLine returns the line of n: the key line of a mapping value, 1 for nil.

func Rat

func Rat(r *big.Rat) string

Rat formats a schema bound: an integer, or a decimal with three places.

func Show

func Show(v any) string

Show formats a schema value (an enum or const member) for a message.

func Validate

func Validate(sch *jsonschema.Schema, doc Doc, file string, iss *Issues) bool

Validate checks doc against sch and records one issue per failing leaf, at the line of the deepest node that exists in doc's AST.

Types

type Doc

type Doc struct {
	Body ast.Node
	JSON []byte
	Val  any
}

Doc is one parsed YAML document: its AST for line numbers, its value as JSON and its value in the JSON Schema instance form (numbers are json.Number) for validation and decoding. Body and Val are nil for an empty document.

func Parse

func Parse(data []byte, file string, iss *Issues) (Doc, bool)

Parse parses data as a single YAML document. Multi-document files, anchors and aliases (which could expand a small file into a huge value) and values that have no JSON form are rejected with an issue at their line.

type Issue

type Issue struct {
	File    string `json:"file"`
	Line    int    `json:"line"`
	Field   string `json:"field"`
	Message string `json:"message"`
}

Issue is one validation problem, printed as "file:line: field: message". Line 0 means the source has no lines (for example an environment variable) and is left out of the printed form; an empty File or Field is left out too.

func Sorted

func Sorted(issues []Issue) []Issue

Sorted returns the issues sorted by file, line, field and message with exact duplicates removed, or nil when there are none.

func (Issue) String

func (i Issue) String() string

String formats the issue as "file:line: field: message".

type Issues

type Issues []Issue

Issues collects issues during a load.

func (*Issues) Add

func (l *Issues) Add(file string, line int, field, msg string)

Add records an issue with a line of at least 1 and a field of at least RootField.

Jump to

Keyboard shortcuts

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