significantly simplified the validator and work continues on query
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
use serde_json::Value;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::validator::context::ValidationContext;
|
||||
use crate::validator::error::ValidationError;
|
||||
@ -13,7 +12,7 @@ impl<'a> ValidationContext<'a> {
|
||||
let current = self.instance;
|
||||
if let Some(obj) = current.as_object() {
|
||||
// Entity Bound Implicit Type Validation
|
||||
if let Some(allowed_types) = &self.schema.obj.compiled_allowed_types {
|
||||
if let Some(allowed_types) = &self.schema.obj.compiled_variations {
|
||||
if let Some(type_val) = obj.get("type") {
|
||||
if let Some(type_str) = type_val.as_str() {
|
||||
if allowed_types.contains(type_str) {
|
||||
@ -62,8 +61,38 @@ impl<'a> ValidationContext<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ref deps) = self.schema.dependencies {
|
||||
for (prop, dep) in deps {
|
||||
if obj.contains_key(prop) {
|
||||
match dep {
|
||||
crate::database::schema::Dependency::Props(required_props) => {
|
||||
for req_prop in required_props {
|
||||
if !obj.contains_key(req_prop) {
|
||||
result.errors.push(ValidationError {
|
||||
code: "DEPENDENCY_MISSING".to_string(),
|
||||
message: format!("Property '{}' requires property '{}'", prop, req_prop),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
crate::database::schema::Dependency::Schema(dep_schema) => {
|
||||
let derived = self.derive_for_schema(dep_schema, false);
|
||||
let dep_res = derived.validate()?;
|
||||
result.evaluated_keys.extend(dep_res.evaluated_keys.clone());
|
||||
result.merge(dep_res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(props) = &self.schema.properties {
|
||||
for (key, sub_schema) in props {
|
||||
if self.overrides.contains(key) {
|
||||
continue; // Skip validation if exactly this property was overridden by a child
|
||||
}
|
||||
|
||||
if let Some(child_instance) = obj.get(key) {
|
||||
let new_path = format!("{}/{}", self.path, key);
|
||||
let is_ref = sub_schema.ref_string.is_some() || sub_schema.obj.compiled_ref.is_some();
|
||||
@ -73,6 +102,7 @@ impl<'a> ValidationContext<'a> {
|
||||
sub_schema,
|
||||
child_instance,
|
||||
&new_path,
|
||||
std::collections::HashSet::new(),
|
||||
next_extensible,
|
||||
false,
|
||||
);
|
||||
@ -80,7 +110,7 @@ impl<'a> ValidationContext<'a> {
|
||||
|
||||
// Entity Bound Implicit Type Interception
|
||||
if key == "type" {
|
||||
if let Some(allowed_types) = &self.schema.obj.compiled_allowed_types {
|
||||
if let Some(allowed_types) = &self.schema.obj.compiled_variations {
|
||||
if let Some(instance_type) = child_instance.as_str() {
|
||||
if allowed_types.contains(instance_type) {
|
||||
item_res
|
||||
@ -109,6 +139,7 @@ impl<'a> ValidationContext<'a> {
|
||||
sub_schema,
|
||||
child_instance,
|
||||
&new_path,
|
||||
std::collections::HashSet::new(),
|
||||
next_extensible,
|
||||
false,
|
||||
);
|
||||
@ -149,6 +180,7 @@ impl<'a> ValidationContext<'a> {
|
||||
additional_schema,
|
||||
child_instance,
|
||||
&new_path,
|
||||
std::collections::HashSet::new(),
|
||||
next_extensible,
|
||||
false,
|
||||
);
|
||||
@ -169,6 +201,7 @@ impl<'a> ValidationContext<'a> {
|
||||
self.root,
|
||||
property_names,
|
||||
&val_str,
|
||||
std::collections::HashSet::new(),
|
||||
self.extensible,
|
||||
self.reporter,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user