cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [cxf] branch master updated: CXF-7982: Extract common OpenAPI / Swagger scaffolding into dedicated module (to prevent/eliminate duplication)
Date Mon, 25 Feb 2019 11:57:56 GMT
This is an automated email from the ASF dual-hosted git repository.

reta 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 85e2ffd  CXF-7982: Extract common OpenAPI / Swagger scaffolding into dedicated module
(to prevent/eliminate duplication)
85e2ffd is described below

commit 85e2ffd0050730339b7422527b86a49f9f08b241
Author: reta <drreta@gmail.com>
AuthorDate: Mon Feb 25 06:57:34 2019 -0500

    CXF-7982: Extract common OpenAPI / Swagger scaffolding into dedicated module (to prevent/eliminate
duplication)
---
 .../karaf/features/src/main/resources/features.xml |   2 +
 .../pom.xml                                        |  45 ++------
 .../common/openapi/DefaultApplicationFactory.java  | 120 +++++++++++++++++++++
 .../jaxrs/common}/openapi/SwaggerProperties.java   |  10 +-
 rt/rs/description-openapi-v3/pom.xml               |   5 +-
 .../apache/cxf/jaxrs/openapi/OpenApiFeature.java   |  51 +--------
 rt/rs/description-swagger/pom.xml                  |   5 +-
 .../apache/cxf/jaxrs/swagger/Swagger2Feature.java  |  72 ++-----------
 rt/rs/pom.xml                                      |   1 +
 9 files changed, 156 insertions(+), 155 deletions(-)

diff --git a/osgi/karaf/features/src/main/resources/features.xml b/osgi/karaf/features/src/main/resources/features.xml
index 19406be..8dbc6b4 100644
--- a/osgi/karaf/features/src/main/resources/features.xml
+++ b/osgi/karaf/features/src/main/resources/features.xml
@@ -310,6 +310,7 @@
     <feature name="cxf-rs-description-swagger2" version="${project.version}">
         <feature version="${project.version}">cxf-jaxrs</feature>
         <feature version="${project.version}">cxf-jackson</feature>
+        <bundle start-level="40">mvn:org.apache.cxf/cxf-rt-rs-service-description-common-openapi/${project.version}</bundle>
         <bundle start-level="35">mvn:org.apache.cxf/cxf-rt-rs-service-description-swagger-ui/${project.version}</bundle>
         <bundle start-level="40">mvn:org.apache.cxf/cxf-rt-rs-service-description-swagger/${project.version}</bundle>
         <bundle start-level="10" dependency="true">mvn:javax.validation/validation-api/${cxf.validation.api.version}</bundle>
@@ -325,6 +326,7 @@
     <feature name="cxf-rs-description-openapi-v3" version="${project.version}">
         <feature version="${project.version}">cxf-jaxrs</feature>
         <feature version="${project.version}">cxf-jackson</feature>
+        <bundle start-level="40">mvn:org.apache.cxf/cxf-rt-rs-service-description-common-openapi/${project.version}</bundle>
         <bundle start-level="35">mvn:org.apache.cxf/cxf-rt-rs-service-description-swagger-ui/${project.version}</bundle>
         <bundle start-level="40">mvn:org.apache.cxf/cxf-rt-rs-service-description-openapi-v3/${project.version}</bundle>
         <bundle dependency="true" start-level="35">mvn:${cxf.servlet-api.group}/${cxf.servlet-api.artifact}/${cxf.servlet-api.version}</bundle>
diff --git a/rt/rs/description-openapi-v3/pom.xml b/rt/rs/description-common-openapi/pom.xml
similarity index 60%
copy from rt/rs/description-openapi-v3/pom.xml
copy to rt/rs/description-common-openapi/pom.xml
index ccd04d7..c05dcaf 100644
--- a/rt/rs/description-openapi-v3/pom.xml
+++ b/rt/rs/description-common-openapi/pom.xml
@@ -19,10 +19,10 @@
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
-    <artifactId>cxf-rt-rs-service-description-openapi-v3</artifactId>
+    <artifactId>cxf-rt-rs-service-description-common-openapi</artifactId>
     <packaging>bundle</packaging>
-    <name>Apache CXF JAX-RS Service Description OpenAPI v3</name>
-    <description>Apache CXF JAX-RS Service Description OpenAPI v3</description>
+    <name>Apache CXF JAX-RS Service Description OpenAPI/Swagger Common</name>
+    <description>Apache CXF JAX-RS Service Description OpenAPI/Swagger Common</description>
     <url>http://cxf.apache.org</url>
     <parent>
         <groupId>org.apache.cxf</groupId>
@@ -31,7 +31,7 @@
         <relativePath>../../../parent/pom.xml</relativePath>
     </parent>
     <properties>
-        <cxf.module.name>org.apache.cxf.rs.openapi.v3</cxf.module.name>
+        <cxf.module.name>org.apache.cxf.rs.common.openapi</cxf.module.name>
         <cxf.osgi.import>
             javax.servlet*;version="${cxf.osgi.javax.servlet.version}",
             javax.annotation;version="${cxf.osgi.javax.annotation.version}",
@@ -39,6 +39,10 @@
     </properties>
     <dependencies>
         <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>
@@ -49,38 +53,5 @@
             <scope>provided</scope>
             <optional>true</optional>
         </dependency>
-        <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-rt-rs-service-description-swagger-ui</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.cxf</groupId>
-            <artifactId>cxf-rt-rs-json-basic</artifactId>
-            <version>${project.version}</version>
-            <scope>provided</scope>
-            <optional>true</optional>
-        </dependency>
-        <dependency>
-            <groupId>io.swagger.core.v3</groupId>
-            <artifactId>swagger-jaxrs2</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>javax.xml.bind</groupId>
-                    <artifactId>jaxb-api</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.core</artifactId>
-            <scope>provided</scope>
-            <optional>true</optional>
-        </dependency>
     </dependencies>
 </project>
diff --git a/rt/rs/description-common-openapi/src/main/java/org/apache/cxf/jaxrs/common/openapi/DefaultApplicationFactory.java
b/rt/rs/description-common-openapi/src/main/java/org/apache/cxf/jaxrs/common/openapi/DefaultApplicationFactory.java
new file mode 100644
index 0000000..a1fd719
--- /dev/null
+++ b/rt/rs/description-common-openapi/src/main/java/org/apache/cxf/jaxrs/common/openapi/DefaultApplicationFactory.java
@@ -0,0 +1,120 @@
+/**
+ * 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.common.openapi;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import javax.ws.rs.core.Application;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Server;
+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;
+
+public final class DefaultApplicationFactory {
+    protected static class DefaultApplication extends Application {
+        private final Set<Class<?>> serviceClasses;
+        
+        DefaultApplication(final Set<Class<?>> serviceClasses) {
+            this.serviceClasses = serviceClasses;
+        }
+
+        DefaultApplication(final List<ClassResourceInfo> cris, final Set<String>
resourcePackages) {
+            this.serviceClasses = cris.stream().map(ClassResourceInfo::getServiceClass).
+                    filter(cls -> (resourcePackages == null || resourcePackages.isEmpty())
|| resourcePackages.stream().
+                            anyMatch(pkg -> cls.getPackage().getName().startsWith(pkg))).collect(Collectors.toSet());
+        }
+
+        @Override
+        public Set<Class<?>> getClasses() {
+            return serviceClasses;
+        }
+    }
+    
+    private DefaultApplicationFactory() {
+    }
+    
+    /**
+     * Detects the application (if present) or creates the default application (in case the
scan is disabled).
+     */
+    public static Application createApplicationOrDefault(final Server server, final ServerProviderFactory
factory, 
+            final JAXRSServiceFactoryBean sfb, final Bus bus, final Set<String> resourcePackages,

+                final boolean scan) {
+
+        ApplicationInfo appInfo = null;
+        if (!scan) {
+            appInfo = factory.getApplicationProvider();
+            
+            if (appInfo == null) {
+                appInfo = createApplicationInfo(sfb, resourcePackages, bus);
+                server.getEndpoint().put(Application.class.getName(), appInfo);
+            }
+        }
+        
+        return (appInfo == null) ? null : appInfo.getProvider();
+    }
+    
+    
+    /**
+     * Detects the application (if present) or creates the default application (in case the
scan is disabled).
+     */
+    public static ApplicationInfo createApplicationInfoOrDefault(final Server server, 
+                final ServerProviderFactory factory, final JAXRSServiceFactoryBean sfb, final
Bus bus, 
+                    final boolean scan) {
+        
+        ApplicationInfo appInfo = null;
+        if (!scan) {
+            appInfo = factory.getApplicationProvider();
+            if (appInfo == null) {
+                Set<Class<?>> serviceClasses = new HashSet<>();
+                for (ClassResourceInfo cri : sfb.getClassResourceInfo()) {
+                    serviceClasses.add(cri.getServiceClass());
+                }
+                appInfo = createApplicationInfo(serviceClasses, bus);
+                server.getEndpoint().put(Application.class.getName(), appInfo);
+            }
+        }
+        
+        return appInfo;
+    }
+    
+    public static ApplicationInfo createApplicationInfo(final Set<Class<?>> serviceClasses,
final Bus bus) {
+        return new ApplicationInfo(createApplication(serviceClasses), bus);
+    }
+    public static ApplicationInfo createApplicationInfo(final JAXRSServiceFactoryBean sfb,

+            final Set<String> resourcePackages, final Bus bus) {
+        return new ApplicationInfo(createApplication(sfb.getClassResourceInfo(), resourcePackages),
bus);
+    }
+
+    public static Application createApplication(final Set<Class<?>> serviceClasses)
{
+        return new DefaultApplication(serviceClasses);
+    }
+    
+    public static Application createApplication(final List<ClassResourceInfo> cris,

+            final Set<String> resourcePackages) {
+        return new DefaultApplication(cris, resourcePackages);
+    }
+}
+
diff --git a/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/SwaggerProperties.java
b/rt/rs/description-common-openapi/src/main/java/org/apache/cxf/jaxrs/common/openapi/SwaggerProperties.java
similarity index 88%
rename from rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/SwaggerProperties.java
rename to rt/rs/description-common-openapi/src/main/java/org/apache/cxf/jaxrs/common/openapi/SwaggerProperties.java
index 3cca3cf..5972bb0 100644
--- a/rt/rs/description-openapi-v3/src/main/java/org/apache/cxf/jaxrs/openapi/SwaggerProperties.java
+++ b/rt/rs/description-common-openapi/src/main/java/org/apache/cxf/jaxrs/common/openapi/SwaggerProperties.java
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.cxf.jaxrs.openapi;
+package org.apache.cxf.jaxrs.common.openapi;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -26,7 +26,11 @@ import java.util.Properties;
 import org.apache.cxf.Bus;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 
-interface SwaggerProperties {
+public interface SwaggerProperties {
+    String DEFAULT_PROPS_LOCATION = "/swagger.properties";
+    String DEFAULT_LICENSE_VALUE = "Apache 2.0 License";
+    String DEFAULT_LICENSE_URL = "http://www.apache.org/licenses/LICENSE-2.0.html";
+
     String RESOURCE_PACKAGE_PROPERTY = "resource.package";
     String TITLE_PROPERTY = "title";
     String VERSION_PROPERTY = "version";
@@ -46,7 +50,7 @@ interface SwaggerProperties {
      * @return the properties if available 
      */
     default Properties getSwaggerProperties(String location, Bus bus) {
-        InputStream is = ResourceUtils.getClasspathResourceStream(location, SwaggerProperties.class,
bus);
+        InputStream is = ResourceUtils.getClasspathResourceStream(location, getClass(), bus);
         Properties props = null;
         
         if (is != null) {
diff --git a/rt/rs/description-openapi-v3/pom.xml b/rt/rs/description-openapi-v3/pom.xml
index ccd04d7..cc310ea 100644
--- a/rt/rs/description-openapi-v3/pom.xml
+++ b/rt/rs/description-openapi-v3/pom.xml
@@ -52,6 +52,10 @@
         <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-service-description-common-openapi</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
@@ -62,7 +66,6 @@
         <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-rs-json-basic</artifactId>
-            <version>${project.version}</version>
             <scope>provided</scope>
             <optional>true</optional>
         </dependency>
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 a03e5fd..c774b40 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,7 +22,6 @@ 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;
@@ -41,8 +40,8 @@ import org.apache.cxf.common.util.StringUtils;
 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.common.openapi.DefaultApplicationFactory;
+import org.apache.cxf.jaxrs.common.openapi.SwaggerProperties;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 import org.apache.cxf.jaxrs.swagger.ui.SwaggerUiConfig;
 import org.apache.cxf.jaxrs.swagger.ui.SwaggerUiSupport;
@@ -63,10 +62,6 @@ import io.swagger.v3.oas.models.security.SecurityScheme;
 
 @Provider(value = Type.Feature, scope = Scope.Server)
 public class OpenApiFeature extends AbstractFeature implements SwaggerUiSupport, SwaggerProperties
{
-    private static final String DEFAULT_PROPS_LOCATION = "/swagger.properties";
-    private static final String DEFAULT_LICENSE_VALUE = "Apache 2.0 License";
-    private static final String DEFAULT_LICENSE_URL = "http://www.apache.org/licenses/LICENSE-2.0.html";
-    
     private String version;
     private String title;
     private String description;
@@ -111,22 +106,6 @@ public class OpenApiFeature extends AbstractFeature implements SwaggerUiSupport,
     private boolean useContextBasedConfig;
     private String ctxId;
 
-    protected static class DefaultApplication extends Application {
-
-        private final Set<Class<?>> serviceClasses;
-
-        DefaultApplication(final List<ClassResourceInfo> cris, final Set<String>
resourcePackages) {
-            this.serviceClasses = cris.stream().map(ClassResourceInfo::getServiceClass).
-                    filter(cls -> (resourcePackages == null || resourcePackages.isEmpty())
|| resourcePackages.stream().
-                            anyMatch(pkg -> cls.getPackage().getName().startsWith(pkg))).collect(Collectors.toSet());
-        }
-
-        @Override
-        public Set<Class<?>> getClasses() {
-            return serviceClasses;
-        }
-    }
-
     @Override
     public void initialize(Server server, Bus bus) {
         final JAXRSServiceFactoryBean sfb = (JAXRSServiceFactoryBean)server
@@ -149,7 +128,8 @@ public class OpenApiFeature extends AbstractFeature implements SwaggerUiSupport,
 
         Properties swaggerProps = null;
         GenericOpenApiContextBuilder<?> openApiConfiguration; 
-        final Application application = getApplicationOrDefault(server, factory, sfb, bus);
+        final Application application = DefaultApplicationFactory.createApplicationOrDefault(server,
factory, 
+            sfb, bus, resourcePackages, isScan());
         
         String defaultConfigLocation = getConfigLocation();
         if (scanKnownConfigLocations && StringUtils.isEmpty(defaultConfigLocation))
{
@@ -487,29 +467,6 @@ public class OpenApiFeature extends AbstractFeature implements SwaggerUiSupport,
     }
 
     /**
-     * Detects the application (if present) or creates the default application (in case the
scan is disabled).
-     */
-    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) {
-                appInfo = new ApplicationInfo(
-                        new DefaultApplication(sfb.getClassResourceInfo(), resourcePackages),
bus);
-                server.getEndpoint().put(Application.class.getName(), appInfo);
-            }
-        }
-        
-        return (appInfo == null) ? null : appInfo.getProvider();
-    }
-
-    /**
      * The info will be used only if there is no @OpenAPIDefinition annotation is present.

      */
     private Info getInfo(final Properties properties) {
diff --git a/rt/rs/description-swagger/pom.xml b/rt/rs/description-swagger/pom.xml
index e7d642c..3a12399 100644
--- a/rt/rs/description-swagger/pom.xml
+++ b/rt/rs/description-swagger/pom.xml
@@ -52,6 +52,10 @@
         <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.cxf</groupId>
+            <artifactId>cxf-rt-rs-service-description-common-openapi</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
@@ -72,7 +76,6 @@
         <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-rt-rs-json-basic</artifactId>
-            <version>${project.version}</version>
             <scope>provided</scope>
             <optional>true</optional>
         </dependency>
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 9bb7fd0..93d3f4b 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
@@ -19,10 +19,8 @@
 package org.apache.cxf.jaxrs.swagger;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.URI;
 import java.util.ArrayList;
-import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
@@ -47,6 +45,8 @@ import org.apache.cxf.annotations.Provider.Type;
 import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
+import org.apache.cxf.jaxrs.common.openapi.DefaultApplicationFactory;
+import org.apache.cxf.jaxrs.common.openapi.SwaggerProperties;
 import org.apache.cxf.jaxrs.ext.ContextProvider;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.model.ApplicationInfo;
@@ -55,7 +55,6 @@ import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 import org.apache.cxf.jaxrs.swagger.ui.SwaggerUiConfig;
 import org.apache.cxf.jaxrs.swagger.ui.SwaggerUiSupport;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
-import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.message.Message;
 
 import io.swagger.jaxrs.config.BeanConfig;
@@ -68,23 +67,8 @@ import io.swagger.models.Swagger;
 import io.swagger.models.auth.SecuritySchemeDefinition;
 
 @Provider(value = Type.Feature, scope = Scope.Server)
-public class Swagger2Feature extends AbstractSwaggerFeature implements SwaggerUiSupport {
-
-    private static final String DEFAULT_LICENSE_VALUE = "Apache 2.0 License";
-    private static final String DEFAULT_LICENSE_URL = "http://www.apache.org/licenses/LICENSE-2.0.html";
-
-    private static final String DEFAULT_PROPS_LOCATION = "/swagger.properties";
-    private static final String RESOURCE_PACKAGE_PROPERTY = "resource.package";
-    private static final String TITLE_PROPERTY = "title";
+public class Swagger2Feature extends AbstractSwaggerFeature implements SwaggerUiSupport,
SwaggerProperties {
     private static final String SCHEMES_PROPERTY = "schemes";
-    private static final String VERSION_PROPERTY = "version";
-    private static final String DESCRIPTION_PROPERTY = "description";
-    private static final String CONTACT_PROPERTY = "contact";
-    private static final String LICENSE_PROPERTY = "license";
-    private static final String LICENSE_URL_PROPERTY = "license.url";
-    private static final String TERMS_URL_PROPERTY = "terms.url";
-    private static final String PRETTY_PRINT_PROPERTY = "pretty.print";
-    private static final String FILTER_CLASS_PROPERTY = "filter.class";
     private static final String HOST_PROPERTY = "host";
     private static final String USE_PATH_CFG_PROPERTY = "use.path.based.config";
 
@@ -129,19 +113,8 @@ public class Swagger2Feature extends AbstractSwaggerFeature implements
SwaggerUi
 
         ServerProviderFactory factory =
             (ServerProviderFactory)server.getEndpoint().get(ServerProviderFactory.class.getName());
-        ApplicationInfo appInfo = null;
-        if (!isScan()) {
-            appInfo = factory.getApplicationProvider();
-            if (appInfo == null) {
-                Set<Class<?>> serviceClasses = new HashSet<>();
-                for (ClassResourceInfo cri : sfb.getClassResourceInfo()) {
-                    serviceClasses.add(cri.getServiceClass());
-                }
-                appInfo = new ApplicationInfo(new DefaultApplication(serviceClasses), bus);
-                server.getEndpoint().put(Application.class.getName(), appInfo);
-            }
-        }
-
+        final ApplicationInfo appInfo = DefaultApplicationFactory.createApplicationInfoOrDefault(server,

+            factory, sfb, bus, isScan());
 
         List<Object> swaggerResources = new LinkedList<>();
 
@@ -159,7 +132,7 @@ public class Swagger2Feature extends AbstractSwaggerFeature implements
SwaggerUi
                                                             customizer));
         }
 
-        final Properties swaggerProps = getSwaggerProperties(bus);
+        final Properties swaggerProps = getSwaggerProperties(propertiesLocation, bus);
         final Registration swaggerUiRegistration = getSwaggerUi(bus, swaggerProps, isRunAsFilter());
 
         if (!isRunAsFilter()) {
@@ -200,28 +173,6 @@ public class Swagger2Feature extends AbstractSwaggerFeature implements
SwaggerUi
         factory.setUserProviders(providers);
     }
 
-    protected Properties getSwaggerProperties(Bus bus) {
-        InputStream is = ResourceUtils.getClasspathResourceStream(propertiesLocation,
-                                                 AbstractSwaggerFeature.class,
-                                                 bus);
-        Properties props = null;
-        if (is != null) {
-            props = new Properties();
-            try {
-                props.load(is);
-            } catch (IOException ex) {
-                props = null;
-            } finally {
-                try {
-                    is.close();
-                } catch (IOException ignore) {
-                    // ignore
-                }
-            }
-        }
-
-        return props;
-    }
     protected void initBeanConfig(BeanConfig beanConfig, Properties props) {
 
         // resource package
@@ -564,15 +515,4 @@ public class Swagger2Feature extends AbstractSwaggerFeature implements
SwaggerUi
             mc.getServletContext().setAttribute(ReaderConfig.class.getName(), rc);
         }
     }
-
-    protected static class DefaultApplication extends Application {
-        Set<Class<?>> serviceClasses;
-        DefaultApplication(Set<Class<?>> serviceClasses) {
-            this.serviceClasses = serviceClasses;
-        }
-        @Override
-        public Set<Class<?>> getClasses() {
-            return serviceClasses;
-        }
-    }
 }
diff --git a/rt/rs/pom.xml b/rt/rs/pom.xml
index 8dba534..4ef749c 100644
--- a/rt/rs/pom.xml
+++ b/rt/rs/pom.xml
@@ -46,5 +46,6 @@
         <module>description-openapi-v3</module>
         <module>description-swagger-ui</module>
         <module>microprofile-client</module>
+        <module>description-common-openapi</module>
     </modules>
 </project>


Mime
View raw message