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 ¶
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 ¶
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 ¶
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.