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-7035] Propagating BeanConfig if dynamicBasePath code detects a basePath mismatch, with thanks to Andriy Redko
Date Thu, 01 Sep 2016 12:45:17 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 9a8a70b19 -> 95e62db0e


[CXF-7035] Propagating BeanConfig if dynamicBasePath code detects a basePath mismatch, with
thanks to Andriy Redko


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

Branch: refs/heads/3.0.x-fixes
Commit: 95e62db0e66d623a67ef07c8d8cf33103e39d587
Parents: 9a8a70b
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Sep 1 13:16:57 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Sep 1 13:45:05 2016 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/swagger/AbstractSwaggerFeature.java    |  2 +-
 .../jaxrs/swagger/DefaultSwagger2Serializers.java    | 15 ++++++++++++++-
 .../apache/cxf/jaxrs/swagger/Swagger2Feature.java    | 13 +++++++++++++
 .../cxf/jaxrs/swagger/Swagger2Serializers.java       |  5 ++++-
 4 files changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/95e62db0/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 386855d..140d7d9 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
@@ -82,7 +82,7 @@ public abstract class AbstractSwaggerFeature extends AbstractFeature {
         }
     }
     
-    private void calculateDefaultBasePath(Server server) {
+    protected void calculateDefaultBasePath(Server server) {
         if (getBasePath() == null || getBasePath().length() == 0) {
             String address = server.getEndpoint().getEndpointInfo().getAddress();
             setBasePathByAddress(address);

http://git-wip-us.apache.org/repos/asf/cxf/blob/95e62db0/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
index 064d5b6..ded370e 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/DefaultSwagger2Serializers.java
@@ -42,6 +42,7 @@ import org.apache.cxf.jaxrs.model.doc.DocumentationProvider;
 import org.apache.cxf.jaxrs.model.doc.JavaDocProvider;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
+import io.swagger.jaxrs.config.BeanConfig;
 import io.swagger.jaxrs.listing.SwaggerSerializers;
 import io.swagger.models.HttpMethod;
 import io.swagger.models.Operation;
@@ -59,6 +60,7 @@ public class DefaultSwagger2Serializers extends SwaggerSerializers implements
Sw
 
     protected List<ClassResourceInfo> cris;
 
+    protected BeanConfig beanConfig;
     @Override
     public void writeTo(
             final Swagger data,
@@ -72,7 +74,12 @@ public class DefaultSwagger2Serializers extends SwaggerSerializers implements
Sw
         if (dynamicBasePath) {
             MessageContext ctx = JAXRSUtils.createContextValue(
                     JAXRSUtils.getCurrentMessage(), null, MessageContext.class);
-            data.setBasePath(StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(),
"/"));
+            String currentBasePath = StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(),
"/");
+            if (!currentBasePath.equals(beanConfig.getBasePath())) {
+                data.setBasePath(currentBasePath);
+                data.setHost(beanConfig.getHost());
+                data.setInfo(beanConfig.getInfo());
+            }
         }
 
         if (replaceTags || javadocProvider != null) {
@@ -195,4 +202,10 @@ public class DefaultSwagger2Serializers extends SwaggerSerializers implements
Sw
     public void setJavaDocURLs(final URL[] javaDocURLs) {
         this.javadocProvider = new JavaDocProvider(javaDocURLs);
     }
+
+    @Override
+    public void setBeanConfig(BeanConfig beanConfig) {
+        this.beanConfig = beanConfig;
+        
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/95e62db0/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 6c79d84..ff011f0 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
@@ -62,6 +62,15 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
     
     private Swagger2Serializers swagger2Serializers;
 
+    private boolean dynamicBasePath;
+   
+    @Override
+    protected void calculateDefaultBasePath(Server server) {
+        dynamicBasePath = true;
+        super.calculateDefaultBasePath(server);
+    }
+ 
+
     @Override
     protected void addSwaggerResource(Server server) {
         ApiListingResource apiListingResource = new ApiListingResource();
@@ -85,6 +94,8 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
             swagger2Serializers = new DefaultSwagger2Serializers();
         }
         swagger2Serializers.setClassResourceInfos(cris);
+        swagger2Serializers.setDynamicBasePath(dynamicBasePath);
+
         providers.add(swagger2Serializers);
 
         providers.add(new ReaderConfigFilter());
@@ -107,6 +118,8 @@ public class Swagger2Feature extends AbstractSwaggerFeature {
         beanConfig.setScan(isScan());
         beanConfig.setPrettyPrint(isPrettyPrint());
         beanConfig.setFilterClass(getFilterClass());
+
+        swagger2Serializers.setBeanConfig(beanConfig);
     }
 
     public String getHost() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/95e62db0/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
----------------------------------------------------------------------
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
index 8665b5a..ba1dec9 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Serializers.java
@@ -26,10 +26,13 @@ import javax.ws.rs.ext.MessageBodyWriter;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.doc.DocumentationProvider;
 
+import io.swagger.jaxrs.config.BeanConfig;
 import io.swagger.models.Swagger;
 
 public interface Swagger2Serializers extends MessageBodyWriter<Swagger> {
 
+    void setBeanConfig(BeanConfig beanConfig);
+    
     void setDynamicBasePath(boolean dynamicBasePath);
 
     void setReplaceTags(boolean replaceTags);
@@ -43,4 +46,4 @@ public interface Swagger2Serializers extends MessageBodyWriter<Swagger>
{
     void setJavaDocPaths(String... javaDocPaths) throws Exception;
 
     void setJavaDocURLs(URL[] javaDocURLs);
-}
\ No newline at end of file
+}


Mime
View raw message