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

OpenAPI: better auto tag when using interfaces / abstract classes #21193

Merged
merged 1 commit into from
Nov 4, 2021
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 @@ -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;
Expand Down Expand Up @@ -427,7 +428,21 @@ private Map<String, String> 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<ClassInfo> allKnownImplementors = apiFilteredIndexViewBuildItem.getIndex()
.getAllKnownImplementors(method.declaringClass().name());
for (ClassInfo impl : allKnownImplementors) {
classNames.put(ref, impl.simpleName());
}
} else if (Modifier.isAbstract(method.declaringClass().flags())) {
Collection<ClassInfo> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T> {
@GET
@Path("/{id}")
T getById(@PathParam("id") long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkus.smallrye.openapi.test.jaxrs;

import javax.ws.rs.Path;

@Path("/address")
public class AutoTagResource implements AbstractAutoTagResource<String> {
@Override
public String getById(long id) {
return "Disney Land, Gate " + id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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"));
}

}