Skip to main content

Crate foundation_jsonschema

Crate foundation_jsonschema 

Source
Expand description

Self-contained JSON Schema validation for ewe_platform.

Validates JSON instances against JSON Schema documents supporting Draft 4, Draft 6, Draft 7, Draft 2019-09, and Draft 2020-12.

§Overview

WHY: The ewe_platform needs a JSON Schema validator that works in std and no_std + alloc environments without pulling in network dependencies like reqwest, tokio, or wasm-bindgen. External reference resolution is handled via a pluggable JsonResolver trait.

WHAT: A compile-once, validate-many JSON Schema validator with structured error reporting and evaluation output.

HOW: Schemas are compiled into an immutable validator tree (SchemaNode). Instances are validated against the compiled tree. Validation errors carry full context (instance path, schema path, error category) via foundation_errstacks.

§Features

  • std (default): Enables std::error::Error impls, tracing, and std-only features of foundation_errstacks.
  • fancy-regex: Enables ECMA-262 compatible regex via fancy-regex for the pattern keyword.

§Quick Start

use foundation_jsonschema::{validator_for, Draft};
use serde_json::json;

let schema = json!({"type": "object", "properties": {"name": {"type": "string"}}});
let validator = validator_for(&schema).unwrap();

assert!(validator.is_valid(&json!({"name": "Alice"})));
assert!(!validator.is_valid(&json!({"name": 42})));

§External References

By default, external $ref URIs are rejected. Provide a custom resolver:

use foundation_jsonschema::ValidationOptions;
use serde_json::json;

let schema = json!({"$ref": "https://example.com/types.json"});
let resolver = MyResolver::new(); // implement JsonResolver
let validator = ValidationOptions::new()
    .with_resolver(resolver)
    .build(&schema)
    .unwrap();

Modules§

draft4
Draft 4 validation convenience functions.
draft6
Draft 6 validation convenience functions.
draft7
Draft 7 validation convenience functions.
draft201909
Draft 2019-09 validation convenience functions.
draft202012
Draft 2020-12 validation convenience functions.
evaluation
Evaluation output — structured validation results (planned API).
formats
Built-in format checkers for the format keyword. Built-in format checkers for the format keyword.
meta_draft4
Meta-schema validation for Draft 4.
meta_draft6
Meta-schema validation for Draft 6.
meta_draft7
Meta-schema validation for Draft 7.
meta_draft201909
Meta-schema validation for Draft 2019-09.
meta_draft202012
Meta-schema validation for Draft 2020-12.
referencing
Referencing engine for URI resolution, registry, and JSON Pointer traversal.
scheme
scheme — Fluent, type-safe JSON Schema builder.

Structs§

InMemoryFetcher
An in-memory resolver pre-loaded with JSON Schema meta-schemas.
JsonTypeSet
Compact bitset holding a set of JsonType values.
LazyLocation
Lazy path construction — defers allocation until materialized.
Location
A materialized JSON Pointer path (e.g., “/foo/bar/0”).
MapResolver
A resolver backed by a pre-loaded map of URI → schema document.
ResolveError
Context type for resolution failures.
ValidationContext
Mutable state for a single validation run.
ValidationErrorBuilder
Builder for creating validation errors with path attachments.
ValidationFailure
A validation error bundled with instance and schema paths.
ValidationOptions
Builder for configuring schema compilation and validation behavior.
Validator
A compiled JSON Schema validator.

Enums§

Draft
JSON Schema specification version.
JsonType
The 7 primitive types defined by JSON Schema.
LocationSegment
A segment in a JSON path — either a property name or array index.
ValidationErrorKind
Categorization of all possible validation failures.

Traits§

JsonResolver
Pluggable external schema resolution.
JsonSchema
Generate a standard JSON Schema representation for a Rust type.
KeywordFactory
Factory trait for creating custom keyword validators.
Validate
The core validation trait implemented by all keyword validators.

Functions§

is_schema_valid
Check if a schema conforms to its meta-schema (boolean result).
is_valid
Validate an instance against a schema (boolean result).
to_failure
Build a ValidationFailure from a ValidationError.
validate
Validate an instance against a schema, returning the first error.
validate_schema
Validate a schema against its meta-schema (auto-detect draft from $schema).
validator_for
Compile a JSON Schema into a reusable validator.

Type Aliases§

BoxedValidator
Type alias for a heap-allocated validator.
ErrorIterator
Lazy iterator over validation errors.
ValidationError
Type alias for validation errors — full foundation_errstacks API.