You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2017/02/20 13:59:36 UTC

cxf git commit: [CXF-7137] Getting Swagger2 security defs actually reported, patch from Dennis Kieselhorst applied with minor updates, This closes #236

Repository: cxf
Updated Branches:
  refs/heads/master 59b972618 -> a2cbe7582


[CXF-7137] Getting Swagger2 security defs actually reported, patch from Dennis Kieselhorst applied with minor updates, This closes #236


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

Branch: refs/heads/master
Commit: a2cbe758286d00b5c5d9c5fbe6be4cc9d7ecf225
Parents: 59b9726
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Mon Feb 20 13:59:22 2017 +0000
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Mon Feb 20 13:59:22 2017 +0000

----------------------------------------------------------------------
 .../jaxrs/swagger/DefaultSwagger2Serializers.java  |  5 +++++
 .../AbstractSwagger2ServiceDescriptionTest.java    | 17 +++++++++++++++--
 ...Swagger2NonAnnotatedServiceDescriptionTest.java |  3 +--
 3 files changed, 21 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a2cbe758/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
----------------------------------------------------------------------
diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
index 194a49e..6a51acc 100644
--- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
+++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
@@ -82,6 +82,11 @@ public class DefaultSwagger2Serializers extends SwaggerSerializers implements Sw
                 data.setHost(beanConfig.getHost());
                 data.setInfo(beanConfig.getInfo());
             }
+            if (beanConfig.getSwagger() != null 
+                && beanConfig.getSwagger().getSecurityDefinitions() != null
+                && data.getSecurityDefinitions() == null) {
+                data.setSecurityDefinitions(beanConfig.getSwagger().getSecurityDefinitions());
+            }
         }
 
         if (replaceTags || javadocProvider != null) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2cbe758/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
index a571adb..1c2529e 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
@@ -49,12 +49,15 @@ import org.apache.cxf.jaxrs.swagger.SwaggerUtils;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
 
+import org.hamcrest.CoreMatchers;
 import org.junit.Ignore;
 import org.junit.Test;
 
 import org.yaml.snakeyaml.Yaml;
 
 public abstract class AbstractSwagger2ServiceDescriptionTest extends AbstractBusClientServerTestBase {
+    private static final String CONTACT = "CXF unittest";
+    private static final String SECURITY_DEFINITION_NAME = "basicAuth";
 
     @Ignore
     public abstract static class Server extends AbstractBusTestServerBase {
@@ -73,14 +76,22 @@ public abstract class AbstractSwagger2ServiceDescriptionTest extends AbstractBus
             sf.setResourceProvider(BookStoreSwagger2.class,
                 new SingletonResourceProvider(new BookStoreSwagger2()));
             sf.setProvider(new JacksonJsonProvider());
-            final Swagger2Feature feature = new Swagger2Feature();
-            feature.setRunAsFilter(runAsFilter);
+            final Swagger2Feature feature = createSwagger2Feature();
             sf.setFeatures(Arrays.asList(feature));
             sf.setAddress("http://localhost:" + port + "/");
             sf.setExtensionMappings(
                  Collections.singletonMap("json", "application/json;charset=UTF-8"));
             sf.create();
         }
+        
+        protected Swagger2Feature createSwagger2Feature() {
+            final Swagger2Feature feature = new Swagger2Feature();
+            feature.setRunAsFilter(runAsFilter);
+            feature.setContact(CONTACT);
+            feature.setSecurityDefinitions(Collections.singletonMap(SECURITY_DEFINITION_NAME,
+               new io.swagger.models.auth.BasicAuthDefinition()));
+            return feature;
+        }
 
         protected static void start(final Server s) {
             try {
@@ -140,6 +151,8 @@ public abstract class AbstractSwagger2ServiceDescriptionTest extends AbstractBus
             assertEquals(1, delOpParams.size());
             assertEquals(ParameterType.PATH, delOpParams.get(0).getType());
 
+            assertThat(swaggerJson, CoreMatchers.containsString(CONTACT));
+            assertThat(swaggerJson, CoreMatchers.containsString(SECURITY_DEFINITION_NAME));
         } finally {
             client.close();
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2cbe758/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2NonAnnotatedServiceDescriptionTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2NonAnnotatedServiceDescriptionTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2NonAnnotatedServiceDescriptionTest.java
index 68e0c8d..5d59f41 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2NonAnnotatedServiceDescriptionTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2NonAnnotatedServiceDescriptionTest.java
@@ -45,8 +45,7 @@ public class Swagger2NonAnnotatedServiceDescriptionTest extends AbstractSwagger2
             sf.setResourceProvider(BookStore.class,
                 new SingletonResourceProvider(new BookStore()));
             sf.setProvider(new JacksonJsonProvider());
-            final Swagger2Feature feature = new Swagger2Feature();
-            feature.setRunAsFilter(runAsFilter);
+            final Swagger2Feature feature = createSwagger2Feature();
             //FIXME swagger-jaxrs 1.5.3 can't handle a self-recursive subresource like Book
             // so we need to exclude "org.apache.cxf.systest.jaxrs" for now.
             feature.setResourcePackage("org.apache.cxf.systest.jaxrs.description.group1");