schema

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 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 schema checks a value against the JSON Schema 2020-12 schemas of the format version the library reads, reporting every keyword that fails with its place (format/README.md, sections 5 and 8). The schemas are a copy of schemas/ of spec.Format at the tag go.mod requires, built into the package, so that the code holds the schemas of the version it runs, as module.FormatVersion holds the version; a test holds the copy to spec.Format byte for byte (R23).

The validator is github.com/santhosh-tekuri/jsonschema/v6. It collects no annotations: the open view walks the schemas by section 6 itself and asks this package only whether a subschema passes (R23). The check of a module and the test of vectors call it.

Index

Constants

This section is empty.

Variables

View Source
var Keywords = []string{
	"$schema", "$id", "$ref", "$defs", "$comment",
	"allOf", "anyOf", "oneOf", "not", "if", "then", "else", "prefixItems", "items", "contains", "properties",
	"patternProperties", "additionalProperties", "propertyNames", "unevaluatedProperties",
	"type", "enum", "const", "multipleOf", "maximum", "exclusiveMaximum", "minimum", "exclusiveMinimum", "maxLength",
	"minLength", "pattern", "maxItems", "minItems", "uniqueItems", "maxProperties", "minProperties", "required",
	"dependentRequired",
	"title", "description", "default", "deprecated", "readOnly", "writeOnly", "examples", "format",
	"x-open",
}

Keywords are the keywords that a schema of the format uses, and so the only ones an Error may name, as section 5 of format/README.md lists them; a test holds the list to the text.

Functions

func Files

func Files() []string

Files names the schemas of the format, as schemas/ of spec.Format names them.

func Pointer

func Pointer(tokens []string) string

Pointer writes a place in a value, token by token, as a JSON Pointer in URI fragment form (RFC 6901, sections 3 and 6): # for the whole value, then / before each token, with ~ written ~0 and / written ~1, and what a fragment of a URI cannot hold percent-encoded, as in #/modules/example~1smallest/0.1.0/withdrawn.

Types

type Error

type Error struct {
	Keyword string
	// The place in the value, token by token from its root: the name of a member, or the index of
	// an element in decimal digits. Pointer writes it as a JSON Pointer.
	Location []string
	Message  string
}

An Error is one keyword that fails, at the place where the schema holding it applies, as an example of the format names it: the object for required, unevaluatedProperties and the other keywords of an object, the array for those of an array, and the value for type, pattern and the other keywords of a value (format/README.md, section 8).

func Validate

func Validate(location string, value any) []Error

Validate checks value against the schema at location: the name of a schema's file, such as task.schema.json, or that name with a JSON Pointer to a subschema in it as its fragment, such as task.schema.json#/$defs/check. value is a JSON value as the reader of YAML gives it: map[string]any, []any, string, int64, float64, bool or nil. It gives every keyword that fails, and none when the value is valid. Each schema is compiled once, and Validate may be called from many goroutines at once.

A location that names no schema of the format, and a schema that does not compile, are faults in module-kit rather than in the value, and Validate panics on them, as regexp.MustCompile does.

func (Error) Pointer

func (e Error) Pointer() string

Pointer gives the place of the error as a JSON Pointer in URI fragment form, as the first line of an invalid example writes it: #/answer_slots/0.

func (Error) String

func (e Error) String() string

Jump to

Keyboard shortcuts

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