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
- func Collect(ve *jsonschema.ValidationError, report func(loc []string, msg string))
- func Compile(url string, data []byte) (*jsonschema.Schema, error)
- func FieldPath(v any, loc []string) string
- func Locate(body ast.Node, loc []string) int
- func Message(k jsonschema.ErrorKind) string
- func NodeLine(n ast.Node) int
- func Rat(r *big.Rat) string
- func Show(v any) string
- func Validate(sch *jsonschema.Schema, doc Doc, file string, iss *Issues) bool
- type Doc
- type Issue
- type Issues
Constants ¶
const MaxFileSize = 1 << 20
MaxFileSize bounds one YAML file read by a loader (1 MiB).
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 ¶
FieldPath formats an instance location as patterns[0].confidence, using the value to tell array indexes from object keys.
func Locate ¶
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.
Types ¶
type Doc ¶
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.
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.