diff --git a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java index bf051288bde8c..40d1b220a8e62 100644 --- a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java +++ b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.lang.reflect.Modifier; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -427,7 +428,21 @@ private Map getClassNamesMethodReferences(OpenApiFilteredIndexVi if (ai.target().kind().equals(AnnotationTarget.Kind.METHOD)) { MethodInfo method = ai.target().asMethod(); String ref = JandexUtil.createUniqueMethodReference(method); - classNames.put(ref, method.declaringClass().simpleName()); + if (Modifier.isInterface(method.declaringClass().flags())) { + Collection allKnownImplementors = apiFilteredIndexViewBuildItem.getIndex() + .getAllKnownImplementors(method.declaringClass().name()); + for (ClassInfo impl : allKnownImplementors) { + classNames.put(ref, impl.simpleName()); + } + } else if (Modifier.isAbstract(method.declaringClass().flags())) { + Collection allKnownSubclasses = apiFilteredIndexViewBuildItem.getIndex() + .getAllKnownSubclasses(method.declaringClass().name()); + for (ClassInfo impl : allKnownSubclasses) { + classNames.put(ref, impl.simpleName()); + } + } else { + classNames.put(ref, method.declaringClass().simpleName()); + } } } return classNames; diff --git a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AbstractAutoTagResource.java b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AbstractAutoTagResource.java new file mode 100644 index 0000000000000..b778172e8653a --- /dev/null +++ b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AbstractAutoTagResource.java @@ -0,0 +1,14 @@ +package io.quarkus.smallrye.openapi.test.jaxrs; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Produces(MediaType.TEXT_PLAIN) +public interface AbstractAutoTagResource { + @GET + @Path("/{id}") + T getById(@PathParam("id") long id); +} \ No newline at end of file diff --git a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AutoTagResource.java b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AutoTagResource.java new file mode 100644 index 0000000000000..b01b89aecb6c2 --- /dev/null +++ b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AutoTagResource.java @@ -0,0 +1,11 @@ +package io.quarkus.smallrye.openapi.test.jaxrs; + +import javax.ws.rs.Path; + +@Path("/address") +public class AutoTagResource implements AbstractAutoTagResource { + @Override + public String getById(long id) { + return "Disney Land, Gate " + id; + } +} \ No newline at end of file diff --git a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AutoTagTestCase.java b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AutoTagTestCase.java index e9cf43e4e92ab..126c8fc2eda39 100644 --- a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AutoTagTestCase.java +++ b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AutoTagTestCase.java @@ -11,7 +11,7 @@ public class AutoTagTestCase { @RegisterExtension static QuarkusUnitTest runner = new QuarkusUnitTest() .withApplicationRoot((jar) -> jar - .addClasses(OpenApiResourceWithNoTag.class)); + .addClasses(OpenApiResourceWithNoTag.class, AutoTagResource.class, AbstractAutoTagResource.class)); @Test public void testAutoSecurityRequirement() { @@ -28,4 +28,13 @@ public void testAutoSecurityRequirement() { } + @Test + public void testTagInOpenApi() { + RestAssured.given().header("Accept", "application/json") + .when().get("/q/openapi") + .then() + .statusCode(200) + .body(Matchers.containsString("Auto Tag Resource")); + } + }