cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6904] Passing Application classes to Swagger BeanConfig is the scan is disabled, patch from Łukasz Dywicki applied with minor updates
Date Mon, 22 Aug 2016 12:32:08 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 3e30d8892 -> 1bf8635b2


[CXF-6904] Passing Application classes to Swagger BeanConfig is the scan is disabled, patch
from Łukasz Dywicki applied with minor updates


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/1bf8635b
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1bf8635b
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1bf8635b

Branch: refs/heads/master
Commit: 1bf8635b2efae39ee3f4b5d8817871aa03a82047
Parents: 3e30d889
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Aug 22 13:31:51 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Aug 22 13:31:51 2016 +0100

----------------------------------------------------------------------
 .../jaxrs/swagger/ApplicationBeanConfig.java    | 38 ++++++++++++++++++++
 .../cxf/jaxrs/swagger/Swagger2Feature.java      | 17 +++++----
 2 files changed, 48 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1bf8635b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/ApplicationBeanConfig.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/ApplicationBeanConfig.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/ApplicationBeanConfig.java
new file mode 100644
index 0000000..84504a6
--- /dev/null
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/ApplicationBeanConfig.java
@@ -0,0 +1,38 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.swagger;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import io.swagger.jaxrs.config.BeanConfig;
+
+public class ApplicationBeanConfig extends BeanConfig {
+    private Set<Class<?>> classes;
+    public ApplicationBeanConfig(Set<Class<?>> classes) {
+        this.classes = classes;
+    }
+    @Override
+    public Set<Class<?>> classes() {
+        Set<Class<?>> allClasses = new HashSet<Class<?>>();     
 
+        allClasses.addAll(super.classes());
+        allClasses.addAll(classes);
+        return classes;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/1bf8635b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
index 763944c..7b757fc 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
@@ -102,19 +102,21 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
     protected void addSwaggerResource(Server server, Bus bus) {
         JAXRSServiceFactoryBean sfb =
             (JAXRSServiceFactoryBean) server.getEndpoint().get(JAXRSServiceFactoryBean.class.getName());
+        
+        ApplicationInfo appInfo = null;
         if (!isScan()) {
             ServerProviderFactory factory = 
                 (ServerProviderFactory)server.getEndpoint().get(ServerProviderFactory.class.getName());
-            ApplicationInfo applicationInfo = factory.getApplicationProvider();
-            if (applicationInfo == null) {
+            appInfo = factory.getApplicationProvider();
+            if (appInfo == null) {
                 Set<Class<?>> serviceClasses = new HashSet<Class<?>>();
                 for (ClassResourceInfo cri : sfb.getClassResourceInfo()) {
                     serviceClasses.add(cri.getServiceClass());
                 }
-                applicationInfo = new ApplicationInfo(new DefaultApplication(serviceClasses),
bus);
-                server.getEndpoint().put(Application.class.getName(), applicationInfo);
+                appInfo = new ApplicationInfo(new DefaultApplication(serviceClasses), bus);
+                server.getEndpoint().put(Application.class.getName(), appInfo);
             }
-        }
+        } 
         
         List<Object> swaggerResources = new LinkedList<Object>();
         ApiListingResource apiListingResource = new ApiListingResource();
@@ -156,8 +158,9 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
 
         ((ServerProviderFactory) server.getEndpoint().get(
                 ServerProviderFactory.class.getName())).setUserProviders(providers);
-
-        BeanConfig beanConfig = new BeanConfig();
+        BeanConfig beanConfig = appInfo == null 
+            ? new BeanConfig() 
+            : new ApplicationBeanConfig(appInfo.getProvider().getClasses());
         beanConfig.setResourcePackage(getResourcePackage());
         beanConfig.setUsePathBasedConfig(isUsePathBasedConfig());
         beanConfig.setVersion(getVersion());


Mime
View raw message