yaml: Anchors and merge keys strangeness
YAML supports sharing data between multiple parts of the document using "anchors", marked with &label
, and "merges", written as *label
. Unfortunately, different tools seem to interpret the spec slightly differently so it's necessary to check how each of these scenarios behave:
- simple sharing (almost certainly ok everywhere)
- merged anchor should not overwrite existing key
- multiple merges should be fine but can merge a sequence instead
%YAML 1.2
---
definitions:
sharedBranch: &sharedBranch
branch: shared
def2: &def2
foo: bar
shouldNotOverwriteExistingKeyButMight:
branch: specific
<<: *sharedBranch
canOverrideMergedWithLaterKey:
<<: *sharedBranch
branch: specific
shouldSupportMultipleMergesButMightNot:
<<: *sharedBranch
<<: *def2
preferred:
<<: [ *sharedBranch, *def2 ]
branch: specific
Published on: 26 Jun 2023