Skip to content

[enhancement] Making @Valid optional for adapter generation, if inferrable #333

@mechite

Description

@mechite

Related to (#666) avaje/avaje-http#666
and related to (#672) avaje/avaje-http#672

#672 implements a warning for avaje-http @Valid used outside of @Controller, which
is one of the issues that we face with the confusing / same annotation naming.

This issue is to request two things:

  1. Issue a warning, if not already doing this, for usages of avaje-validator @Valid (or the
    @jakarta.validation.Valid etc that we support) - given that the type has no actual
    constraint usages declared

    Is it easy to determine if no constraints are declared?
    This update would do the same that #672 does.

  2. Potentially more difficult update - @ValidatorModule annotation that goes on either
    a module-info or package-info for package/module-wide generation of validator adapters.

    This would have to walk the exports (or the annotated package) to list out what types contain
    usages of constraint annotations (annotations marked with @Constraint, etc).

    Then, the following example:

    import io.avaje.validation.constraints.NotBlank;
    
    //@Valid not required
    record User(@NotBlank String name, int age) {}

    ...becomes all that is required to generate a validation adapter.
    Whether that adapter is actually used with a call to validate doesn't matter


    An issue with this approach is similar to what @rbygrave said about "redundant @Inject",
    which also reminds me about Java not requiring @Override - a lot of these serve as a
    documentation tool.

    I like it for @Inject, I like it for @Controller @Valid, but I'm not sure if we need to say
    that an adapter is being generated, if it never gets used anyway.

    Marking a module as @ValidatorModule already does give some "explicit-ness" to this?
    (I chose that name here to be analogous to @InjectModule)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions