Skip to content

fix(core): Fix validation errors for nested props of same name#2531

Open
lucas-koehler wants to merge 2 commits intomasterfrom
lk/2521-nested-props-same-name
Open

fix(core): Fix validation errors for nested props of same name#2531
lucas-koehler wants to merge 2 commits intomasterfrom
lk/2521-nested-props-same-name

Conversation

@lucas-koehler
Copy link
Contributor

  • Remove obsolete safeguard against adding a property name a second time to a validation error's control path.
  • Add comment in errors.ts to clarify behavior
  • Add unit tests for getControlPath and errorAt
  • Add example for nested required property of same name

fixes #2521

- Remove obsolete safeguard against adding a property name a second time to a validation error's control path.
- Add comment in errors.ts to clarify behavior
- Add unit tests for getControlPath and errorAt
- Add example for nested required property of same name

fixes #2521
@lucas-koehler lucas-koehler requested a review from sdirix January 14, 2026 13:38
@netlify
Copy link

netlify bot commented Jan 14, 2026

Deploy Preview for jsonforms-examples ready!

Name Link
🔨 Latest commit a3414f0
🔍 Latest deploy log https://app.netlify.com/projects/jsonforms-examples/deploys/69bd233e482fe60008221ecb
😎 Deploy Preview https://deploy-preview-2531--jsonforms-examples.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me!


const invalidProperty = getInvalidProperty(error);
if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
if (invalidProperty !== undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why we originally added the endsWith check? There must have been a reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not completely sure. Three reasons come to mind:

  • AJV calculated error paths differently in the past
  • This was a precaution that was never actually necessary
  • We handled more cases in getInvalidProperty explicitly in the past. However, the current three cases all need the invalidProperty attached anyway because they point to the parent object. See code snipped below
const getInvalidProperty = (error: ErrorObject): string | undefined => {
  switch (error.keyword) {
    case 'required':
    case 'dependencies':
      return error.params.missingProperty;
    case 'additionalProperties':
      return error.params.additionalProperty;
    default:
      return undefined;
  }
};

@lucas-koehler
Copy link
Contributor Author

@sdirix Thanks for the review 😊 I addressed the comments

@lucas-koehler lucas-koehler requested a review from sdirix March 20, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Required validation missing for nested property of same name as parent

2 participants