fix(validation): recurse nested ValidationErrors so 422 errors[] carry dotted field paths #280

Merged
vas2000-work merged 1 commit from fix/pms-330-nested-validation-field-paths into main 2026-06-16 23:51:49 +02:00
Owner

The From<validator::ValidationErrors> conversion flattened only top-level field_errors(), silently dropping ValidationErrorsKind::Struct / ::List entries produced by #[validate(nested)]. A 422 for a bad nested field (e.g. address.country, address.postal_code on a company/site request) therefore arrived with an empty errors[], leaving non-form API consumers unable to tell which field was wrong.

Replace the single-level flatten with flatten_validation_errors, which walks the full ValidationErrors tree: Field entries append a FieldError (still honoring the PMS-364 cross-field re-key), Struct entries recurse under a prefix.field dotted path, and List entries recurse under a prefix.field[index] path. Top-level behavior is unchanged. Adds a unit test covering dotted struct paths and an indexed list path surfacing in errors[].

#PMS-330

The `From<validator::ValidationErrors>` conversion flattened only top-level `field_errors()`, silently dropping `ValidationErrorsKind::Struct` / `::List` entries produced by `#[validate(nested)]`. A 422 for a bad nested field (e.g. `address.country`, `address.postal_code` on a company/site request) therefore arrived with an empty `errors[]`, leaving non-form API consumers unable to tell which field was wrong. Replace the single-level flatten with `flatten_validation_errors`, which walks the full `ValidationErrors` tree: `Field` entries append a `FieldError` (still honoring the PMS-364 cross-field re-key), `Struct` entries recurse under a `prefix.field` dotted path, and `List` entries recurse under a `prefix.field[index]` path. Top-level behavior is unchanged. Adds a unit test covering dotted struct paths and an indexed list path surfacing in `errors[]`. #PMS-330
fix(validation): recurse nested ValidationErrors so 422 errors[] carry dotted field paths
All checks were successful
E2E / Playwright against staging (pull_request) Successful in 38s
Check / fmt + clippy + compile + unit/doc tests (pull_request) Successful in 1m3s
Integration / integration tests (pull_request) Successful in 2m53s
Create release / Create release from merged PR (pull_request) Has been skipped
29c12e3a9b
The `From<validator::ValidationErrors>` conversion flattened only top-level `field_errors()`, silently dropping `ValidationErrorsKind::Struct` / `::List` entries produced by `#[validate(nested)]`. A 422 for a bad nested field (e.g. `address.country`, `address.postal_code` on a company/site request) therefore arrived with an empty `errors[]`, leaving non-form API consumers unable to tell which field was wrong.

Replace the single-level flatten with `flatten_validation_errors`, which walks the full `ValidationErrors` tree: `Field` entries append a `FieldError` (still honoring the PMS-364 cross-field re-key), `Struct` entries recurse under a `prefix.field` dotted path, and `List` entries recurse under a `prefix.field[index]` path. Top-level behavior is unchanged. Adds a unit test covering dotted struct paths and an indexed list path surfacing in `errors[]`.

#PMS-330
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/mokosh-server!280
No description provided.