Skip to content

Commit

Permalink
Merge pull request #254 from pramoth/iss175
Browse files Browse the repository at this point in the history
Renard validator(MyValidationInterceptor) should not apply on rest enpoint that not extends renarde.Controller
  • Loading branch information
FroMage authored Nov 25, 2024
2 parents edfd7a4 + 4ecc0e3 commit eecff35
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
30 changes: 30 additions & 0 deletions integration-tests/src/main/java/rest/ValidationController.java
Original file line number Diff line number Diff line change
@@ -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) {

}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit eecff35

Please sign in to comment.