diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-27 08:58:01 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-27 09:09:44 +0900 |
| commit | 2e4a3cf59df1bc85b0f626f598a5d45bcae8d77a (patch) | |
| tree | f125fb944ad57b1819447eb61b5adfa687f25e34 /crates/shirabe/src | |
| parent | 901878ee3f2bee6605b02d321cc4c92bc32fd5b0 (diff) | |
| download | php-shirabe-2e4a3cf59df1bc85b0f626f598a5d45bcae8d77a.tar.gz php-shirabe-2e4a3cf59df1bc85b0f626f598a5d45bcae8d77a.tar.zst php-shirabe-2e4a3cf59df1bc85b0f626f598a5d45bcae8d77a.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src')
| -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 { |
