Reputation: 11
All of this was tested/tried on springboot 3.3.0.
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.Map;
@ConfigurationProperties(prefix = "app")
public record AppProperties(Map<String, MapConfig> map, UseConfig config) {
record MapConfig(String value1, String value2) {}
record UseConfig(String use) {}
}
app:
map: <-- This is a Map<String, Object>
key1: <-- This is a user defined key that I cannot control through enums, so it's a String
...
key2:
...
config:
use: key1 <-- Use one key from the `app.map` keySet
What I want to do, is to provide a nice user experience by having hints provided by the IDE.
app.config.use
suggestions should be [key1, key2]
.app.config.use
with value key3
should be marked as a configuration errorspring-boot-configuration-metadata
project.But it seems that I cannot provide dynamic hints based on the keys of a map.
I tried configuring hints manually, but couldn't find a way with the current value providers:
I would have expected something like that to fulfill my needs:
{
"name": "app.config.use",
"providers": [
{
"name": "property-source",
"parameters": {
"property": "app.map.keys"
}
}
]
}
Note that I'm using .keys
to specify the key set of such property. Just as mentioned in the value hint doc which states:
If your property is of type Map, you can provide hints for both the keys and the values (but not for the map itself). The special .keys and .values suffixes must refer to the keys and the values, respectively.
Upvotes: 1
Views: 59