-
Notifications
You must be signed in to change notification settings - Fork 40.7k
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
Add support for enum default values in configuration processor #7562
Comments
This is something that can be extracted from code and the IDE is supposed to do that for you. I am not keen to write such duplication in the metadata. Why are you asking for this? Which IDE do you use? |
I use IntelliJ IDEA but the wish for this came up outside the context of an IDE when trying to use the configuration meta-data to generate documentation describing all properties and their default values. |
For example, I was hoping to generate tables with default configuration using cat **/spring-boot-sample-property-validation/**/spring-configuration-metadata.json | \
jq -r '.properties[] | [.name, .description, .type, .defaultValue | tostring] | @csv' | \
csvfix ascii_table -h "Name, Description, Type, Default value"
|
It sounds to me like there's some confusion here between listing all possible values for a property with an enum type (which an IDE can do automatically) and listing the default value for such a property. In our own metadata I'd expect there to be a default value listed for {
"name": "security.headers.hsts",
"type": "org.springframework.boot.autoconfigure.security.SecurityProperties$Headers$HSTS",
"description": "HTTP Strict Transport Security (HSTS) mode (none, domain, all).",
"sourceType": "org.springframework.boot.autoconfigure.security.SecurityProperties$Headers"
}, This means that the IDE (I checked in IntelliJ) doesn't display a default value. It does, however, list the three possible values as completion options having extracted them from the enum. |
Wow, for some reason my brain read "list of values" instead of default value. Thank you @wilkinsona for pointing that mistake. Yes, we should try to improve this. If you want to give that a try, please note we use a canonical representation for as much content as we can ( Clearly, it means the same work should be done when detecting |
Is there a built-in function somewhere in Spring [Boot] I can use to do this conversion? …or is it OK that I use the function |
@qerub ConfigurationMetadata.toDashedCase(String) should be able to do that for you. |
@wilkinsona: Just checked |
Gah! Sorry, I should have remembered that. The behaviour is intentional (see #5330). I think lower case and replace should be good enough. |
Let's try to have another look still. |
This commit improves the configuration metadata annotation processor to detect a default enum value. The algorithm is best-effort, similarly to what it already does for well known prefixes (period, duration, etc). Based on an expression and an identifier, the default value is inferred if the expression matches the declaration of the property type. See gh-7562
It's quite common to use enums for configuration properties, but the configuration processor is currently unable to extract the default value for those (because of lack of support in
JavaCompilerFieldValuesParser
). This means that the generated configuration JSON specification is currently incomplete/incorrect wrt. to enum properties. Unless this functionality has been left out on purpose I can take a stab at adding it.The text was updated successfully, but these errors were encountered: