rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Recipe 'MergeYaml' doesn't add a new row to a table

Open dmbelyaev opened this issue 3 years ago • 1 comments

The issue can be reproduced by following test case. I executed it locally by adding it to the MergeYamlTest class.

    @Test
    fun mergeSequenceMap() = assertChanged(
        recipe = MergeYaml(
            "$",
            """
            testing:
              table:
                - row1key1: v111
                  row1key2: v222
            """.trimIndent(),
            false,
            null
        ),
        before = """
            testing:
              table:
                - row2key1: v111
                  row2key2: v222
        """,
        after = """
            testing:
              table:
                - row1key1: v111
                  row1key2: v222
                - row2key1: v111
                  row2key2: v222
        """
    )

dmbelyaev avatar Aug 18 '22 15:08 dmbelyaev

Hi @dmbelyaev, At this time MergeYaml only supports merging scalars into sequences, determining the equality of two mappings is required to prevent the recipe from continually re-adding the same sequence value. At this time determining mapping equality is one of the challenges preventing support for merging non scalars into sequences.

check out this test https://github.com/openrewrite/rewrite/blob/88b334f3cea1bbd895340bed27a643515bfc573a/rewrite-yaml/src/test/kotlin/org/openrewrite/yaml/MergeYamlTest.kt#L111-L140

pway99 avatar Aug 22 '22 22:08 pway99

fixed by #2240

pway99 avatar Oct 03 '22 17:10 pway99