Custom %Directives unaccessible?

Issue #363 wontfix
Johannes Heinen created an issue

Hi Andrey,

  1. thanks for your great work on this! Everything works nicely, but there is one thing in which i currently stuck a little bit:

Currently, it seems that each of Yaml.load() Yaml.loadAll() Yaml.parse()

seem to skip "custom" directives like "%mydirective dosomething".

Please consider a simple *.yaml like

%mydirective dosomething
---
key:
    value1: ...
    value2: ...

Parsing works nicely, even a missing "---" start doc separator after the directives section is properly complained about by the parser itself. Maybe the documentation simply does not mention how to access the parsed directives by calling low-level API or something like that? Or most probably you could simply pass back a RTFM with a pointer to docs? Or are directives simply skipped and dumped/ignored, if they have no "special" meaning as defined in the yaml specs?

Why "custom" directives? My particular usecase is that i implement some environment aware configuration hierarchy and to do so i just introduced a "%extends baseconfig.[json|.properties|yaml]" custom directive on top of each "config.{env}.yaml" file to build my configuration a little bit more flexible. Might be that this is a violent "misuse" of yaml directives at all ...

Any advice on that is for sure appreciated, so thanks in advance!

Best regards from Köln Joshi

Comments (4)

  1. Johannes Heinen reporter

    Addendum: StreamStartEvent.getStartMark() and getEndMark() contain both the same token:

    in 'reader', line 1, column 1:
        %extends ./config.base.json
        ^
    
  2. Johannes Heinen reporter

    :) Thank you for your kind reply, you are right, the behaviour of snakeyaml is definitively correct according to the specs. I just stumbled over the same section of that document. So sorry for wasting your time :-/ I decided to go for the symfony framework way to simply add an "imports" key on top of the document, that fits perfectly unless nobody plans to introduce an own "imports" config key ... Thanks again, and if you don't mind, i close that ticket immediately.

  3. Log in to comment