Skip to content

Commit

Permalink
Revert support for scanning resource methods without JAX-RS HTTP methods
Browse files Browse the repository at this point in the history
Fixes #1234

Signed-off-by: Michael Edgar <michael@xlate.io>
  • Loading branch information
MikeEdgar committed Sep 5, 2022
1 parent faadf58 commit aded91a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,6 @@ public static Map<ClassInfo, MethodInfo> ancestry(MethodInfo method, AugmentedIn
return ancestry;
}

public static List<MethodInfo> overriddenMethods(MethodInfo method, List<MethodInfo> candidates) {
return candidates.stream()
.filter(m -> !method.equals(m))
.filter(m -> isSameSignature(method, m))
.collect(Collectors.toList());
}

public static boolean isSameSignature(MethodInfo m1, MethodInfo m2) {
return Objects.equals(m1.name(), m2.name())
&& m1.parametersCount() == m2.parametersCount()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.smallrye.openapi.jaxrs;

import static io.smallrye.openapi.runtime.util.JandexUtil.overriddenMethods;

import java.lang.reflect.Modifier;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
Expand Down Expand Up @@ -276,12 +274,7 @@ private void processResourceMethods(final AnnotationScannerContext context,

JaxRsConstants.HTTP_METHODS
.stream()
.filter(httpMethod -> {
if (methodInfo.hasAnnotation(httpMethod)) {
return true;
}
return overriddenMethods(methodInfo, methods).stream().anyMatch(m -> m.hasAnnotation(httpMethod));
})
.filter(methodInfo::hasAnnotation)
.map(DotName::withoutPackagePrefix)
.map(PathItem.HttpMethod::valueOf)
.forEach(httpMethod -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import java.util.NavigableMap;

import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponseSchema;
import org.eclipse.microprofile.openapi.models.OpenAPI;
Expand Down Expand Up @@ -396,4 +397,52 @@ public java.util.concurrent.CompletionStage<jakarta.ws.rs.core.Response> deleteI
assertJsonEquals("responses.api-response-schema-variations.json", result);
}

@Test
/*
* Test case for Smallrye OpenAPI issue #1234.
*
* https://github.com/smallrye/smallrye-open-api/issues/1234
*/
void testNonJaxRsMethodsSkipped() throws IOException, JSONException {
@Schema(name = "Reference")
abstract class Reference {
abstract String getName();
}
@Schema(name = "ReferencesResponse")
abstract class ReferencesResponse {
abstract List<Reference> getReferences();
}
abstract class TreeApi {
abstract ReferencesResponse getAllReferences();

@APIResponseSchema(value = ReferencesResponse.class, responseDescription = "Will not be scanned")
abstract Reference getDefaultBranch();
}
@jakarta.ws.rs.Path("trees")
class HttpTreeApi extends TreeApi {

@Override
@jakarta.ws.rs.GET
public ReferencesResponse getAllReferences() {
return null;
}

@Override
@jakarta.ws.rs.GET
@jakarta.ws.rs.Path("tree")
public Reference getDefaultBranch() {
return null;
}
}

Index index = indexOf(
TreeApi.class,
HttpTreeApi.class,
Reference.class,
ReferencesResponse.class);
OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), index);
OpenAPI result = scanner.scan();
printToConsole(result);
assertJsonEquals("responses.nonjaxrs-methods-skipped.json", result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"name": "upsilon",
"in": "query",
"schema": {
"default": false,
"default": true,
"type": "boolean"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"openapi": "3.0.3",
"paths": {
"/trees": {
"get": {
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/ReferencesResponse"
}
}
}
}
}
}
},
"/trees/tree": {
"get": {
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"$ref": "#/components/schemas/Reference"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Reference": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"ReferencesResponse": {
"type": "object",
"properties": {
"references": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Reference"
}
}
}
}
}
}
}

0 comments on commit aded91a

Please sign in to comment.