1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
//! 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
//!
//! ```ignore
//! 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:
//!
//! ```ignore
//! 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();
//! ```
extern crate alloc;
extern crate std;
// ── Schema Generation ──────────────────────────────────────────────
pub use JsonSchema;
// ── Core Types (Feature 0) ──────────────────────────────────────────
// ── Error Reporting (Feature 5) ─────────────────────────────────────
// ── Referencing Engine (Feature 1) ──────────────────────────────────
// ── Keywords & Validators (Feature 2) ───────────────────────────────
// ── Format Validation (Feature 7) ──────────────────────────────────
/// Built-in format checkers for the `format` keyword.
// ── Compiler (Feature 3) ────────────────────────────────────────────
// ── Validation Engine (Feature 4) ───────────────────────────────────
/// Evaluation output — structured validation results (planned API).
///
/// This module provides the types for the three JSON Schema output formats:
/// flag, list, and hierarchical. These types represent the structured result
/// of evaluating a JSON instance against a compiled schema.
///
/// # Planned Usage
///
/// In a future release, the `Validator` will produce an `Evaluation` tree
/// that can be queried via `to_list()` or `to_hierarchical()` for detailed
/// reporting, or via `valid()` for the simple boolean flag output.
// ── In-Memory Fetcher (Meta-schema bundle) ───────────────────────────
// ── Schema Builder (Feature 12) ─────────────────────────────────
// ── Meta-Schema Validation ───────────────────────────────────────────
// ── Public API ──────────────────────────────────────────────────────
pub use Draft;
pub use ;
pub use KeywordFactory;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Validator;
pub use InMemoryFetcher;
pub use ValidationOptions;
// Re-export meta-schema validation
pub use ;
pub use ;
pub use ;
/// Validate an instance against a schema (boolean result).
///
/// WHY: Convenience function for the common case where you only need
/// to know if an instance is valid, without error details.
///
/// WHAT: Returns `true` if the instance validates against the schema.
///
/// HOW: Compiles the schema with default options, then checks validity.
/// For custom resolvers or draft selection, use `ValidationOptions`.
///
/// # Errors
///
/// Returns an error if schema compilation fails (e.g., invalid schema structure).
/// Validate an instance against a schema, returning the first error.
///
/// WHY: Convenience function for the common case where you need the first
/// validation error but don't care about collecting all errors.
///
/// WHAT: Returns `Ok(())` if valid, or `Err` with the first validation failure.
///
/// HOW: Compiles the schema with default options, then validates.
///
/// # Errors
///
/// Returns a compilation error if the schema is invalid, or a validation error
/// if the instance fails validation.
/// Compile a JSON Schema into a reusable validator.
///
/// WHY: The most common entry point for schema validation. Compiles the schema
/// with default options (`NoopResolver`, draft auto-detection).
///
/// WHAT: Returns a `Validator` that can validate many instances against the schema.
///
/// HOW: Delegates to `ValidationOptions::new().build()`.
///
/// # Errors
///
/// Returns an error if the schema cannot be compiled (invalid structure,
/// unresolvable references, etc.).
// Draft-specific convenience modules
/// Draft 4 validation convenience functions.
/// Draft 6 validation convenience functions.
/// Draft 7 validation convenience functions.
/// Draft 2019-09 validation convenience functions.
/// Draft 2020-12 validation convenience functions.