Skip to content

Commit

Permalink
chore: Update jsonschema to 0.20.0
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <dmitry.dygalo@workato.com>
  • Loading branch information
Stranger6667 committed Sep 20, 2024
1 parent a479e6c commit 57b73b0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 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.19.0", default-features = false }
jsonschema = { version = "0.20", default-features = false }
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
28 changes: 14 additions & 14 deletions schemars/tests/integration/test_helper.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use jsonschema::JSONSchema as CompiledSchema;
use jsonschema::Validator;
use schemars::{
generate::{Contract, SchemaSettings},
JsonSchema, Schema,
Expand All @@ -17,8 +17,8 @@ pub struct TestHelper<T: JsonSchema> {
phantom: PhantomData<T>,
de_schema: Schema,
ser_schema: Schema,
de_schema_compiled: OnceCell<CompiledSchema>,
ser_schema_compiled: OnceCell<CompiledSchema>,
de_schema_validator: OnceCell<Validator>,
ser_schema_validator: OnceCell<Validator>,
validator: fn(&T) -> bool,
}

Expand All @@ -33,8 +33,8 @@ impl<T: JsonSchema> TestHelper<T> {
phantom: PhantomData,
de_schema,
ser_schema,
de_schema_compiled: OnceCell::new(),
ser_schema_compiled: OnceCell::new(),
de_schema_validator: OnceCell::new(),
ser_schema_validator: OnceCell::new(),
validator: |_| true,
}
}
Expand All @@ -52,8 +52,8 @@ impl<T: JsonSchema> TestHelper<T> {
phantom: PhantomData,
de_schema,
ser_schema,
de_schema_compiled: OnceCell::new(),
ser_schema_compiled: OnceCell::new(),
de_schema_validator: OnceCell::new(),
ser_schema_validator: OnceCell::new(),
validator: |_| true,
}
}
Expand Down Expand Up @@ -137,22 +137,22 @@ 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))
self.de_schema_validator
.get_or_init(|| build_validator(&self.de_schema))
.is_valid(instance)
}

fn ser_schema_validate(&self, instance: &Value) -> bool {
self.ser_schema_compiled
.get_or_init(|| compile_schema(&self.ser_schema))
self.ser_schema_validator
.get_or_init(|| build_validator(&self.ser_schema))
.is_valid(instance)
}
}

fn compile_schema(schema: &Schema) -> CompiledSchema {
CompiledSchema::options()
fn build_validator(schema: &Schema) -> Validator {
jsonschema::options()
.should_validate_formats(true)
.compile(schema.as_value())
.build(schema.as_value())
.expect("valid schema")
}

Expand Down

0 comments on commit 57b73b0

Please sign in to comment.