input

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 19 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 input reads one input document, JSON or YAML, and reports every problem with it as diagnostics that say where the problem is. No diagnostic carries a value of the input: the texts of encoding/json, of the YAML library, and of the schema library quote the input, so none of them is ever passed on.

Index

Constants

View Source
const UnsupportedVersion = "schema.unsupported_version"

UnsupportedVersion is the code of a document whose schema_version the schema does not accept. Check reports nothing else about such a document.

Variables

This section is empty.

Functions

func ReadFile

func ReadFile(path string) ([]byte, diag.List)

ReadFile reads the file at path, or says in a diagnostic why it cannot be read.

Types

type Document

type Document struct {
	// Value is nil, bool, string, json.Number, []any or map[string]any.
	Value any
	// contains filtered or unexported fields
}

Document is one input after it was read: the JSON value, and where each part of it stands in the text.

func DecodeJSON

func DecodeJSON(raw []byte) (*Document, diag.List)

DecodeJSON reads JSON text. The document is nil when nothing could be read.

func DecodeYAML

func DecodeYAML(raw []byte) (*Document, diag.List)

DecodeYAML reads YAML text that holds one document, and gives the JSON value it stands for. The document is nil when nothing could be read.

The YAML library only parses. What a value is, is decided here by the core schema of YAML 1.2, the reading that editors apply: a scalar in quotes or in block form is a text, and a plain scalar is null, a boolean, or a number when it has that form, and a text otherwise. So a date stays the text that was written. Aliases, tags, merge keys, and directives are not read.

func (*Document) Locate

func (d *Document) Locate(pointer string, key bool) diag.Location

Locate returns the location of the value at pointer, or of the member's key when key is true. Line and Column are 0 for a pointer the document lacks.

type Resource

type Resource struct {
	Name string // as the $ref names it, such as model.schema.json
	JSON []byte
}

Resource is a schema that the main schema refers to by a relative $ref.

type Schema

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

Schema is a compiled JSON Schema that reports problems as diagnostics.

func MustCompile

func MustCompile(schemaJSON []byte, others ...Resource) *Schema

MustCompile compiles schema bytes, with the schemas that they refer to. It panics on a broken schema, which is a defect of the build, and never loads anything but the bytes it was given.

func (*Schema) Check

func (s *Schema) Check(d *Document) diag.List

Check returns every place where the document departs from the schema. An incomplete document is not checked: the reader has reported what it left out, and the check would report the gap again, or work a huge number out.

Jump to

Keyboard shortcuts

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