Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renard validator(MyValidationInterceptor) should not apply on rest enpoint that not extends renarde.Controller #254

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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