Skip to content

Commit

Permalink
Don't ignore Spring Rest controllers interfaces if contains errors
Browse files Browse the repository at this point in the history
Related to quarkusio#43704
  • Loading branch information
aureamunoz committed Nov 27, 2024
1 parent d99e142 commit 886b8da
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.quarkus.spring.web.test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;

import jakarta.ws.rs.QueryParam;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.quarkus.test.QuarkusProdModeTest;

public class UnbuildableSpringRestControllerInterfaceTest {

@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.withApplicationRoot((jar) -> jar
.addClasses(UnbuildableControllerInterface.class))
.setApplicationName("unbuildable-rest-controller-interface")
.setApplicationVersion("0.1-SNAPSHOT")
.assertBuildException(throwable -> {
assertThat(throwable).isInstanceOf(RuntimeException.class);
assertThat(throwable).hasMessageContaining(
"Cannot have more than one of @PathParam, @QueryParam, @HeaderParam, @FormParam, @CookieParam, @BeanParam, @Context on method");
});

@Test
public void testBuildLogs() {
fail("Should not be called");
}

@RestController
@RequestMapping("/unbuildable")
public interface UnbuildableControllerInterface {
@GetMapping("/ping")
String ping();

@PostMapping("/hello")
String hello(@RequestParam(required = false) @QueryParam("dung") String params);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,23 @@ public Optional<ResourceClass> createEndpoints(ClassInfo classInfo, boolean cons

return Optional.of(clazz);
} catch (Exception e) {
if (Modifier.isInterface(classInfo.flags()) || Modifier.isAbstract(classInfo.flags())) {
//kinda bogus, but we just ignore failed interfaces for now
//they can have methods that are not valid until they are actually extended by a concrete type
log.debug("Ignoring interface " + classInfo.name(), e);
return Optional.empty();
if (!isSpringRestController(classInfo)) {
if (Modifier.isInterface(classInfo.flags()) || Modifier.isAbstract(classInfo.flags())) {
//kinda bogus, but we just ignore failed interfaces for now
//they can have methods that are not valid until they are actually extended by a concrete type
log.debug("Ignoring interface " + classInfo.name(), e);
return Optional.empty();
}
}
throw new RuntimeException(e);
}
}

private boolean isSpringRestController(ClassInfo classInfo) {
return classInfo
.declaredAnnotation(DotName.createSimple("org.springframework.web.bind.annotation.RestController")) != null;
}

private String sanitizePath(String path) {
// this simply replaces the whitespace characters (not part of a path variable) with %20
// TODO: this might have to be more complex, URL encoding maybe?
Expand Down

0 comments on commit 886b8da

Please sign in to comment.