use serde_json::Value;
use crate::Error;
pub(crate) fn compile(schema: &Value) -> Result<jsonschema::Validator, Error> {
jsonschema::meta::validate(schema).map_err(|error| {
Error::new("INVALID_SCHEMA", "node I/O schema is invalid").with_details(error.to_string())
})?;
jsonschema::options()
.should_validate_formats(true)
.build(schema)
.map_err(|error| {
Error::new("INVALID_SCHEMA", "node I/O schema cannot be compiled")
.with_details(error.to_string())
})
}
pub(crate) fn validate(
validator: &jsonschema::Validator,
value: &Value,
code: &str,
message: &str,
) -> Result<(), Error> {
validator
.validate(value)
.map_err(|error| Error::new(code, message).with_details(error.to_string()))
}