85 lines
2.1 KiB
Rust
85 lines
2.1 KiB
Rust
use crate::validator::context::ValidationContext;
|
|
use crate::validator::error::ValidationError;
|
|
use crate::validator::result::ValidationResult;
|
|
|
|
pub mod array;
|
|
pub mod cases;
|
|
pub mod core;
|
|
pub mod extensible;
|
|
pub mod format;
|
|
pub mod not;
|
|
pub mod numeric;
|
|
pub mod object;
|
|
pub mod polymorphism;
|
|
pub mod string;
|
|
pub mod util;
|
|
|
|
impl<'a> ValidationContext<'a> {
|
|
pub(crate) fn validate_scoped(&self) -> Result<ValidationResult, ValidationError> {
|
|
let mut result = ValidationResult::new();
|
|
|
|
// Structural Limits
|
|
if !self.validate_depth(&mut result)? {
|
|
return Ok(result);
|
|
}
|
|
if !self.validate_always_fail(&mut result)? {
|
|
return Ok(result);
|
|
}
|
|
if !self.validate_family(&mut result)? {
|
|
return Ok(result);
|
|
}
|
|
if !self.validate_type_inheritance(&mut result)? {
|
|
return Ok(result);
|
|
}
|
|
|
|
// Core Type Constraints
|
|
self.validate_core(&mut result)?;
|
|
self.validate_numeric(&mut result)?;
|
|
self.validate_string(&mut result)?;
|
|
self.validate_format(&mut result)?;
|
|
|
|
// Complex Structures
|
|
self.validate_object(&mut result)?;
|
|
self.validate_array(&mut result)?;
|
|
|
|
// Multipliers & Conditionals
|
|
if !self.validate_one_of(&mut result)? {
|
|
return Ok(result);
|
|
}
|
|
self.validate_not(&mut result)?;
|
|
self.validate_cases(&mut result)?;
|
|
|
|
// State Tracking
|
|
self.validate_extensible(&mut result)?;
|
|
self.validate_strictness(&mut result)?;
|
|
|
|
Ok(result)
|
|
}
|
|
|
|
fn validate_depth(&self, _result: &mut ValidationResult) -> Result<bool, ValidationError> {
|
|
if self.depth > 100 {
|
|
Err(ValidationError {
|
|
code: "RECURSION_LIMIT_EXCEEDED".to_string(),
|
|
message: "Recursion limit exceeded".to_string(),
|
|
path: self.path.to_string(),
|
|
})
|
|
} else {
|
|
Ok(true)
|
|
}
|
|
}
|
|
|
|
fn validate_always_fail(&self, result: &mut ValidationResult) -> Result<bool, ValidationError> {
|
|
if self.schema.always_fail {
|
|
result.errors.push(ValidationError {
|
|
code: "FALSE_SCHEMA".to_string(),
|
|
message: "Schema is false".to_string(),
|
|
path: self.path.to_string(),
|
|
});
|
|
// Short-circuit
|
|
Ok(false)
|
|
} else {
|
|
Ok(true)
|
|
}
|
|
}
|
|
}
|