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): Enablesstd::error::Errorimpls, tracing, andstd-only features offoundation_errstacks.fancy-regex: Enables ECMA-262 compatible regex viafancy-regexfor thepatternkeyword.
§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
formatkeyword. Built-in format checkers for theformatkeyword. - 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§
- InMemory
Fetcher - An in-memory resolver pre-loaded with JSON Schema meta-schemas.
- Json
Type Set - Compact bitset holding a set of
JsonTypevalues. - Lazy
Location - 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.
- Resolve
Error - Context type for resolution failures.
- Validation
Context - Mutable state for a single validation run.
- Validation
Error Builder - Builder for creating validation errors with path attachments.
- Validation
Failure - A validation error bundled with instance and schema paths.
- Validation
Options - Builder for configuring schema compilation and validation behavior.
- Validator
- A compiled JSON Schema validator.
Enums§
- Draft
- JSON Schema specification version.
- Json
Type - The 7 primitive types defined by JSON Schema.
- Location
Segment - A segment in a JSON path — either a property name or array index.
- Validation
Error Kind - Categorization of all possible validation failures.
Traits§
- Json
Resolver - Pluggable external schema resolution.
- Json
Schema - Generate a standard JSON Schema representation for a Rust type.
- Keyword
Factory - 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
ValidationFailurefrom aValidationError. - 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§
- Boxed
Validator - Type alias for a heap-allocated validator.
- Error
Iterator - Lazy iterator over validation errors.
- Validation
Error - Type alias for validation errors — full
foundation_errstacksAPI.