Skip to content

Commit

Permalink
Fix scanning of empty SecurityRequirements on resource class (#2012)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Edgar <[email protected]>
  • Loading branch information
MikeEdgar authored Oct 10, 2024
1 parent bba36d1 commit e44da1b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
}

0 comments on commit e44da1b

Please sign in to comment.