Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typesafe/Hocon config: variable substitution: reference path

We have a project with huge configuration files built using hocon configs. There is an intention to use variables to create template_section and set up some values in the template based on some options.

The problem is that while using variables in this config, I have to refer to the absolute path all the time. Is it possible somehow to use the canonical name (if properties located on the same level)?

Example:

foo {
    bar = 4
    baz = ${foo.bar} // work perfect
    baz = ${[this].bar} // can I do smth like that? Any ideas.
}

A more real-life example. What I'm actually looking for is general OOP abilities in building hocon configs. I have some parent configuration template_config with important_option inside that really depends on implementation: custom_config1 or custom_config2, I currently have to implement important_option in both child configurations because with absolute paths, I have to refer to custom config sections names.

custom_config1: $template_config {
    child_option = child_value1
}

custom_config2: $template_config {
    child_option = child_value2
}

template_config {
    important_option = ${child_option} // NOT POSSIBLE
    child_option = not_implemented
}
like image 784
vvg Avatar asked Dec 19 '25 09:12

vvg


1 Answers

Sadly, your hypothetical baz = ${[this].bar} path self-reference is not a thing that is supported by HOCON (as of 2022)

like image 200
Daenyth Avatar answered Dec 22 '25 01:12

Daenyth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!