iop_coeus_node/policy/subtree/
schema.rs1use super::*;
2
3impl SubtreePolicy for SchemaPolicy {
4 fn validate(
5 &self, _state: &State, policy_domain: &Domain, domain_after_op: &Domain,
6 ) -> Result<()> {
7 let mut scope = json_schema::Scope::new();
8 let schema = scope
9 .compile_and_return(self.schema.clone(), true)
10 .with_context(|| format!("Domain {} has invalid schema", policy_domain.name()))?;
11 let validation_state = schema.validate(domain_after_op.data());
12 ensure!(
13 validation_state.is_strictly_valid(),
14 "Domain {} data does not match schema of {}",
15 domain_after_op.name(),
16 policy_domain.name(),
17 );
18 Ok(())
19 }
20}