In version 0.35.0, schemas with custom or unknown $schema URIs require their meta-schema to be explicitly registered using a Registry before you can build a validator.
Custom meta-schemas automatically inherit the draft-specific behavior of their underlying draft by walking the meta-schema chain. To override this behavior and explicitly set a draft version, use .with_draft() in your ValidationOptions.
use jsonschema::{Registry, Resource, Draft};
let meta_schema = json!({
"$id": "http://example.com/custom",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$vocabulary": {
"https://json-schema.org/draft/2020-12/vocab/core": true,
"https://json-schema.org/draft/2020-12/vocab/validation": true,
}
});
let registry = Registry::try_from_resources(
[("http://example.com/custom", Resource::from_contents(meta_schema))]
)?;
let validator = jsonschema::options()
.with_registry(registry)
.build(&schema)?;