-
Notifications
You must be signed in to change notification settings - Fork 116
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
Proposal for Configurable Naming Strategy in ConfigMapping #1091
Comments
Thank you for the proposal. Any chance to work on this? :) |
@radcortez Thank You very much! I would be happy, but your magic is much beyond my knowledge. I have just opened source code: byte code manipulation, etc. Sorry 😥 Maybe I can send my JsonConfigSource and Spring integration? 🤣 |
It shouldn't require changes in the bytecode generation parts. The naming strategy is applied by calling this method: smallrye-config/implementation/src/main/java/io/smallrye/config/ConfigMappingContext.java Lines 114 to 121 in 55209a5
Generated code will call that method to pass the current naming strategy, but if we add a global one, I believe it just needs to be checked with some logic in that method. I can have a look into that.
The JSON support is already provided by our YAML Config Source. The Spring integration sounds interesting. Do you have the code available somewhere so I can have a look? |
Your integration is more related to MicroProfile Config than SmallRye Config. You could probably replace the Bean creator to use I recommend staying away from A If we move to provide some sort of Spring integration (which I would definitely love to), I would prefer to just stick with |
@radcortez I was busy… 🙏
1 and 2 → very easy But if all 4 are implemented, you can write anything you like: @Value("${$gst$ Example ${1 + 2} <%= this.getClass().getSuperclass() %> } ")
private String g3;
@ConfigProperty(name = "$gst$ Example ${2 + 2} <%= this.getClass().getSuperclass() %> ")
private String g4;
@Autowired
private @NonNull SmallRyeConfig config1;
@ConfigMapping
private SmallRyeConfigTest.SimpleObj3 obj30;
@ConfigMapping(prefix = "obj2")
private SmallRyeConfigTest.SimpleObj3 obj40;
@ConfigProperties
private SmallRyeConfigTest.SimpleObj3 obj3;
@ConfigProperties(prefix = "obj2")
private SmallRyeConfigTest.SimpleObj3 obj4; |
I know it is possible to support all kinds of annotations. From the SR Config perspective, the only annotation that we should provide support for is |
This is not straightforward to implement. The While I see some value in the feature, the effort to support it is quite high, which makes it less interesting to add. For the time being, I'm closing this. |
I am writing to propose a change that would allow the ConfigMapping.namingStrategy to be configured from the application's configuration.
Currently, the naming strategy for configuration properties is determined by the method namingStrategy() in the @ConfigMapping annotation interface, with the default value NamingStrategy.KEBAB_CASE.
You could add an additional ENUM constant: CONFIGURABLE and make it default.
This strategy would read config key
smallrye.config.naming.strategy = VERBATIM
orKEBAB_CASE
orSNAKE_CASE
and if present, use its value.
If
smallrye.config.naming.strategy
is absent, thenNamingStrategy.KEBAB_CASE
is used.So, no backward compatibility is broken.
But one can change it in configuration file instead of tedious repeating in every annotation.
https://github.com/smallrye/smallrye-config/blob/main/implementation/src/main/java/io/smallrye/config/ConfigMapping.java
The text was updated successfully, but these errors were encountered: