diff --git a/pom.xml b/pom.xml
index 6adf25e..5a4e51e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
io.sinistral
proteus-core
- 0.3.7-SNAPSHOT
+ 0.3.7
proteus core
Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow.
http://github.com/noboomu/proteus
@@ -192,9 +192,6 @@
test
-
-
org.junit.jupiter
junit-jupiter-api
@@ -202,7 +199,6 @@
test
-
org.junit.vintage
junit-vintage-engine
diff --git a/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java b/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java
index dcc3cc7..002096e 100644
--- a/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java
+++ b/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java
@@ -13,7 +13,6 @@
import io.sinistral.proteus.server.ServerRequest;
import io.sinistral.proteus.server.ServerResponse;
import io.sinistral.proteus.server.endpoints.EndpointInfo;
-import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
@@ -34,10 +33,8 @@
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import java.io.File;
-import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.*;
import java.net.URI;
import java.net.URL;
import java.util.*;
@@ -354,12 +351,30 @@ protected void addClassMethodHandlers(TypeSpec.Builder typeBuilder, Class> cla
List typeLevelSecurityDefinitions = new ArrayList<>();
if (Optional.ofNullable(clazz.getAnnotation(Path.class)).isPresent()) {
- SecurityRequirement securityRequirementAnnotation = clazz.getAnnotation(SecurityRequirement.class);
+
+ Annotation[] annotations = clazz.getAnnotations();
+
+ Annotation securityRequirementAnnotation = Arrays.stream(annotations).filter(a -> a.getClass().getName().contains("SecurityRequirement" +
+ "")).findFirst().orElse(null);
if (securityRequirementAnnotation != null) {
- String securityRequirement = securityRequirementAnnotation.name();
- typeLevelSecurityDefinitions.add(securityRequirement);
+ if (securityRequirementAnnotation != null) {
+
+ try {
+ Field nameField = securityRequirementAnnotation.getClass().getField("name");
+
+ if (nameField != null) {
+ Object securityRequirement = nameField.get(securityRequirementAnnotation);
+ typeLevelSecurityDefinitions.add(securityRequirement.toString());
+ }
+
+ } catch (Exception e) {
+ log.warn("No name field on security requirement");
+ }
+
+ }
+
}
}
@@ -754,12 +769,31 @@ protected void addClassMethodHandlers(TypeSpec.Builder typeBuilder, Class> cla
*/
if (Optional.ofNullable(m.getAnnotation(Path.class)).isPresent()) {
- SecurityRequirement securityRequirementAnnotation = m.getAnnotation(SecurityRequirement.class);
+
+ Annotation[] annotations = clazz.getAnnotations();
+
+ Annotation securityRequirementAnnotation = Arrays.stream(annotations).filter( a -> a.getClass().getName().contains("SecurityRequirement") ).findFirst().orElse(null);
if (securityRequirementAnnotation != null) {
- String securityRequirement = securityRequirementAnnotation.name();
- securityDefinitions.add(securityRequirement);
+ if (securityRequirementAnnotation != null) {
+
+ try
+ {
+ Field nameField = securityRequirementAnnotation.getClass().getField("name");
+
+ if(nameField != null) {
+ Object securityRequirement = nameField.get(securityRequirementAnnotation);
+ securityDefinitions.add(securityRequirement.toString());
+ }
+
+ } catch( Exception e )
+ {
+ log.warn("No name field on security requirement");
+ }
+
+ }
+
}
}
diff --git a/src/test/java/io/sinistral/proteus/test/controllers/Tests.java b/src/test/java/io/sinistral/proteus/test/controllers/Tests.java
index 27769cc..820466b 100644
--- a/src/test/java/io/sinistral/proteus/test/controllers/Tests.java
+++ b/src/test/java/io/sinistral/proteus/test/controllers/Tests.java
@@ -44,8 +44,10 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.tags.Tags;
+import io.swagger.v3.oas.models.servers.Server;
import io.undertow.server.HttpServerExchange;
/**
@@ -108,7 +110,7 @@ public void exchangeJsonSerializeToBytes(HttpServerExchange exchange)
@GET
- @Path("/exchange/user/json")
+ @Path("exchange/user/json")
@Operation(description = "User serialization endpoint" )
public void exchangeUserJson(HttpServerExchange exchange)
{
@@ -116,7 +118,7 @@ public void exchangeUserJson(HttpServerExchange exchange)
}
@GET
- @Path("/exchange/user/xml")
+ @Path("exchange/user/xml")
@Produces((MediaType.APPLICATION_XML))
@Operation(description = "User serialization endpoint" )
public void exchangeUserXml(HttpServerExchange exchange)
@@ -125,7 +127,7 @@ public void exchangeUserXml(HttpServerExchange exchange)
}
@GET
- @Path("/response/user/json")
+ @Path("response/user/json")
@Operation(description = "User serialization endpoint" )
public ServerResponse responseUserJson(ServerRequest request)
{
@@ -135,7 +137,7 @@ public ServerResponse responseUserJson(ServerRequest request)
}
@GET
- @Path("/response/user/xml")
+ @Path("response/user/xml")
@Produces((MediaType.APPLICATION_XML))
@Operation(description = "User serialization endpoint" )
public ServerResponse responseUserXml(ServerRequest request)
@@ -147,7 +149,7 @@ public ServerResponse responseUserXml(ServerRequest request)
@GET
- @Path("/exchange/plaintext")
+ @Path("exchange/plaintext")
@Produces((MediaType.TEXT_PLAIN))
@Operation(description = "Plaintext endpoint" )
public void exchangePlaintext(HttpServerExchange exchange)
@@ -157,7 +159,7 @@ public void exchangePlaintext(HttpServerExchange exchange)
}
@GET
- @Path("/exchange/plaintext2")
+ @Path("exchange/plaintext2")
@Produces((MediaType.TEXT_PLAIN))
@Operation(description = "Plaintext endpoint 2" )
public void exchangePlaintext2(HttpServerExchange exchange)
@@ -167,7 +169,7 @@ public void exchangePlaintext2(HttpServerExchange exchange)
}
@GET
- @Path("/response/plaintext")
+ @Path("response/plaintext")
@Produces((MediaType.TEXT_PLAIN))
@Operation(description = "Plaintext endpoint" )
public ServerResponse responsePlaintext(ServerRequest request)
@@ -177,7 +179,7 @@ public ServerResponse responsePlaintext(ServerRequest request)
}
@GET
- @Path("/response/future/map")
+ @Path("response/future/map")
@Operation(description = "Future map endpoint" )
public CompletableFuture>> responseFutureMap( ServerRequest request )
{
@@ -186,7 +188,7 @@ public CompletableFuture>> responseFutureMap(
}
@GET
- @Path("/response/map")
+ @Path("response/map")
@Operation(description = "Map endpoint" )
public ServerResponse