Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ConfigurationProperties not functioning correctly on nested configuration when using KSP #10943

Open
cainecridland opened this issue Jul 3, 2024 · 0 comments
Labels
lang: kotlin Issues or features specific to Kotlin type: bug Something isn't working

Comments

@cainecridland
Copy link

Expected Behavior

The @ConfigurationProperties annotation should apply to both the piece of configuration specified and any configuration nested under it.

Actual Behaviour

If we have a config item uses @ConfigurationProperties to override what the property is called in the application.yml (ie to something that wouldn't be the default) then it will be correctly set, but any values nested underneath this item will not be set. Strangely this does not affect nested objects, just nested values.

If an additional config line is added to the application.yml that matches the name of the property then the values will be successfully looked up, but from the overridden path, not the path that matches the name. If the path that matches the name is removed then the lookup will fail.

Steps To Reproduce

Reproduction steps are available in the README of the example application below, but generally:

  1. Define a 2 level configuration structure in the application.yml file like the following:
example-project:
 level-one:
   level-one-value: ONE
   level-two:
     levelTwoValue: TWO
  1. Create a corresponding configuration class in the test directory like the following:
@ConfigurationProperties("example-project")
class Configuration {
    @Inject internal var levelOne = LevelOne()
    @ConfigurationProperties("level-one")
    internal class LevelOne {
        internal lateinit var levelOneValue: String
        @Inject internal var levelTwo = LevelTwo()
        @ConfigurationProperties("level-two")
        internal class LevelTwo {
            lateinit var levelTwoValue: String
        }
    }
}
  1. Create a unit test that uses the @MicronautTest annotation, injects the configuration and prints the values of levelOneValue and levelTwoValue.
  2. Run the test to observe that it passes.
  3. Refactor the var levelOne to be called something else i.e notLevelOne, this should not affect anything as @ConfigurationProperties should point to the correct piece of configuration in the .yml file.
  4. Rerun the test and levelOneValue and levelTwoValue will not have been initialised.

Environment Information

  • Kotlin 2.0
  • JDK 17

Example Application

https://github.com/cainecridland/micronaut-nested-config-problem-example

Version

4.4.0

@graemerocher graemerocher added lang: kotlin Issues or features specific to Kotlin type: bug Something isn't working labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang: kotlin Issues or features specific to Kotlin type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants