diff --git a/core/src/main/java/io/smallrye/openapi/runtime/scanner/spi/AnnotationScanner.java b/core/src/main/java/io/smallrye/openapi/runtime/scanner/spi/AnnotationScanner.java index 497b8436b..bc7dde3b7 100644 --- a/core/src/main/java/io/smallrye/openapi/runtime/scanner/spi/AnnotationScanner.java +++ b/core/src/main/java/io/smallrye/openapi/runtime/scanner/spi/AnnotationScanner.java @@ -665,6 +665,7 @@ default void processSecurityRequirementAnnotation(AnnotationScannerContext conte if (securityRequirements.isEmpty() && !emptyContainerPresent) { securityRequirements = context.io().securityIO().readRequirements(resourceClass); + emptyContainerPresent = isEmptySecurityRequirements(context, resourceClass); } if (securityRequirements.isEmpty() && emptyContainerPresent) { diff --git a/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/JaxRsAnnotationScannerTest.java b/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/JaxRsAnnotationScannerTest.java index 4f9283c87..092fc3953 100644 --- a/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/JaxRsAnnotationScannerTest.java +++ b/extension-jaxrs/src/test/java/io/smallrye/openapi/runtime/scanner/JaxRsAnnotationScannerTest.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; import io.smallrye.openapi.api.OpenApiConfig; import io.smallrye.openapi.api.OpenApiDocument; @@ -286,24 +287,15 @@ void testTagScanning_OrderGivenStaticFile(Index i) throws IOException, JSONExcep assertJsonEquals("resource.tags.ordergiven.staticfile.json", result); } - @Test - void testJavaxEmptySecurityRequirements() throws IOException, JSONException { - Indexer indexer = new Indexer(); - index(indexer, "test/io/smallrye/openapi/runtime/scanner/resources/javax/EmptySecurityRequirementsResource.class"); - - testEmptySecurityRequirements(indexer.complete()); - } - - @Test - void testJakartaEmptySecurityRequirements() throws IOException, JSONException { - Indexer indexer = new Indexer(); - index(indexer, "test/io/smallrye/openapi/runtime/scanner/resources/jakarta/EmptySecurityRequirementsResource.class"); - - testEmptySecurityRequirements(indexer.complete()); - } - - void testEmptySecurityRequirements(Index i) throws IOException, JSONException { - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); + @ParameterizedTest + @ValueSource(classes = { + test.io.smallrye.openapi.runtime.scanner.resources.jakarta.EmptySecurityRequirementsResource.class, + test.io.smallrye.openapi.runtime.scanner.resources.jakarta.EmptySecurityRequirementsResourceMethod.class, + test.io.smallrye.openapi.runtime.scanner.resources.javax.EmptySecurityRequirementsResource.class, + test.io.smallrye.openapi.runtime.scanner.resources.javax.EmptySecurityRequirementsResourceMethod.class, + }) + void testEmptySecurityRequirements(Class resourceClass) throws IOException, JSONException { + OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), Index.of(resourceClass)); OpenAPI result = scanner.scan("JAX-RS"); diff --git a/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/EmptySecurityRequirementsResource.java b/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/EmptySecurityRequirementsResource.java index 0013b83e9..183bc0f1c 100644 --- a/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/EmptySecurityRequirementsResource.java +++ b/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/EmptySecurityRequirementsResource.java @@ -6,10 +6,10 @@ import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirements; @Path("/public") +@SecurityRequirements public class EmptySecurityRequirementsResource { @GET - @SecurityRequirements public String getPublicResponse() { return "response value"; } diff --git a/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/EmptySecurityRequirementsResourceMethod.java b/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/EmptySecurityRequirementsResourceMethod.java new file mode 100644 index 000000000..d41be013c --- /dev/null +++ b/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/EmptySecurityRequirementsResourceMethod.java @@ -0,0 +1,16 @@ +package test.io.smallrye.openapi.runtime.scanner.resources.jakarta; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirements; + +@Path("/public") +public class EmptySecurityRequirementsResourceMethod { + + @GET + @SecurityRequirements + public String getPublicResponse() { + return "response value"; + } +} diff --git a/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/EmptySecurityRequirementsResource.java b/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/EmptySecurityRequirementsResource.java index af1160df3..baff80e05 100644 --- a/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/EmptySecurityRequirementsResource.java +++ b/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/EmptySecurityRequirementsResource.java @@ -6,10 +6,10 @@ import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirements; @Path("/public") +@SecurityRequirements public class EmptySecurityRequirementsResource { @GET - @SecurityRequirements public String getPublicResponse() { return "response value"; } diff --git a/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/EmptySecurityRequirementsResourceMethod.java b/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/EmptySecurityRequirementsResourceMethod.java new file mode 100644 index 000000000..577b56bce --- /dev/null +++ b/extension-jaxrs/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/EmptySecurityRequirementsResourceMethod.java @@ -0,0 +1,16 @@ +package test.io.smallrye.openapi.runtime.scanner.resources.javax; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirements; + +@Path("/public") +public class EmptySecurityRequirementsResourceMethod { + + @GET + @SecurityRequirements + public String getPublicResponse() { + return "response value"; + } +}