-
Notifications
You must be signed in to change notification settings - Fork 2.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
Validation on configuration using interfaces doesn't work #15081
Comments
Just to add an additional comment - when using interfaces, putting validation on the getters doesn't work in general. @ConfigProperties(prefix = "greeting")
public interface GreetingConfiguration {
String getMessage();
@ConfigProperty(defaultValue = "!")
String getSuffix();
Optional<String> getName();
@Positive
Integer getPrizeAmount();
} with configuration greeting.message=hello
greeting.name=quarkus
greeting.prize-amount=0 should produce an error at startup, but it does not |
I'll take a look this week |
Your code isn't correct: You need to add
That results in the proper error message being triggered. As for the issue with validation not being triggered on interfaces, I can confirm it |
THanks @geoand I can confirm adding Do you want me to open a separate issue for the interfaces? Or just continue with this issue for that (I can update the reproducer example). |
I'd say just update the title, description and reproducer for this one is fine |
Is it expected that validation should work when using interfaces? |
Not really. I'm looking into how it can be added. |
This can be done, but not without adding a ton of complexity to the So unless this gets asked for again, I'll hold off on implementing it. |
Noted - but I might add something to the documentation mentioning that validation isn't supported/implemented when using interfaces. Honestly I only discovered it when looking at the docs and thinking it was cool. Reduces a lot of boilerplate. |
That's a good point |
#15086 is what is actually necessary to make this happen |
Looks good to me! Ship it! :D |
I'll need to rethink it, not to mention add the necessary tests (it did work on your example though) |
@geoand we can probably think about dropping Right now, it seems we are just duplicating effort. Regarding validation, We can check some other things that we are missing and port them to SR. We also support other stuff that |
Whatever the decision going forward is let's just keep in mind the top-level use case: As a developer I should be able to expose type-safe configuration and/or hierarchies of configuration and be able to validate the configuration against a set of rules. Currently the "interface-way" of defining configuration doesn't support that requirement whereas the "class-way" does. If the "interface-way" continues to be a "thing", then it should support the requirement in some fashion, no? |
@radcortez yes, let's sync sometime before 1.13 and name a decision |
No worries. This is just the internal implementation. It shouldn't matter to the end user. And yes, interfaces should support validation as well. |
Describe the bug
According to https://quarkus.io/guides/config-reference#additional-notes-on-configproperties I should be able to validate nested configuration using interfaces but it doesn't seem to work.
Expected behavior
I would expect the application to fail when starting up
Actual behavior
The application starts up without error
To Reproduce
Reproducer application attached
quarkus-config-sample.zip
The text was updated successfully, but these errors were encountered: