Skip to content

Support for "<<: reference" #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JordiPolo opened this issue May 9, 2017 · 9 comments
Open

Support for "<<: reference" #68

JordiPolo opened this issue May 9, 2017 · 9 comments

Comments

@JordiPolo
Copy link

I'm surprised there is no reference to this in the documentation as in my experience is widely used.

This is a good example of the expected output given "<<":
https://gist.github.com/bowsersenior/979804

But I get:
https://gist.github.com/JordiPolo/ce19f90de8ffc8ac31721a5961d1cc77

@alyssais
Copy link
Contributor

FWIW I also needed this and came across https://gitlab.kitware.com/utils/rust-yaml-merge-keys, which adds support for << on top on this library.

Would still love it if it could be supported by yaml-rust by default, though!

@JordiPolo
Copy link
Author

Thanks for the pointer. I've tried to make it work (I'm using serde-yaml) but it seems I'm not able to.
Support here would be ideal as it would just work™

@mathstuf
Copy link

mathstuf commented Nov 8, 2017

yaml-merge-keys developer here. It supports serde-yaml using the serde_yaml feature. We use it in our code just fine.

@sinesc
Copy link

sinesc commented Feb 11, 2018

@mathstuf I don't think it was questioned whether it works. The relevant function merge_keys_serde simply does not show up in the documentation on docs.rs (feature not enabled), so one has to find it in the source code of your library.

Since this issue comes up in a google search, here's a minimal example:

let value = serde_yaml::from_str(&input_yaml_string).unwrap(); // Value
let merged = yaml_merge_keys::merge_keys_serde(value).unwrap(); // merged Value
let typed_value: T = serde_yaml::from_value(merged).unwrap(); // merged T

@mathstuf
Copy link

I looked into it and it now seems possible to specify features for documentation builds. I'll do that for the crate.

@mathstuf
Copy link

Ah, I had done so, but hadn't made a release since then.

@mathstuf
Copy link

I've just published 0.2.1.

@tmccombs
Copy link

There is a spec for this, althouth it is not part of 1.2 itself: https://yaml.org/type/merge.html

@mathstuf
Copy link

I've seen multiple parsers get very loose around the merge key spec. Apparently this is valid for the Ruby parser:

foo:
  <<: *bar
  <<: *baz

(given anchors named bar and baz) but seems like…quite cavalier YAML without the supplemental spec. If you want to apply the merge keys spec, my crate handles that for you and it works with plain yaml-rust and serde_yaml. Other YAML libraries can be considered (through feature flags).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants