Reference multiple YAML objects from one destination #653
LucasPickering
started this conversation in
Ideas
Replies: 1 comment
-
I haven't seen such syntax before as it's not shown as a use case in the 1.1 Spec, so even if you can make it work in Slumber, I'd be wary of de/serialization through other tools. # test.yaml
foo: &foo
x: 1
y: 2
bar: &bar
x: 3
z: 4
data1:
<<: [*foo, *bar]
data2:
<<: [{$ref: "#/foo"}, {$ref: "#/bar"}]$ yq --yaml-fix-merge-anchor-to-spec . test.yaml
foo: &foo
x: 1
y: 2
bar: &bar
x: 3
z: 4
data1:
!!merge <<: [*foo, *bar]
data2:
!!merge <<: [{$ref: "#/foo"}, {$ref: "#/bar"}]# you'd have to expand the $ref's BEFORE !!merge for this to work,
# and if the YAML round trips through JSON, it wouldn't even work
$ yq --yaml-fix-merge-anchor-to-spec -oj . test.yaml
{
"foo": {
"x": 1,
"y": 2
},
"bar": {
"x": 3,
"z": 4
},
"data1": {
"x": 1,
"y": 2,
"z": 4
},
"data2": {
"$ref": "#/foo"
}
}(with |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
From @erhhung in this comment:
We should support this use case. We could:
$refobjects:$refkeys in one object. I think it's possible with the saphyr parser but I'm not sure, need to look into it more. It does trigger a lint error with the YAML language server I use in zed, so that sucks.Beta Was this translation helpful? Give feedback.
All reactions