Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MergeYaml giving unexpected results where JSON path value of key includes wildcards #3310

Open
wabrit opened this issue Jun 12, 2023 · 2 comments · May be fixed by #4708
Open

MergeYaml giving unexpected results where JSON path value of key includes wildcards #3310

wabrit opened this issue Jun 12, 2023 · 2 comments · May be fixed by #4708
Labels
bug Something isn't working

Comments

@wabrit
Copy link

wabrit commented Jun 12, 2023

I am using

  • OpenRewrite v1.19.4
  • Maven plugin org.openrewrite.maven:rewrite-maven-plugin:4.46.0

I'm attempting to use the MergeYaml recipe in this scenario:

Old Yaml

list:
  services:
    foo:
      alpha: randomValue1
    bar:
      alpha: randomValue2

New Yaml

list:
  services:
    foo:
      alpha: randomValue1
      beta: fixedValue
    bar:
      alpha: randomValue2
      beta: fixedValue

I tried using MergeYaml with key set to $.list.services.* and yaml set to beta: fixedValue, but it gives me:

list:
  services:
    foo:
      alpha: randomValue1
    bar:
      alpha: randomValue2
    beta: fixedValue
@wabrit wabrit added the bug Something isn't working label Jun 12, 2023
@timtebeek
Copy link
Contributor

Hi! Sounds like you want to insert a specific key into each element matching your wildcard key, correct?
I'm not seeing such a scenario in our existing test coverage yet, but it should be easy to replicate there.
Then you could even step through with the debugger to see if there's an easy fix in the MergeYaml recipe.

@timtebeek timtebeek moved this to Backlog in OpenRewrite Jun 12, 2023
@wabrit
Copy link
Author

wabrit commented Jun 12, 2023

Just for completeness', I have found that JsonPathMatcher appears not to support the wildcard * character as documented here.

e.g. for the same YAML mapping entry

  new JsonPathMatcher("$.a.b.c").matches(getCursor()); // returns TRUE
  new JsonPathMatcher("$.a.*.c").matches(getCursor()); // returns FALSE

Interestingly new JsonPathMatcher("$.a..c").matches(getCursor()) does appear to work as expected in this case.

As the failing scenario in this bug uses a trailing wildcard in the JSON path, it seems reasonably likely that the lack of support for * in JsonPathMatcher is contributing to the error (also because its a trailing wildcard, the use of recursive descent is not available).

knutwannheden added a commit that referenced this issue Nov 24, 2024
@timtebeek timtebeek linked a pull request Nov 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

Successfully merging a pull request may close this issue.

2 participants