Skip to content

Default values of var-based properties are not documented properly #15397

@Simon3

Description

@Simon3

Generating configuration metadata from @ConfigurationProperties items written in Kotlin doesn't work for defaultValue fields. It works fine for all the other fields. In java, it works fine for everything. Here is an example. Note that I'm using Spring Boot 2.0 and Gradle.

kapt 'org.springframework.boot:spring-boot-configuration-processor'
kapt {
  arguments {
    arg("org.springframework.boot.configurationprocessor.additionalMetadataLocations", "$projectDir/src/main/resources")
   }
}
compileJava.dependsOn(processResources)

My @ConfigurationProperties file looks like this:

@Component
@ConfigurationProperties("flowr.epg")
class EpgProperties {
    /** Whether or not schedules should be computed/refreshed on (re)start */
    var refreshOnRestart = true
    /** Number of threads used to store new images */
    var nImagesUploadThreads = 10
}

The result looks like this:

{
  "hints": [],
  "groups": [
    {
      "sourceType": "com.taktik.flowr.epg.properties.EpgProperties",
      "name": "flowr.epg",
      "type": "com.taktik.flowr.epg.properties.EpgProperties"
    }
  ],
  "properties": [
{
  "sourceType": "com.taktik.flowr.epg.properties.EpgProperties",
  "defaultValue": false,
  "name": "flowr.epg.refresh-on-restart",
  "description": "Whether or not schedules should be computed\/refreshed on (re)start",
  "type": "java.lang.Boolean"
},
{
  "sourceType": "com.taktik.flowr.epg.properties.EpgProperties",
  "defaultValue": 0,
  "name": "flowr.epg.n-images-upload-threads",
  "description": "Number of threads used to store new images",
  "type": "java.lang.Integer"
}
}

Support for default values in Kotlin would be a really nice feature to have for my company.

Note: replicated from https://stackoverflow.com/questions/53636533/spring-boot-configurationproperties-metadata-generation-wrong-default-values

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions