jsonschemax

package
v0.2.60 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MPL-2.0 Imports: 5 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 jsonschemax is the one place the chassis compiles a JSON Schema that came from a tenant: a rule's `WITH schema`, a capability's typed input, `txco://schema/check`. It pins the draft, bounds the size, and refuses every reference the schema cannot satisfy from itself.

The last point is the reason the package exists. santhosh-tekuri's compiler resolves an unknown `$ref` through a global loader registry whose `file` entry opens the path on this host, so an untrusted schema with `$ref: "file:///etc/hosts"` would read the chassis's disk. Compile sets the compiler's LoadURL to a function that refuses, so the only resource a schema can reach is itself.

Index

Constants

View Source
const MaxSchemaBytes = 256 << 10

MaxSchemaBytes bounds one schema. A tool's parameters or an answer schema is a few hundred bytes to a few kilobytes; a quarter megabyte is already far past anything a model should be handed.

Variables

View Source
var ErrEmpty = errors.New("empty schema")

ErrEmpty is returned for an empty schema.

View Source
var ErrRemoteRef = errors.New("a $ref to another document is refused")

ErrRemoteRef is wrapped by the error a compile returns when the schema refers to a document outside itself.

View Source
var ErrTooLarge = errors.New("schema is too large")

ErrTooLarge is wrapped by the error a compile returns for a schema past MaxSchemaBytes.

Functions

func Compile

func Compile(raw []byte) (*jsonschema.Schema, error)

Compile parses and compiles raw as a JSON Schema (draft 2020-12 when the schema names no `$schema`). Every `$ref` must point inside the schema itself: a reference to a file or a URL is refused with ErrRemoteRef.

Types

type Problem

type Problem struct {
	Path    string `json:"path"`
	Message string `json:"message"`
}

Problem is one place a value fails its schema: a JSON Pointer into the value ("" is the value itself) and the validator's sentence.

func Check

func Check(sch *jsonschema.Schema, value any) []Problem

Check validates value (a decoded JSON document) against sch and returns the leaf problems: the innermost failures, each with its own pointer, and not the wrapper nodes that only say a parent "doesn't validate". A nil result means the value is valid.

func Validate

func Validate(raw []byte, value any) (ok bool, problems []Problem, err error)

Validate compiles raw and checks value against it in one call. ok is false with the problems listed when the value fails; err is set only when the schema itself cannot be compiled.

Jump to

Keyboard shortcuts

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