fix(core): interpolate {{value}} with the key for field: "@key"#2967
Open
slegarraga wants to merge 1 commit into
Open
fix(core): interpolate {{value}} with the key for field: "@key"#2967slegarraga wants to merge 1 commit into
field: "@key"#2967slegarraga wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
With
field: "@key", the{{value}}message placeholder interpolated toObject{}instead of the property key. Fixes #2922.Root cause
getLintTargetscorrectly passes the property key as the target value for@key(so the function itself runs against the key). But when building the message variables,processTargetResultsrecomputed the value from the resolved path:For a
@keytarget the path points at the keyed entry (['responses', '404']), soget(document.data, path)returns the value stored there (an object), and{{value}}rendered asObject{}.Fix
Pass
then.fieldthrough toprocessTargetResultsand, for@keytargets, 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: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.