Skip to content

Commit

Permalink
Merge pull request #27206 from MikeEdgar/sroai-2.2.0
Browse files Browse the repository at this point in the history
Bump smallrye-open-api from 2.1.23 to 2.2.0
  • Loading branch information
gsmet authored Aug 18, 2022
2 parents cfef00b + 1a37111 commit 7db91d2
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 46 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<smallrye-config.version>2.11.1</smallrye-config.version>
<smallrye-health.version>3.2.1</smallrye-health.version>
<smallrye-metrics.version>3.0.5</smallrye-metrics.version>
<smallrye-open-api.version>2.1.23</smallrye-open-api.version>
<smallrye-open-api.version>2.2.0</smallrye-open-api.version>
<smallrye-graphql.version>1.7.0</smallrye-graphql.version>
<smallrye-opentracing.version>2.1.1</smallrye-opentracing.version>
<smallrye-fault-tolerance.version>5.5.0</smallrye-fault-tolerance.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,46 +535,50 @@ private List<String> getAuthenticatedMethodReferences(
}

private Map<String, String> getClassNamesMethodReferences(OpenApiFilteredIndexViewBuildItem apiFilteredIndexViewBuildItem) {
FilteredIndexView filteredIndex = apiFilteredIndexViewBuildItem.getIndex();
List<AnnotationInstance> openapiAnnotations = new ArrayList<>();
Set<DotName> allOpenAPIEndpoints = getAllOpenAPIEndpoints();
for (DotName dotName : allOpenAPIEndpoints) {
openapiAnnotations.addAll(apiFilteredIndexViewBuildItem.getIndex().getAnnotations(dotName));
openapiAnnotations.addAll(filteredIndex.getAnnotations(dotName));
}

Map<String, String> classNames = new HashMap<>();

for (AnnotationInstance ai : openapiAnnotations) {
if (ai.target().kind().equals(AnnotationTarget.Kind.METHOD)) {
MethodInfo method = ai.target().asMethod();
if (Modifier.isInterface(method.declaringClass().flags())) {
Collection<ClassInfo> allKnownImplementors = apiFilteredIndexViewBuildItem.getIndex()
.getAllKnownImplementors(method.declaringClass().name());
for (ClassInfo impl : allKnownImplementors) {
MethodInfo implMethod = impl.method(method.name(), method.parameterTypes().toArray(new Type[] {}));
if (implMethod != null) {
String implRef = JandexUtil.createUniqueMethodReference(impl, method);
classNames.put(implRef, impl.simpleName());
}
}
} else if (Modifier.isAbstract(method.declaringClass().flags())) {
Collection<ClassInfo> allKnownSubclasses = apiFilteredIndexViewBuildItem.getIndex()
.getAllKnownSubclasses(method.declaringClass().name());
for (ClassInfo impl : allKnownSubclasses) {
MethodInfo implMethod = impl.method(method.name(), method.parameterTypes().toArray(new Type[] {}));
if (implMethod != null) {
String implRef = JandexUtil.createUniqueMethodReference(impl, method);
classNames.put(implRef, impl.simpleName());
}
}
ClassInfo declaringClass = method.declaringClass();
Type[] params = method.parameterTypes().toArray(new Type[] {});

if (Modifier.isInterface(declaringClass.flags())) {
addMethodImplementationClassNames(method, params, filteredIndex
.getAllKnownImplementors(declaringClass.name()), classNames);
} else if (Modifier.isAbstract(declaringClass.flags())) {
addMethodImplementationClassNames(method, params, filteredIndex
.getAllKnownSubclasses(declaringClass.name()), classNames);
} else {
String ref = JandexUtil.createUniqueMethodReference(method.declaringClass(), method);
classNames.put(ref, method.declaringClass().simpleName());
String ref = JandexUtil.createUniqueMethodReference(declaringClass, method);
classNames.put(ref, declaringClass.simpleName());
}
}
}
return classNames;
}

void addMethodImplementationClassNames(MethodInfo method, Type[] params, Collection<ClassInfo> classes,
Map<String, String> classNames) {
for (ClassInfo impl : classes) {
String simpleClassName = impl.simpleName();
MethodInfo implMethod = impl.method(method.name(), params);

if (implMethod != null) {
classNames.put(JandexUtil.createUniqueMethodReference(impl, implMethod), simpleClassName);
}

classNames.put(JandexUtil.createUniqueMethodReference(impl, method), simpleClassName);
}
}

private boolean isValidOpenAPIMethodForAutoAdd(MethodInfo method, DotName securityRequirement) {
return isOpenAPIEndpoint(method) && !method.hasAnnotation(securityRequirement)
&& method.declaringClass().classAnnotation(securityRequirement) == null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.smallrye.openapi.test.jaxrs;

import java.util.List;

import javax.ws.rs.GET;

public abstract class AutoTagFetchableResource<T> implements AbstractAutoTagResource<T> {

@GET
abstract List<T> getAll();

@Override
public T getById(long id) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package io.quarkus.smallrye.openapi.test.jaxrs;

import java.util.List;

import javax.ws.rs.Path;

@Path("/address")
public class AutoTagResource implements AbstractAutoTagResource<String> {
@Path("/tagged")
public class AutoTagResource extends AutoTagFetchableResource<String> {

@Override
public String getById(long id) {
return "Disney Land, Gate " + id;
}
}

@Override
public List<String> getAll() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,27 @@
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class AutoTagTestCase {
class AutoTagTestCase {
@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addClasses(OpenApiResourceWithNoTag.class, AutoTagResource.class, AbstractAutoTagResource.class));
.addClasses(OpenApiResourceWithNoTag.class, AutoTagResource.class, AutoTagFetchableResource.class,
AbstractAutoTagResource.class));

@Test
public void testAutoSecurityRequirement() {
void testTagInOpenApi() {
RestAssured.given().header("Accept", "application/json")
.when().get("/q/openapi")
.when()
.get("/q/openapi")
.then()
.log().body()
.and()
.log().ifValidationFails()
.assertThat()
.statusCode(200)
.body("paths.'/tagged'.get.tags", Matchers.hasItem("Auto Tag Resource"))
.body("paths.'/tagged/{id}'.get.tags", Matchers.hasItem("Auto Tag Resource"))
.body("paths.'/resource/annotated'.get.tags", Matchers.hasItem("From Annotation"))
.and()
.body("paths.'/resource/auto'.get.tags", Matchers.hasItem("Open Api Resource With No Tag"))
.and()
.body("paths.'/resource/auto'.post.tags", Matchers.hasItem("Open Api Resource With No Tag"));

}

@Test
public void testTagInOpenApi() {
RestAssured.given().header("Accept", "application/json")
.when().get("/q/openapi")
.then()
.statusCode(200)
.body(Matchers.containsString("Auto Tag Resource"));
}

}
2 changes: 1 addition & 1 deletion jakarta/rewrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ recipeList:
newValue: 4.0.0-RC1
- org.openrewrite.maven.ChangePropertyValue:
key: smallrye-open-api.version
newValue: 3.0.0-RC1
newValue: 3.0.0-RC3
- org.openrewrite.maven.ChangePropertyValue:
key: microprofile-opentracing-api.version
newValue: 3.0
Expand Down

0 comments on commit 7db91d2

Please sign in to comment.