-
Notifications
You must be signed in to change notification settings - Fork 119
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
Allow to fetch multiple config parameters as a Map #579
Conversation
Hi @radcortez it is the PR related to my comment. It is very basic because there are many things unspecified (like for example how to manage default values in case of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
how to manage default values in case of
@ConfigProperty
,
We could support something likekey=value
and parse the default value if the injection is a map. Alternatively, we could just disallow it all together and throw a validation exception.
how to deal with
config.getValue
in case of map since we have no way to get the Parameterized types)
We would need to support something similar to aGenericType
like JAX-RS to carry type information, but for now we could just assume that the programmatic API for Map returns aMap<String,String>
.
cdi/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java
Outdated
Show resolved
Hide resolved
I just added the support of default value with the next format
I added a new BuiltIn Converter for the Map to be able to support |
@radcortez Hi, all your remarks have been addressed, this PR is ready for review now. Thank you in advance 🙏 |
Finally I rather added new dedicated methods as extensions for the map support such that I don't need the Map converter to be part of the Builtin converters |
I expected to have it included into Quarkus 2.0, I guess it is too late now 😢 |
I wouldn't be too worried about it. Quarkus has a very high release cadence, so it we miss the boat now, we will get the next one soon :) Anyway, we still need to test this in Quarkus. Did you try it? In the meantime I'll have review the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is going into the right direction. Left a few comments for us to discuss :) Thanks!
cdi/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java
Outdated
Show resolved
Hide resolved
implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java
Outdated
Show resolved
Hide resolved
implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java
Outdated
Show resolved
Hide resolved
@essobedo Thank you! I think we are almost done. Just one last detail: can we document the new feature here: https://github.com/smallrye/smallrye-config/blob/fecdcf541a0ad979cc3f83f8e5f4829da61e5be8/doc/modules/ROOT/pages/config/config.adoc. You can follow the indexed properties example. |
Also, I recommend to make a build and test it with Quarkus master. Did you try it with Quarkus as is? |
Not yet but I will test it today and let you know the results. |
implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java
Outdated
Show resolved
Hide resolved
@radcortez just to let you know that I had to make couple of additional fixes to make it work with Quarkus, knowing that even on Quarkus side there are some little changes to make. I have not yet finished but I could make injection with
|
@radcortez After a deeper investigation, it appears that I need to move the method |
implementation/src/main/java/io/smallrye/config/ConfigMappingGenerator.java
Show resolved
Hide resolved
So I tested it successfully on Quarkus (modulo a small patch to support map) with the next use case: The main configuration class:
The class
The yaml configuration used for the test:
And if I remove the configuration, I get Let me know if it is good enough for you or you have another uses in mind to test, meanwhile I start working on the doc. |
FYI here is my test branch for Quarkus https://github.com/quarkusio/quarkus/compare/main...essobedo:add-map-support?expand=1 |
@radcortez I added the doc, so now all your remarks have been addressed |
cdi/src/main/java/io/smallrye/config/inject/ConfigProducerUtil.java
Outdated
Show resolved
Hide resolved
implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java
Outdated
Show resolved
Hide resolved
implementation/src/main/java/io/smallrye/config/SmallRyeConfig.java
Outdated
Show resolved
Hide resolved
implementation/src/main/java/io/smallrye/config/ConfigMappingGenerator.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@essobedo Thank you for your patience. Very good job. Just a few more minor things (leftovers from the other proposals and we should be good to go).
@radcortez Done, please check again. Do you want me to squash my commits? |
Yes, please. Thank you :) |
Done |
@essobedo Thank you very much for all the work. I hope you can continue to contribute :) Can you please open a Draft PR for Quarkus with the changes required? It it fine to use the SNAPSHOT (the CI won't build it as draft). We can update the version once we release, so the PR is for us to not forget the changes. I think we may need some other fixes for Quarkus in other areas, so we need these in before doing the final release. |
You're welcome, it is always with great pleasure that I contribute to open source projects. If you would like me to help you (if I can) on another tickets, please let me know, I will be more than happy to help 😄
Here it is quarkusio/quarkus#17579 |
Thanks a lot @essobedo ! |
fixes #578
Motivation
When we need a dynamic configuration, it can be very helpful to use a map. For example, let's say that I want to keep in my configuration the custom reason phrases to return to the enduser according to the http status code.
I would like to have:
The expected code
The expected configuration
Modifications
<key1>=<value1>;<key2>=<value2>...
into aMap
.ConfigMappingGenerator
getValues(String name, Class<K> kClass, Class<V> vClass)
andgetOptionalValues(String name, Class<K> kClass, Class<V> vClass)
to support properly the map from the classSmallRyeConfig