From 458d02f3aba345b3dc10b961b5d598c79ab88ff1 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Sun, 9 Nov 2025 16:15:36 +1100 Subject: [PATCH] Bumping to go-yaml 4-rc3 --- go.mod | 2 +- go.sum | 4 +- .../operators/anchor-and-alias-operators.md | 144 +++++++++++++++++- 3 files changed, 146 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 7d978dba..a98b661c 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/spf13/cobra v1.10.1 github.com/spf13/pflag v1.0.10 github.com/yuin/gopher-lua v1.1.1 - go.yaml.in/yaml/v4 v4.0.0-rc.2 + go.yaml.in/yaml/v4 v4.0.0-rc.3 golang.org/x/net v0.43.0 golang.org/x/text v0.28.0 gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 diff --git a/go.sum b/go.sum index f5f348c2..9b6c8833 100644 --- a/go.sum +++ b/go.sum @@ -50,8 +50,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M= github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= -go.yaml.in/yaml/v4 v4.0.0-rc.2 h1:/FrI8D64VSr4HtGIlUtlFMGsm7H7pWTbj6vOLVZcA6s= -go.yaml.in/yaml/v4 v4.0.0-rc.2/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= +go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go= +go.yaml.in/yaml/v4 v4.0.0-rc.3/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/pkg/yqlib/doc/operators/anchor-and-alias-operators.md b/pkg/yqlib/doc/operators/anchor-and-alias-operators.md index ab5a6572..b5dc62eb 100644 --- a/pkg/yqlib/doc/operators/anchor-and-alias-operators.md +++ b/pkg/yqlib/doc/operators/anchor-and-alias-operators.md @@ -191,13 +191,19 @@ Given a sample.yml file of: ```yaml f: a: &a cat - *a: b + *a : b ``` then ```bash yq 'explode(.f)' sample.yml ``` will output +```yaml +f: + a: cat + cat: b +``` + ## Dereference and update a field Use explode with multiply to dereference an object @@ -339,3 +345,139 @@ x: 1 y: 2 ``` +## FIXED: Explode with merge anchors +Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour (flag will default to true in late 2025). +Observe that foobarList.b property is still foobarList_b. + +Given a sample.yml file of: +```yaml +foo: &foo + a: foo_a + thing: foo_thing + c: foo_c +bar: &bar + b: bar_b + thing: bar_thing + c: bar_c +foobarList: + b: foobarList_b + !!merge <<: + - *foo + - *bar + c: foobarList_c +foobar: + c: foobar_c + !!merge <<: *foo + thing: foobar_thing +``` +then +```bash +yq 'explode(.)' sample.yml +``` +will output +```yaml +foo: + a: foo_a + thing: foo_thing + c: foo_c +bar: + b: bar_b + thing: bar_thing + c: bar_c +foobarList: + b: foobarList_b + a: foo_a + thing: foo_thing + c: foobarList_c +foobar: + c: foobar_c + a: foo_a + thing: foobar_thing +``` + +## FIXED: Merge multiple maps +Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour (flag will default to true in late 2025). +Taken from https://yaml.org/type/merge.html. Same values as legacy, but with the correct key order. + +Given a sample.yml file of: +```yaml +- &CENTER + x: 1 + y: 2 +- &LEFT + x: 0 + y: 2 +- &BIG + r: 10 +- &SMALL + r: 1 +- !!merge <<: + - *CENTER + - *BIG +``` +then +```bash +yq '.[4] | explode(.)' sample.yml +``` +will output +```yaml +x: 1 +y: 2 +r: 10 +``` + +## FIXED: Override +Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour (flag will default to true in late 2025). +Taken from https://yaml.org/type/merge.html. Same values as legacy, but with the correct key order. + +Given a sample.yml file of: +```yaml +- &CENTER + x: 1 + y: 2 +- &LEFT + x: 0 + y: 2 +- &BIG + r: 10 +- &SMALL + r: 1 +- !!merge <<: + - *BIG + - *LEFT + - *SMALL + x: 1 +``` +then +```bash +yq '.[4] | explode(.)' sample.yml +``` +will output +```yaml +r: 10 +y: 2 +x: 1 +``` + +## Exploding inline merge anchor +Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour (flag will default to true in late 2025). + + +Given a sample.yml file of: +```yaml +a: + b: &b 42 +!!merge <<: + c: *b +``` +then +```bash +yq 'explode(.) | sort_keys(.)' sample.yml +``` +will output +```yaml +a: + b: 42 +c: 42 +``` +