jspg error refactoring checkpoint

This commit is contained in:
2026-06-23 17:03:27 -04:00
parent fb25224d22
commit d77765cb61
25 changed files with 362 additions and 218 deletions

View File

@ -1,4 +1,4 @@
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};
use serde_json::Value;
@ -38,10 +38,9 @@ impl<'a> ValidationContext<'a> {
} else {
result.errors.push(ValidationError {
code: "CONST_VIOLATED".to_string(), // Aligning with original const override errors natively
message: format!(
"Type '{}' is not a valid descendant for this entity bound schema",
type_str
),
values: Some(HashMap::from([
("value".to_string(), type_str.to_string()),
])),
path: self.join_path("type"),
});
}
@ -50,10 +49,9 @@ impl<'a> ValidationContext<'a> {
// Because it's a global entity target, the payload must structurally provide a discriminator natively
result.errors.push(ValidationError {
code: "MISSING_TYPE".to_string(),
message: format!(
"Schema mechanically requires type discrimination '{}'",
expected_type
),
values: Some(HashMap::from([
("expected".to_string(), expected_type.to_string()),
])),
path: self.path.clone(), // Empty boundary
});
}
@ -70,8 +68,7 @@ impl<'a> ValidationContext<'a> {
if obj.get("kind").is_none() {
result.errors.push(ValidationError {
code: "MISSING_KIND".to_string(),
message: "Schema mechanically requires horizontal kind discrimination"
.to_string(),
values: None,
path: self.path.clone(),
});
} else {
@ -106,8 +103,11 @@ impl<'a> ValidationContext<'a> {
&& (obj.len() as f64) < min
{
result.errors.push(ValidationError {
code: "MIN_PROPERTIES".to_string(),
message: "Too few properties".to_string(),
code: "MIN_PROPERTIES_VIOLATED".to_string(),
values: Some(HashMap::from([
("count".to_string(), obj.len().to_string()),
("limit".to_string(), min.to_string()),
])),
path: self.path.to_string(),
});
}
@ -116,8 +116,11 @@ impl<'a> ValidationContext<'a> {
&& (obj.len() as f64) > max
{
result.errors.push(ValidationError {
code: "MAX_PROPERTIES".to_string(),
message: "Too many properties".to_string(),
code: "MAX_PROPERTIES_VIOLATED".to_string(),
values: Some(HashMap::from([
("count".to_string(), obj.len().to_string()),
("limit".to_string(), max.to_string()),
])),
path: self.path.to_string(),
});
}
@ -128,13 +131,17 @@ impl<'a> ValidationContext<'a> {
if field == "type" {
result.errors.push(ValidationError {
code: "MISSING_TYPE".to_string(),
message: "Missing type discriminator".to_string(),
values: Some(HashMap::from([
("field_name".to_string(), "type".to_string()),
])),
path: self.join_path(field),
});
} else {
result.errors.push(ValidationError {
code: "REQUIRED_FIELD_MISSING".to_string(),
message: format!("Missing {}", field),
values: Some(HashMap::from([
("field_name".to_string(), field.to_string()),
])),
path: self.join_path(field),
});
}
@ -151,7 +158,10 @@ impl<'a> ValidationContext<'a> {
if !obj.contains_key(req_prop) {
result.errors.push(ValidationError {
code: "DEPENDENCY_MISSING".to_string(),
message: format!("Property '{}' requires property '{}'", prop, req_prop),
values: Some(HashMap::from([
("property_name".to_string(), prop.to_string()),
("required_property".to_string(), req_prop.to_string()),
])),
path: self.path.to_string(),
});
}