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

HV-2073 Add new OneOfValidator for CharSequence validation #1540

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aalamu
Copy link

@aalamu aalamu commented Dec 30, 2024

Description:

Contributed a new OneOfValidator for the Hibernate Validator project.

This validator checks if a given CharSequence matches one of the allowed values specified in the OneOf annotation.

Features:

  • Validates if a CharSequence is one of the allowed values.
  • Supports case-sensitive and case-insensitive validation based on the ignoreCase flag.
  • Supports both Enum constants and manually provided allowed values.

The validator is implemented with the following:

  • OneOfValidator class implementing ConstraintValidator<OneOf, CharSequence>.
  • Adds values from allowedValues() and enumClass() in the OneOf annotation for validation.
  • Provides methods to handle case-sensitive and case-insensitive validation.

Tests have been added, and all tests pass.

[Please describe here what your change is about]


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on licensing, please check here.


Description:
Contributed a new OneOfValidator for the Hibernate Validator project.

This validator checks if a given CharSequence matches one of the allowed values specified in the OneOf annotation.

Features:
- Validates if a CharSequence is one of the allowed values.
- Supports case-sensitive and case-insensitive validation based on the ignoreCase flag.
- Supports both Enum constants and manually provided allowed values.

The validator is implemented with the following:
- OneOfValidator class implementing ConstraintValidator<OneOf, CharSequence>.
- Adds values from allowedValues() and enumClass() in the OneOf annotation for validation.
- Provides methods to handle case-sensitive and case-insensitive validation.

Tests have been added, and all tests pass.
@marko-bekhta
Copy link
Member

Hey @aalamu 👋🏻
Thanks for starting a pull request! I'll try to take a closer look and think more about the suggested constraint this week, but here are a few things:

@aalamu
Copy link
Author

aalamu commented Jan 9, 2025

Hi @marko-bekhta,

I would go through the details. Thank you.

@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Jan 17, 2025

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

…nstraint, ConstraintHelper, TypeNames.

2. Added OneOfDef and its unit test.
3. Added documentation in ch02.asciidoc.
4. Updated OneOf constraints to accept different array data types like int, long, float and double.
5. Updated OneOfValidator to map to Object instead of CharSequence so that it can be used on fields with Integer, Long, Float, Double and String types.
6. Added detailed unit tests for OneOf in OneOfValidatorTest.
7. Added validation messages for OneOf message code or key in ValidationMessages_[LOCALE].properties files.
@aalamu
Copy link
Author

aalamu commented Jan 17, 2025

Hi @marko-bekhta ,

I've made an to the PR. I refactored the OneOf validator to make it versatile with different types.

I also tried to investigate the Sonar analysis failure, I couldn't find enough details regarding it except unknown host or service.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants