CertainLach/jrsonnet

Manifesting a yaml tag

Jezza opened this issue · 2 comments

Jezza commented

YAML has support for tags like:

includes:
- !include components/accounts.yaml

That !include is a directive that the code the uses to invoke some code-side constructor.
Weird, but it's supported. (yml in a nutshell)

When the yml document is manifested, the string is checked to see if it starts with a !, if it does, then it quotes the string.

I'm wondering if there's a workaround for this, or if we could change this.

Tags are not intended to be produced by serializer, and deserializer is free to drop tags, if it doesn't have special handling for them, thus this does break roundtrip, as

std.manifestYamlDoc(std.parseYaml("a: !tag world")) == '"a": "world"'

If you really need to produce directive - you can write your own manifestYamlDoc, by copying the default implementation

But in your case, why not just process includes on jsonnet side?

{
  includes: [
    std.parseYaml(importstr 'components/accounts.yaml'),
    // Or rewrite accounts.yaml to jsonnet, and then
    import 'components/accounts.jsonnet',
  ],
}

In any case, this thing (modification to the standard library) should not be discussed here, but in jsonnet issue tracker: https://github.com/google/jsonnet/issues

Jezza commented

For includes, I just end up dropping them, and writing the content directly.
That's fine, but there's a couple of other tags that cause issues.
I'll find some workarounds.

Thanks for your time!