validator refactor progress

This commit is contained in:
2026-03-03 00:13:37 -05:00
parent e14f53e7d9
commit 3898c43742
81 changed files with 6331 additions and 7934 deletions

View File

@ -0,0 +1,83 @@
use crate::validator::context::ValidationContext;
use crate::validator::error::ValidationError;
use crate::validator::result::ValidationResult;
impl<'a> ValidationContext<'a> {
pub(crate) fn validate_combinators(
&self,
result: &mut ValidationResult,
) -> Result<bool, ValidationError> {
if let Some(ref all_of) = self.schema.all_of {
for sub in all_of {
let derived = self.derive_for_schema(sub, true);
let res = derived.validate()?;
result.merge(res);
}
}
if let Some(ref any_of) = self.schema.any_of {
let mut valid = false;
for sub in any_of {
let derived = self.derive_for_schema(sub, true);
let sub_res = derived.validate()?;
if sub_res.is_valid() {
valid = true;
result.merge(sub_res);
}
}
if !valid {
result.errors.push(ValidationError {
code: "ANY_OF_VIOLATED".to_string(),
message: "Matches none of anyOf schemas".to_string(),
path: self.path.to_string(),
});
}
}
if let Some(ref one_of) = self.schema.one_of {
let mut valid_count = 0;
let mut valid_res = ValidationResult::new();
for sub in one_of {
let derived = self.derive_for_schema(sub, true);
let sub_res = derived.validate()?;
if sub_res.is_valid() {
valid_count += 1;
valid_res = sub_res;
}
}
if valid_count == 1 {
result.merge(valid_res);
} else if valid_count == 0 {
result.errors.push(ValidationError {
code: "ONE_OF_VIOLATED".to_string(),
message: "Matches none of oneOf schemas".to_string(),
path: self.path.to_string(),
});
} else {
result.errors.push(ValidationError {
code: "ONE_OF_VIOLATED".to_string(),
message: format!("Matches {} of oneOf schemas (expected 1)", valid_count),
path: self.path.to_string(),
});
}
}
if let Some(ref not_schema) = self.schema.not {
let derived = self.derive_for_schema(not_schema, true);
let sub_res = derived.validate()?;
if sub_res.is_valid() {
result.errors.push(ValidationError {
code: "NOT_VIOLATED".to_string(),
message: "Matched 'not' schema".to_string(),
path: self.path.to_string(),
});
}
}
Ok(true)
}
}