Skip to content

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

Open
lucas-koehler wants to merge 1 commit 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 1 commit 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 7e3f68e
🔍 Latest deploy log https://app.netlify.com/projects/jsonforms-examples/deploys/69679c70598940000823ccc3
😎 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!


/**
* Checks for an additionally specified property that the error relates to.
* This may be added to an error's instancePath to show it add the violating property's control.
Copy link
Member

Choose a reason for hiding this comment

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

Typo: "to show it add the violating" should be "to show it at the violating".


// remove '.' chars at the beginning of paths
controlPath = controlPath.replace(/^./, '');
controlPath = controlPath.replace(/^\./, '');
Copy link
Member

Choose a reason for hiding this comment

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

Good catch 👍

t.is(controlPath, 'parent.child');
});

test('getControlPath - prevents duplicate property when path already ends with property', (t) => {
Copy link
Member

Choose a reason for hiding this comment

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

This test name is misleading. It says "prevents duplicate" but this is not what we want?

import * as string from './examples/string';
import * as prependAppendSlots from './examples/prepend-append-slots';
import * as validationNestedSameNameValidation from './examples/validation-nested-same-name';
export * from './register';
Copy link
Member

Choose a reason for hiding this comment

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

nit: validationNestedSameNameValidation has redundant "Validation" in the name. validationNestedSameName would be enough.


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

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