Skip to content

Commit 1911d0f

Browse files
authored
fix optional checktype (#344)
1 parent a09f5ef commit 1911d0f

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

validator-constraints/src/main/java/io/avaje/validation/constraints/NotBlank.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @author Hardy Ferentschik
1919
* @see Character#isWhitespace(char)
2020
*/
21-
@Constraint
21+
@Constraint(targets = CharSequence.class)
2222
@Documented
2323
@Target({METHOD, FIELD, ANNOTATION_TYPE, PARAMETER, TYPE_USE})
2424
@Retention(RUNTIME)

validator-generator/src/main/java/io/avaje/validation/generator/AdapterHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ void write() {
106106
if (hasValid) {
107107
if (mainType.param0().fullWithoutAnnotations().equals(recursiveType)) {
108108
// cascade validate
109-
writer.eol().append("%s .andThen(this)", indent, mainType.param0().shortType());
109+
writer.eol().append("%s .andThen(this)", indent, mainType.param0().shortWithoutAnnotations());
110110
} else {
111111
// cascade validate
112-
writer.eol().append("%s .andThen(ctx.adapter(%s.class))", indent, mainType.param0().shortType());
112+
writer.eol().append("%s .andThen(ctx.adapter(%s.class))", indent, mainType.param0().shortWithoutAnnotations());
113113
}
114114
}
115115
writer.eol().append("%s .optional()", indent);

validator-generator/src/main/java/io/avaje/validation/generator/ElementAnnotationContainer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ private static AnnotationMirror checkType(Element element, UType uType, Annotati
8686
.map(ConstraintPrism::targets)
8787
.filter(l -> !l.isEmpty())
8888
.ifPresent(l -> {
89-
if (l.stream().noneMatch(t -> APContext.types().isAssignable(uType.mirror(), t))) {
89+
if (l.stream().noneMatch(t ->
90+
APContext.types().isAssignable(uType.mirror(), t)
91+
|| "java.util.Optional".equals(uType.mainType())
92+
&& APContext.types().isAssignable(uType.param0().mirror(), t))) {
9093
APContext.logError(
9194
element,
9295
"@%s cannot be used on %s",

validator-generator/src/test/java/io/avaje/validation/generator/models/valid/Ship.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
@Valid
1111
public record Ship(
1212
@NotEmpty(message = "sus ", groups = Ship.class)
13-
Map<
14-
@NotEmpty(groups = Ship.class) @NotBlank String,
15-
@NotBlank(groups = Ship.class) @Valid CrewMate>
16-
crew,
13+
Map<@NotEmpty(groups = Ship.class) @NotBlank String, @Valid CrewMate> crew,
1714
@NotEmpty(message = "tasks,=(testing wierd chars&rparen; ")
1815
List<
1916
@NotEmpty(groups = List.class)

0 commit comments

Comments
 (0)