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 ¶
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 ¶
var ErrEmpty = errors.New("empty schema")
ErrEmpty is returned for an empty schema.
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.
var ErrTooLarge = errors.New("schema is too large")
ErrTooLarge is wrapped by the error a compile returns for a schema past MaxSchemaBytes.
Functions ¶
Types ¶
type Problem ¶
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.