rodnansol / spring-configuration-property-documenter

Tool to document Spring Configuration Properties - Leave us a feedback: https://github.com/rodnansol/spring-configuration-property-documenter/discussions/74
Apache License 2.0
37 stars 5 forks source link

Multiple use of nested configuration results in multiple properties #71

Closed Riggs333 closed 1 year ago

Riggs333 commented 1 year ago

Given this type with nested configuration:

@ConfigurationProperties("my.app.parent.my-app-configuration")
public record MyApplicationConfiguration(
        String foo,
        MyNestedChildConfiguration abc,
        MyNestedChildConfiguration efg,
        MyNestedChildConfiguration xyz
) {
    record MyNestedChildConfiguration(String bar) {
    }
}

resulting in spring-configuration-metadata.json:

{
  "groups": [
    {
      "name": "my.app.parent.my-app-configuration",
      "type": "com.playground.springplayground.MyApplicationConfiguration",
      "sourceType": "com.playground.springplayground.MyApplicationConfiguration"
    },
    {
      "name": "my.app.parent.my-app-configuration.abc",
      "type": "com.playground.springplayground.MyApplicationConfiguration$MyNestedChildConfiguration",
      "sourceType": "com.playground.springplayground.MyApplicationConfiguration",
      "sourceMethod": "abc()"
    },
    {
      "name": "my.app.parent.my-app-configuration.efg",
      "type": "com.playground.springplayground.MyApplicationConfiguration$MyNestedChildConfiguration",
      "sourceType": "com.playground.springplayground.MyApplicationConfiguration",
      "sourceMethod": "efg()"
    },
    {
      "name": "my.app.parent.my-app-configuration.xyz",
      "type": "com.playground.springplayground.MyApplicationConfiguration$MyNestedChildConfiguration",
      "sourceType": "com.playground.springplayground.MyApplicationConfiguration",
      "sourceMethod": "xyz()"
    }
  ],
  "properties": [
    {
      "name": "my.app.parent.my-app-configuration.abc.bar",
      "type": "java.lang.String",
      "sourceType": "com.playground.springplayground.MyApplicationConfiguration$MyNestedChildConfiguration"
    },
    {
      "name": "my.app.parent.my-app-configuration.efg.bar",
      "type": "java.lang.String",
      "sourceType": "com.playground.springplayground.MyApplicationConfiguration$MyNestedChildConfiguration"
    },
    {
      "name": "my.app.parent.my-app-configuration.foo",
      "type": "java.lang.String",
      "sourceType": "com.playground.springplayground.MyApplicationConfiguration"
    },
    {
      "name": "my.app.parent.my-app-configuration.xyz.bar",
      "type": "java.lang.String",
      "sourceType": "com.playground.springplayground.MyApplicationConfiguration$MyNestedChildConfiguration"
    }
  ],
  "hints": []
}

results in the generated markdown having the bar property wrongly three times inside each nested child group:


...

Unknown group

Class: Unknown

Key Type Description Default value Deprecation

my.app.parent.my-app-configuration

Class: com.playground.springplayground.MyApplicationConfiguration

Key Type Description Default value Deprecation
foo java.lang.String

my.app.parent.my-app-configuration.abc

Class: com.playground.springplayground.MyApplicationConfiguration$MyNestedChildConfiguration

Key Type Description Default value Deprecation
bar java.lang.String
bar java.lang.String
bar java.lang.String

my.app.parent.my-app-configuration.efg

Class: com.playground.springplayground.MyApplicationConfiguration$MyNestedChildConfiguration

Key Type Description Default value Deprecation
bar java.lang.String
bar java.lang.String
bar java.lang.String

my.app.parent.my-app-configuration.xyz

Class: com.playground.springplayground.MyApplicationConfiguration$MyNestedChildConfiguration

Key Type Description Default value Deprecation
bar java.lang.String
bar java.lang.String
bar java.lang.String

Used versions:

pom.xml snippet for plugin usage:

...
            <plugin>
                <groupId>org.rodnansol</groupId>
                <artifactId>spring-configuration-property-documenter-maven-plugin</artifactId>
                <version>0.6.0</version>
                <executions>
                    <execution>
                        <id>generate-markdown</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>generate-property-document</goal>
                        </goals>
                        <configuration>
                            <type>MARKDOWN</type>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
...
nandorholozsnyak commented 1 year ago

Hello @Riggs333 Thank you for the report, let me try to address these issues in the near future.

nandorholozsnyak commented 1 year ago

The fix will arrive in the 0.6.1 version.

nandorholozsnyak commented 1 year ago

Release is running, if it succeeds you should see the 0.6.1 in the Maven Central soon. Until then if you have some time I'm curious about how you found the project and using it, can you drop an answer here? :)

Tell us how you use the project!

Thanks in advance!

Riggs333 commented 1 year ago

Hey @nandorholozsnyak - awesome! šŸ„³ That was really fast! šŸ‘šŸ» Thank you very much! šŸ™‡šŸ» I will answer the questions in the discussions.

nandorholozsnyak commented 1 year ago

I appreciate the feedback. I'm trying to fix the issues as soon as I can. :)