fix(validation): recurse nested ValidationErrors so 422 errors[] carry dotted field paths #280
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/pms-330-nested-validation-field-paths"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The
From<validator::ValidationErrors>conversion flattened only top-levelfield_errors(), silently droppingValidationErrorsKind::Struct/::Listentries produced by#[validate(nested)]. A 422 for a bad nested field (e.g.address.country,address.postal_codeon a company/site request) therefore arrived with an emptyerrors[], leaving non-form API consumers unable to tell which field was wrong.Replace the single-level flatten with
flatten_validation_errors, which walks the fullValidationErrorstree:Fieldentries append aFieldError(still honoring the PMS-364 cross-field re-key),Structentries recurse under aprefix.fielddotted path, andListentries recurse under aprefix.field[index]path. Top-level behavior is unchanged. Adds a unit test covering dotted struct paths and an indexed list path surfacing inerrors[].#PMS-330