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

Bump smallrye-open-api from 2.1.23 to 2.2.0 #27206

Merged
merged 3 commits into from Aug 18, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bom/application/pom.xml
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
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
@@ -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;
}
}
@@ -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;
}

}
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
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