spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.58k stars 40.55k forks source link

ConfigurationProcessor : description missing from dependency #18366

Open jjoslet opened 4 years ago

jjoslet commented 4 years ago

Spring Boot version: 2.1.8.RELEASE

When using a class imported from a dependency as a @ConfigurationProperties, the generated configuration properties meta-data does not contains the description for this class' properties.

Scenario to reproduce: I test the example described in the documentation to create two data sources : https://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html#howto-two-datasources.

The produced spring-configuration-metadata.json does not include the description for the properties of DataSourceProperties class.

Here is a sample of the produced meta-data:

{
   "name": "app.datasource.first.name",
   "type": "java.lang.String",
   "sourceType": "org.springframework.boot.autoconfigure.jdbc.DataSourceProperties"
},

Sample project: demo.zip

snicoll commented 4 years ago

This is working as expected I am afraid. If the source code of DataSourceProperties is not available, we can't extract the documentation and default value as the annotation processor doesn't have access to the source model.

However, I can see how that's annoying and how the doc example is misleading. Flagging for team attention.

jjoslet commented 4 years ago

Since this is an annotation processor, this is hard to retrieve the JavaDoc from a compiled class.

I think this pattern can have a different behavior for the computation of the default value too.

Have you planned another way to produce the description which does not suffer from this limitation ?

Maybe another annotation that is used to describe the property ?

snicoll commented 4 years ago

@jjoslet I think I wrote exactly that in my previous comment, didn't I? We haven't scheduled anything at this point but I'd like to discuss it a bit more which is why I've flagged it.

wilkinsona commented 4 years ago

We may be able to find the existing metadata that was generated for DataSourceProperties from the classpath and splice it into the metadata that is being generated.

jjoslet commented 4 years ago

That will solve the issue for the particular DataSourceProperties example since it already produces meta-data. But it'll not handle the case where a third party class is not originally annotated with @ConfigurationProperties and is used in an application with @ConfigurationProperties.

Example in Spring Boot: HikariDataSource, org.apache.tomcat.jdbc.pool.DataSource. org.apache.commons.dbcp2.BasicDataSource, etc.

snicoll commented 4 years ago

We have metadata for that too. Ssl is more what you meant and we'll have to figure out how we can update the annotation processor to handle it. I think the issue is well understood, we now need to design it.

jjoslet commented 4 years ago

Yes, metadata are present but they miss the description.

snicoll commented 4 years ago

It's a third party type, they don't have description as it's not a @ConfigurationProperties type to begin with.

cachescrubber commented 4 years ago

Since #19500 is closed: My use-case is not to generate metadata for external 3rd-party classes outside my control. I am the maintainer of the jar providing the @ConfigurationProperty type and would cooperate in providing the required metadata - for example by using annotations instead of JavaDoc or by means of manually publishing the required metadata within my jar.

snicoll commented 4 years ago

I got that. Generating the metadata and reusing it is covered here too.

wilkinsona commented 1 year ago

34210 is related to this. It proposed allowing the configuration processor to consume multiple additional metadata files.