cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject cxf git commit: [CXF-6512] The host property is missing in Swagger2 feature's configuration properties
Date Fri, 31 Jul 2015 15:56:05 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 3228637a5 -> e95903ef8


[CXF-6512] The host property is missing in Swagger2 feature's configuration properties


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

Branch: refs/heads/master
Commit: e95903ef8be9db3b9019023e39ac266eeb99d6c7
Parents: 3228637
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Fri Jul 31 17:48:12 2015 +0200
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Fri Jul 31 17:55:57 2015 +0200

----------------------------------------------------------------------
 .../jaxrs/swagger/AbstractSwaggerFeature.java   |  1 +
 .../cxf/jaxrs/swagger/Swagger2Feature.java      | 16 +++++-
 .../cxf/jaxrs/swagger/Swagger2FeatureTest.java  | 53 ++++++++++++++++++++
 .../cxf/jaxrs/swagger/SwaggerFeatureTest.java   | 45 +++++++++++++++++
 4 files changed, 113 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e95903ef/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
index 44f5f08..66b65b8 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/AbstractSwaggerFeature.java
@@ -29,6 +29,7 @@ abstract class AbstractSwaggerFeature extends AbstractFeature {
     protected boolean runAsFilter;
     private String resourcePackage;
     private String version = "1.0.0";
+    // depending on swagger version basePath is set differently
     private String basePath;
     private String title = "Sample REST Application";
     private String description = "The Application";

http://git-wip-us.apache.org/repos/asf/cxf/blob/e95903ef/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
index 279a581..1441b5c 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java
@@ -42,6 +42,7 @@ import io.swagger.jaxrs.listing.ApiListingResource;
 import io.swagger.jaxrs.listing.SwaggerSerializers;
 
 public class Swagger2Feature extends AbstractSwaggerFeature {
+    private String host;
 
     @Override
     protected void addSwaggerResource(Server server) {
@@ -70,6 +71,7 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
         beanConfig.setResourcePackage(getResourcePackage());
         beanConfig.setVersion(getVersion());
         beanConfig.setBasePath(getBasePath());
+        beanConfig.setHost(getHost());
         beanConfig.setTitle(getTitle());
         beanConfig.setDescription(getDescription());
         beanConfig.setContact(getContact());
@@ -78,13 +80,23 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
         beanConfig.setScan(isScan());
     }
 
+    public String getHost() {
+        return host;
+    }
+    public void setHost(String host) {
+        this.host = host;
+    }
+
     @Override
     protected void setBasePathByAddress(String address) {
         if (!address.startsWith("/")) {
             // get the path part
-            address = URI.create(address).getPath();
+            URI u = URI.create(address); 
+            setBasePath(u.getPath());
+            setHost(u.getPort() < 0 ? u.getHost() : u.getHost() + ":" + u.getPort());
+        } else {
+            setBasePath(address);
         }
-        setBasePath(address);
     }
 
     @PreMatching

http://git-wip-us.apache.org/repos/asf/cxf/blob/e95903ef/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/swagger/Swagger2FeatureTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/swagger/Swagger2FeatureTest.java
b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/swagger/Swagger2FeatureTest.java
new file mode 100644
index 0000000..c87b041
--- /dev/null
+++ b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/swagger/Swagger2FeatureTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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 org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class Swagger2FeatureTest extends Assert {
+    @Test
+    public void testSetBasePathByAddress() {
+        Swagger2Feature f = new Swagger2Feature();
+
+        f.setBasePathByAddress("http://localhost:8080/foo");
+        assertEquals("/foo", f.getBasePath());
+        assertEquals("localhost:8080", f.getHost());
+        unsetBasePath(f);
+
+        f.setBasePathByAddress("http://localhost/foo");
+        assertEquals("/foo", f.getBasePath());
+        assertEquals("localhost", f.getHost());
+        unsetBasePath(f);
+
+        f.setBasePathByAddress("/foo");
+        assertEquals("/foo", f.getBasePath());
+        assertNull(f.getHost());
+        unsetBasePath(f);
+    }
+
+    private static void unsetBasePath(Swagger2Feature f) {
+        f.setBasePath(null);
+        f.setHost(null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/e95903ef/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/swagger/SwaggerFeatureTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/swagger/SwaggerFeatureTest.java
b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/swagger/SwaggerFeatureTest.java
new file mode 100644
index 0000000..a1922d5
--- /dev/null
+++ b/rt/rs/description/src/test/java/org/apache/cxf/jaxrs/swagger/SwaggerFeatureTest.java
@@ -0,0 +1,45 @@
+/**
+ * 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 org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class SwaggerFeatureTest extends Assert {
+    @Test
+    public void testSetBasePathByAddress() {
+        SwaggerFeature f = new SwaggerFeature();
+
+        f.setBasePathByAddress("http://localhost:8080/foo");
+        assertEquals("http://localhost:8080/foo", f.getBasePath());
+        unsetBasePath(f);
+
+        f.setBasePathByAddress("/foo");
+        assertEquals("/foo", f.getBasePath());
+        unsetBasePath(f);
+    }
+
+    private static void unsetBasePath(SwaggerFeature f) {
+        f.setBasePath(null);
+    }
+}


Mime
View raw message