Skip to main content

valico/json_schema/keywords/
not.rs

1use serde_json::Value;
2
3use super::super::helpers;
4use super::super::schema;
5use super::super::validators;
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() || not.is_boolean() {
14            Ok(Some(Box::new(validators::Not {
15                url: helpers::alter_fragment_path(
16                    ctx.url.clone(),
17                    [ctx.escaped_fragment().as_ref(), "not"].join("/"),
18                ),
19            })))
20        } else {
21            Err(schema::SchemaError::Malformed {
22                path: ctx.fragment.join("/"),
23                detail: "The value of `not` MUST be an object or a boolean".to_string(),
24            })
25        }
26    }
27}