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

Fix scanning of empty SecurityRequirements on resource class #2012

Merged
merged 1 commit into from
Oct 10, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
}
}