Index: jsonschema/Cargo.toml =================================================================== --- jsonschema.orig/Cargo.toml 2026-06-14 18:53:15.107529614 -0400 +++ jsonschema/Cargo.toml 2026-06-14 18:53:15.104078243 -0400 @@ -54,14 +54,6 @@ path = "src/lib.rs" [[test]] -name = "output_suite" -path = "tests/output_suite.rs" - -[[test]] -name = "suite" -path = "tests/suite.rs" - -[[test]] name = "wasm" path = "tests/wasm.rs" @@ -69,35 +61,35 @@ name = "wasm_wasi" path = "tests/wasm_wasi.rs" -[[bench]] -name = "errors" -path = "benches/errors.rs" -harness = false - -[[bench]] -name = "jsonschema" -path = "benches/jsonschema.rs" -harness = false - -[[bench]] -name = "keywords" -path = "benches/keywords.rs" -harness = false - -[[bench]] -name = "location" -path = "benches/location.rs" -harness = false - -[[bench]] -name = "unevaluated_items" -path = "benches/unevaluated_items.rs" -harness = false - -[[bench]] -name = "unevaluated_properties" -path = "benches/unevaluated_properties.rs" -harness = false +#[[bench]] +#name = "errors" +#path = "benches/errors.rs" +#harness = false + +#[[bench]] +#name = "jsonschema" +#path = "benches/jsonschema.rs" +#harness = false + +#[[bench]] +#name = "keywords" +#path = "benches/keywords.rs" +#harness = false + +#[[bench]] +#name = "location" +#path = "benches/location.rs" +#harness = false + +#[[bench]] +#name = "unevaluated_items" +#path = "benches/unevaluated_items.rs" +#harness = false + +#[[bench]] +#name = "unevaluated_properties" +#path = "benches/unevaluated_properties.rs" +#harness = false [dependencies.ahash] version = "0.8" @@ -118,7 +110,7 @@ version = "0.2.9" [dependencies.fancy-regex] -version = "0.16" +version = "0.11" [dependencies.fraction] version = "0.15" @@ -180,7 +172,7 @@ version = "3" [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies.wasm-bindgen-test] -version = "0.3.55" +version = "0.3" [target.'cfg(not(target_arch = "wasm32"))'.dependencies.reqwest] version = "0.12" @@ -199,13 +191,13 @@ ] optional = true -[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.codspeed-criterion-compat] -version = "4.1" -default-features = false - -[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.criterion] -version = "0.7" -default-features = false +#[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.codspeed-criterion-compat] +#version = "4.1" +#default-features = false + +#[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.criterion] +#version = "0.7" +#default-features = false [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.tempfile] version = "3.13.0" @@ -220,9 +212,9 @@ "rt", ] -[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom] -version = "0.3.4" -features = ["wasm_js"] +#[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom] +#version = "0.2" +#features = ["wasm_js"] [target.'cfg(target_arch = "wasm32")'.dependencies.reqwest] version = "0.12" Index: jsonschema/benches/errors.rs =================================================================== --- jsonschema.orig/benches/errors.rs 2026-06-14 18:53:15.107529614 -0400 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,36 +0,0 @@ -#[cfg(not(target_arch = "wasm32"))] -mod bench { - pub(crate) use benchmark::run_error_formatting_benchmarks; - pub(crate) use criterion::{criterion_group, BenchmarkId, Criterion}; - pub(crate) use serde_json::Value; - - pub(crate) fn bench_error_formatting( - c: &mut Criterion, - name: &str, - schema: &Value, - instance: &Value, - ) { - let validator = jsonschema::validator_for(schema).expect("Valid schema"); - let error = validator.validate(instance).unwrap_err(); - - c.bench_with_input( - BenchmarkId::new("error_formatting", name), - &error, - |b, error| b.iter_with_large_drop(|| error.to_string()), - ); - } - - pub(crate) fn run_benchmarks(c: &mut Criterion) { - run_error_formatting_benchmarks(&mut |name, schema, instance| { - bench_error_formatting(c, name, schema, instance); - }); - } - - criterion_group!(error_formatting, run_benchmarks); -} - -#[cfg(not(target_arch = "wasm32"))] -criterion::criterion_main!(bench::error_formatting); - -#[cfg(target_arch = "wasm32")] -fn main() {} Index: jsonschema/benches/jsonschema.rs =================================================================== --- jsonschema.orig/benches/jsonschema.rs 2026-06-14 18:53:15.107529614 -0400 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,69 +0,0 @@ -#[cfg(not(target_arch = "wasm32"))] -mod bench { - use std::hint::black_box; - - pub(crate) use benchmark::Benchmark; - pub(crate) use codspeed_criterion_compat::{criterion_group, BenchmarkId, Criterion}; - pub(crate) use serde_json::Value; - - pub(crate) fn bench_build(c: &mut Criterion, name: &str, schema: &Value) { - c.bench_with_input(BenchmarkId::new("build", name), schema, |b, schema| { - b.iter_with_large_drop(|| jsonschema::validator_for(schema).expect("Valid schema")); - }); - } - - pub(crate) fn bench_is_valid(c: &mut Criterion, name: &str, schema: &Value, instance: &Value) { - let validator = jsonschema::validator_for(schema).expect("Valid schema"); - c.bench_with_input( - BenchmarkId::new("is_valid", name), - instance, - |b, instance| { - b.iter(|| black_box(validator.is_valid(instance))); - }, - ); - } - - pub(crate) fn bench_validate(c: &mut Criterion, name: &str, schema: &Value, instance: &Value) { - let validator = jsonschema::validator_for(schema).expect("Valid schema"); - c.bench_with_input( - BenchmarkId::new("validate", name), - instance, - |b, instance| { - b.iter(|| black_box(validator.validate(instance))); - }, - ); - } - - pub(crate) fn bench_evaluate(c: &mut Criterion, name: &str, schema: &Value, instance: &Value) { - let validator = jsonschema::validator_for(schema).expect("Valid schema"); - c.bench_with_input( - BenchmarkId::new("evaluate", name), - instance, - |b, instance| { - b.iter_with_large_drop(|| black_box(validator.evaluate(instance))); - }, - ); - } - - pub(crate) fn run_benchmarks(c: &mut Criterion) { - for benchmark in Benchmark::iter() { - benchmark.run(&mut |name, schema, instances| { - bench_build(c, name, schema); - for instance in instances { - let name = format!("{}/{}", name, instance.name); - bench_is_valid(c, &name, schema, &instance.data); - bench_validate(c, &name, schema, &instance.data); - bench_evaluate(c, &name, schema, &instance.data); - } - }); - } - } - - criterion_group!(jsonschema, run_benchmarks); -} - -#[cfg(not(target_arch = "wasm32"))] -codspeed_criterion_compat::criterion_main!(bench::jsonschema); - -#[cfg(target_arch = "wasm32")] -fn main() {} Index: jsonschema/benches/keywords.rs =================================================================== --- jsonschema.orig/benches/keywords.rs 2026-06-14 18:53:15.107529614 -0400 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,74 +0,0 @@ -#[cfg(not(target_arch = "wasm32"))] -mod bench { - pub(crate) use benchmark::run_keyword_benchmarks; - pub(crate) use criterion::{criterion_group, BenchmarkId, Criterion}; - pub(crate) use serde_json::Value; - - pub(crate) fn validator_for(schema: &Value) -> jsonschema::Validator { - jsonschema::options() - .with_draft(jsonschema::Draft::Draft7) - .build(schema) - .expect("Schema used in benchmarks should compile") - } - - pub(crate) fn bench_keyword_build(c: &mut Criterion, name: &str, schema: &Value) { - c.bench_function(&format!("keyword/{name}/build"), |b| { - b.iter_with_large_drop(|| validator_for(schema)); - }); - } - - pub(crate) fn bench_keyword_is_valid( - c: &mut Criterion, - name: &str, - schema: &Value, - instance: &Value, - ) { - let validator = validator_for(schema); - c.bench_with_input( - BenchmarkId::new(format!("keyword/{name}"), "is_valid"), - instance, - |b, instance| { - b.iter(|| { - let _ = validator.is_valid(instance); - }); - }, - ); - } - - pub(crate) fn bench_keyword_validate( - c: &mut Criterion, - name: &str, - schema: &Value, - instance: &Value, - ) { - let validator = validator_for(schema); - c.bench_with_input( - BenchmarkId::new(format!("keyword/{name}"), "validate"), - instance, - |b, instance| { - b.iter(|| { - let _ = validator.validate(instance); - }); - }, - ); - } - - pub(crate) fn run_benchmarks(c: &mut Criterion) { - run_keyword_benchmarks(&mut |name, schema, instances| { - bench_keyword_build(c, name, schema); - for instance in instances { - let name = format!("jsonschema/{}/{}", name, instance.name); - bench_keyword_is_valid(c, &name, schema, &instance.data); - bench_keyword_validate(c, &name, schema, &instance.data); - } - }); - } - - criterion_group!(keywords, run_benchmarks); -} - -#[cfg(not(target_arch = "wasm32"))] -criterion::criterion_main!(bench::keywords); - -#[cfg(target_arch = "wasm32")] -fn main() {} Index: jsonschema/benches/location.rs =================================================================== --- jsonschema.orig/benches/location.rs 2026-06-14 18:53:15.107529614 -0400 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ -#[cfg(not(target_arch = "wasm32"))] -mod bench { - pub(crate) use criterion::{criterion_group, BenchmarkId, Criterion}; - pub(crate) use jsonschema::paths::{Location, LocationSegment}; - pub(crate) use std::hint::black_box; - - pub(crate) fn benchmark_into_iterator(c: &mut Criterion) { - let empty = Location::new(); - let small = vec!["a", "b", "c"] - .into_iter() - .map(LocationSegment::from) - .chain((0..3).map(LocationSegment::from)) - .collect::(); - let large = (0..500) - .map(|_| LocationSegment::from("abc")) - .chain((0..500).map(LocationSegment::from)) - .collect::(); - - for (parameter, input) in [("empty", empty), ("small", small), ("large", large)] { - c.bench_with_input( - BenchmarkId::new("IntoIterator", parameter), - &input, - |b, i| b.iter_with_large_drop(|| black_box(i).into_iter().collect::>()), - ); - } - } - - pub(crate) fn benchmark_from_iterator(c: &mut Criterion) { - let empty = vec![]; - let small = vec![ - LocationSegment::from("a"), - LocationSegment::from("b"), - LocationSegment::from("c"), - ]; - let large = (0..1000) - .map(|_| LocationSegment::from("abc")) - .collect::>(); - - for (parameter, input) in [("empty", empty), ("small", small), ("large", large)] { - c.bench_with_input( - BenchmarkId::new("FromIterator", parameter), - &input, - |b, i| { - b.iter_batched( - || i.clone().into_iter(), - |i| black_box(i).collect::(), - criterion::BatchSize::SmallInput, - ); - }, - ); - } - } - - criterion_group!(benches, benchmark_into_iterator, benchmark_from_iterator); -} - -#[cfg(not(target_arch = "wasm32"))] -criterion::criterion_main!(bench::benches); - -#[cfg(target_arch = "wasm32")] -fn main() {} Index: jsonschema/benches/unevaluated_items.rs =================================================================== --- jsonschema.orig/benches/unevaluated_items.rs 2026-06-14 18:53:15.107529614 -0400 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,182 +0,0 @@ -#[cfg(not(target_arch = "wasm32"))] -mod bench { - use codspeed_criterion_compat::{criterion_group, BenchmarkId, Criterion}; - use serde_json::{json, Value}; - use std::hint::black_box; - - fn large_schema() -> Value { - json!({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "array", - "prefixItems": [ - {"type": "string"}, - {"type": "number"}, - {"type": "boolean"} - ], - "contains": { - "type": "object", - "properties": { - "special": {"type": "boolean"} - } - }, - "allOf": [ - { - "if": { - "contains": {"const": "trigger"} - }, - "then": { - "prefixItems": [ - {"type": "string"}, - {"type": "number"}, - {"type": "boolean"}, - {"type": "string"} - ] - }, - "else": { - "prefixItems": [ - {"type": "string"}, - {"type": "number"}, - {"type": "boolean"}, - {"type": "number"} - ] - } - } - ], - "anyOf": [ - { - "contains": {"type": "string"} - }, - { - "contains": {"type": "number"} - } - ], - "oneOf": [ - { - "prefixItems": [ - {"type": "string"}, - {"type": "number"}, - {"type": "boolean"}, - {"type": "string"}, - {"type": "array"} - ] - }, - { - "prefixItems": [ - {"type": "string"}, - {"type": "number"}, - {"type": "boolean"}, - {"type": "number"}, - {"type": "object"} - ] - } - ], - "unevaluatedItems": false - }) - } - - fn large_invalid_instance() -> Value { - json!([ - "string", - 42, - true, - 123, - {"special": true}, - "unexpected" // This should trigger unevaluatedItems: false - ]) - } - - fn bench_build(c: &mut Criterion, name: &str, schema: &Value) { - c.bench_with_input(BenchmarkId::new("build", name), schema, |b, schema| { - b.iter_with_large_drop(|| jsonschema::draft202012::new(schema).unwrap()); - }); - } - - fn bench_is_valid( - c: &mut Criterion, - name: &str, - validator: &jsonschema::Validator, - instance: &Value, - ) { - c.bench_with_input( - BenchmarkId::new("is_valid", name), - instance, - |b, instance| { - b.iter(|| { - black_box(validator.is_valid(instance)); - }); - }, - ); - } - - fn bench_validate( - c: &mut Criterion, - name: &str, - validator: &jsonschema::Validator, - instance: &Value, - ) { - c.bench_with_input( - BenchmarkId::new("validate", name), - instance, - |b, instance| { - b.iter(|| { - let _ = black_box(validator.validate(instance)); - }); - }, - ); - } - - fn bench_evaluate( - c: &mut Criterion, - name: &str, - validator: &jsonschema::Validator, - instance: &Value, - ) { - c.bench_with_input( - BenchmarkId::new("evaluate", name), - instance, - |b, instance| { - b.iter_with_large_drop(|| black_box(validator.evaluate(instance))); - }, - ); - } - - fn bench_iter_errors( - c: &mut Criterion, - name: &str, - validator: &jsonschema::Validator, - instance: &Value, - ) { - c.bench_with_input( - BenchmarkId::new("iter_errors", name), - instance, - |b, instance| { - b.iter(|| { - for error in validator.iter_errors(instance) { - black_box(error); - } - }); - }, - ); - } - - fn run_benchmarks(c: &mut Criterion) { - let large = large_schema(); - bench_build(c, "unevaluated_items", &large); - - let validator = jsonschema::draft202012::new(&large).unwrap(); - let invalid = large_invalid_instance(); - - bench_is_valid(c, "unevaluated_items", &validator, &invalid); - bench_validate(c, "unevaluated_items", &validator, &invalid); - bench_evaluate(c, "unevaluated_items", &validator, &invalid); - bench_iter_errors(c, "unevaluated_items", &validator, &invalid); - } - - criterion_group!(benches, run_benchmarks); -} - -#[cfg(not(target_arch = "wasm32"))] -codspeed_criterion_compat::criterion_main!(bench::benches); - -#[cfg(target_arch = "wasm32")] -fn main() {} Index: jsonschema/benches/unevaluated_properties.rs =================================================================== --- jsonschema.orig/benches/unevaluated_properties.rs 2026-06-14 18:53:15.107529614 -0400 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,166 +0,0 @@ -#[cfg(not(target_arch = "wasm32"))] -mod bench { - use codspeed_criterion_compat::{criterion_group, BenchmarkId, Criterion}; - use serde_json::{json, Value}; - use std::hint::black_box; - - fn large_schema() -> Value { - let mut properties = serde_json::Map::new(); - for i in 0..50 { - properties.insert(format!("prop{i}"), json!({"type": "string"})); - } - - json!({ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "type": "object", - "properties": properties, - "patternProperties": { - "^meta_": {"type": "string"} - }, - "allOf": [ - { - "if": { - "properties": { - "type": {"const": "user"} - } - }, - "then": { - "properties": { - "email": {"type": "string", "format": "email"}, - "age": {"type": "integer", "minimum": 0} - } - }, - "else": { - "properties": { - "organization": {"type": "string"} - } - } - } - ], - "anyOf": [ - { - "properties": { - "status": {"enum": ["active", "inactive"]} - } - }, - { - "properties": { - "archived": {"type": "boolean"} - } - } - ], - "dependentSchemas": { - "credit_card": { - "properties": { - "billing_address": {"type": "string"} - } - } - }, - "unevaluatedProperties": false - }) - } - - fn large_invalid_instance() -> Value { - let mut obj = serde_json::Map::new(); - for i in 0..50 { - obj.insert(format!("prop{i}"), json!("value")); - } - obj.insert("unexpected".to_string(), json!("property")); - Value::Object(obj) - } - - fn bench_build(c: &mut Criterion, name: &str, schema: &Value) { - c.bench_with_input(BenchmarkId::new("build", name), schema, |b, schema| { - b.iter_with_large_drop(|| jsonschema::draft202012::new(schema).unwrap()); - }); - } - - fn bench_is_valid( - c: &mut Criterion, - name: &str, - validator: &jsonschema::Validator, - instance: &Value, - ) { - c.bench_with_input( - BenchmarkId::new("is_valid", name), - instance, - |b, instance| { - b.iter(|| { - black_box(validator.is_valid(instance)); - }); - }, - ); - } - - fn bench_validate( - c: &mut Criterion, - name: &str, - validator: &jsonschema::Validator, - instance: &Value, - ) { - c.bench_with_input( - BenchmarkId::new("validate", name), - instance, - |b, instance| { - b.iter(|| { - let _ = black_box(validator.validate(instance)); - }); - }, - ); - } - - fn bench_evaluate( - c: &mut Criterion, - name: &str, - validator: &jsonschema::Validator, - instance: &Value, - ) { - c.bench_with_input( - BenchmarkId::new("evaluate", name), - instance, - |b, instance| { - b.iter_with_large_drop(|| black_box(validator.evaluate(instance))); - }, - ); - } - - fn bench_iter_errors( - c: &mut Criterion, - name: &str, - validator: &jsonschema::Validator, - instance: &Value, - ) { - c.bench_with_input( - BenchmarkId::new("iter_errors", name), - instance, - |b, instance| { - b.iter(|| { - for error in validator.iter_errors(instance) { - black_box(error); - } - }); - }, - ); - } - - fn run_benchmarks(c: &mut Criterion) { - let large = large_schema(); - bench_build(c, "unevaluated_properties", &large); - - let validator = jsonschema::draft202012::new(&large).unwrap(); - let invalid = large_invalid_instance(); - - bench_is_valid(c, "unevaluated_properties", &validator, &invalid); - bench_validate(c, "unevaluated_properties", &validator, &invalid); - bench_evaluate(c, "unevaluated_properties", &validator, &invalid); - bench_iter_errors(c, "unevaluated_properties", &validator, &invalid); - } - - criterion_group!(benches, run_benchmarks); -} - -#[cfg(not(target_arch = "wasm32"))] -codspeed_criterion_compat::criterion_main!(bench::benches); - -#[cfg(target_arch = "wasm32")] -fn main() {} Index: jsonschema/src/validator.rs =================================================================== --- jsonschema.orig/src/validator.rs 2026-06-14 18:53:15.107529614 -0400 +++ jsonschema/src/validator.rs 2026-06-14 18:53:15.104554355 -0400 @@ -335,17 +335,17 @@ use serde_json::{json, Map, Value}; use std::sync::LazyLock; - #[cfg(not(target_arch = "wasm32"))] - fn load(path: &str, idx: usize) -> Value { - use std::{fs::File, io::Read, path::Path}; - let path = Path::new(path); - let mut file = File::open(path).unwrap(); - let mut content = String::new(); - file.read_to_string(&mut content).ok().unwrap(); - let data: Value = serde_json::from_str(&content).unwrap(); - let case = &data.as_array().unwrap()[idx]; - case.get("schema").unwrap().clone() - } + //disabled, file missing #[cfg(not(target_arch = "wasm32"))] + //fn load(path: &str, idx: usize) -> Value { + // use std::{fs::File, io::Read, path::Path}; + // let path = Path::new(path); + // let mut file = File::open(path).unwrap(); + // let mut content = String::new(); + // file.read_to_string(&mut content).ok().unwrap(); + // let data: Value = serde_json::from_str(&content).unwrap(); + // let case = &data.as_array().unwrap()[idx]; + // case.get("schema").unwrap().clone() + //} #[test] fn only_keyword() { @@ -360,16 +360,16 @@ assert!(validator.validate(&value2).is_err()); } - #[test] - #[cfg(not(target_arch = "wasm32"))] - fn validate_ref() { - let schema = load("tests/suite/tests/draft7/ref.json", 1); - let value = json!({"bar": 3}); - let validator = crate::validator_for(&schema).unwrap(); - assert!(validator.validate(&value).is_ok()); - let value = json!({"bar": true}); - assert!(validator.validate(&value).is_err()); - } + //disabled, file missing #[test] + //#[cfg(not(target_arch = "wasm32"))] + //fn validate_ref() { + // let schema = load("tests/suite/tests/draft7/ref.json", 1); + // let value = json!({"bar": 3}); + // let validator = crate::validator_for(&schema).unwrap(); + // assert!(validator.validate(&value).is_ok()); + // let value = json!({"bar": true}); + // assert!(validator.validate(&value).is_err()); + //} #[test] fn wrong_schema_type() { Index: jsonschema/tests/output_suite.rs =================================================================== --- jsonschema.orig/tests/output_suite.rs 2026-06-14 18:53:15.107529614 -0400 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,181 +0,0 @@ -#![cfg(not(target_arch = "wasm32"))] - -use jsonschema::{validator_for, Draft, Evaluation, Retrieve, Uri, Validator}; -use serde_json::Value; -use std::sync::OnceLock; -use testsuite::{output_suite, OutputRemote, OutputTest}; - -#[output_suite( - path = "crates/jsonschema/tests/suite/output-tests", - drafts = [ - "v1" - ] -)] -fn output_suite(test: OutputTest) { - run_output_case(test); -} - -#[output_suite( - path = "crates/jsonschema/tests/output-extra", - drafts = [ - "v1-extra" - ] -)] -fn output_suite_extra(test: OutputTest) { - run_output_case(test); -} - -#[allow(clippy::print_stderr)] -fn run_output_case(test: OutputTest) { - let OutputTest { - version, - file, - schema, - case, - description, - data, - outputs, - remotes, - } = test; - - let prepared_schema = prepare_schema_for_version(&schema, version); - let validator = build_validator(&prepared_schema, version, file); - let evaluation = validator.evaluate(&data); - let retriever = output_schema_retriever(remotes); - - for expected in outputs { - let format = expected.format; - let schema = expected.schema; - let expected_schema = prepare_schema_for_version(&schema, version); - let actual_output = produce_output(&evaluation, format).unwrap_or_else(|| { - panic!( - "Output format `{format}` is not supported (file: {file}, case: `{case}`, test: `{description}`)" - ) - }); - validate_against_output_spec(&actual_output); - let mut options = jsonschema::options().with_retriever(retriever); - if let Some(draft) = version_draft_override(version) { - options = options.with_draft(draft); - } - let output_validator = options.build(&expected_schema).unwrap_or_else(|err| { - panic!("Invalid output schema for {file} format {format}: {err}") - }); - if let Err(error) = output_validator.validate(&actual_output) { - eprintln!("Output validation error: {error:?}"); - panic!( - "Output format `{format}` failed for {file} (case: `{case}`, test: `{description}`): {error}" - ); - } - } -} - -fn output_spec_validator() -> &'static Validator { - static VALIDATOR: OnceLock = OnceLock::new(); - VALIDATOR.get_or_init(|| { - let mut schema: Value = serde_json::from_str(include_str!("output_spec_schema.json")) - .expect("output spec schema JSON is valid"); - if let Value::Object(ref mut map) = schema { - map.remove("$schema"); - } - validator_for(&schema).expect("output spec schema must be valid") - }) -} - -fn validate_against_output_spec(value: &Value) { - if let Err(error) = output_spec_validator().validate(value) { - panic!("Output does not match JSON Schema validation-output schema: {error}"); - } -} - -fn build_validator(schema: &Value, version: &str, file: &str) -> Validator { - match version_draft_override(version) { - Some(draft) => jsonschema::options() - .with_draft(draft) - .build(schema) - .unwrap_or_else(|err| panic!("Invalid schema in {file}: {err}")), - None => { - validator_for(schema).unwrap_or_else(|err| panic!("Invalid schema in {file}: {err}")) - } - } -} - -fn produce_output(evaluation: &Evaluation, format: &str) -> Option { - match format { - "flag" => { - let value = serde_json::to_value(evaluation.flag()).expect("flag output serializable"); - debug_output("flag", &value); - Some(value) - } - "list" => { - let value = serde_json::to_value(evaluation.list()).expect("list output serializable"); - debug_output("list", &value); - Some(value) - } - "hierarchical" => { - let value = serde_json::to_value(evaluation.hierarchical()) - .expect("hierarchical output serializable"); - debug_output("hierarchical", &value); - Some(value) - } - _ => None, - } -} - -// Prints serialized output when `JSONSCHEMA_DEBUG_OUTPUT` is set. -#[allow(clippy::print_stderr)] -fn debug_output(format: &str, value: &Value) { - if std::env::var("JSONSCHEMA_DEBUG_OUTPUT").is_ok() { - eprintln!( - "=== {format} ===\n{}", - serde_json::to_string_pretty(value).expect("output to stringify") - ); - } -} - -fn prepare_schema_for_version(schema: &Value, version: &str) -> Value { - if is_v1(version) { - if let Value::Object(mut map) = schema.clone() { - map.remove("$schema"); - map.into() - } else { - schema.clone() - } - } else { - schema.clone() - } -} - -fn version_draft_override(version: &str) -> Option { - match version { - v if is_v1(v) => Some(Draft::Draft202012), - _ => None, - } -} - -fn is_v1(version: &str) -> bool { - version == "v1" || version.starts_with("v1-") -} - -fn output_schema_retriever(remotes: &'static [OutputRemote]) -> OutputSchemaRetriever { - OutputSchemaRetriever { documents: remotes } -} - -#[derive(Clone, Copy)] -struct OutputSchemaRetriever { - documents: &'static [OutputRemote], -} - -impl Retrieve for OutputSchemaRetriever { - fn retrieve( - &self, - uri: &Uri, - ) -> Result> { - self.documents - .iter() - .find(|doc| doc.uri == uri.as_str()) - .map(|doc| { - serde_json::from_str(doc.contents).expect("Output schema must be valid JSON") - }) - .ok_or_else(|| format!("Unknown output schema reference: {uri}").into()) - } -} Index: jsonschema/tests/suite.rs =================================================================== --- jsonschema.orig/tests/suite.rs 2026-06-14 18:53:15.107529614 -0400 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,249 +0,0 @@ -#![allow(clippy::large_stack_arrays)] - -mod tests { - use jsonschema::{Draft, PatternOptions}; - #[cfg(not(target_arch = "wasm32"))] - use std::env; - #[cfg(not(target_arch = "wasm32"))] - use std::fs; - use testsuite::{suite, Test}; - - #[suite( - path = "crates/jsonschema/tests/suite", - drafts = [ - "draft4", - "draft6", - "draft7", - "draft2019-09", - "draft2020-12", - ], - xfail = [ - "draft4::optional::bignum::integer::a_bignum_is_an_integer", - "draft4::optional::bignum::integer::a_negative_bignum_is_an_integer", - ] -)] - fn test_suite(test: &Test) { - enum RegexEngine { - Regex, - FancyRegex, - } - - let mut options = jsonschema::options(); - match test.draft { - "draft4" => { - options = options.with_draft(Draft::Draft4); - } - "draft6" => { - options = options.with_draft(Draft::Draft6); - } - "draft7" => { - options = options.with_draft(Draft::Draft7); - } - "draft2019-09" | "draft2020-12" => {} - _ => panic!("Unsupported draft"), - } - if should_skip_draft(test.draft) { - return; - } - if test.is_optional { - options = options.should_validate_formats(true); - } - options = options.with_retriever(testsuite_retriever()); - - for engine in [RegexEngine::FancyRegex, RegexEngine::Regex] { - match engine { - RegexEngine::Regex => { - options = options.with_pattern_options(PatternOptions::regex()); - } - RegexEngine::FancyRegex => { - options = options.with_pattern_options(PatternOptions::fancy_regex()); - } - } - let validator = options - .build(&test.schema) - .expect("Failed to build a schema"); - - if test.valid { - if let Some(first) = validator.iter_errors(&test.data).next() { - panic!( - "Test case should not have validation errors:\nGroup: {}\nTest case: {}\nSchema: {}\nInstance: {}\nError: {first:?}", - test.case, - test.description, - pretty_json(&test.schema), - pretty_json(&test.data), - ); - } - assert!( - validator.is_valid(&test.data), - "Test case should be valid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", - test.case, - test.description, - pretty_json(&test.schema), - pretty_json(&test.data), - ); - assert!( - validator.validate(&test.data).is_ok(), - "Test case should be valid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", - test.case, - test.description, - pretty_json(&test.schema), - pretty_json(&test.data), - ); - let evaluation = validator.evaluate(&test.data); - assert!( - evaluation.flag().valid, - "Evaluation output should be valid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", - test.case, - test.description, - pretty_json(&test.schema), - pretty_json(&test.data), - ); - let _ = - serde_json::to_value(evaluation.list()).expect("List output should serialize"); - let _ = serde_json::to_value(evaluation.hierarchical()) - .expect("Hierarchical output should serialize"); - } else { - let errors = validator.iter_errors(&test.data).collect::>(); - assert!( - !errors.is_empty(), - "Test case should have validation errors:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", - test.case, - test.description, - pretty_json(&test.schema), - pretty_json(&test.data), - ); - for error in errors { - let pointer = error.instance_path().as_str(); - assert_eq!( - test.data.pointer(pointer), Some(error.instance().as_ref()), - "Expected error instance did not match actual error instance:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}\nExpected pointer: {:#?}\nActual pointer: {:#?}", - test.case, - test.description, - pretty_json(&test.schema), - pretty_json(&test.data), - error.instance().as_ref(), - &pointer, - ); - } - assert!( - !validator.is_valid(&test.data), - "Test case should be invalid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", - test.case, - test.description, - pretty_json(&test.schema), - pretty_json(&test.data), - ); - let Some(error) = validator.validate(&test.data).err() else { - panic!( - "Test case should be invalid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", - test.case, - test.description, - pretty_json(&test.schema), - pretty_json(&test.data), - ); - }; - let pointer = error.instance_path().as_str(); - assert_eq!( - test.data.pointer(pointer), Some(error.instance().as_ref()), - "Expected error instance did not match actual error instance:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}\nExpected pointer: {:#?}\nActual pointer: {:#?}", - test.case, - test.description, - pretty_json(&test.schema), - pretty_json(&test.data), - error.instance().as_ref(), - &pointer, - ); - let evaluation = validator.evaluate(&test.data); - assert!( - !evaluation.flag().valid, - "Evaluation output should be invalid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", - test.case, - test.description, - pretty_json(&test.schema), - pretty_json(&test.data), - ); - let _ = - serde_json::to_value(evaluation.list()).expect("List output should serialize"); - let _ = serde_json::to_value(evaluation.hierarchical()) - .expect("Hierarchical output should serialize"); - } - } - } - - fn pretty_json(v: &serde_json::Value) -> String { - serde_json::to_string_pretty(v).expect("Failed to format JSON") - } - - #[cfg(not(target_arch = "wasm32"))] - #[test] - fn test_instance_path() { - let expectations: serde_json::Value = - serde_json::from_str(include_str!("draft7_instance_paths.json")).expect("Valid JSON"); - for (filename, expected) in expectations.as_object().expect("Is object") { - let test_file = fs::read_to_string(format!("tests/suite/tests/draft7/{filename}")) - .unwrap_or_else(|_| panic!("Valid file: {filename}")); - let data: serde_json::Value = serde_json::from_str(&test_file).expect("Valid JSON"); - for item in expected.as_array().expect("Is array") { - let suite_id = usize::try_from(item["suite_id"].as_u64().expect("Is integer")) - .expect("suite_id fits in usize"); - let schema = &data[suite_id]["schema"]; - let validator = jsonschema::options() - .with_draft(Draft::Draft7) - .with_retriever(testsuite_retriever()) - .build(schema) - .unwrap_or_else(|_| { - panic!( - "Valid schema. File: {filename}; Suite ID: {suite_id}; Schema: {schema}", - ) - }); - for test_data in item["tests"].as_array().expect("Valid array") { - let test_id = usize::try_from(test_data["id"].as_u64().expect("Is integer")) - .expect("test_id fits in usize"); - let mut instance_path = String::new(); - - for segment in test_data["instance_path"].as_array().expect("Valid array") { - instance_path.push('/'); - instance_path.push_str(segment.as_str().expect("A string")); - } - let instance = &data[suite_id]["tests"][test_id]["data"]; - let error = validator.validate(instance).expect_err(&format!( - "\nFile: {}\nSuite: {}\nTest: {}", - filename, - &data[suite_id]["description"], - &data[suite_id]["tests"][test_id]["description"], - )); - assert_eq!( - error.instance_path().as_str(), - instance_path, - "\nFile: {}\nSuite: {}\nTest: {}\nError: {}", - filename, - &data[suite_id]["description"], - &data[suite_id]["tests"][test_id]["description"], - &error - ); - } - } - } - } - - fn should_skip_draft(draft: &str) -> bool { - if let Some(filter) = allowed_draft_filter() { - for entry in filter.split(',') { - if entry.trim().eq_ignore_ascii_case(draft) { - return false; - } - } - true - } else { - false - } - } - - fn allowed_draft_filter() -> Option { - #[cfg(not(target_arch = "wasm32"))] - if let Ok(value) = env::var("JSONSCHEMA_SUITE_DRAFT_FILTER") { - return Some(value); - } - option_env!("JSONSCHEMA_SUITE_DRAFT_FILTER").map(str::to_string) - } -}