Add support for customizing spring boot ConfigurationProperties (#1897)
This adds an option which allows users to control exactly how `@ConfigurationProperties` annotations are attached to classes. This helps when: * Spring Boot users don't have a single root class, but multiple classes that are injected in disparate places * Pkl's module structure doesn't match the resulting `.properties` layout
This commit is contained in:
1 parent
f973fd6717
commit
88a50d167e
15 files changed
+294
-10
No files matched your search
@@ -1651,6 +1651,65 @@ class JavaCodeGeneratorTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `spring boot -- explicitly configured ConfigurationProperties`() {
|
||||
val javaCode =
|
||||
generateJavaCode(
|
||||
"""
|
||||
module my.mod
|
||||
|
||||
class Server
|
||||
"""
|
||||
.trimIndent(),
|
||||
JavaCodeGeneratorOptions(
|
||||
generateSpringBootConfig = true,
|
||||
springBootConfigurationProperties =
|
||||
mapOf("my.mod" to "", "my.mod#Server" to "my-server-prefix"),
|
||||
),
|
||||
)
|
||||
assertThat(javaCode)
|
||||
.contains(
|
||||
"""
|
||||
|@ConfigurationProperties
|
||||
|public final class Mod {
|
||||
| private Mod() {
|
||||
| }
|
||||
"""
|
||||
.trimMargin()
|
||||
)
|
||||
assertThat(javaCode)
|
||||
.contains(
|
||||
"""
|
||||
| @ConfigurationProperties("my-server-prefix")
|
||||
| public static final class Server {
|
||||
"""
|
||||
.trimMargin()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `spring boot -- explicity configured properties means no interface`() {
|
||||
val javaCode =
|
||||
generateJavaCode(
|
||||
"""
|
||||
module my.mod
|
||||
|
||||
server: Server
|
||||
|
||||
class Server
|
||||
"""
|
||||
.trimIndent(),
|
||||
JavaCodeGeneratorOptions(
|
||||
generateSpringBootConfig = true,
|
||||
springBootConfigurationProperties = mapOf("foo" to "foo"),
|
||||
),
|
||||
)
|
||||
// normally this would generate `@ConfigurationProperties` annotations through inference.
|
||||
// but setting this option means that the user is in total control of how these annotations
|
||||
// get produced.
|
||||
assertThat(javaCode).doesNotContain("@ConfigurationProperties")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `import module`() {
|
||||
val library =
|
||||
|
||||
Reference in new issue
Block a user