bringing back type constants for validation via new overrides vocabulary
This commit is contained in:
@ -1,9 +1,13 @@
|
||||
use std::{borrow::Cow, cmp::min, collections::HashSet, fmt::Write};
|
||||
|
||||
use ahash::AHashSet;
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use crate::{util::*, *};
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
struct Override<'s>(AHashSet<&'s str>);
|
||||
|
||||
macro_rules! prop {
|
||||
($prop:expr) => {
|
||||
InstanceToken::Prop(Cow::Borrowed($prop))
|
||||
@ -37,6 +41,7 @@ pub(crate) fn validate<'s, 'v>(
|
||||
schemas,
|
||||
scope,
|
||||
options,
|
||||
overrides: Override::default(), // Start with an empty override context
|
||||
uneval: Uneval::from(v, schema, options.be_strict),
|
||||
errors: vec![],
|
||||
bool_result: false,
|
||||
@ -90,6 +95,7 @@ struct Validator<'v, 's, 'd, 'e> {
|
||||
schemas: &'s Schemas,
|
||||
scope: Scope<'d>,
|
||||
options: ValidationOptions,
|
||||
overrides: Override<'s>,
|
||||
uneval: Uneval<'v>,
|
||||
errors: Vec<ValidationError<'s, 'v>>,
|
||||
bool_result: bool, // is interested to know valid or not (but not actuall error)
|
||||
@ -190,7 +196,7 @@ impl<'v, 's> Validator<'v, 's, '_, '_> {
|
||||
}
|
||||
|
||||
// type specific validations
|
||||
impl<'v> Validator<'v, '_, '_, '_> {
|
||||
impl<'v> Validator<'v, '_, '_,'_> {
|
||||
fn obj_validate(&mut self, obj: &'v Map<String, Value>) {
|
||||
let s = self.schema;
|
||||
macro_rules! add_err {
|
||||
@ -244,6 +250,11 @@ impl<'v> Validator<'v, '_, '_, '_> {
|
||||
|
||||
let mut additional_props = vec![];
|
||||
for (pname, pvalue) in obj {
|
||||
if self.overrides.0.contains(pname.as_str()) {
|
||||
self.uneval.props.remove(pname);
|
||||
continue;
|
||||
}
|
||||
|
||||
if self.bool_result && !self.errors.is_empty() {
|
||||
return;
|
||||
}
|
||||
@ -835,6 +846,11 @@ impl<'v, 's> Validator<'v, 's, '_, '_> {
|
||||
new_options.be_strict = false;
|
||||
}
|
||||
|
||||
let mut overrides = Override::default();
|
||||
for pname in &schema.override_properties {
|
||||
overrides.0.insert(pname.as_str());
|
||||
}
|
||||
|
||||
let (result, _reply) = Validator {
|
||||
v,
|
||||
vloc: self.vloc,
|
||||
@ -842,6 +858,7 @@ impl<'v, 's> Validator<'v, 's, '_, '_> {
|
||||
schemas: self.schemas,
|
||||
scope,
|
||||
options: new_options,
|
||||
overrides,
|
||||
uneval: Uneval::from(v, schema, new_options.be_strict || !self.uneval.is_empty()),
|
||||
errors: vec![],
|
||||
bool_result: self.bool_result,
|
||||
@ -872,6 +889,11 @@ impl<'v, 's> Validator<'v, 's, '_, '_> {
|
||||
new_options.be_strict = false;
|
||||
}
|
||||
|
||||
let mut overrides = self.overrides.clone();
|
||||
for pname in &self.schema.override_properties {
|
||||
overrides.0.insert(pname.as_str());
|
||||
}
|
||||
|
||||
let (result, reply) = Validator {
|
||||
v: self.v,
|
||||
vloc: self.vloc,
|
||||
@ -879,6 +901,7 @@ impl<'v, 's> Validator<'v, 's, '_, '_> {
|
||||
schemas: self.schemas,
|
||||
scope,
|
||||
options: new_options,
|
||||
overrides,
|
||||
uneval: self.uneval.clone(),
|
||||
errors: vec![],
|
||||
bool_result: self.bool_result || bool_result,
|
||||
|
||||
Reference in New Issue
Block a user