From 6ec61e831d2c9a482fc462b6a6eb18f5d931e846 Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Wed, 11 Sep 2024 12:51:29 +0100 Subject: [PATCH] Update jsonschema --- Cargo.lock | 4 ++-- schemars/Cargo.toml | 2 +- schemars/tests/integration/test_helper.rs | 23 ++++++----------------- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eda127bc..82b84cf4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -368,9 +368,9 @@ dependencies = [ [[package]] name = "jsonschema" -version = "0.18.1" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5f037c58cadb17e8591b620b523cc6a7ab2b91b6ce3121f8eb4171f8d80115c" +checksum = "aa6bbf317803d2832b013425c11c67c38accba75a13653b0e64a8d31f5592f4a" dependencies = [ "ahash", "anyhow", diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index 64efb1a3..1fcb99b9 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -37,7 +37,7 @@ uuid1 = { version = "1.0", default-features = false, optional = true, package = pretty_assertions = "1.2.1" trybuild = "1.0" serde = { version = "1.0", features = ["derive"] } -jsonschema = { version = "0.18.1", default-features = false, features = ["draft201909", "draft202012"] } +jsonschema = { version = "0.18.2", default-features = false, features = ["draft201909", "draft202012"] } snapbox = { version = "0.6.17", features = ["json"] } serde_repr = "0.1.19" # Use github source until published garde version supports `length(equal = ...)` attr diff --git a/schemars/tests/integration/test_helper.rs b/schemars/tests/integration/test_helper.rs index 88d4aba7..92272c43 100644 --- a/schemars/tests/integration/test_helper.rs +++ b/schemars/tests/integration/test_helper.rs @@ -128,7 +128,7 @@ impl TestHelper { fn de_schema_validate(&self, instance: &Value) -> bool { self.de_schema_compiled .get_or_init(|| compile_schema(&self.de_schema)) - // Can't use `.validate(instance)` due to https://github.com/Stranger6667/jsonschema-rs/issues/496 + // Can't use `.is_valid(instance)` due to https://github.com/Stranger6667/jsonschema-rs/issues/496 .validate(instance) .is_ok() } @@ -136,28 +136,17 @@ impl TestHelper { fn ser_schema_validate(&self, instance: &Value) -> bool { self.ser_schema_compiled .get_or_init(|| compile_schema(&self.ser_schema)) - // Can't use `.validate(instance)` due to https://github.com/Stranger6667/jsonschema-rs/issues/496 + // Can't use `.is_valid(instance)` due to https://github.com/Stranger6667/jsonschema-rs/issues/496 .validate(instance) .is_ok() } } fn compile_schema(schema: &Schema) -> CompiledSchema { - use jsonschema::Draft; - - let meta_schema = schema.get("$schema").and_then(Value::as_str).unwrap_or(""); - let mut options = CompiledSchema::options(); - options.should_validate_formats(true); - - if meta_schema.contains("draft-07") { - options.with_draft(Draft::Draft7); - } else if meta_schema.contains("2019-09") { - options.with_draft(Draft::Draft201909); - } else if meta_schema.contains("2020-12") { - options.with_draft(Draft::Draft202012); - }; - - options.compile(schema.as_value()).expect("valid schema") + CompiledSchema::options() + .should_validate_formats(true) + .compile(schema.as_value()) + .expect("valid schema") } impl Deserialize<'de>> TestHelper {