Skip to content
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

Rendering template using yaml data file containing anchors #520

Closed
alghazanth opened this issue Jun 9, 2024 · 4 comments · Fixed by #531
Closed

Rendering template using yaml data file containing anchors #520

alghazanth opened this issue Jun 9, 2024 · 4 comments · Fixed by #531
Labels
enhancement New feature or request

Comments

@alghazanth
Copy link

Description

Currently yaml anchors inside yaml data files are not fully supported because of serde_yaml author refused to implement them. There is wonderful yaml-rust2 that could help mitigate the issue. Would you mind to consider migration from serde_yaml to yaml-rust2?

Additional helpful information:

  • Version of minijinja: 2.0.1
  • Version of rustc: 1.78
  • Operating system and version: Arch Linux

What did you expect

Structures like:

dict1: &dict1_anchor
  key1: value1
  key2: value2

dict2:
  <<: *dict1_anchor

should serialize into:

dict1:
  key1: value1
  key2: value2

dict2:
  key1: value1
  key2: value2
@mitsuhiko
Copy link
Owner

I would love to support this. Unfortunately yaml-rust2 does not support serde today. serde_yaml2 which uses yaml-rust2 does support serde, but it does not support anchors: https://github.com/zim32/serde_yaml2/blob/06d2d5ecca84c6d3c0d5e2f3cbac75bf2cc97e1e/src/de/mod.rs#L275-L277

So the actual work required here is quite high. Ideally support for this lands in a YAML library that directly supports serde.

@mitsuhiko mitsuhiko added the enhancement New feature or request label Jun 9, 2024
@alghazanth
Copy link
Author

Well, the library you mentioned doesn't seem to be well maintained too unfortunately. Also, is it that hard to convert serde_yaml's Value into yaml-rust2's Yaml (by implementing TryFrom or something)? Sorry for naive question, I'm a novice in Rust.

@mitsuhiko
Copy link
Owner

I cannot say because I'm not entirely sure how Alias is being handled in yaml-rust2. With buffering it wouldn't be too hard would be my guess but again, I cannot say. In general that is something I would not want to maintain as part of MiniJinja. If functionality lands in a serde compatible crate I would switch to it.

@mitsuhiko
Copy link
Owner

Turns out serde_yml does support aliases but it only supports a singular merge key. So this would not be supported:

dict1: &dict1_anchor
  key1: value1

dict2: &dict2_anchor
  key2: value2

dict3:
  <<: *dict1_anchor
  <<: *dict2_anchor
  key3: value3

However this would be:

dict1: &dict1_anchor
  key1: value1

dict2: &dict2_anchor
  key2: value2

dict3:
  <<: [*dict1_anchor, *dict2_anchor]
  key3: value3

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

Successfully merging a pull request may close this issue.

2 participants