From 2e4a3cf59df1bc85b0f626f598a5d45bcae8d77a Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 27 Jun 2026 08:58:01 +0900 Subject: fix(json): include property name in required-property errors The jsonschema crate reports a missing required property against its parent object, leaving the instance path empty at the root. This skipped the "PROPERTY : MESSAGE" formatting that Composer produces. Append the missing property name to the path so the output shape matches. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/json/json_file.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'crates/shirabe/src/json') 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 = 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 { -- cgit v1.3.1