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

Ignore client interfaces when detecting duplicate endpoints #44248

Merged
merged 1 commit into from
Nov 1, 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
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ public class ResteasyReactiveProcessor {
private static final int SECURITY_EXCEPTION_MAPPERS_PRIORITY = Priorities.USER + 1;
private static final String[] EMPTY_STRING_ARRAY = new String[0];

private static final DotName QUARKUS_TEST_MOCK = DotName.createSimple("io.quarkus.test.Mock");

@BuildStep
public FeatureBuildItem buildSetup() {
return new FeatureBuildItem(Feature.REST);
Expand Down Expand Up @@ -697,21 +699,23 @@ public Supplier<Boolean> apply(ClassInfo classInfo) {
generatedClassBuildItemBuildProducer, applicationClassPredicate, reflectiveClassBuildItemBuildProducer));
serverEndpointIndexer = serverEndpointIndexerBuilder.build();

Map<String, List<EndpointConfig>> allMethods = new HashMap<>();
for (ClassInfo i : scannedResources.values()) {
Optional<ResourceClass> endpoints = serverEndpointIndexer.createEndpoints(i, true);
Map<String, List<EndpointConfig>> allServerMethods = new HashMap<>();
for (ClassInfo ci : scannedResources.values()) {
Optional<ResourceClass> endpoints = serverEndpointIndexer.createEndpoints(ci, true);
if (endpoints.isPresent()) {
if (singletonClasses.contains(i.name().toString())) {
endpoints.get().setFactory(new SingletonBeanFactory<>(i.name().toString()));
if (singletonClasses.contains(ci.name().toString())) {
endpoints.get().setFactory(new SingletonBeanFactory<>(ci.name().toString()));
}
resourceClasses.add(endpoints.get());
for (ResourceMethod rm : endpoints.get().getMethods()) {
addResourceMethodByPath(allMethods, endpoints.get().getPath(), i, rm);
if (!ignoreResourceForDuplicateDetection(ci)) {
for (ResourceMethod rm : endpoints.get().getMethods()) {
addResourceMethodByPath(allServerMethods, endpoints.get().getPath(), ci, rm);
}
}
}
}

checkForDuplicateEndpoint(config, allMethods);
checkForDuplicateEndpoint(config, allServerMethods);

//now index possible sub resources. These are all classes that have method annotations
//that are not annotated @Path
Expand Down Expand Up @@ -782,6 +786,14 @@ public Supplier<Boolean> apply(ClassInfo classInfo) {
handleDateFormatReflection(reflectiveClassBuildItemBuildProducer, index);
}

// TODO: this is really just a hackish way of allowing the use of @Mock so we might need something better
private boolean ignoreResourceForDuplicateDetection(ClassInfo ci) {
if (ci.hasAnnotation(QUARKUS_TEST_MOCK)) {
return true;
}
return false;
}

private boolean filtersAccessResourceMethod(ResourceInterceptors resourceInterceptors) {
AtomicBoolean ab = new AtomicBoolean(false);
ResourceInterceptors.FiltersVisitor visitor = new ResourceInterceptors.FiltersVisitor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.quarkus.resteasy.reactive.server.test.duplicate;

import static io.restassured.RestAssured.when;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.Mock;
import io.quarkus.test.QuarkusUnitTest;

public class DuplicateResourceAndClientTest {

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(Client.class, Resource.class));

@Test
public void dummy() {
when()
.get("/hello")
.then()
.statusCode(200);
}

@Path("/hello")
public interface Client {

@GET
@Produces(MediaType.TEXT_PLAIN)
String hello();
}

@Mock
public static class ClientMock implements Client {

@Override
public String hello() {
return "";
}
}

@Path("/hello")
public static class Resource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello";
}
}
}
Loading