valico/json_schema/keywords/
not.rs
1use serde_json::{Value};
2
3use super::super::schema;
4use super::super::validators;
5use super::super::helpers;
6
7#[allow(missing_copy_implementations)]
8pub struct Not;
9impl super::Keyword for Not {
10 fn compile(&self, def: &Value, ctx: &schema::WalkContext) -> super::KeywordResult {
11 let not = keyword_key_exists!(def, "not");
12
13 if not.is_object() {
14 Ok(Some(Box::new(validators::Not {
15 url: helpers::alter_fragment_path(ctx.url.clone(), [
16 ctx.escaped_fragment().as_ref(),
17 "not"
18 ].join("/"))
19 })))
20 } else {
21 Err(schema::SchemaError::Malformed {
22 path: ctx.fragment.join("/"),
23 detail: "The value of `not` MUST be an object".to_string()
24 })
25 }
26 }
27}