jsonschema

package
v0.0.0-...-e8da5e4 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package jsonschema provides lossless JSON Schema Draft 7 values used by OpenRPC. It supports both object and boolean schemas without reflection.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrValidationPolicy reports invalid compilation or diagnostic bounds.
	ErrValidationPolicy = errors.New("jsonschema: invalid validation policy")
	// ErrSchemaCompile reports a schema that is not valid Draft 7 or contains
	// a reference absent from the explicit resource set.
	ErrSchemaCompile = errors.New("jsonschema: Draft 7 compilation failed")
	// ErrInvalidInstance reports an invalid zero instance value.
	ErrInvalidInstance = errors.New("jsonschema: invalid instance")
	// ErrValidationResourceLimit reports that bounded validation could not
	// complete without exceeding its configured work limit.
	ErrValidationResourceLimit = errors.New("jsonschema: validation resource limit exceeded")
)
View Source
var ErrInvalidSchema = errors.New("jsonschema: schema must be an object or boolean")

ErrInvalidSchema reports a valid JSON value that is neither an object nor a boolean and therefore cannot be a Draft 7 schema.

Functions

This section is empty.

Types

type Issue

type Issue struct {
	InstancePointer string
	SchemaPointer   string
	Keyword         string
	Message         string
}

Issue is one safe validation failure. Messages contain no instance value.

type Report

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

Report is one immutable bounded validation result.

func (Report) Err

func (report Report) Err() error

Err reports cancellation, invalid policy, or an invalid instance.

func (Report) Issues

func (report Report) Issues() []Issue

Issues returns an owned diagnostic snapshot.

func (Report) Truncated

func (report Report) Truncated() bool

Truncated reports that more failures existed than the configured bound.

func (Report) Valid

func (report Report) Valid() bool

Valid reports successful validation and no execution error.

type Schema

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

Schema is an immutable object or boolean JSON Schema value.

func FromValue

func FromValue(value jsonvalue.Value) (Schema, error)

FromValue classifies an already validated JSON value as a Draft 7 schema.

func Parse

func Parse(input []byte, policy jsonvalue.Policy) (Schema, error)

Parse validates and preserves an object or boolean JSON Schema value under policy. Keyword and reference semantics are validated separately.

func (Schema) Boolean

func (schema Schema) Boolean() (bool, bool)

Boolean returns the schema value and true for a boolean schema. The second result is false for an object schema.

func (Schema) Bytes

func (schema Schema) Bytes() []byte

Bytes returns an owned copy of the exact schema JSON.

func (Schema) MarshalJSON

func (schema Schema) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Schema) Value

func (schema Schema) Value() jsonvalue.Value

Value returns the immutable generic JSON representation.

type ValidationOptions

type ValidationOptions struct {
	BaseURI        string
	Resources      map[string]Schema
	MaxResources   int
	MaxSchemaBytes int
	MaxIssues      int
	RegexpTimeout  time.Duration
}

ValidationOptions configures Draft 7 compilation and bounded reporting. Resources are the only external schemas available during compilation; no filesystem or network loader is installed.

func DefaultValidationOptions

func DefaultValidationOptions() ValidationOptions

DefaultValidationOptions returns strict Draft 7 compilation with finite diagnostic output and no external resources.

type Validator

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

Validator is an immutable compiled Draft 7 schema safe for concurrent use.

func Compile

func Compile(schema Schema, options ValidationOptions) (Validator, error)

Compile compiles one Draft 7 schema using only explicitly supplied resources. It never performs network or filesystem access.

func (Validator) Validate

func (compiled Validator) Validate(ctx context.Context, instance jsonvalue.Value) Report

Validate checks one immutable JSON value and converts dependency diagnostics into stable, payload-free package-owned issues.

func (Validator) WithMaxIssues

func (compiled Validator) WithMaxIssues(maxIssues int) (Validator, error)

WithMaxIssues returns a validator sharing the immutable compiled schema with a replacement diagnostic bound.

Jump to

Keyboard shortcuts

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