Unable to add to array using MergeYaml
#7107
-
|
Hi. I'm trying to add values to an array using versions:
./gradlew rewriteRun -Drewrite.activeRecipe=test# rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: test
recipeList:
- org.openrewrite.yaml.MergeYaml:
key: $
yaml: |
fruit:
- name: blueberry
filePattern: config/hoge.yml
objectIdentifyingProperty: fruit# config/hoge.yml
---
fruit:
- name: apple
specs:
- id: 1expected: ---
fruit:
- name: apple
specs:
- id: 1
- name: blueberryactual: ---
fruit:
- name: apple
specs:
- id: 1
- name: blueberry |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
|
Hi @seachicken, thanks for reporting this. The issue is with the In your case, the sequence entries under ---
type: specs.openrewrite.org/v1beta/recipe
name: test
recipeList:
- org.openrewrite.yaml.MergeYaml:
key: $
yaml: |
fruit:
- name: blueberry
filePattern: config/hoge.yml
objectIdentifyingProperty: nameWith
This should give you the expected output: ---
fruit:
- name: apple
specs:
- id: 1
- name: blueberryLet us know if this resolves the issue! |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for the quick reply. I tried # config/hoge.yml
---
fruit:
- name: apple
specs:
- id: 1 |
Beta Was this translation helpful? Give feedback.
-
|
This has been fixed on Added regression tests to confirm both with and without explicit @Issue("https://github.com/openrewrite/rewrite/discussions/7107")
@Test
void mergeSequenceWithCompactIndentationAndNestedSequence() {
rewriteRun(
spec -> spec
.recipe(new MergeYaml(
"$",
//language=yaml
"""
fruit:
- name: blueberry
""",
false,
"name",
null, null, null, null
)),
yaml(
"""
fruit:
- name: apple
specs:
- id: 1
""",
"""
fruit:
- name: apple
specs:
- id: 1
- name: blueberry
"""
)
);
} |
Beta Was this translation helpful? Give feedback.
This has been fixed on
mainand will be available in the next release. WithobjectIdentifyingProperty: name, MergeYaml correctly appends a new entry as a sibling in the sequence, even with compact YAML indentation (dash at the same level as the parent key).Added regression tests to confirm both with and without explicit
---document separator: