| 1 |
Index: jsonschema/Cargo.toml |
| 2 |
=================================================================== |
| 3 |
--- jsonschema.orig/Cargo.toml 2026-06-14 18:53:15.107529614 -0400 |
| 4 |
+++ jsonschema/Cargo.toml 2026-06-14 18:53:15.104078243 -0400 |
| 5 |
@@ -54,14 +54,6 @@ |
| 6 |
path = "src/lib.rs" |
| 7 |
|
| 8 |
[[test]] |
| 9 |
-name = "output_suite" |
| 10 |
-path = "tests/output_suite.rs" |
| 11 |
- |
| 12 |
-[[test]] |
| 13 |
-name = "suite" |
| 14 |
-path = "tests/suite.rs" |
| 15 |
- |
| 16 |
-[[test]] |
| 17 |
name = "wasm" |
| 18 |
path = "tests/wasm.rs" |
| 19 |
|
| 20 |
@@ -69,35 +61,35 @@ |
| 21 |
name = "wasm_wasi" |
| 22 |
path = "tests/wasm_wasi.rs" |
| 23 |
|
| 24 |
-[[bench]] |
| 25 |
-name = "errors" |
| 26 |
-path = "benches/errors.rs" |
| 27 |
-harness = false |
| 28 |
- |
| 29 |
-[[bench]] |
| 30 |
-name = "jsonschema" |
| 31 |
-path = "benches/jsonschema.rs" |
| 32 |
-harness = false |
| 33 |
- |
| 34 |
-[[bench]] |
| 35 |
-name = "keywords" |
| 36 |
-path = "benches/keywords.rs" |
| 37 |
-harness = false |
| 38 |
- |
| 39 |
-[[bench]] |
| 40 |
-name = "location" |
| 41 |
-path = "benches/location.rs" |
| 42 |
-harness = false |
| 43 |
- |
| 44 |
-[[bench]] |
| 45 |
-name = "unevaluated_items" |
| 46 |
-path = "benches/unevaluated_items.rs" |
| 47 |
-harness = false |
| 48 |
- |
| 49 |
-[[bench]] |
| 50 |
-name = "unevaluated_properties" |
| 51 |
-path = "benches/unevaluated_properties.rs" |
| 52 |
-harness = false |
| 53 |
+#[[bench]] |
| 54 |
+#name = "errors" |
| 55 |
+#path = "benches/errors.rs" |
| 56 |
+#harness = false |
| 57 |
+ |
| 58 |
+#[[bench]] |
| 59 |
+#name = "jsonschema" |
| 60 |
+#path = "benches/jsonschema.rs" |
| 61 |
+#harness = false |
| 62 |
+ |
| 63 |
+#[[bench]] |
| 64 |
+#name = "keywords" |
| 65 |
+#path = "benches/keywords.rs" |
| 66 |
+#harness = false |
| 67 |
+ |
| 68 |
+#[[bench]] |
| 69 |
+#name = "location" |
| 70 |
+#path = "benches/location.rs" |
| 71 |
+#harness = false |
| 72 |
+ |
| 73 |
+#[[bench]] |
| 74 |
+#name = "unevaluated_items" |
| 75 |
+#path = "benches/unevaluated_items.rs" |
| 76 |
+#harness = false |
| 77 |
+ |
| 78 |
+#[[bench]] |
| 79 |
+#name = "unevaluated_properties" |
| 80 |
+#path = "benches/unevaluated_properties.rs" |
| 81 |
+#harness = false |
| 82 |
|
| 83 |
[dependencies.ahash] |
| 84 |
version = "0.8" |
| 85 |
@@ -118,7 +110,7 @@ |
| 86 |
version = "0.2.9" |
| 87 |
|
| 88 |
[dependencies.fancy-regex] |
| 89 |
-version = "0.16" |
| 90 |
+version = "0.11" |
| 91 |
|
| 92 |
[dependencies.fraction] |
| 93 |
version = "0.15" |
| 94 |
@@ -180,7 +172,7 @@ |
| 95 |
version = "3" |
| 96 |
|
| 97 |
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies.wasm-bindgen-test] |
| 98 |
-version = "0.3.55" |
| 99 |
+version = "0.3" |
| 100 |
|
| 101 |
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.reqwest] |
| 102 |
version = "0.12" |
| 103 |
@@ -199,13 +191,13 @@ |
| 104 |
] |
| 105 |
optional = true |
| 106 |
|
| 107 |
-[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.codspeed-criterion-compat] |
| 108 |
-version = "4.1" |
| 109 |
-default-features = false |
| 110 |
- |
| 111 |
-[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.criterion] |
| 112 |
-version = "0.7" |
| 113 |
-default-features = false |
| 114 |
+#[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.codspeed-criterion-compat] |
| 115 |
+#version = "4.1" |
| 116 |
+#default-features = false |
| 117 |
+ |
| 118 |
+#[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.criterion] |
| 119 |
+#version = "0.7" |
| 120 |
+#default-features = false |
| 121 |
|
| 122 |
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.tempfile] |
| 123 |
version = "3.13.0" |
| 124 |
@@ -220,9 +212,9 @@ |
| 125 |
"rt", |
| 126 |
] |
| 127 |
|
| 128 |
-[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom] |
| 129 |
-version = "0.3.4" |
| 130 |
-features = ["wasm_js"] |
| 131 |
+#[target.'cfg(target_arch = "wasm32")'.dependencies.getrandom] |
| 132 |
+#version = "0.2" |
| 133 |
+#features = ["wasm_js"] |
| 134 |
|
| 135 |
[target.'cfg(target_arch = "wasm32")'.dependencies.reqwest] |
| 136 |
version = "0.12" |
| 137 |
Index: jsonschema/benches/errors.rs |
| 138 |
=================================================================== |
| 139 |
--- jsonschema.orig/benches/errors.rs 2026-06-14 18:53:15.107529614 -0400 |
| 140 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 141 |
@@ -1,36 +0,0 @@ |
| 142 |
-#[cfg(not(target_arch = "wasm32"))] |
| 143 |
-mod bench { |
| 144 |
- pub(crate) use benchmark::run_error_formatting_benchmarks; |
| 145 |
- pub(crate) use criterion::{criterion_group, BenchmarkId, Criterion}; |
| 146 |
- pub(crate) use serde_json::Value; |
| 147 |
- |
| 148 |
- pub(crate) fn bench_error_formatting( |
| 149 |
- c: &mut Criterion, |
| 150 |
- name: &str, |
| 151 |
- schema: &Value, |
| 152 |
- instance: &Value, |
| 153 |
- ) { |
| 154 |
- let validator = jsonschema::validator_for(schema).expect("Valid schema"); |
| 155 |
- let error = validator.validate(instance).unwrap_err(); |
| 156 |
- |
| 157 |
- c.bench_with_input( |
| 158 |
- BenchmarkId::new("error_formatting", name), |
| 159 |
- &error, |
| 160 |
- |b, error| b.iter_with_large_drop(|| error.to_string()), |
| 161 |
- ); |
| 162 |
- } |
| 163 |
- |
| 164 |
- pub(crate) fn run_benchmarks(c: &mut Criterion) { |
| 165 |
- run_error_formatting_benchmarks(&mut |name, schema, instance| { |
| 166 |
- bench_error_formatting(c, name, schema, instance); |
| 167 |
- }); |
| 168 |
- } |
| 169 |
- |
| 170 |
- criterion_group!(error_formatting, run_benchmarks); |
| 171 |
-} |
| 172 |
- |
| 173 |
-#[cfg(not(target_arch = "wasm32"))] |
| 174 |
-criterion::criterion_main!(bench::error_formatting); |
| 175 |
- |
| 176 |
-#[cfg(target_arch = "wasm32")] |
| 177 |
-fn main() {} |
| 178 |
Index: jsonschema/benches/jsonschema.rs |
| 179 |
=================================================================== |
| 180 |
--- jsonschema.orig/benches/jsonschema.rs 2026-06-14 18:53:15.107529614 -0400 |
| 181 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 182 |
@@ -1,69 +0,0 @@ |
| 183 |
-#[cfg(not(target_arch = "wasm32"))] |
| 184 |
-mod bench { |
| 185 |
- use std::hint::black_box; |
| 186 |
- |
| 187 |
- pub(crate) use benchmark::Benchmark; |
| 188 |
- pub(crate) use codspeed_criterion_compat::{criterion_group, BenchmarkId, Criterion}; |
| 189 |
- pub(crate) use serde_json::Value; |
| 190 |
- |
| 191 |
- pub(crate) fn bench_build(c: &mut Criterion, name: &str, schema: &Value) { |
| 192 |
- c.bench_with_input(BenchmarkId::new("build", name), schema, |b, schema| { |
| 193 |
- b.iter_with_large_drop(|| jsonschema::validator_for(schema).expect("Valid schema")); |
| 194 |
- }); |
| 195 |
- } |
| 196 |
- |
| 197 |
- pub(crate) fn bench_is_valid(c: &mut Criterion, name: &str, schema: &Value, instance: &Value) { |
| 198 |
- let validator = jsonschema::validator_for(schema).expect("Valid schema"); |
| 199 |
- c.bench_with_input( |
| 200 |
- BenchmarkId::new("is_valid", name), |
| 201 |
- instance, |
| 202 |
- |b, instance| { |
| 203 |
- b.iter(|| black_box(validator.is_valid(instance))); |
| 204 |
- }, |
| 205 |
- ); |
| 206 |
- } |
| 207 |
- |
| 208 |
- pub(crate) fn bench_validate(c: &mut Criterion, name: &str, schema: &Value, instance: &Value) { |
| 209 |
- let validator = jsonschema::validator_for(schema).expect("Valid schema"); |
| 210 |
- c.bench_with_input( |
| 211 |
- BenchmarkId::new("validate", name), |
| 212 |
- instance, |
| 213 |
- |b, instance| { |
| 214 |
- b.iter(|| black_box(validator.validate(instance))); |
| 215 |
- }, |
| 216 |
- ); |
| 217 |
- } |
| 218 |
- |
| 219 |
- pub(crate) fn bench_evaluate(c: &mut Criterion, name: &str, schema: &Value, instance: &Value) { |
| 220 |
- let validator = jsonschema::validator_for(schema).expect("Valid schema"); |
| 221 |
- c.bench_with_input( |
| 222 |
- BenchmarkId::new("evaluate", name), |
| 223 |
- instance, |
| 224 |
- |b, instance| { |
| 225 |
- b.iter_with_large_drop(|| black_box(validator.evaluate(instance))); |
| 226 |
- }, |
| 227 |
- ); |
| 228 |
- } |
| 229 |
- |
| 230 |
- pub(crate) fn run_benchmarks(c: &mut Criterion) { |
| 231 |
- for benchmark in Benchmark::iter() { |
| 232 |
- benchmark.run(&mut |name, schema, instances| { |
| 233 |
- bench_build(c, name, schema); |
| 234 |
- for instance in instances { |
| 235 |
- let name = format!("{}/{}", name, instance.name); |
| 236 |
- bench_is_valid(c, &name, schema, &instance.data); |
| 237 |
- bench_validate(c, &name, schema, &instance.data); |
| 238 |
- bench_evaluate(c, &name, schema, &instance.data); |
| 239 |
- } |
| 240 |
- }); |
| 241 |
- } |
| 242 |
- } |
| 243 |
- |
| 244 |
- criterion_group!(jsonschema, run_benchmarks); |
| 245 |
-} |
| 246 |
- |
| 247 |
-#[cfg(not(target_arch = "wasm32"))] |
| 248 |
-codspeed_criterion_compat::criterion_main!(bench::jsonschema); |
| 249 |
- |
| 250 |
-#[cfg(target_arch = "wasm32")] |
| 251 |
-fn main() {} |
| 252 |
Index: jsonschema/benches/keywords.rs |
| 253 |
=================================================================== |
| 254 |
--- jsonschema.orig/benches/keywords.rs 2026-06-14 18:53:15.107529614 -0400 |
| 255 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 256 |
@@ -1,74 +0,0 @@ |
| 257 |
-#[cfg(not(target_arch = "wasm32"))] |
| 258 |
-mod bench { |
| 259 |
- pub(crate) use benchmark::run_keyword_benchmarks; |
| 260 |
- pub(crate) use criterion::{criterion_group, BenchmarkId, Criterion}; |
| 261 |
- pub(crate) use serde_json::Value; |
| 262 |
- |
| 263 |
- pub(crate) fn validator_for(schema: &Value) -> jsonschema::Validator { |
| 264 |
- jsonschema::options() |
| 265 |
- .with_draft(jsonschema::Draft::Draft7) |
| 266 |
- .build(schema) |
| 267 |
- .expect("Schema used in benchmarks should compile") |
| 268 |
- } |
| 269 |
- |
| 270 |
- pub(crate) fn bench_keyword_build(c: &mut Criterion, name: &str, schema: &Value) { |
| 271 |
- c.bench_function(&format!("keyword/{name}/build"), |b| { |
| 272 |
- b.iter_with_large_drop(|| validator_for(schema)); |
| 273 |
- }); |
| 274 |
- } |
| 275 |
- |
| 276 |
- pub(crate) fn bench_keyword_is_valid( |
| 277 |
- c: &mut Criterion, |
| 278 |
- name: &str, |
| 279 |
- schema: &Value, |
| 280 |
- instance: &Value, |
| 281 |
- ) { |
| 282 |
- let validator = validator_for(schema); |
| 283 |
- c.bench_with_input( |
| 284 |
- BenchmarkId::new(format!("keyword/{name}"), "is_valid"), |
| 285 |
- instance, |
| 286 |
- |b, instance| { |
| 287 |
- b.iter(|| { |
| 288 |
- let _ = validator.is_valid(instance); |
| 289 |
- }); |
| 290 |
- }, |
| 291 |
- ); |
| 292 |
- } |
| 293 |
- |
| 294 |
- pub(crate) fn bench_keyword_validate( |
| 295 |
- c: &mut Criterion, |
| 296 |
- name: &str, |
| 297 |
- schema: &Value, |
| 298 |
- instance: &Value, |
| 299 |
- ) { |
| 300 |
- let validator = validator_for(schema); |
| 301 |
- c.bench_with_input( |
| 302 |
- BenchmarkId::new(format!("keyword/{name}"), "validate"), |
| 303 |
- instance, |
| 304 |
- |b, instance| { |
| 305 |
- b.iter(|| { |
| 306 |
- let _ = validator.validate(instance); |
| 307 |
- }); |
| 308 |
- }, |
| 309 |
- ); |
| 310 |
- } |
| 311 |
- |
| 312 |
- pub(crate) fn run_benchmarks(c: &mut Criterion) { |
| 313 |
- run_keyword_benchmarks(&mut |name, schema, instances| { |
| 314 |
- bench_keyword_build(c, name, schema); |
| 315 |
- for instance in instances { |
| 316 |
- let name = format!("jsonschema/{}/{}", name, instance.name); |
| 317 |
- bench_keyword_is_valid(c, &name, schema, &instance.data); |
| 318 |
- bench_keyword_validate(c, &name, schema, &instance.data); |
| 319 |
- } |
| 320 |
- }); |
| 321 |
- } |
| 322 |
- |
| 323 |
- criterion_group!(keywords, run_benchmarks); |
| 324 |
-} |
| 325 |
- |
| 326 |
-#[cfg(not(target_arch = "wasm32"))] |
| 327 |
-criterion::criterion_main!(bench::keywords); |
| 328 |
- |
| 329 |
-#[cfg(target_arch = "wasm32")] |
| 330 |
-fn main() {} |
| 331 |
Index: jsonschema/benches/location.rs |
| 332 |
=================================================================== |
| 333 |
--- jsonschema.orig/benches/location.rs 2026-06-14 18:53:15.107529614 -0400 |
| 334 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 335 |
@@ -1,61 +0,0 @@ |
| 336 |
-#[cfg(not(target_arch = "wasm32"))] |
| 337 |
-mod bench { |
| 338 |
- pub(crate) use criterion::{criterion_group, BenchmarkId, Criterion}; |
| 339 |
- pub(crate) use jsonschema::paths::{Location, LocationSegment}; |
| 340 |
- pub(crate) use std::hint::black_box; |
| 341 |
- |
| 342 |
- pub(crate) fn benchmark_into_iterator(c: &mut Criterion) { |
| 343 |
- let empty = Location::new(); |
| 344 |
- let small = vec!["a", "b", "c"] |
| 345 |
- .into_iter() |
| 346 |
- .map(LocationSegment::from) |
| 347 |
- .chain((0..3).map(LocationSegment::from)) |
| 348 |
- .collect::<Location>(); |
| 349 |
- let large = (0..500) |
| 350 |
- .map(|_| LocationSegment::from("abc")) |
| 351 |
- .chain((0..500).map(LocationSegment::from)) |
| 352 |
- .collect::<Location>(); |
| 353 |
- |
| 354 |
- for (parameter, input) in [("empty", empty), ("small", small), ("large", large)] { |
| 355 |
- c.bench_with_input( |
| 356 |
- BenchmarkId::new("IntoIterator", parameter), |
| 357 |
- &input, |
| 358 |
- |b, i| b.iter_with_large_drop(|| black_box(i).into_iter().collect::<Vec<_>>()), |
| 359 |
- ); |
| 360 |
- } |
| 361 |
- } |
| 362 |
- |
| 363 |
- pub(crate) fn benchmark_from_iterator(c: &mut Criterion) { |
| 364 |
- let empty = vec![]; |
| 365 |
- let small = vec![ |
| 366 |
- LocationSegment::from("a"), |
| 367 |
- LocationSegment::from("b"), |
| 368 |
- LocationSegment::from("c"), |
| 369 |
- ]; |
| 370 |
- let large = (0..1000) |
| 371 |
- .map(|_| LocationSegment::from("abc")) |
| 372 |
- .collect::<Vec<_>>(); |
| 373 |
- |
| 374 |
- for (parameter, input) in [("empty", empty), ("small", small), ("large", large)] { |
| 375 |
- c.bench_with_input( |
| 376 |
- BenchmarkId::new("FromIterator", parameter), |
| 377 |
- &input, |
| 378 |
- |b, i| { |
| 379 |
- b.iter_batched( |
| 380 |
- || i.clone().into_iter(), |
| 381 |
- |i| black_box(i).collect::<Location>(), |
| 382 |
- criterion::BatchSize::SmallInput, |
| 383 |
- ); |
| 384 |
- }, |
| 385 |
- ); |
| 386 |
- } |
| 387 |
- } |
| 388 |
- |
| 389 |
- criterion_group!(benches, benchmark_into_iterator, benchmark_from_iterator); |
| 390 |
-} |
| 391 |
- |
| 392 |
-#[cfg(not(target_arch = "wasm32"))] |
| 393 |
-criterion::criterion_main!(bench::benches); |
| 394 |
- |
| 395 |
-#[cfg(target_arch = "wasm32")] |
| 396 |
-fn main() {} |
| 397 |
Index: jsonschema/benches/unevaluated_items.rs |
| 398 |
=================================================================== |
| 399 |
--- jsonschema.orig/benches/unevaluated_items.rs 2026-06-14 18:53:15.107529614 -0400 |
| 400 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 401 |
@@ -1,182 +0,0 @@ |
| 402 |
-#[cfg(not(target_arch = "wasm32"))] |
| 403 |
-mod bench { |
| 404 |
- use codspeed_criterion_compat::{criterion_group, BenchmarkId, Criterion}; |
| 405 |
- use serde_json::{json, Value}; |
| 406 |
- use std::hint::black_box; |
| 407 |
- |
| 408 |
- fn large_schema() -> Value { |
| 409 |
- json!({ |
| 410 |
- "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 411 |
- "type": "array", |
| 412 |
- "prefixItems": [ |
| 413 |
- {"type": "string"}, |
| 414 |
- {"type": "number"}, |
| 415 |
- {"type": "boolean"} |
| 416 |
- ], |
| 417 |
- "contains": { |
| 418 |
- "type": "object", |
| 419 |
- "properties": { |
| 420 |
- "special": {"type": "boolean"} |
| 421 |
- } |
| 422 |
- }, |
| 423 |
- "allOf": [ |
| 424 |
- { |
| 425 |
- "if": { |
| 426 |
- "contains": {"const": "trigger"} |
| 427 |
- }, |
| 428 |
- "then": { |
| 429 |
- "prefixItems": [ |
| 430 |
- {"type": "string"}, |
| 431 |
- {"type": "number"}, |
| 432 |
- {"type": "boolean"}, |
| 433 |
- {"type": "string"} |
| 434 |
- ] |
| 435 |
- }, |
| 436 |
- "else": { |
| 437 |
- "prefixItems": [ |
| 438 |
- {"type": "string"}, |
| 439 |
- {"type": "number"}, |
| 440 |
- {"type": "boolean"}, |
| 441 |
- {"type": "number"} |
| 442 |
- ] |
| 443 |
- } |
| 444 |
- } |
| 445 |
- ], |
| 446 |
- "anyOf": [ |
| 447 |
- { |
| 448 |
- "contains": {"type": "string"} |
| 449 |
- }, |
| 450 |
- { |
| 451 |
- "contains": {"type": "number"} |
| 452 |
- } |
| 453 |
- ], |
| 454 |
- "oneOf": [ |
| 455 |
- { |
| 456 |
- "prefixItems": [ |
| 457 |
- {"type": "string"}, |
| 458 |
- {"type": "number"}, |
| 459 |
- {"type": "boolean"}, |
| 460 |
- {"type": "string"}, |
| 461 |
- {"type": "array"} |
| 462 |
- ] |
| 463 |
- }, |
| 464 |
- { |
| 465 |
- "prefixItems": [ |
| 466 |
- {"type": "string"}, |
| 467 |
- {"type": "number"}, |
| 468 |
- {"type": "boolean"}, |
| 469 |
- {"type": "number"}, |
| 470 |
- {"type": "object"} |
| 471 |
- ] |
| 472 |
- } |
| 473 |
- ], |
| 474 |
- "unevaluatedItems": false |
| 475 |
- }) |
| 476 |
- } |
| 477 |
- |
| 478 |
- fn large_invalid_instance() -> Value { |
| 479 |
- json!([ |
| 480 |
- "string", |
| 481 |
- 42, |
| 482 |
- true, |
| 483 |
- 123, |
| 484 |
- {"special": true}, |
| 485 |
- "unexpected" // This should trigger unevaluatedItems: false |
| 486 |
- ]) |
| 487 |
- } |
| 488 |
- |
| 489 |
- fn bench_build(c: &mut Criterion, name: &str, schema: &Value) { |
| 490 |
- c.bench_with_input(BenchmarkId::new("build", name), schema, |b, schema| { |
| 491 |
- b.iter_with_large_drop(|| jsonschema::draft202012::new(schema).unwrap()); |
| 492 |
- }); |
| 493 |
- } |
| 494 |
- |
| 495 |
- fn bench_is_valid( |
| 496 |
- c: &mut Criterion, |
| 497 |
- name: &str, |
| 498 |
- validator: &jsonschema::Validator, |
| 499 |
- instance: &Value, |
| 500 |
- ) { |
| 501 |
- c.bench_with_input( |
| 502 |
- BenchmarkId::new("is_valid", name), |
| 503 |
- instance, |
| 504 |
- |b, instance| { |
| 505 |
- b.iter(|| { |
| 506 |
- black_box(validator.is_valid(instance)); |
| 507 |
- }); |
| 508 |
- }, |
| 509 |
- ); |
| 510 |
- } |
| 511 |
- |
| 512 |
- fn bench_validate( |
| 513 |
- c: &mut Criterion, |
| 514 |
- name: &str, |
| 515 |
- validator: &jsonschema::Validator, |
| 516 |
- instance: &Value, |
| 517 |
- ) { |
| 518 |
- c.bench_with_input( |
| 519 |
- BenchmarkId::new("validate", name), |
| 520 |
- instance, |
| 521 |
- |b, instance| { |
| 522 |
- b.iter(|| { |
| 523 |
- let _ = black_box(validator.validate(instance)); |
| 524 |
- }); |
| 525 |
- }, |
| 526 |
- ); |
| 527 |
- } |
| 528 |
- |
| 529 |
- fn bench_evaluate( |
| 530 |
- c: &mut Criterion, |
| 531 |
- name: &str, |
| 532 |
- validator: &jsonschema::Validator, |
| 533 |
- instance: &Value, |
| 534 |
- ) { |
| 535 |
- c.bench_with_input( |
| 536 |
- BenchmarkId::new("evaluate", name), |
| 537 |
- instance, |
| 538 |
- |b, instance| { |
| 539 |
- b.iter_with_large_drop(|| black_box(validator.evaluate(instance))); |
| 540 |
- }, |
| 541 |
- ); |
| 542 |
- } |
| 543 |
- |
| 544 |
- fn bench_iter_errors( |
| 545 |
- c: &mut Criterion, |
| 546 |
- name: &str, |
| 547 |
- validator: &jsonschema::Validator, |
| 548 |
- instance: &Value, |
| 549 |
- ) { |
| 550 |
- c.bench_with_input( |
| 551 |
- BenchmarkId::new("iter_errors", name), |
| 552 |
- instance, |
| 553 |
- |b, instance| { |
| 554 |
- b.iter(|| { |
| 555 |
- for error in validator.iter_errors(instance) { |
| 556 |
- black_box(error); |
| 557 |
- } |
| 558 |
- }); |
| 559 |
- }, |
| 560 |
- ); |
| 561 |
- } |
| 562 |
- |
| 563 |
- fn run_benchmarks(c: &mut Criterion) { |
| 564 |
- let large = large_schema(); |
| 565 |
- bench_build(c, "unevaluated_items", &large); |
| 566 |
- |
| 567 |
- let validator = jsonschema::draft202012::new(&large).unwrap(); |
| 568 |
- let invalid = large_invalid_instance(); |
| 569 |
- |
| 570 |
- bench_is_valid(c, "unevaluated_items", &validator, &invalid); |
| 571 |
- bench_validate(c, "unevaluated_items", &validator, &invalid); |
| 572 |
- bench_evaluate(c, "unevaluated_items", &validator, &invalid); |
| 573 |
- bench_iter_errors(c, "unevaluated_items", &validator, &invalid); |
| 574 |
- } |
| 575 |
- |
| 576 |
- criterion_group!(benches, run_benchmarks); |
| 577 |
-} |
| 578 |
- |
| 579 |
-#[cfg(not(target_arch = "wasm32"))] |
| 580 |
-codspeed_criterion_compat::criterion_main!(bench::benches); |
| 581 |
- |
| 582 |
-#[cfg(target_arch = "wasm32")] |
| 583 |
-fn main() {} |
| 584 |
Index: jsonschema/benches/unevaluated_properties.rs |
| 585 |
=================================================================== |
| 586 |
--- jsonschema.orig/benches/unevaluated_properties.rs 2026-06-14 18:53:15.107529614 -0400 |
| 587 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 588 |
@@ -1,166 +0,0 @@ |
| 589 |
-#[cfg(not(target_arch = "wasm32"))] |
| 590 |
-mod bench { |
| 591 |
- use codspeed_criterion_compat::{criterion_group, BenchmarkId, Criterion}; |
| 592 |
- use serde_json::{json, Value}; |
| 593 |
- use std::hint::black_box; |
| 594 |
- |
| 595 |
- fn large_schema() -> Value { |
| 596 |
- let mut properties = serde_json::Map::new(); |
| 597 |
- for i in 0..50 { |
| 598 |
- properties.insert(format!("prop{i}"), json!({"type": "string"})); |
| 599 |
- } |
| 600 |
- |
| 601 |
- json!({ |
| 602 |
- "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 603 |
- "type": "object", |
| 604 |
- "properties": properties, |
| 605 |
- "patternProperties": { |
| 606 |
- "^meta_": {"type": "string"} |
| 607 |
- }, |
| 608 |
- "allOf": [ |
| 609 |
- { |
| 610 |
- "if": { |
| 611 |
- "properties": { |
| 612 |
- "type": {"const": "user"} |
| 613 |
- } |
| 614 |
- }, |
| 615 |
- "then": { |
| 616 |
- "properties": { |
| 617 |
- "email": {"type": "string", "format": "email"}, |
| 618 |
- "age": {"type": "integer", "minimum": 0} |
| 619 |
- } |
| 620 |
- }, |
| 621 |
- "else": { |
| 622 |
- "properties": { |
| 623 |
- "organization": {"type": "string"} |
| 624 |
- } |
| 625 |
- } |
| 626 |
- } |
| 627 |
- ], |
| 628 |
- "anyOf": [ |
| 629 |
- { |
| 630 |
- "properties": { |
| 631 |
- "status": {"enum": ["active", "inactive"]} |
| 632 |
- } |
| 633 |
- }, |
| 634 |
- { |
| 635 |
- "properties": { |
| 636 |
- "archived": {"type": "boolean"} |
| 637 |
- } |
| 638 |
- } |
| 639 |
- ], |
| 640 |
- "dependentSchemas": { |
| 641 |
- "credit_card": { |
| 642 |
- "properties": { |
| 643 |
- "billing_address": {"type": "string"} |
| 644 |
- } |
| 645 |
- } |
| 646 |
- }, |
| 647 |
- "unevaluatedProperties": false |
| 648 |
- }) |
| 649 |
- } |
| 650 |
- |
| 651 |
- fn large_invalid_instance() -> Value { |
| 652 |
- let mut obj = serde_json::Map::new(); |
| 653 |
- for i in 0..50 { |
| 654 |
- obj.insert(format!("prop{i}"), json!("value")); |
| 655 |
- } |
| 656 |
- obj.insert("unexpected".to_string(), json!("property")); |
| 657 |
- Value::Object(obj) |
| 658 |
- } |
| 659 |
- |
| 660 |
- fn bench_build(c: &mut Criterion, name: &str, schema: &Value) { |
| 661 |
- c.bench_with_input(BenchmarkId::new("build", name), schema, |b, schema| { |
| 662 |
- b.iter_with_large_drop(|| jsonschema::draft202012::new(schema).unwrap()); |
| 663 |
- }); |
| 664 |
- } |
| 665 |
- |
| 666 |
- fn bench_is_valid( |
| 667 |
- c: &mut Criterion, |
| 668 |
- name: &str, |
| 669 |
- validator: &jsonschema::Validator, |
| 670 |
- instance: &Value, |
| 671 |
- ) { |
| 672 |
- c.bench_with_input( |
| 673 |
- BenchmarkId::new("is_valid", name), |
| 674 |
- instance, |
| 675 |
- |b, instance| { |
| 676 |
- b.iter(|| { |
| 677 |
- black_box(validator.is_valid(instance)); |
| 678 |
- }); |
| 679 |
- }, |
| 680 |
- ); |
| 681 |
- } |
| 682 |
- |
| 683 |
- fn bench_validate( |
| 684 |
- c: &mut Criterion, |
| 685 |
- name: &str, |
| 686 |
- validator: &jsonschema::Validator, |
| 687 |
- instance: &Value, |
| 688 |
- ) { |
| 689 |
- c.bench_with_input( |
| 690 |
- BenchmarkId::new("validate", name), |
| 691 |
- instance, |
| 692 |
- |b, instance| { |
| 693 |
- b.iter(|| { |
| 694 |
- let _ = black_box(validator.validate(instance)); |
| 695 |
- }); |
| 696 |
- }, |
| 697 |
- ); |
| 698 |
- } |
| 699 |
- |
| 700 |
- fn bench_evaluate( |
| 701 |
- c: &mut Criterion, |
| 702 |
- name: &str, |
| 703 |
- validator: &jsonschema::Validator, |
| 704 |
- instance: &Value, |
| 705 |
- ) { |
| 706 |
- c.bench_with_input( |
| 707 |
- BenchmarkId::new("evaluate", name), |
| 708 |
- instance, |
| 709 |
- |b, instance| { |
| 710 |
- b.iter_with_large_drop(|| black_box(validator.evaluate(instance))); |
| 711 |
- }, |
| 712 |
- ); |
| 713 |
- } |
| 714 |
- |
| 715 |
- fn bench_iter_errors( |
| 716 |
- c: &mut Criterion, |
| 717 |
- name: &str, |
| 718 |
- validator: &jsonschema::Validator, |
| 719 |
- instance: &Value, |
| 720 |
- ) { |
| 721 |
- c.bench_with_input( |
| 722 |
- BenchmarkId::new("iter_errors", name), |
| 723 |
- instance, |
| 724 |
- |b, instance| { |
| 725 |
- b.iter(|| { |
| 726 |
- for error in validator.iter_errors(instance) { |
| 727 |
- black_box(error); |
| 728 |
- } |
| 729 |
- }); |
| 730 |
- }, |
| 731 |
- ); |
| 732 |
- } |
| 733 |
- |
| 734 |
- fn run_benchmarks(c: &mut Criterion) { |
| 735 |
- let large = large_schema(); |
| 736 |
- bench_build(c, "unevaluated_properties", &large); |
| 737 |
- |
| 738 |
- let validator = jsonschema::draft202012::new(&large).unwrap(); |
| 739 |
- let invalid = large_invalid_instance(); |
| 740 |
- |
| 741 |
- bench_is_valid(c, "unevaluated_properties", &validator, &invalid); |
| 742 |
- bench_validate(c, "unevaluated_properties", &validator, &invalid); |
| 743 |
- bench_evaluate(c, "unevaluated_properties", &validator, &invalid); |
| 744 |
- bench_iter_errors(c, "unevaluated_properties", &validator, &invalid); |
| 745 |
- } |
| 746 |
- |
| 747 |
- criterion_group!(benches, run_benchmarks); |
| 748 |
-} |
| 749 |
- |
| 750 |
-#[cfg(not(target_arch = "wasm32"))] |
| 751 |
-codspeed_criterion_compat::criterion_main!(bench::benches); |
| 752 |
- |
| 753 |
-#[cfg(target_arch = "wasm32")] |
| 754 |
-fn main() {} |
| 755 |
Index: jsonschema/src/validator.rs |
| 756 |
=================================================================== |
| 757 |
--- jsonschema.orig/src/validator.rs 2026-06-14 18:53:15.107529614 -0400 |
| 758 |
+++ jsonschema/src/validator.rs 2026-06-14 18:53:15.104554355 -0400 |
| 759 |
@@ -335,17 +335,17 @@ |
| 760 |
use serde_json::{json, Map, Value}; |
| 761 |
use std::sync::LazyLock; |
| 762 |
|
| 763 |
- #[cfg(not(target_arch = "wasm32"))] |
| 764 |
- fn load(path: &str, idx: usize) -> Value { |
| 765 |
- use std::{fs::File, io::Read, path::Path}; |
| 766 |
- let path = Path::new(path); |
| 767 |
- let mut file = File::open(path).unwrap(); |
| 768 |
- let mut content = String::new(); |
| 769 |
- file.read_to_string(&mut content).ok().unwrap(); |
| 770 |
- let data: Value = serde_json::from_str(&content).unwrap(); |
| 771 |
- let case = &data.as_array().unwrap()[idx]; |
| 772 |
- case.get("schema").unwrap().clone() |
| 773 |
- } |
| 774 |
+ //disabled, file missing #[cfg(not(target_arch = "wasm32"))] |
| 775 |
+ //fn load(path: &str, idx: usize) -> Value { |
| 776 |
+ // use std::{fs::File, io::Read, path::Path}; |
| 777 |
+ // let path = Path::new(path); |
| 778 |
+ // let mut file = File::open(path).unwrap(); |
| 779 |
+ // let mut content = String::new(); |
| 780 |
+ // file.read_to_string(&mut content).ok().unwrap(); |
| 781 |
+ // let data: Value = serde_json::from_str(&content).unwrap(); |
| 782 |
+ // let case = &data.as_array().unwrap()[idx]; |
| 783 |
+ // case.get("schema").unwrap().clone() |
| 784 |
+ //} |
| 785 |
|
| 786 |
#[test] |
| 787 |
fn only_keyword() { |
| 788 |
@@ -360,16 +360,16 @@ |
| 789 |
assert!(validator.validate(&value2).is_err()); |
| 790 |
} |
| 791 |
|
| 792 |
- #[test] |
| 793 |
- #[cfg(not(target_arch = "wasm32"))] |
| 794 |
- fn validate_ref() { |
| 795 |
- let schema = load("tests/suite/tests/draft7/ref.json", 1); |
| 796 |
- let value = json!({"bar": 3}); |
| 797 |
- let validator = crate::validator_for(&schema).unwrap(); |
| 798 |
- assert!(validator.validate(&value).is_ok()); |
| 799 |
- let value = json!({"bar": true}); |
| 800 |
- assert!(validator.validate(&value).is_err()); |
| 801 |
- } |
| 802 |
+ //disabled, file missing #[test] |
| 803 |
+ //#[cfg(not(target_arch = "wasm32"))] |
| 804 |
+ //fn validate_ref() { |
| 805 |
+ // let schema = load("tests/suite/tests/draft7/ref.json", 1); |
| 806 |
+ // let value = json!({"bar": 3}); |
| 807 |
+ // let validator = crate::validator_for(&schema).unwrap(); |
| 808 |
+ // assert!(validator.validate(&value).is_ok()); |
| 809 |
+ // let value = json!({"bar": true}); |
| 810 |
+ // assert!(validator.validate(&value).is_err()); |
| 811 |
+ //} |
| 812 |
|
| 813 |
#[test] |
| 814 |
fn wrong_schema_type() { |
| 815 |
Index: jsonschema/tests/output_suite.rs |
| 816 |
=================================================================== |
| 817 |
--- jsonschema.orig/tests/output_suite.rs 2026-06-14 18:53:15.107529614 -0400 |
| 818 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 819 |
@@ -1,181 +0,0 @@ |
| 820 |
-#![cfg(not(target_arch = "wasm32"))] |
| 821 |
- |
| 822 |
-use jsonschema::{validator_for, Draft, Evaluation, Retrieve, Uri, Validator}; |
| 823 |
-use serde_json::Value; |
| 824 |
-use std::sync::OnceLock; |
| 825 |
-use testsuite::{output_suite, OutputRemote, OutputTest}; |
| 826 |
- |
| 827 |
-#[output_suite( |
| 828 |
- path = "crates/jsonschema/tests/suite/output-tests", |
| 829 |
- drafts = [ |
| 830 |
- "v1" |
| 831 |
- ] |
| 832 |
-)] |
| 833 |
-fn output_suite(test: OutputTest) { |
| 834 |
- run_output_case(test); |
| 835 |
-} |
| 836 |
- |
| 837 |
-#[output_suite( |
| 838 |
- path = "crates/jsonschema/tests/output-extra", |
| 839 |
- drafts = [ |
| 840 |
- "v1-extra" |
| 841 |
- ] |
| 842 |
-)] |
| 843 |
-fn output_suite_extra(test: OutputTest) { |
| 844 |
- run_output_case(test); |
| 845 |
-} |
| 846 |
- |
| 847 |
-#[allow(clippy::print_stderr)] |
| 848 |
-fn run_output_case(test: OutputTest) { |
| 849 |
- let OutputTest { |
| 850 |
- version, |
| 851 |
- file, |
| 852 |
- schema, |
| 853 |
- case, |
| 854 |
- description, |
| 855 |
- data, |
| 856 |
- outputs, |
| 857 |
- remotes, |
| 858 |
- } = test; |
| 859 |
- |
| 860 |
- let prepared_schema = prepare_schema_for_version(&schema, version); |
| 861 |
- let validator = build_validator(&prepared_schema, version, file); |
| 862 |
- let evaluation = validator.evaluate(&data); |
| 863 |
- let retriever = output_schema_retriever(remotes); |
| 864 |
- |
| 865 |
- for expected in outputs { |
| 866 |
- let format = expected.format; |
| 867 |
- let schema = expected.schema; |
| 868 |
- let expected_schema = prepare_schema_for_version(&schema, version); |
| 869 |
- let actual_output = produce_output(&evaluation, format).unwrap_or_else(|| { |
| 870 |
- panic!( |
| 871 |
- "Output format `{format}` is not supported (file: {file}, case: `{case}`, test: `{description}`)" |
| 872 |
- ) |
| 873 |
- }); |
| 874 |
- validate_against_output_spec(&actual_output); |
| 875 |
- let mut options = jsonschema::options().with_retriever(retriever); |
| 876 |
- if let Some(draft) = version_draft_override(version) { |
| 877 |
- options = options.with_draft(draft); |
| 878 |
- } |
| 879 |
- let output_validator = options.build(&expected_schema).unwrap_or_else(|err| { |
| 880 |
- panic!("Invalid output schema for {file} format {format}: {err}") |
| 881 |
- }); |
| 882 |
- if let Err(error) = output_validator.validate(&actual_output) { |
| 883 |
- eprintln!("Output validation error: {error:?}"); |
| 884 |
- panic!( |
| 885 |
- "Output format `{format}` failed for {file} (case: `{case}`, test: `{description}`): {error}" |
| 886 |
- ); |
| 887 |
- } |
| 888 |
- } |
| 889 |
-} |
| 890 |
- |
| 891 |
-fn output_spec_validator() -> &'static Validator { |
| 892 |
- static VALIDATOR: OnceLock<Validator> = OnceLock::new(); |
| 893 |
- VALIDATOR.get_or_init(|| { |
| 894 |
- let mut schema: Value = serde_json::from_str(include_str!("output_spec_schema.json")) |
| 895 |
- .expect("output spec schema JSON is valid"); |
| 896 |
- if let Value::Object(ref mut map) = schema { |
| 897 |
- map.remove("$schema"); |
| 898 |
- } |
| 899 |
- validator_for(&schema).expect("output spec schema must be valid") |
| 900 |
- }) |
| 901 |
-} |
| 902 |
- |
| 903 |
-fn validate_against_output_spec(value: &Value) { |
| 904 |
- if let Err(error) = output_spec_validator().validate(value) { |
| 905 |
- panic!("Output does not match JSON Schema validation-output schema: {error}"); |
| 906 |
- } |
| 907 |
-} |
| 908 |
- |
| 909 |
-fn build_validator(schema: &Value, version: &str, file: &str) -> Validator { |
| 910 |
- match version_draft_override(version) { |
| 911 |
- Some(draft) => jsonschema::options() |
| 912 |
- .with_draft(draft) |
| 913 |
- .build(schema) |
| 914 |
- .unwrap_or_else(|err| panic!("Invalid schema in {file}: {err}")), |
| 915 |
- None => { |
| 916 |
- validator_for(schema).unwrap_or_else(|err| panic!("Invalid schema in {file}: {err}")) |
| 917 |
- } |
| 918 |
- } |
| 919 |
-} |
| 920 |
- |
| 921 |
-fn produce_output(evaluation: &Evaluation, format: &str) -> Option<Value> { |
| 922 |
- match format { |
| 923 |
- "flag" => { |
| 924 |
- let value = serde_json::to_value(evaluation.flag()).expect("flag output serializable"); |
| 925 |
- debug_output("flag", &value); |
| 926 |
- Some(value) |
| 927 |
- } |
| 928 |
- "list" => { |
| 929 |
- let value = serde_json::to_value(evaluation.list()).expect("list output serializable"); |
| 930 |
- debug_output("list", &value); |
| 931 |
- Some(value) |
| 932 |
- } |
| 933 |
- "hierarchical" => { |
| 934 |
- let value = serde_json::to_value(evaluation.hierarchical()) |
| 935 |
- .expect("hierarchical output serializable"); |
| 936 |
- debug_output("hierarchical", &value); |
| 937 |
- Some(value) |
| 938 |
- } |
| 939 |
- _ => None, |
| 940 |
- } |
| 941 |
-} |
| 942 |
- |
| 943 |
-// Prints serialized output when `JSONSCHEMA_DEBUG_OUTPUT` is set. |
| 944 |
-#[allow(clippy::print_stderr)] |
| 945 |
-fn debug_output(format: &str, value: &Value) { |
| 946 |
- if std::env::var("JSONSCHEMA_DEBUG_OUTPUT").is_ok() { |
| 947 |
- eprintln!( |
| 948 |
- "=== {format} ===\n{}", |
| 949 |
- serde_json::to_string_pretty(value).expect("output to stringify") |
| 950 |
- ); |
| 951 |
- } |
| 952 |
-} |
| 953 |
- |
| 954 |
-fn prepare_schema_for_version(schema: &Value, version: &str) -> Value { |
| 955 |
- if is_v1(version) { |
| 956 |
- if let Value::Object(mut map) = schema.clone() { |
| 957 |
- map.remove("$schema"); |
| 958 |
- map.into() |
| 959 |
- } else { |
| 960 |
- schema.clone() |
| 961 |
- } |
| 962 |
- } else { |
| 963 |
- schema.clone() |
| 964 |
- } |
| 965 |
-} |
| 966 |
- |
| 967 |
-fn version_draft_override(version: &str) -> Option<Draft> { |
| 968 |
- match version { |
| 969 |
- v if is_v1(v) => Some(Draft::Draft202012), |
| 970 |
- _ => None, |
| 971 |
- } |
| 972 |
-} |
| 973 |
- |
| 974 |
-fn is_v1(version: &str) -> bool { |
| 975 |
- version == "v1" || version.starts_with("v1-") |
| 976 |
-} |
| 977 |
- |
| 978 |
-fn output_schema_retriever(remotes: &'static [OutputRemote]) -> OutputSchemaRetriever { |
| 979 |
- OutputSchemaRetriever { documents: remotes } |
| 980 |
-} |
| 981 |
- |
| 982 |
-#[derive(Clone, Copy)] |
| 983 |
-struct OutputSchemaRetriever { |
| 984 |
- documents: &'static [OutputRemote], |
| 985 |
-} |
| 986 |
- |
| 987 |
-impl Retrieve for OutputSchemaRetriever { |
| 988 |
- fn retrieve( |
| 989 |
- &self, |
| 990 |
- uri: &Uri<String>, |
| 991 |
- ) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> { |
| 992 |
- self.documents |
| 993 |
- .iter() |
| 994 |
- .find(|doc| doc.uri == uri.as_str()) |
| 995 |
- .map(|doc| { |
| 996 |
- serde_json::from_str(doc.contents).expect("Output schema must be valid JSON") |
| 997 |
- }) |
| 998 |
- .ok_or_else(|| format!("Unknown output schema reference: {uri}").into()) |
| 999 |
- } |
| 1000 |
-} |
| 1001 |
Index: jsonschema/tests/suite.rs |
| 1002 |
=================================================================== |
| 1003 |
--- jsonschema.orig/tests/suite.rs 2026-06-14 18:53:15.107529614 -0400 |
| 1004 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 1005 |
@@ -1,249 +0,0 @@ |
| 1006 |
-#![allow(clippy::large_stack_arrays)] |
| 1007 |
- |
| 1008 |
-mod tests { |
| 1009 |
- use jsonschema::{Draft, PatternOptions}; |
| 1010 |
- #[cfg(not(target_arch = "wasm32"))] |
| 1011 |
- use std::env; |
| 1012 |
- #[cfg(not(target_arch = "wasm32"))] |
| 1013 |
- use std::fs; |
| 1014 |
- use testsuite::{suite, Test}; |
| 1015 |
- |
| 1016 |
- #[suite( |
| 1017 |
- path = "crates/jsonschema/tests/suite", |
| 1018 |
- drafts = [ |
| 1019 |
- "draft4", |
| 1020 |
- "draft6", |
| 1021 |
- "draft7", |
| 1022 |
- "draft2019-09", |
| 1023 |
- "draft2020-12", |
| 1024 |
- ], |
| 1025 |
- xfail = [ |
| 1026 |
- "draft4::optional::bignum::integer::a_bignum_is_an_integer", |
| 1027 |
- "draft4::optional::bignum::integer::a_negative_bignum_is_an_integer", |
| 1028 |
- ] |
| 1029 |
-)] |
| 1030 |
- fn test_suite(test: &Test) { |
| 1031 |
- enum RegexEngine { |
| 1032 |
- Regex, |
| 1033 |
- FancyRegex, |
| 1034 |
- } |
| 1035 |
- |
| 1036 |
- let mut options = jsonschema::options(); |
| 1037 |
- match test.draft { |
| 1038 |
- "draft4" => { |
| 1039 |
- options = options.with_draft(Draft::Draft4); |
| 1040 |
- } |
| 1041 |
- "draft6" => { |
| 1042 |
- options = options.with_draft(Draft::Draft6); |
| 1043 |
- } |
| 1044 |
- "draft7" => { |
| 1045 |
- options = options.with_draft(Draft::Draft7); |
| 1046 |
- } |
| 1047 |
- "draft2019-09" | "draft2020-12" => {} |
| 1048 |
- _ => panic!("Unsupported draft"), |
| 1049 |
- } |
| 1050 |
- if should_skip_draft(test.draft) { |
| 1051 |
- return; |
| 1052 |
- } |
| 1053 |
- if test.is_optional { |
| 1054 |
- options = options.should_validate_formats(true); |
| 1055 |
- } |
| 1056 |
- options = options.with_retriever(testsuite_retriever()); |
| 1057 |
- |
| 1058 |
- for engine in [RegexEngine::FancyRegex, RegexEngine::Regex] { |
| 1059 |
- match engine { |
| 1060 |
- RegexEngine::Regex => { |
| 1061 |
- options = options.with_pattern_options(PatternOptions::regex()); |
| 1062 |
- } |
| 1063 |
- RegexEngine::FancyRegex => { |
| 1064 |
- options = options.with_pattern_options(PatternOptions::fancy_regex()); |
| 1065 |
- } |
| 1066 |
- } |
| 1067 |
- let validator = options |
| 1068 |
- .build(&test.schema) |
| 1069 |
- .expect("Failed to build a schema"); |
| 1070 |
- |
| 1071 |
- if test.valid { |
| 1072 |
- if let Some(first) = validator.iter_errors(&test.data).next() { |
| 1073 |
- panic!( |
| 1074 |
- "Test case should not have validation errors:\nGroup: {}\nTest case: {}\nSchema: {}\nInstance: {}\nError: {first:?}", |
| 1075 |
- test.case, |
| 1076 |
- test.description, |
| 1077 |
- pretty_json(&test.schema), |
| 1078 |
- pretty_json(&test.data), |
| 1079 |
- ); |
| 1080 |
- } |
| 1081 |
- assert!( |
| 1082 |
- validator.is_valid(&test.data), |
| 1083 |
- "Test case should be valid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", |
| 1084 |
- test.case, |
| 1085 |
- test.description, |
| 1086 |
- pretty_json(&test.schema), |
| 1087 |
- pretty_json(&test.data), |
| 1088 |
- ); |
| 1089 |
- assert!( |
| 1090 |
- validator.validate(&test.data).is_ok(), |
| 1091 |
- "Test case should be valid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", |
| 1092 |
- test.case, |
| 1093 |
- test.description, |
| 1094 |
- pretty_json(&test.schema), |
| 1095 |
- pretty_json(&test.data), |
| 1096 |
- ); |
| 1097 |
- let evaluation = validator.evaluate(&test.data); |
| 1098 |
- assert!( |
| 1099 |
- evaluation.flag().valid, |
| 1100 |
- "Evaluation output should be valid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", |
| 1101 |
- test.case, |
| 1102 |
- test.description, |
| 1103 |
- pretty_json(&test.schema), |
| 1104 |
- pretty_json(&test.data), |
| 1105 |
- ); |
| 1106 |
- let _ = |
| 1107 |
- serde_json::to_value(evaluation.list()).expect("List output should serialize"); |
| 1108 |
- let _ = serde_json::to_value(evaluation.hierarchical()) |
| 1109 |
- .expect("Hierarchical output should serialize"); |
| 1110 |
- } else { |
| 1111 |
- let errors = validator.iter_errors(&test.data).collect::<Vec<_>>(); |
| 1112 |
- assert!( |
| 1113 |
- !errors.is_empty(), |
| 1114 |
- "Test case should have validation errors:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", |
| 1115 |
- test.case, |
| 1116 |
- test.description, |
| 1117 |
- pretty_json(&test.schema), |
| 1118 |
- pretty_json(&test.data), |
| 1119 |
- ); |
| 1120 |
- for error in errors { |
| 1121 |
- let pointer = error.instance_path().as_str(); |
| 1122 |
- assert_eq!( |
| 1123 |
- test.data.pointer(pointer), Some(error.instance().as_ref()), |
| 1124 |
- "Expected error instance did not match actual error instance:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}\nExpected pointer: {:#?}\nActual pointer: {:#?}", |
| 1125 |
- test.case, |
| 1126 |
- test.description, |
| 1127 |
- pretty_json(&test.schema), |
| 1128 |
- pretty_json(&test.data), |
| 1129 |
- error.instance().as_ref(), |
| 1130 |
- &pointer, |
| 1131 |
- ); |
| 1132 |
- } |
| 1133 |
- assert!( |
| 1134 |
- !validator.is_valid(&test.data), |
| 1135 |
- "Test case should be invalid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", |
| 1136 |
- test.case, |
| 1137 |
- test.description, |
| 1138 |
- pretty_json(&test.schema), |
| 1139 |
- pretty_json(&test.data), |
| 1140 |
- ); |
| 1141 |
- let Some(error) = validator.validate(&test.data).err() else { |
| 1142 |
- panic!( |
| 1143 |
- "Test case should be invalid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", |
| 1144 |
- test.case, |
| 1145 |
- test.description, |
| 1146 |
- pretty_json(&test.schema), |
| 1147 |
- pretty_json(&test.data), |
| 1148 |
- ); |
| 1149 |
- }; |
| 1150 |
- let pointer = error.instance_path().as_str(); |
| 1151 |
- assert_eq!( |
| 1152 |
- test.data.pointer(pointer), Some(error.instance().as_ref()), |
| 1153 |
- "Expected error instance did not match actual error instance:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}\nExpected pointer: {:#?}\nActual pointer: {:#?}", |
| 1154 |
- test.case, |
| 1155 |
- test.description, |
| 1156 |
- pretty_json(&test.schema), |
| 1157 |
- pretty_json(&test.data), |
| 1158 |
- error.instance().as_ref(), |
| 1159 |
- &pointer, |
| 1160 |
- ); |
| 1161 |
- let evaluation = validator.evaluate(&test.data); |
| 1162 |
- assert!( |
| 1163 |
- !evaluation.flag().valid, |
| 1164 |
- "Evaluation output should be invalid:\nCase: {}\nTest: {}\nSchema: {}\nInstance: {}", |
| 1165 |
- test.case, |
| 1166 |
- test.description, |
| 1167 |
- pretty_json(&test.schema), |
| 1168 |
- pretty_json(&test.data), |
| 1169 |
- ); |
| 1170 |
- let _ = |
| 1171 |
- serde_json::to_value(evaluation.list()).expect("List output should serialize"); |
| 1172 |
- let _ = serde_json::to_value(evaluation.hierarchical()) |
| 1173 |
- .expect("Hierarchical output should serialize"); |
| 1174 |
- } |
| 1175 |
- } |
| 1176 |
- } |
| 1177 |
- |
| 1178 |
- fn pretty_json(v: &serde_json::Value) -> String { |
| 1179 |
- serde_json::to_string_pretty(v).expect("Failed to format JSON") |
| 1180 |
- } |
| 1181 |
- |
| 1182 |
- #[cfg(not(target_arch = "wasm32"))] |
| 1183 |
- #[test] |
| 1184 |
- fn test_instance_path() { |
| 1185 |
- let expectations: serde_json::Value = |
| 1186 |
- serde_json::from_str(include_str!("draft7_instance_paths.json")).expect("Valid JSON"); |
| 1187 |
- for (filename, expected) in expectations.as_object().expect("Is object") { |
| 1188 |
- let test_file = fs::read_to_string(format!("tests/suite/tests/draft7/{filename}")) |
| 1189 |
- .unwrap_or_else(|_| panic!("Valid file: {filename}")); |
| 1190 |
- let data: serde_json::Value = serde_json::from_str(&test_file).expect("Valid JSON"); |
| 1191 |
- for item in expected.as_array().expect("Is array") { |
| 1192 |
- let suite_id = usize::try_from(item["suite_id"].as_u64().expect("Is integer")) |
| 1193 |
- .expect("suite_id fits in usize"); |
| 1194 |
- let schema = &data[suite_id]["schema"]; |
| 1195 |
- let validator = jsonschema::options() |
| 1196 |
- .with_draft(Draft::Draft7) |
| 1197 |
- .with_retriever(testsuite_retriever()) |
| 1198 |
- .build(schema) |
| 1199 |
- .unwrap_or_else(|_| { |
| 1200 |
- panic!( |
| 1201 |
- "Valid schema. File: {filename}; Suite ID: {suite_id}; Schema: {schema}", |
| 1202 |
- ) |
| 1203 |
- }); |
| 1204 |
- for test_data in item["tests"].as_array().expect("Valid array") { |
| 1205 |
- let test_id = usize::try_from(test_data["id"].as_u64().expect("Is integer")) |
| 1206 |
- .expect("test_id fits in usize"); |
| 1207 |
- let mut instance_path = String::new(); |
| 1208 |
- |
| 1209 |
- for segment in test_data["instance_path"].as_array().expect("Valid array") { |
| 1210 |
- instance_path.push('/'); |
| 1211 |
- instance_path.push_str(segment.as_str().expect("A string")); |
| 1212 |
- } |
| 1213 |
- let instance = &data[suite_id]["tests"][test_id]["data"]; |
| 1214 |
- let error = validator.validate(instance).expect_err(&format!( |
| 1215 |
- "\nFile: {}\nSuite: {}\nTest: {}", |
| 1216 |
- filename, |
| 1217 |
- &data[suite_id]["description"], |
| 1218 |
- &data[suite_id]["tests"][test_id]["description"], |
| 1219 |
- )); |
| 1220 |
- assert_eq!( |
| 1221 |
- error.instance_path().as_str(), |
| 1222 |
- instance_path, |
| 1223 |
- "\nFile: {}\nSuite: {}\nTest: {}\nError: {}", |
| 1224 |
- filename, |
| 1225 |
- &data[suite_id]["description"], |
| 1226 |
- &data[suite_id]["tests"][test_id]["description"], |
| 1227 |
- &error |
| 1228 |
- ); |
| 1229 |
- } |
| 1230 |
- } |
| 1231 |
- } |
| 1232 |
- } |
| 1233 |
- |
| 1234 |
- fn should_skip_draft(draft: &str) -> bool { |
| 1235 |
- if let Some(filter) = allowed_draft_filter() { |
| 1236 |
- for entry in filter.split(',') { |
| 1237 |
- if entry.trim().eq_ignore_ascii_case(draft) { |
| 1238 |
- return false; |
| 1239 |
- } |
| 1240 |
- } |
| 1241 |
- true |
| 1242 |
- } else { |
| 1243 |
- false |
| 1244 |
- } |
| 1245 |
- } |
| 1246 |
- |
| 1247 |
- fn allowed_draft_filter() -> Option<String> { |
| 1248 |
- #[cfg(not(target_arch = "wasm32"))] |
| 1249 |
- if let Ok(value) = env::var("JSONSCHEMA_SUITE_DRAFT_FILTER") { |
| 1250 |
- return Some(value); |
| 1251 |
- } |
| 1252 |
- option_env!("JSONSCHEMA_SUITE_DRAFT_FILTER").map(str::to_string) |
| 1253 |
- } |
| 1254 |
-} |