spring-projects / spring-projects/spring-data-rest

NestedPath is ignored when validating nested Entities [DATAREST-718]

Open
#1,087 0 comments 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since Dec 31, 2020.

in: repository type: bug
Dominant language
Java
Stars
958
Forks
568
PR merge metrics
No merged PRs in 30d

Description

Tim Meißner opened DATAREST-718 and commented

I have a rest resource "dashboard" which has a list of embedded resources (no repository for them) of class "widget". I have a class DashboardValidator and a WidgetValidator. Now i want to validate the dashboard resource before saving it, by validating each object of class widget with the widget validator.

for (int i = 0; i < dashboard.getWidgets().size(); i++) {
           Widget widget = dashboard.getWidgets().get(i);
           errors.pushNestedPath("widgets["+i+"]");
           ValidationUtils.invokeValidator(widgetValidator, widget, errors);
           errors.popNestedPath();
       }

The response i get is the following:

errors: [{entity: "Dashboard", message: "Widget name should not be empty", invalidValue: "Test",…}]}
errors: [{entity: "Dashboard", message: "Widget name should not be empty", invalidValue: "Test",…}]
0: {entity: "Dashboard", message: "Widget name should not be empty", invalidValue: "Test",…}
entity: "Dashboard"
invalidValue: "Test"
message: "Widget name should not be empty"
property: "name"

I posted a Dashboard called "Test" with a widget that has an empty name. Obviously the error doesn't indicate that widget[0].name is the rejected property and the invalidValue property is also wrong (because it shows the dashboards name and not the name of the embedded widget which caused the error)


Affects: 2.4.1 (Gosling SR1)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.