Skip to content

Commit

Permalink
Update jsonschema
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Sep 11, 2024
1 parent 7310b48 commit 6ec61e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 6 additions & 17 deletions schemars/tests/integration/test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,36 +128,25 @@ impl<T: JsonSchema> TestHelper<T> {
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()
}

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<T: JsonSchema + Serialize + for<'de> Deserialize<'de>> TestHelper<T> {
Expand Down

0 comments on commit 6ec61e8

Please sign in to comment.