diff --git a/integration-tests/src/main/java/rest/ValidationController.java b/integration-tests/src/main/java/rest/ValidationController.java new file mode 100644 index 0000000..98607b6 --- /dev/null +++ b/integration-tests/src/main/java/rest/ValidationController.java @@ -0,0 +1,30 @@ +package rest; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +import org.jboss.resteasy.reactive.RestQuery; + +import io.quarkiverse.renarde.Controller; + +public class ValidationController { + @Path("/ValidationController") + public static class RenardController extends Controller { + @GET + @Path("/RenardController") + public void renardValidate(@Valid @NotNull @RestQuery String input) { + + } + } + + @Path("/ValidationController") + public static class RestController { + @GET + @Path("/RestController") + public void restValidate(@Valid @NotNull @RestQuery String input) { + + } + } +} diff --git a/integration-tests/src/test/java/io/quarkiverse/renarde/it/ValidationTest.java b/integration-tests/src/test/java/io/quarkiverse/renarde/it/ValidationTest.java new file mode 100644 index 0000000..260205a --- /dev/null +++ b/integration-tests/src/test/java/io/quarkiverse/renarde/it/ValidationTest.java @@ -0,0 +1,26 @@ +package io.quarkiverse.renarde.it; + +import static io.restassured.RestAssured.given; + +import org.junit.jupiter.api.Test; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +public class ValidationTest { + @Test + public void validateOnRenardeEndpointShouldResponse20x() { + given() + .when().get("/ValidationController/RenardController") + .then() + .statusCode(204); + } + + @Test + public void validateOnRestEndpointShouldResponse400() { + given() + .when().get("/ValidationController/RestController") + .then() + .statusCode(400); + } +} diff --git a/runtime/src/main/java/io/quarkiverse/renarde/util/MyValidationInterceptor.java b/runtime/src/main/java/io/quarkiverse/renarde/util/MyValidationInterceptor.java index d34bb81..0afac20 100644 --- a/runtime/src/main/java/io/quarkiverse/renarde/util/MyValidationInterceptor.java +++ b/runtime/src/main/java/io/quarkiverse/renarde/util/MyValidationInterceptor.java @@ -12,6 +12,7 @@ import jakarta.validation.Validator; import jakarta.validation.executable.ExecutableValidator; +import io.quarkiverse.renarde.Controller; import io.quarkus.hibernate.validator.runtime.interceptor.AbstractMethodValidationInterceptor; import io.quarkus.hibernate.validator.runtime.jaxrs.JaxrsEndPointValidated; import io.quarkus.hibernate.validator.runtime.jaxrs.ResteasyReactiveViolationException; @@ -35,8 +36,12 @@ public Object validateMethodInvocation(InvocationContext ctx) throws Exception { ctx.getMethod(), ctx.getParameters()); if (!violations.isEmpty()) { - // just collect them and go on - validation.addErrors(violations); + if (ctx.getTarget() instanceof Controller) { + // just collect them and go on + validation.addErrors(violations); + } else { + throw new ResteasyReactiveViolationException(violations); + } } Object result = ctx.proceed();