jsonschema

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package jsonschema adapts immutable contract-catalog JSON assets to the JSON Schema validator without exposing the JSON Schema library to domain code.

Index

Constants

View Source
const MaxInputBytes = 8 << 20

MaxInputBytes is the maximum size of one JSON instance accepted by Validate. The finite 8 MiB limit bounds decoding and schema-validation memory use.

Variables

This section is empty.

Functions

func ReadinessAuthority

func ReadinessAuthority(schemaID ports.AssetID) bool

ReadinessAuthority reports whether schemaID is an authoritative readiness contract. Only the provider and platform v1 evidence schemas are authority.

Types

type Diagnostic

type Diagnostic struct {
	Stage    Stage
	Path     string
	SchemaID ports.AssetID
}

Diagnostic is a redacted, typed failure produced at the JSON Schema adapter boundary. Path is a JSON Pointer-like location. It deliberately retains no implementation cause, so validation input cannot escape through error chains.

func (*Diagnostic) DocumentViolation

func (diagnostic *Diagnostic) DocumentViolation() bool

DocumentViolation reports whether this diagnostic was caused by provider document bytes rather than validator configuration or runtime state.

func (*Diagnostic) Error

func (diagnostic *Diagnostic) Error() string

Error implements error without rendering untrusted input or the underlying error text, which may be more detailed than this boundary should expose.

type Stage

type Stage string

Stage identifies the adapter boundary at which processing failed.

const (
	StageCatalog    Stage = "catalog"
	StageCompile    Stage = "compile"
	StageContext    Stage = "context"
	StageDecode     Stage = "decode"
	StageSchema     Stage = "schema"
	StageRuntime    Stage = "runtime"
	StageValidation Stage = "validation"
)

type Validator

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

Validator is an immutable, compiled set of catalog JSON schemas and copied JSON examples. It does not retain caller-provided validation bytes.

func New

func New(ctx context.Context, catalog ports.ContractCatalog) (*Validator, error)

New loads, verifies, and compiles every schema in catalog. Compilation is fail-closed: schemas must be draft 2020-12 resources whose JSON $id exactly matches the catalog AssetID, references must be local fragments, and the compiler's loader always denies external resources.

func (*Validator) Validate

func (validator *Validator) Validate(ctx context.Context, schemaID ports.AssetID, raw []byte) (result error)

Validate strictly decodes raw as exactly one JSON value before applying the compiled schema identified by schemaID.

func (*Validator) ValidatePair

func (validator *Validator) ValidatePair(ctx context.Context, schemaID, exampleID ports.AssetID) error

ValidatePair validates the one catalog example paired with schemaID by the embedded file catalog. Both IDs must name the compiled schema and copied JSON example captured when the validator was constructed.

Jump to

Keyboard shortcuts

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