From aded91a1e9edc401a8ad133c16624393819fb511 Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Fri, 2 Sep 2022 16:31:50 -0400 Subject: [PATCH] Revert support for scanning resource methods without JAX-RS HTTP methods Fixes #1234 Signed-off-by: Michael Edgar --- .../openapi/runtime/util/JandexUtil.java | 7 --- .../openapi/jaxrs/JaxRsAnnotationScanner.java | 9 +-- .../runtime/scanner/ApiResponseTests.java | 49 +++++++++++++++ ...urce.inheritance.param-default-values.json | 2 +- .../responses.nonjaxrs-methods-skipped.json | 60 +++++++++++++++++++ 5 files changed, 111 insertions(+), 16 deletions(-) create mode 100644 extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/responses.nonjaxrs-methods-skipped.json diff --git a/core/src/main/java/io/smallrye/openapi/runtime/util/JandexUtil.java b/core/src/main/java/io/smallrye/openapi/runtime/util/JandexUtil.java index b0348d472..177f68c7d 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/util/JandexUtil.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/util/JandexUtil.java @@ -802,13 +802,6 @@ public static Map ancestry(MethodInfo method, AugmentedIn return ancestry; } - public static List overriddenMethods(MethodInfo method, List 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() diff --git a/extension-jaxrs/src/main/java/io/smallrye/openapi/jaxrs/JaxRsAnnotationScanner.java b/extension-jaxrs/src/main/java/io/smallrye/openapi/jaxrs/JaxRsAnnotationScanner.java index 55d991388..8b050503c 100644 --- a/extension-jaxrs/src/main/java/io/smallrye/openapi/jaxrs/JaxRsAnnotationScanner.java +++ b/extension-jaxrs/src/main/java/io/smallrye/openapi/jaxrs/JaxRsAnnotationScanner.java @@ -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; @@ -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 -> { diff --git a/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/ApiResponseTests.java b/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/ApiResponseTests.java index 2e0ef3440..6b9eec49c 100644 --- a/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/ApiResponseTests.java +++ b/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/ApiResponseTests.java @@ -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; @@ -396,4 +397,52 @@ public java.util.concurrent.CompletionStage 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 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); + } } diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/resource.inheritance.param-default-values.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/resource.inheritance.param-default-values.json index f30a7aaf9..4565d69bd 100644 --- a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/resource.inheritance.param-default-values.json +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/resource.inheritance.param-default-values.json @@ -35,7 +35,7 @@ "name": "upsilon", "in": "query", "schema": { - "default": false, + "default": true, "type": "boolean" } } diff --git a/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/responses.nonjaxrs-methods-skipped.json b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/responses.nonjaxrs-methods-skipped.json new file mode 100644 index 000000000..3848e176c --- /dev/null +++ b/extension-jaxrs/src/test/resources/io/smallrye/openapi/runtime/scanner/responses.nonjaxrs-methods-skipped.json @@ -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" + } + } + } + } + } + } +}