micronaut-projects / micronaut-projects/micronaut-validation
Add support for message interpolator for validation messages
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9
- Forks
- 8
- Avg merge
- 20h 7m
- Merged PRs (30d)
- 9
Description
Feature description
Message interpolators are currently not supported (DefaultValidatorFactory and DefaultValidatorConfiguration throw UnsupportedOperationException). Would it be possible to add it in the future, or does it require reflections to work?
We're currently migrating one of our projects from Spring Boot to Micronaut. We're using message interpolators to handle simple expressions that evaluate to other message keys within validation messages, this is the only thing still missing for us to be able to get rid of hibernate validator.
Example:
validation.validateDateRange={start} should be ${condition.getText()} {end}
validation.validateDateRange.earlierOrEqual=earlier or equal to
validation.validateDateRange.earlier=earlier than
@Target({TYPE, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Constraint(validatedBy = DateRangeValidator.class)
@Repeatable(ValidDateContainer.class)
public @interface ValidateDateRange {
String message() default "validation.validateDateRange";
String start();
String end();
Condition condition();
Class[] groups() default {};
Class[] payload() default {};
enum Condition implements LocalizedText {
EARLIER_OR_EQUAL("validation.validateDateRange.earlierOrEqual"),
EARLIER("validation.validateDateRange.earlier");
private final String text;
Condition(String text) {
this.text = text;
}
public String getText() {
return text;
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading DefaultValidatorFactory and DefaultValidatorConfiguration, where message interpolators currently throw UnsupportedOperationException. Trace how validation messages are resolved and assess the provided properties and Java annotation example; done means equivalent message-key and expression interpolation works without those exceptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100