diff --git a/ktor-server/ktor-server-core/jvmAndNix/src/io/ktor/server/config/MergedApplicationConfig.kt b/ktor-server/ktor-server-core/jvmAndNix/src/io/ktor/server/config/MergedApplicationConfig.kt index 256c90a3df4..165df3762e7 100644 --- a/ktor-server/ktor-server-core/jvmAndNix/src/io/ktor/server/config/MergedApplicationConfig.kt +++ b/ktor-server/ktor-server-core/jvmAndNix/src/io/ktor/server/config/MergedApplicationConfig.kt @@ -30,15 +30,11 @@ internal class MergedApplicationConfig( else -> second.propertyOrNull(path) } - override fun config(path: String): ApplicationConfig = when { - firstKeys.contains(path) -> first.config(path) - else -> second.config(path) - } + override fun config(path: String): ApplicationConfig = + MergedApplicationConfig(first.config(path), second.config(path)) - override fun configList(path: String): List = when { - firstKeys.contains(path) -> first.configList(path) - else -> second.configList(path) - } + override fun configList(path: String): List = + first.configList(path) + second.configList(path) override fun keys(): Set = firstKeys + second.keys() diff --git a/ktor-server/ktor-server-core/jvmAndNix/test/io/ktor/server/config/MergedApplicationConfigTest.kt b/ktor-server/ktor-server-core/jvmAndNix/test/io/ktor/server/config/MergedApplicationConfigTest.kt index 6a7fce14b2c..7aefa864dda 100644 --- a/ktor-server/ktor-server-core/jvmAndNix/test/io/ktor/server/config/MergedApplicationConfigTest.kt +++ b/ktor-server/ktor-server-core/jvmAndNix/test/io/ktor/server/config/MergedApplicationConfigTest.kt @@ -17,6 +17,39 @@ class MergedApplicationConfigTest { assertEquals("value3", config.property("second").getString()) } + @Test + fun testConfig() { + val first = MapApplicationConfig("first.second.third1" to "value1", "first.second.third2" to "value2") + val second = MapApplicationConfig("first.second.third1" to "ignored", "first.second.third3" to "value3") + val config = MergedApplicationConfig(first, second) + val mergedNestedConfig = config.config("first.second") + assertEquals("value1", mergedNestedConfig.property("third1").getString()) + assertEquals("value2", mergedNestedConfig.property("third2").getString()) + assertEquals("value3", mergedNestedConfig.property("third3").getString()) + assertEquals(setOf("third1", "third2", "third3"), mergedNestedConfig.keys()) + } + + @Test + fun testConfigList() { + val first = MapApplicationConfig( + "first.second.size" to "2", + "first.second.0.third" to "value1", + "first.second.1.third" to "value2" + ) + val second = MapApplicationConfig( + "first.second.size" to "2", + "first.second.0.third" to "value3", + "first.second.1.third" to "value4" + ) + val config = MergedApplicationConfig(first, second) + val configs = config.configList("first.second") + assertEquals(4, configs.size) + assertEquals("value1", configs[0].property("third").getString()) + assertEquals("value2", configs[1].property("third").getString()) + assertEquals("value3", configs[2].property("third").getString()) + assertEquals("value4", configs[3].property("third").getString()) + } + @Test fun testPropertyOrNull() { val first = MapApplicationConfig("first" to "value1")