File tree Expand file tree Collapse file tree 5 files changed +31
-5
lines changed
http-api/src/main/java/io/avaje/http/api
http-generator-core/src/main/java/io/avaje/http/generator/core
tests/test-javalin-jsonb/src/main/java/org/example/myapp/web Expand file tree Collapse file tree 5 files changed +31
-5
lines changed Original file line number Diff line number Diff line change
1
+ package io .avaje .http .api ;
2
+
3
+ import static java .lang .annotation .ElementType .METHOD ;
4
+ import static java .lang .annotation .ElementType .PARAMETER ;
5
+ import static java .lang .annotation .ElementType .TYPE ;
6
+ import static java .lang .annotation .RetentionPolicy .SOURCE ;
7
+
8
+ import java .lang .annotation .Retention ;
9
+ import java .lang .annotation .Target ;
10
+
11
+ /**
12
+ *
13
+ * Add @Valid annotation on a controller/method/BeanParam that we want bean validation to be included for.
14
+ * When we do this controller methods that take a request payload will then have the request bean
15
+ * (populated by JSON payload or form parameters) validated before it is passed to the controller
16
+ * method.
17
+ *
18
+ * When trying to validate a @BeanParam bean, this will need to be placed on the BeanParam type
19
+
20
+ */
21
+ @ Retention (SOURCE )
22
+ @ Target ({METHOD , TYPE , PARAMETER })
23
+ public @interface Valid {}
Original file line number Diff line number Diff line change @@ -162,6 +162,7 @@ private boolean initDocHidden() {
162
162
private boolean initHasValid () {
163
163
164
164
return findAnnotation (JavaxValidPrism ::getOptionalOn ).isPresent ()
165
+ || findAnnotation (JakartaValidPrism ::getOptionalOn ).isPresent ()
165
166
|| findAnnotation (ValidPrism ::getOptionalOn ).isPresent ();
166
167
}
167
168
Original file line number Diff line number Diff line change @@ -129,7 +129,9 @@ private boolean useValidation() {
129
129
}
130
130
final var elementType = typeElement (rawType );
131
131
return elementType != null
132
- && (ValidPrism .isPresent (elementType ) || JavaxValidPrism .isPresent (elementType ));
132
+ && (ValidPrism .isPresent (elementType )
133
+ || JavaxValidPrism .isPresent (elementType )
134
+ || JakartaValidPrism .isPresent (elementType ));
133
135
}
134
136
135
137
private void readAnnotations (Element element , ParamType defaultType ) {
Original file line number Diff line number Diff line change 26
26
@ GeneratePrism (value = io .avaje .http .api .OpenAPIResponse .class , publicAccess = true )
27
27
@ GeneratePrism (value = io .avaje .http .api .OpenAPIResponses .class , publicAccess = true )
28
28
@ GeneratePrism (value = io .swagger .v3 .oas .annotations .Hidden .class , publicAccess = true )
29
- @ GeneratePrism (value = javax .validation .Valid .class , name = "JavaxValidPrism" , publicAccess = true )
30
- @ GeneratePrism (value = jakarta .validation .Valid .class , publicAccess = true )
31
29
@ GeneratePrism (value = org .jetbrains .annotations .NotNull .class , publicAccess = true )
32
30
@ GeneratePrism (value = io .avaje .http .api .Client .class , publicAccess = true )
33
31
@ GeneratePrism (value = io .avaje .http .api .Client .Import .class , publicAccess = true )
34
32
@ GeneratePrism (value = io .avaje .http .api .RequestTimeout .class , publicAccess = true )
33
+ @ GeneratePrism (value = javax .validation .Valid .class , name = "JavaxValidPrism" )
34
+ @ GeneratePrism (value = jakarta .validation .Valid .class , name = "JakartaValidPrism" )
35
+ @ GeneratePrism (value = io .avaje .http .api .Valid .class )
35
36
package io .avaje .http .generator .core ;
36
37
37
38
import io .avaje .prism .GeneratePrism ;
Original file line number Diff line number Diff line change 8
8
import java .util .concurrent .CompletableFuture ;
9
9
import java .util .concurrent .Executors ;
10
10
11
- import javax .validation .Valid ;
12
-
13
11
import org .example .myapp .service .MyService ;
14
12
15
13
import io .avaje .http .api .BeanParam ;
23
21
import io .avaje .http .api .Post ;
24
22
import io .avaje .http .api .Produces ;
25
23
import io .avaje .http .api .QueryParam ;
24
+ import io .avaje .http .api .Valid ;
26
25
import io .javalin .http .Context ;
27
26
import io .swagger .v3 .oas .annotations .Hidden ;
28
27
import jakarta .inject .Inject ;
You can’t perform that action at this time.
0 commit comments