jspg error refactoring checkpoint
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::validator::context::ValidationContext;
|
||||
use crate::validator::error::ValidationError;
|
||||
use crate::validator::result::ValidationResult;
|
||||
@ -22,7 +24,7 @@ impl<'a> ValidationContext<'a> {
|
||||
if conflicts {
|
||||
result.errors.push(ValidationError {
|
||||
code: "INVALID_SCHEMA".to_string(),
|
||||
message: "family must be used exclusively without other constraints".to_string(),
|
||||
values: None,
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
return Ok(false);
|
||||
@ -35,7 +37,7 @@ impl<'a> ValidationContext<'a> {
|
||||
} else {
|
||||
result.errors.push(ValidationError {
|
||||
code: "UNCOMPILED_FAMILY".to_string(),
|
||||
message: "Encountered family block that could not be mapped to deterministic options during db schema compilation.".to_string(),
|
||||
values: None,
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
return Ok(false);
|
||||
@ -55,7 +57,7 @@ impl<'a> ValidationContext<'a> {
|
||||
} else {
|
||||
result.errors.push(ValidationError {
|
||||
code: "UNCOMPILED_ONEOF".to_string(),
|
||||
message: "Encountered oneOf block that could not be mapped to deterministic compiled options natively.".to_string(),
|
||||
values: None,
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
return Ok(false);
|
||||
@ -109,10 +111,9 @@ impl<'a> ValidationContext<'a> {
|
||||
} else {
|
||||
result.errors.push(ValidationError {
|
||||
code: "MISSING_COMPILED_SCHEMA".to_string(),
|
||||
message: format!(
|
||||
"Polymorphic router target '{}' does not exist in the database schemas map",
|
||||
target_id
|
||||
),
|
||||
values: Some(HashMap::from([
|
||||
("target_id".to_string(), target_id.to_string()),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
return Ok(false);
|
||||
@ -132,10 +133,9 @@ impl<'a> ValidationContext<'a> {
|
||||
} else {
|
||||
result.errors.push(ValidationError {
|
||||
code: "MISSING_COMPILED_SCHEMA".to_string(),
|
||||
message: format!(
|
||||
"Polymorphic index target '{}' does not exist in the local oneOf array",
|
||||
idx
|
||||
),
|
||||
values: Some(HashMap::from([
|
||||
("index".to_string(), idx.to_string()),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
return Ok(false);
|
||||
@ -144,10 +144,15 @@ impl<'a> ValidationContext<'a> {
|
||||
return Ok(false);
|
||||
}
|
||||
} else {
|
||||
let disc_msg = if let Some(d) = self.schema.compiled_discriminator.get() {
|
||||
format!("discriminator {}='{}'", d, val)
|
||||
let values = if let Some(d) = self.schema.compiled_discriminator.get() {
|
||||
Some(HashMap::from([
|
||||
("discriminator".to_string(), d.to_string()),
|
||||
("value".to_string(), val.to_string()),
|
||||
]))
|
||||
} else {
|
||||
format!("structural JSON base primitive '{}'", val)
|
||||
Some(HashMap::from([
|
||||
("primitive".to_string(), val.to_string()),
|
||||
]))
|
||||
};
|
||||
result.errors.push(ValidationError {
|
||||
code: if self.schema.family.is_some() {
|
||||
@ -155,10 +160,7 @@ impl<'a> ValidationContext<'a> {
|
||||
} else {
|
||||
"NO_ONEOF_MATCH".to_string()
|
||||
},
|
||||
message: format!(
|
||||
"Payload matched no candidate boundaries based on its {}",
|
||||
disc_msg
|
||||
),
|
||||
values,
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
return Ok(false);
|
||||
@ -167,10 +169,9 @@ impl<'a> ValidationContext<'a> {
|
||||
if let Some(d) = self.schema.compiled_discriminator.get() {
|
||||
result.errors.push(ValidationError {
|
||||
code: "MISSING_TYPE".to_string(),
|
||||
message: format!(
|
||||
"Missing explicit '{}' discriminator. Unable to resolve polymorphic boundaries",
|
||||
d
|
||||
),
|
||||
values: Some(HashMap::from([
|
||||
("discriminator".to_string(), d.to_string()),
|
||||
])),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user