micronaut-projects / micronaut-projects/micronaut-validation

Add support for message interpolator for validation messages

Open
#692 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: under consideration type: enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.