aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject [aries-jax-rs-whiteboard] branch master updated: ARIES-2055: support Swagger annotations on JAX-RS application
Date Sun, 20 Jun 2021 16:20:51 GMT
This is an automated email from the ASF dual-hosted git repository.

csierra pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-jax-rs-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 3851504  ARIES-2055: support Swagger annotations on JAX-RS application
3851504 is described below

commit 3851504540db372ef4bdc3fd6884397c887a5b82
Author: Jozsef Borcsok <jozsef.borcsok@blackbelt.hu>
AuthorDate: Sat Jun 19 19:04:59 2021 +0200

    ARIES-2055: support Swagger annotations on JAX-RS application
---
 .../openapi-itest/src/main/java/test/OpenApiTest.java       | 12 +++---------
 .../main/java/test/types/TestApplicationWithClasses.java    | 13 +++++++++++++
 .../apache/aries/jax/rs/openapi/JaxrsWhiteboardScanner.java | 11 +++++++++--
 .../org/apache/aries/jax/rs/openapi/OpenApiResource.java    |  2 +-
 4 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/integrations/openapi/openapi-itest/src/main/java/test/OpenApiTest.java b/integrations/openapi/openapi-itest/src/main/java/test/OpenApiTest.java
index b2e6205..83cb529 100644
--- a/integrations/openapi/openapi-itest/src/main/java/test/OpenApiTest.java
+++ b/integrations/openapi/openapi-itest/src/main/java/test/OpenApiTest.java
@@ -163,15 +163,6 @@ public class OpenApiTest extends TestHelper {
 
         OpenAPI openAPI = new OpenAPI();
 
-        openAPI.info(
-            new Info()
-                .title("My Service")
-                .description("Service REST API")
-                .contact(
-                    new Contact()
-                        .email("oschweitzer@me.com"))
-        );
-
         @SuppressWarnings({"unchecked", "rawtypes", "serial"})
         ServiceRegistration<OpenAPI> serviceRegistration =
             bundleContext.registerService(
@@ -195,6 +186,9 @@ public class OpenApiTest extends TestHelper {
 
             String response = webTarget.request().get(String.class);
 
+            assertTrue(response.matches(".*\"title\":\\s*\"My Service\".*"));
+            assertTrue(response.matches(".*\"description\":\\s*\"Service REST API\".*"));
+            assertTrue(response.matches(".*\"email\":\\s*\"oschweitzer@me.com\".*"));
             assertTrue(response.contains("\"/operation\":"));
 
             webTarget = createDefaultTarget().
diff --git a/integrations/openapi/openapi-itest/src/main/java/test/types/TestApplicationWithClasses.java
b/integrations/openapi/openapi-itest/src/main/java/test/types/TestApplicationWithClasses.java
index 1eba429..057e77d 100644
--- a/integrations/openapi/openapi-itest/src/main/java/test/types/TestApplicationWithClasses.java
+++ b/integrations/openapi/openapi-itest/src/main/java/test/types/TestApplicationWithClasses.java
@@ -17,6 +17,10 @@
 
 package test.types;
 
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.info.Contact;
+import io.swagger.v3.oas.annotations.info.Info;
+
 import java.util.Collections;
 import java.util.Set;
 
@@ -25,6 +29,15 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Application;
 
+@OpenAPIDefinition(
+        info = @Info(
+                title = "My Service",
+                description = "Service REST API",
+                contact = @Contact(
+                        email = "oschweitzer@me.com"
+                )
+        )
+)
 public class TestApplicationWithClasses extends Application {
 
     @Override
diff --git a/integrations/openapi/openapi-resource/src/main/java/org/apache/aries/jax/rs/openapi/JaxrsWhiteboardScanner.java
b/integrations/openapi/openapi-resource/src/main/java/org/apache/aries/jax/rs/openapi/JaxrsWhiteboardScanner.java
index 6a133cc..5eb2a8c 100644
--- a/integrations/openapi/openapi-resource/src/main/java/org/apache/aries/jax/rs/openapi/JaxrsWhiteboardScanner.java
+++ b/integrations/openapi/openapi-resource/src/main/java/org/apache/aries/jax/rs/openapi/JaxrsWhiteboardScanner.java
@@ -1,5 +1,6 @@
 package org.apache.aries.jax.rs.openapi;
 
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -8,10 +9,14 @@ import org.apache.aries.jax.rs.whiteboard.ApplicationClasses;
 import io.swagger.v3.oas.integration.api.OpenAPIConfiguration;
 import io.swagger.v3.oas.integration.api.OpenApiScanner;
 
+import javax.ws.rs.core.Application;
+
 public class JaxrsWhiteboardScanner implements OpenApiScanner {
 
+    private final Application application;
     private final ApplicationClasses applicationClasses;
-    public JaxrsWhiteboardScanner(ApplicationClasses applicationClasses) {
+    public JaxrsWhiteboardScanner(Application application, ApplicationClasses applicationClasses)
{
+        this.application = application;
         this.applicationClasses = applicationClasses;
     }
 
@@ -21,7 +26,9 @@ public class JaxrsWhiteboardScanner implements OpenApiScanner {
 
     @Override
     public Set<Class<?>> classes() {
-        return applicationClasses.classes();
+        Set<Class<?>> classes = new HashSet<>(applicationClasses.classes());
+        classes.add(application.getClass());
+        return classes;
     }
 
     @Override
diff --git a/integrations/openapi/openapi-resource/src/main/java/org/apache/aries/jax/rs/openapi/OpenApiResource.java
b/integrations/openapi/openapi-resource/src/main/java/org/apache/aries/jax/rs/openapi/OpenApiResource.java
index 03d1828..6a61f9b 100644
--- a/integrations/openapi/openapi-resource/src/main/java/org/apache/aries/jax/rs/openapi/OpenApiResource.java
+++ b/integrations/openapi/openapi-resource/src/main/java/org/apache/aries/jax/rs/openapi/OpenApiResource.java
@@ -70,7 +70,7 @@ public class OpenApiResource extends BaseOpenApiResource {
             .ctxId(ctxId)
             .buildContext(false);
 
-        ctx.setOpenApiScanner(new JaxrsWhiteboardScanner(applicationClasses));
+        ctx.setOpenApiScanner(new JaxrsWhiteboardScanner(app, applicationClasses));
 
         ctx.init();
 

Mime
View raw message