diff options
Diffstat (limited to 'crates/shirabe/src/json/json_file.rs')
| -rw-r--r-- | crates/shirabe/src/json/json_file.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs index 27540fe..b38de1e 100644 --- a/crates/shirabe/src/json/json_file.rs +++ b/crates/shirabe/src/json/json_file.rs @@ -404,11 +404,25 @@ impl JsonFile { let errors: Vec<String> = validator .iter_errors(&data_value) .map(|error| { - let property = error + let mut property = error .instance_path() .as_str() .trim_start_matches('/') .replace('/', "."); + // A missing required property is reported against its parent object, so the + // instance path is the parent (empty at the root). Composer points the error at + // the missing property itself, so append its name to match the `PROPERTY : MESSAGE` + // shape. + if let jsonschema::error::ValidationErrorKind::Required { property: missing } = + error.kind() + && let Some(name) = missing.as_str() + { + if property.is_empty() { + property = name.to_string(); + } else { + property = format!("{}.{}", property, name); + } + } if property.is_empty() { error.to_string() } else { |
