hoplite: Using strict() throws an error loading config listing unused Environment Variables.
Using the following example:
application.yaml
foo:
enabled: true
and this code
import com.sksamuel.hoplite.ConfigLoader
import com.sksamuel.hoplite.PropertySource
object Application {
@JvmStatic
fun main(args: Array<String>) {
ConfigLoader.Builder()
.addSource(PropertySource.resource("/application.yaml"))
.strict()
.build()
.loadConfigOrThrow<Config>()
}
}
data class Config(val foo: Foo)
data class Foo(val enabled: Boolean)
fails, with an error similar to:
Exception in thread "main" com.sksamuel.hoplite.ConfigException: Error loading config because:
Config values were not used: PATH, ...snip...
at com.sksamuel.hoplite.ConfigLoader$returnOrThrow$1.invoke(ConfigLoader.kt:335)
at com.sksamuel.hoplite.ConfigLoader$returnOrThrow$1.invoke(ConfigLoader.kt:20)
at com.sksamuel.hoplite.fp.ValidatedKt.getOrElse(Validated.kt:93)
at com.sksamuel.hoplite.ConfigLoader.returnOrThrow(ConfigLoader.kt:332)
...
Can the Environment, System and UserSettings property sources be optional for strict?
Perhaps change strict() to accept override flags (with defaults matching current usage):
strict(
includeEnvironmentVariables = true,
includeSystemProperties = true,
includeUserSettings = true
)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 21 (11 by maintainers)
Yes i have a lot done locally and want to release with kotlin 1.6 as durations will be no longer experimental.
On Thu, 30 Sep 2021, 18:06 Chris Ryan, @.***> wrote:
I think strict on env’s makes no sense actually, as there’s always likely to be env’s no used. I mean hoplite doesn’t control the entire env right 😃 Same for system properties. I’m surprised the tests didn’t catch this. It should only apply to files imo.
I think here the solution is don’t use the env property source. The built in env param mapper will do the ${name} replacements.
Still need this. Any progress on the 2.0 version?
Yes, I was waiting for Kotlin 1.5 to come out to make these changes, and release a 2.0 version (since it will require breaking some internals, which may affect some people who write custom decoders). Since Kotlin 1.5 came out yesterday I’ll do this work at the weekend and release then.
On Wed, 5 May 2021 at 07:54, John Newman @.***> wrote: