mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-07 19:16:56 +00:00
ParameterError: construct XPath like string to identify nested properties
This commit is contained in:
parent
b5ea4f9bb2
commit
9ec9d1f9e6
@ -46,6 +46,17 @@ impl ParameterError {
|
|||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.len() == 0
|
self.len() == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_errors(&mut self, prefix: &str, err: Error) {
|
||||||
|
if let Some(param_err) = err.downcast_ref::<ParameterError>() {
|
||||||
|
for (sub_key, sub_err) in param_err.errors().iter() {
|
||||||
|
self.push(format!("{}/{}", prefix, sub_key), format_err!("{}", sub_err));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.push(prefix.to_string(), err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ParameterError {
|
impl fmt::Display for ParameterError {
|
||||||
@ -1079,8 +1090,13 @@ pub fn verify_json_array(data: &Value, schema: &ArraySchema) -> Result<(), Error
|
|||||||
|
|
||||||
schema.check_length(list.len())?;
|
schema.check_length(list.len())?;
|
||||||
|
|
||||||
for item in list {
|
for (i, item) in list.iter().enumerate() {
|
||||||
verify_json(item, &schema.items)?;
|
let result = verify_json(item, &schema.items);
|
||||||
|
if let Err(err) = result {
|
||||||
|
let mut errors = ParameterError::new();
|
||||||
|
errors.add_errors(&format!("[{}]", i), err);
|
||||||
|
return Err(errors.into());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -1097,7 +1113,6 @@ pub fn verify_json_object(
|
|||||||
_ => bail!("Expected object - got scalar value."),
|
_ => bail!("Expected object - got scalar value."),
|
||||||
};
|
};
|
||||||
|
|
||||||
// fixme: improve error messages from nested objects/arrays
|
|
||||||
let mut errors = ParameterError::new();
|
let mut errors = ParameterError::new();
|
||||||
|
|
||||||
let additional_properties = schema.additional_properties();
|
let additional_properties = schema.additional_properties();
|
||||||
@ -1110,7 +1125,7 @@ pub fn verify_json_object(
|
|||||||
_ => verify_json(value, prop_schema),
|
_ => verify_json(value, prop_schema),
|
||||||
};
|
};
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
errors.push(key.to_string(), err);
|
errors.add_errors(key, err);
|
||||||
};
|
};
|
||||||
} else if !additional_properties {
|
} else if !additional_properties {
|
||||||
errors.push(key.to_string(), format_err!("schema does not allow additional properties."));
|
errors.push(key.to_string(), format_err!("schema does not allow additional properties."));
|
||||||
|
Loading…
Reference in New Issue
Block a user