[cxf] branch master updated: Ensuring OpenApiFeature.DefaultApplication does only consider the classes from the specified resourcePackages (if provided)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[cxf] branch master updated: Ensuring OpenApiFeature.DefaultApplication does only consider the classes from the specified resourcePackages (if provided)

ilgrosso
This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new e7b178a  Ensuring OpenApiFeature.DefaultApplication does only consider the classes from the specified resourcePackages (if provided)
e7b178a is described below

commit e7b178a92302786eca0233f9d176ded2d9086dde
Author: Francesco Chicchiriccò <[hidden email]>
AuthorDate: Thu Feb 8 14:14:11 2018 +0100

    Ensuring OpenApiFeature.DefaultApplication does only consider the classes from the specified resourcePackages (if provided)
---
 .../apache/cxf/jaxrs/openapi/OpenApiFeature.java   | 32 ++++++++++++++--------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiFeature.java b/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiFeature.java
index c327b1f..68f837c 100644
--- a/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiFeature.java
+++ b/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/OpenApiFeature.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Properties;
@@ -40,6 +41,7 @@ import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
 import org.apache.cxf.jaxrs.model.ApplicationInfo;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 import org.apache.cxf.jaxrs.swagger.SwaggerUiSupport;
 
@@ -99,11 +101,19 @@ public class OpenApiFeature extends AbstractFeature implements SwaggerUiSupport,
     private String propertiesLocation = DEFAULT_PROPS_LOCATION;
 
     protected static class DefaultApplication extends Application {
+
         private final Set<Class<?>> serviceClasses;
-        
-        DefaultApplication(Set<Class<?>> serviceClasses) {
-            this.serviceClasses = serviceClasses;
+
+        DefaultApplication(final List<ClassResourceInfo> cris, final Set<String> resourcePackages) {
+            this.serviceClasses = cris.stream().map(ClassResourceInfo::getServiceClass).
+                    filter(cls -> {
+                    return resourcePackages == null || resourcePackages.isEmpty()
+                           ? true
+                           : resourcePackages.stream().
+                               anyMatch(pkg -> cls.getPackage().getName().startsWith(pkg));
+                }).collect(Collectors.toSet());
         }
+
         @Override
         public Set<Class<?>> getClasses() {
             return serviceClasses;
@@ -424,21 +434,21 @@ public class OpenApiFeature extends AbstractFeature implements SwaggerUiSupport,
     }
 
     /**
-     * Detects the application (if present) or creates the default application (in case the
-     * scan is disabled)
+     * Detects the application (if present) or creates the default application (in case the scan is disabled).
      */
-    protected Application getApplicationOrDefault(Server server, ServerProviderFactory factory,
-            JAXRSServiceFactoryBean sfb, Bus bus) {
+    protected Application getApplicationOrDefault(
+            final Server server,
+            final ServerProviderFactory factory,
+            final JAXRSServiceFactoryBean sfb,
+            final Bus bus) {
 
         ApplicationInfo appInfo = null;
         if (!isScan()) {
             appInfo = factory.getApplicationProvider();
             
             if (appInfo == null) {
-                Set<Class<?>> serviceClasses = sfb.getClassResourceInfo().stream().
-                        map(cri -> cri.getServiceClass()).
-                        collect(Collectors.toSet());
-                appInfo = new ApplicationInfo(new DefaultApplication(serviceClasses), bus);
+                appInfo = new ApplicationInfo(
+                        new DefaultApplication(sfb.getClassResourceInfo(), resourcePackages), bus);
                 server.getEndpoint().put(Application.class.getName(), appInfo);
             }
         }

--
To stop receiving notification emails like this one, please contact
[hidden email].