charleskorn / kaml

YAML support for kotlinx.serialization
Apache License 2.0
524 stars 50 forks source link

Support for variable substitution #28

Closed smax48 closed 4 years ago

smax48 commented 4 years ago

Is it possible to parse yaml files with variables in values (something like ${VARIABLE:-default} )? Looks like snakeyaml-engine has this support, with possibility to provide a custom map as an input. Would be great to do similar things with kaml - so it would be possible to use this project for app configuration etc. For example, YamlConfiguration could accept a Map<String, String> with custom variable values and pass that into YamlParser (so it can use that with snakeyaml-engine). What do you think?

charleskorn commented 4 years ago

Hey @smax48, thanks for the suggestion. This isn't something that's supported at the moment and I'm not keen to add further functionality to kaml (I'm trying to keep it as focused as possible to make it easy to add support for Kotlin/Native in the future).

If you'd like to build something that adds this functionality on top of kaml, I'd be happy to discuss adding some extension points to support this.

smax48 commented 4 years ago

Hey @charleskorn, extension would be fine, as long as it is possible to get access to snakeyaml-engine load settings ;)

That's the main problem - YamlParser instantiates & uses that internally. From what I see, there's no other simple way to implement this functionality, other than completely separate the process of values substitution (before calling kaml). But that would be re-implementing the already existing thing, which I would like to avoid.

UPDATE: My original idea was to integrate kaml with koin DI, for configuration loading from yaml files with variables that are actually references to koin properties ;)

charleskorn commented 4 years ago

Hey @smax48, could you implement this as a post-processing step after loading the configuration from YAML? Or perhaps a custom serializer?

I'm not keen to expose access to snakeyaml-engine's settings - it's an internal implementation detail that could change in the future.

charleskorn commented 4 years ago

Given there's been no activity on this issue for a while, I'm going to go ahead and close it. If you have any further questions, feel free to add a comment here or open a new issue.