pub fn validator_map_for(
schema: &Value,
) -> Result<ValidatorMap, ValidationError<'static>>Expand description
Create a ValidatorMap from the input schema using automatic draft detection and
default options.
Every reachable subschema is compiled eagerly. The root schema is always present
under the key "#". Subschemas that fail to compile (e.g. unresolvable $ref) are
silently omitted.
§Examples
use serde_json::json;
let schema = json!({
"$defs": {
"User": {"type": "object", "required": ["name"]}
}
});
let map = jsonschema::validator_map_for(&schema)?;
let user_validator = map.get("#/$defs/User").unwrap();
assert!(user_validator.is_valid(&json!({"name": "Alice"})));
assert!(!user_validator.is_valid(&json!({})));§Errors
Returns an error if the schema is invalid or external references cannot be resolved.
§Panics
This function must not be called from within an async runtime if the schema contains
external references that require network requests, or it will panic when attempting to block.
Use async_validator_map_for for async contexts, or run this in a separate blocking thread
via tokio::task::spawn_blocking.