Skip to content

fix(core): interpolate {{value}} with the key for field: "@key"#2967

Open
slegarraga wants to merge 1 commit into
stoplightio:developfrom
slegarraga:fix/key-field-value-interpolation
Open

fix(core): interpolate {{value}} with the key for field: "@key"#2967
slegarraga wants to merge 1 commit into
stoplightio:developfrom
slegarraga:fix/key-field-value-interpolation

Conversation

@slegarraga

Copy link
Copy Markdown
Contributor

Summary

With field: "@key", the {{value}} message placeholder interpolated to Object{} instead of the property key. Fixes #2922.

Root cause

getLintTargets correctly passes the property key as the target value for @key (so the function itself runs against the key). But when building the message variables, processTargetResults recomputed the value from the resolved path:

const value = path.length === 0 ? document.data : get(document.data, path);

For a @key target the path points at the keyed entry (['responses', '404']), so get(document.data, path) returns the value stored there (an object), and {{value}} rendered as Object{}.

Fix

Pass then.field through to processTargetResults and, for @key targets, use the key (the last path segment) as the message value, consistent with the value the function already received.

Test

Added a test in linter.test.ts. Observed output after the fix:

code: 'rule1'
message: '"404" must be equal to one of the allowed values: "200", "400"'
path: ['responses', '404']
severity: Warning

yarn jest packages/core/src/__tests__/linter.test.ts → 49 passed.

Note: this fixes the {{value}} interpolation. The reported result range still points at the keyed value rather than the key node; that is a separate concern and can be a follow-up if desired.

For a `field: "@key"` target the linted value is the property key, but the
message vars recomputed the value from the path, yielding the value stored
there (e.g. an object). So `{{value}}` rendered as `Object{}` instead of the
key. Pass the field through to result processing and use the key for `@key`.

Closes stoplightio#2922
@slegarraga slegarraga requested a review from a team as a code owner June 3, 2026 02:41
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.

Interpolation of {{value}} is incorrect when using field: "@key"

1 participant