jsonschema

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 30 Imported by: ? 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 jsonschema loads and compares authored Draft 2020-12 schema resources.

Draft 2020-12 is the only supported dialect. A $dynamicRef that needs dynamic scope resolution is an error. YAML input must be JSON-compatible, so anchors, aliases and non-string keys are errors too.

Index

Constants

View Source
const Dialect = "https://json-schema.org/draft/2020-12/schema"

Dialect is the supported JSON Schema dialect.

Variables

View Source
var ErrNotSchema = errors.New("expected a Draft 2020-12 JSON Schema declaration")

ErrNotSchema identifies an input without a supported standalone schema declaration.

Functions

func Compare

func Compare(left, right *Document, rules *wc.BreakingRulesConfig) (*wc.SchemaChanges, error)

Compare uses the schema comparator on authored constraints. Each referenced resource is compared once, independent of the number of references to it.

rules holds explicit overrides only. Each rule it contains replaces the verdict for that keyword in both directions, so merged defaults such as GenerateDefaultBreakingRules would mark a widening edit as breaking. Pass nil for the direction-aware defaults. A root replaced by a boolean, or the reverse, has no keyword and no override.

func MatchResources

func MatchResources(left, right *Document) map[*Resource]*Resource

MatchResources pairs the original and modified resources by resolved ID, then by source path and embedded pointer. A comparison of two single schemas always pairs their roots. Unmatched resources have no entry in the returned map.

func PropertyPath

func PropertyPath(path, key string) string

PropertyPath appends an object key to a JSONPath without changing its identity.

Types

type Document

type Document struct {
	Root       *Resource
	Resources  []*Resource
	Sources    map[string]*Source
	References []Reference
	Rolodex    *index.Rolodex
	// contains filtered or unexported fields
}

Document owns the resources and source locations for a comparison input.

func Load

func Load(data []byte, source string, config *datamodel.DocumentConfiguration, explicit bool) (*Document, error)

Load reads one root and all its referenced resources using the supplied source configuration. Explicit mode accepts unmarked object and boolean schemas.

func LoadCollection

func LoadCollection(members map[string][]byte, directory string, config *datamodel.DocumentConfiguration) (*Document, error)

LoadCollection registers all named schema sources before resolving references. Names are slash-separated paths relative to directory. An empty snapshot is valid. The returned document has a nil Root and one entry in Sources per physical file.

func (*Document) IsSchema

func (d *Document) IsSchema(node *yaml.Node) bool

IsSchema reports whether a node occupies a schema-bearing position in this input.

func (*Document) Release

func (d *Document) Release()

Release frees the indexes and drops references to the retained source buffers.

type MemberError

type MemberError struct {
	Name string
	Err  error
}

MemberError identifies the collection member that failed to load. Its text is the member's own diagnostic, which already names the file.

func (*MemberError) Error

func (e *MemberError) Error() string

func (*MemberError) Unwrap

func (e *MemberError) Unwrap() error

type Reference

type Reference struct {
	From, To *yaml.Node
	Value    string
	// Keyword identifies the authored $ref or $dynamicRef.
	Keyword string
	// contains filtered or unexported fields
}

Reference connects an authored reference site to a schema in this snapshot.

type Resource

type Resource struct {
	ID      string
	Pointer string
	Source  *Source
	Node    *yaml.Node
	// contains filtered or unexported fields
}

Resource is a root schema or an embedded schema with its own base URI.

func (*Resource) Label

func (r *Resource) Label() string

Label returns the authored title or a name derived from the resource.

type Source

type Source struct {
	Name  string
	Data  []byte
	Node  *yaml.Node
	Index *index.SpecIndex
	// contains filtered or unexported fields
}

Source holds the physical document once, even when several resources share it.

Jump to

Keyboard shortcuts

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