Skip to content
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

4.x: Allowed values are now checked when validating a builder. #7400

Merged
merged 4 commits into from
Aug 21, 2023

Conversation

tomas-langer
Copy link
Member

@tomas-langer tomas-langer commented Aug 17, 2023

Description

When using @ConfiguredOption(allowedValues=...) the generated builders now validate (during build) that the option is within the allowed values.

  • for an option, if not null, a check is made of its String.valueOf() against the String allowed value set
  • for a list of options, each value in the list is check (if any)

This change required modifying Annotation to support typed values and nested annotations, this has been done as well.

Documentation

This enhancement enforces an existing API in ConfiguredOption.
Annotation now supports nested annotations and typed values. Methods to obtain a typed value are now added to the Annotation type (in helidon-common-types)

Resolves #6403
Resolves #6231

@tomas-langer tomas-langer added 4.x Version 4.x builder Related to the builder support labels Aug 17, 2023
@tomas-langer tomas-langer self-assigned this Aug 17, 2023
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Aug 17, 2023
@@ -52,7 +52,7 @@ interface MyConfigBeanBlueprint {
*/
@ConfiguredOption(key = "port", value = "8080", allowedValues = {
@ConfiguredValue(value = "8080", description = "t1"),
@ConfiguredValue(value = "false", description = "t2")})
@ConfiguredValue(value = "80", description = "t2")})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is really needed here is a range of good values. I think ultimately for this we need to refer to a method or class to instantiate to perform dynamic validations for complex cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false is never a good value for an integer port. Not sure what you mean by this. If you need better validation, you can always have a custom decorator

@tomas-langer tomas-langer merged commit 21b5c03 into helidon-io:main Aug 21, 2023
@tomas-langer tomas-langer deleted the 6403-allowed-values branch August 21, 2023 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x builder Related to the builder support OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants