valico/json_schema/validators/
not.rs1use serde_json::Value;
2
3use super::super::errors;
4use super::super::scope;
5
6#[allow(missing_copy_implementations)]
7pub struct Not {
8 pub url: url::Url,
9}
10
11impl super::Validator for Not {
12 fn validate(
13 &self,
14 val: &Value,
15 path: &str,
16 scope: &scope::Scope,
17 _: &super::ValidationState,
18 ) -> super::ValidationState {
19 let schema = scope.resolve(&self.url);
20 let mut state = super::ValidationState::new();
21
22 if let Some(schema) = schema {
23 if schema.validate_in(val, path).is_valid() {
24 state.errors.push(Box::new(errors::Not {
25 path: path.to_string(),
26 }))
27 }
28 } else {
29 state.missing.push(self.url.clone());
30 }
31
32 state
33 }
34}