1

I am using pureconfig to read config for my Scala application. The application.conf file is in HOCON format. My config file looks something like this

weathers {
    ${?HUMID_WEATHER_ID} {
      temperature = 10
      temperature = ${?HUMID_WEATHER_TEMPERATURR}
    }
    ${?HOT_WEATHER_ID} {
      temperature = 10
      temperature = ${?HOT_WEATHER_TEMPERATURR}
    }
}

weathers is a map whose keys should be substituted by the environment variables HUMID_WEATHER_ID and HOT_WEATHER_ID. But when I read the config I get this exception

 135) Unable to parse the configuration: expecting a close parentheses ')' here, not: '${'HUMID_WEATHER_ID'}'.

The substitutions work fine in values but not in Keys. Is this intended? Is there a way to get around this?

Ashwin
  • 12,691
  • 31
  • 118
  • 190
  • 1
    I believe it's intended. One way is to make the keys static like `humid_wheather` and put another key inside it with the value being the env variable. This will force you to adapt slightly the app code though. – Gaël J Oct 31 '22 at 06:42
  • Yeah the HOCON spec effectively disallows substitutions for keys. It's not exactly clear what the intention here is for dynamic keys like this, what higher-level problem this proposes to solve. – Levi Ramsey Nov 01 '22 at 12:14

0 Answers0