mikefarah / yq

yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
https://mikefarah.gitbook.io/yq/
MIT License
12.33k stars 602 forks source link

Explode with merge aliases throw an error #2178

Open jfrz38 opened 1 month ago

jfrz38 commented 1 month ago

Describe the bug I'm trying to work with anchors and alias operators but I'm getting an error merge anchor only supports maps, got !!seq instead while I'm exploding the yaml.

It seems the line - <<: *my-anchor is the problem since I can work without that line but if it exists then throw the error.

Docs say

yq supports merge aliases (like <<: *blah) ...

So I didn't expected the error.

Version of yq: 4.44.3 Operating system: linux Installed via: binary release

Input Yaml

level_1:
- name: one
  level_2: &my-anchor
    - name: one_v1
      level_3:
        - name: foo
- name: two
  level_2:
    - <<: *my-anchor # uses my-anchor configuration
    - name: one_v1
      level_3: # add level_3.name: bar to my-anchor
        - name: bar

Command

yq 'explode(.)' data1.yml

Actual behavior

It throws an error:

Error: merge anchor only supports maps, got !!seq instead

Expected behavior

Just expand yaml and generate something like this:

---
level_1:
  - name: one
    level_2:
      - name: one_v1
        level_3:
          - name: foo
  - name: two
    level_2:
      - name: one_v1 # this is the anchor property
        level_3:
          - name: foo
      - name: one_v1
        level_3:
          - name: bar

I've tried using other linters but format seems ok and could be possible to expand.
Also I've tried to expand without - <<: *my-anchor line and not throw an error and I've run yq '.level_1[0] | explode(.)' data1.yml and also works fine. So problem seems to be the definition - <<: *my-anchor.