Skip to content
3 changes: 3 additions & 0 deletions crates/jsonschema-referencing/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ impl Registry {
Err(Error::no_such_anchor(name.to_string()))
}
}
pub fn get_document(&self, uri: &Uri<String>) -> Option<&Value> {
self.documents.get(uri).map(|v| (**v).as_ref())
}
/// Resolves a reference URI against a base URI using registry's cache.
///
/// # Errors
Expand Down
63 changes: 62 additions & 1 deletion crates/jsonschema/benches/jsonschema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,66 @@ fn run_benchmarks(c: &mut Criterion) {
}
}

criterion_group!(jsonschema, run_benchmarks);
fn bench_is_valid2(c: &mut Criterion) {
// let schema = serde_json::json!({"properties": {"name": {"maxLength": 5}}});

let schema = serde_json::json!({
"properties": {
"name": {
"$ref": "#/$defs/Name"
}
},
"$defs": {
"Name": {
"maxLength": 5
}
}
});
let schema = serde_json::json!({
"properties": {
"name": {"maxLength": 3},
"child": {"$ref": "#"}
}
});
let config = jsonschema::options();
let validator2 = jsonschema::compiler_v2::build(config, &schema);
let validator = jsonschema::validator_for(&schema).expect("Valid schema");
c.bench_function("new_is_valid", |b| {
// let instance = serde_json::json!({"name": "abc"});
let instance = serde_json::json!({
"name": "Bob",
"child": {
"name": "Ann",
"child": {
"name": "Joe",
"child": {
"name": "Sam",
"child": {
"name": "Max",
"child": {
"name": "Eve",
"child": {
"name": "Roy",
"child": {
"name": "Zoe",
"child": {
"name": "Leo",
"child": {
"name": "Amy"
}
}
}
}
}
}
}
}
}
});
b.iter(|| {
let _ = validator2.is_valid(&instance);
})
});
}
criterion_group!(jsonschema, run_benchmarks, bench_is_valid2);
criterion_main!(jsonschema);
4 changes: 3 additions & 1 deletion crates/jsonschema/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pub(crate) fn build_validator(
)
};
let vocabularies = registry.find_vocabularies(draft, schema);
let resolver = Rc::new(registry.resolver(base_uri));
let resolver = Rc::new(registry.resolver(base_uri.clone()));

let config = Arc::new(config);
let ctx = Context::new(
Expand All @@ -286,6 +286,8 @@ pub(crate) fn build_validator(
validate_schema(draft, schema)?;
}

// crate::ir::build(base_uri, draft, &registry);

// Finally, compile the validator
let root = compile(&ctx, resource_ref).map_err(|err| err.to_owned())?;
Ok(Validator { root, config })
Expand Down
Loading
Loading