Skip to content

Fix MergeYaml wildcard, flow-style sequence, and comment handling#7291

Merged
timtebeek merged 2 commits intomainfrom
tim/mergeyaml-issue-triage
Apr 6, 2026
Merged

Fix MergeYaml wildcard, flow-style sequence, and comment handling#7291
timtebeek merged 2 commits intomainfrom
tim/mergeyaml-issue-triage

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented Apr 6, 2026

Summary

Fixes three MergeYaml bugs and adds test coverage for two more issues:

Test plan

  • All 163 MergeYamlTest tests pass
  • All JsonPathMatcherTest tests pass (no regressions)
  • CI passes

…ng comments

- Fix JsonPathMatcher wildcard handling to expand trailing wildcards
  (e.g. `$.list.services.*`) to individual child entries (#3310)
- Fix MergeYamlVisitor.mergeSequence() to handle flow-style sequences
  by using comma separators instead of newline-based indent (#2834)
- Fix MergeYamlVisitor.mergeMapping() to preserve inline comments
  stored on Document.End when appending to deeply nested mappings (#5135)
- Add documenting test for DeleteKey + MergeYaml 2-cycle behavior (#3950)
- Add confirmation test for fixed multi-document merge (#3539)
@steve-aom-elliott
Copy link
Copy Markdown
Contributor

The rest seems good aside from the question I had above.

The YAML AST stores flow-style separators as trailingCommaPrefix on entries
and spaces as the scalar block's prefix, not the entry's prefix. Updated
mergeSequence() to correctly set trailingCommaPrefix on the last existing
entry and the block prefix on new entries.

Added tests for merging multi-element flow-style sequences and sequences
where some incoming values already exist.
Comment on lines +3678 to +3694
"$.value",
//language=yaml
"[16, 17]",
false,
null,
null,
null,
null,
null
)),
yaml(
"""
value: [17]
""",
"""
value: [17, 16]
"""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think for a simple example like this, this is probably fine. I guess I'm wondering if this gets messy for more complicated structures where the ordering requested may actually matter. Perhaps I'm just overthinking it, though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah there's definitely limits, but seeing how this is for flow style object I'm hoping it's rare that folks use complex values there. Do you see any object to merge this as is?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suppose it would also fit with scenarios where simple values order matters, but yeah, it may be stretching the use case beyond where it typically would exist. No concerns other than that for merging.

@timtebeek timtebeek merged commit 34acf1c into main Apr 6, 2026
1 check passed
@timtebeek timtebeek deleted the tim/mergeyaml-issue-triage branch April 6, 2026 21:34
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment