You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pkg/yqlib/doc/operators/anchor-and-alias-operators.md
+11-3Lines changed: 11 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,14 @@ Use the `alias` and `anchor` operators to read and write yaml aliases and anchor
5
5
`yq` supports merge aliases (like `<<: *blah`) however this is no longer in the standard yaml spec (1.2) and so `yq` will automatically add the `!!merge` tag to these nodes as it is effectively a custom tag.
6
6
7
7
8
+
## NOTE --yaml-fix-merge-anchor-to-spec flag
9
+
`yq` doesn't merge anchors `<<:` to spec, in some circumstances it incorrectly overrides existing keys when the spec documents not to do that.
10
+
11
+
To minimise disruption while still fixing the issue, a flag has been added to toggle this behaviour. This will first default to false; and log warnings to users. Then it will default to true (and still allow users to specify false if needed)
12
+
13
+
See examples of the flag difference below.
14
+
15
+
8
16
## Merge one map
9
17
see https://yaml.org/type/merge.html
10
18
@@ -285,7 +293,7 @@ thingTwo:
285
293
```
286
294
287
295
## LEGACY: Explode with merge anchors
288
-
Caution: this is for when --yaml-fix-merge-anchor-to-spec=false; it's not to YAML spec because the merge anchors incorrectly override the object values. Flag will default to true in late 2025
296
+
Caution: this is for when --yaml-fix-merge-anchor-to-spec=false; it's not to YAML spec because the merge anchors incorrectly override the object values (foobarList.b is set to bar_b when it should still be foobarList_b). Flag will default to true in late 2025
289
297
290
298
Given a sample.yml file of:
291
299
```yaml
@@ -334,7 +342,7 @@ foobar:
334
342
```
335
343
336
344
## FIXED: Explode with merge anchors
337
-
Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025
345
+
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025
338
346
339
347
Given a sample.yml file of:
340
348
```yaml
@@ -383,7 +391,7 @@ foobar:
383
391
```
384
392
385
393
## FIXED: Explode with merge anchors
386
-
Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025
394
+
See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025
Copy file name to clipboardExpand all lines: pkg/yqlib/doc/operators/headers/anchor-and-alias-operators.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,3 +4,11 @@ Use the `alias` and `anchor` operators to read and write yaml aliases and anchor
4
4
5
5
`yq` supports merge aliases (like `<<: *blah`) however this is no longer in the standard yaml spec (1.2) and so `yq` will automatically add the `!!merge` tag to these nodes as it is effectively a custom tag.
6
6
7
+
8
+
## NOTE --yaml-fix-merge-anchor-to-spec flag
9
+
`yq` doesn't merge anchors `<<:` to spec, in some circumstances it incorrectly overrides existing keys when the spec documents not to do that.
10
+
11
+
To minimise disruption while still fixing the issue, a flag has been added to toggle this behaviour. This will first default to false; and log warnings to users. Then it will default to true (and still allow users to specify false if needed)
This is the simplest (and perhaps most used) operator. It is used to navigate deeply into yaml structures.
4
+
5
+
6
+
## NOTE --yaml-fix-merge-anchor-to-spec flag
7
+
`yq` doesn't merge anchors `<<:` to spec, in some circumstances it incorrectly overrides existing keys when the spec documents not to do that.
8
+
9
+
To minimise disruption while still fixing the issue, a flag has been added to toggle this behaviour. This will first default to false; and log warnings to users. Then it will default to true (and still allow users to specify false if needed)
Copy file name to clipboardExpand all lines: pkg/yqlib/doc/operators/traverse-read.md
+13-4Lines changed: 13 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,15 @@
2
2
3
3
This is the simplest (and perhaps most used) operator. It is used to navigate deeply into yaml structures.
4
4
5
+
6
+
## NOTE --yaml-fix-merge-anchor-to-spec flag
7
+
`yq` doesn't merge anchors `<<:` to spec, in some circumstances it incorrectly overrides existing keys when the spec documents not to do that.
8
+
9
+
To minimise disruption while still fixing the issue, a flag has been added to toggle this behaviour. This will first default to false; and log warnings to users. Then it will default to true (and still allow users to specify false if needed)
10
+
11
+
See examples of the flag differences below.
12
+
13
+
5
14
## Simple map navigation
6
15
Given a sample.yml file of:
7
16
```yaml
@@ -352,7 +361,7 @@ a
352
361
c
353
362
```
354
363
355
-
## Traversing merge anchors with override
364
+
## LEGACY: Traversing merge anchors with override
356
365
This is legacy behaviour, see --yaml-fix-merge-anchor-to-spec
357
366
358
367
Given a sample.yml file of:
@@ -385,7 +394,7 @@ will output
385
394
foo_c
386
395
```
387
396
388
-
## Traversing merge anchor lists
397
+
## LEGACY: Traversing merge anchor lists
389
398
Note that the later merge anchors override previous, but this is legacy behaviour, see --yaml-fix-merge-anchor-to-spec
390
399
391
400
Given a sample.yml file of:
@@ -418,7 +427,7 @@ will output
418
427
bar_thing
419
428
```
420
429
421
-
## Splatting merge anchors
430
+
## LEGACY: Splatting merge anchors
422
431
With legacy override behaviour, see --yaml-fix-merge-anchor-to-spec
423
432
424
433
Given a sample.yml file of:
@@ -453,7 +462,7 @@ foo_a
453
462
foobar_thing
454
463
```
455
464
456
-
## Splatting merge anchor lists
465
+
## LEGACY: Splatting merge anchor lists
457
466
With legacy override behaviour, see --yaml-fix-merge-anchor-to-spec
log.Warning("--yaml-fix-merge-anchor-to-spec is false; causing merge anchors to override the existing values which isn't to the yaml spec. This flag will default to true in late 2025.")
165
+
log.Warning("--yaml-fix-merge-anchor-to-spec is false; causing merge anchors to override the existing values which isn't to the yaml spec. This flag will default to true in late 2025. See https://mikefarah.gitbook.io/yq/operators/anchor-and-alias-operators for more details.")
Copy file name to clipboardExpand all lines: pkg/yqlib/operator_anchors_aliases_test.go
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -104,14 +104,14 @@ var fixedAnchorOperatorScenarios = []expressionScenario{
104
104
{
105
105
skipDoc: true,
106
106
description: "merge anchor after existing keys",
107
-
subdescription: "Does not override existing keys",
107
+
subdescription: "Does not override existing keys - note the name field in the second element is still ellipse.",
108
108
document: explodeWhenKeysExistDocument,
109
109
expression: "explode(.)",
110
110
expected: []string{explodeWhenKeysExistExpected},
111
111
},
112
112
{
113
113
description: "FIXED: Explode with merge anchors",
114
-
subdescription: "Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025 ",
114
+
subdescription: "See the foobarList.b property is still foobarList_b. Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Flag will default to true in late 2025 ",
@@ -148,7 +148,7 @@ var badAnchorOperatorScenarios = []expressionScenario{
148
148
},
149
149
{
150
150
description: "LEGACY: Explode with merge anchors", // incorrect overrides
151
-
subdescription: "Caution: this is for when --yaml-fix-merge-anchor-to-spec=false; it's not to YAML spec because the merge anchors incorrectly override the object values. Flag will default to true in late 2025",
151
+
subdescription: "Caution: this is for when --yaml-fix-merge-anchor-to-spec=false; it's not to YAML spec because the merge anchors incorrectly override the object values (foobarList.b is set to bar_b when it should still be foobarList_b). Flag will default to true in late 2025",
log.Warning("--yaml-fix-merge-anchor-to-spec is false; causing merge anchors to override the existing values which isn't to the yaml spec. This flag will default to true in late 2025.")
298
+
log.Warning("--yaml-fix-merge-anchor-to-spec is false; causing merge anchors to override the existing values which isn't to the yaml spec. This flag will default to true in late 2025. See https://mikefarah.gitbook.io/yq/operators/traverse-read for more details.")
subdescription: "Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Note that the keys earlier in the merge anchors sequence override later ones",
41
+
document: mergeDocSample,
42
+
expression: `.foobarList.thing`,
44
43
expected: []string{
45
-
"D0, P[foobar c], (!!str)::foobar_c\n",
44
+
"D0, P[foo thing], (!!str)::foo_thing\n",
46
45
},
47
46
},
48
47
{
49
-
skipDoc: true,
50
-
description: "Splatting mergeanchors",
51
-
document: mergeDocSample,
52
-
expression: `.foobar[]`,
48
+
description: "FIXED: Splatting merge anchors",
49
+
subdescription: "Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Note that the keys earlier in the merge anchors sequence override later ones",
subdescription: "Set `--yaml-fix-merge-anchor-to-spec=true` to get this correct merge behaviour. Note that the keys earlier in the merge anchors sequence override later ones",
61
+
document: mergeDocSample,
62
+
expression: `.foobarList[]`,
64
63
expected: []string{
65
64
"D0, P[foobarList b], (!!str)::foobarList_b\n",
66
65
"D0, P[foo thing], (!!str)::foo_thing\n",
@@ -80,7 +79,7 @@ var fixedTraversePathOperatorScenarios = []expressionScenario{
0 commit comments