Skip to content

fix: ignore internal references when ordering object keys - #3129

Open
xianjianlf2 wants to merge 1 commit into
hapijs:masterfrom
xianjianlf2:fix/nested-duplicate-key-ref-2877
Open

fix: ignore internal references when ordering object keys#3129
xianjianlf2 wants to merge 1 commit into
hapijs:masterfrom
xianjianlf2:fix/nested-duplicate-key-ref-2877

Conversation

@xianjianlf2

Copy link
Copy Markdown

Problem

When an object key holds a nested object whose value references a sibling key that shares a name with an ancestor key, the reference propagated up as a root reference of the outer key. This made that key depend on itself and threw "Item cannot come after itself" during key ordering.

For example, an outer command key containing a nested command key (referenced by a sibling params via .conditional('command', ...)) would fail to build.

Fix

When computing the topological ordering of object keys, skip references that a child object resolves internally (i.e. references that match one of the child's own keys). Genuine cross-object circular dependencies are still surfaced.

Testing

Added a test in test/types/object.js covering an object whose nested key references a duplicated sibling key name, verifying the schema builds and validates correctly (including the conditional/switch branches).

Closes #2877

When an object key holds a nested object whose value references a sibling
key that shares a name with an ancestor key, the reference propagated up
as a root reference of the outer key, making that key depend on itself and
throwing "Item cannot come after itself" during key ordering.

Skip references that a child object resolves internally (i.e. that match
one of the child's own keys) when computing the topological ordering, while
still surfacing genuine cross-object circular dependencies.

Closes hapijs#2877
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.

"Item cannot come after itself" from ref with a duplicated property name

1 participant