camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/2] camel git commit: CAMEL-7800: camel-swagger-java - work in progress
Date Fri, 18 Sep 2015 12:02:50 GMT
CAMEL-7800: camel-swagger-java - work in progress


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

Branch: refs/heads/swagger
Commit: 112c58e5487dd6c8c274d49d8bae609c23d04b85
Parents: 64852d2
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Sep 18 14:04:07 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Sep 18 14:04:07 2015 +0200

----------------------------------------------------------------------
 .../RestSwaggerApiDeclarationServlet.java       | 52 +++++++++++++++-----
 .../apache/camel/swagger/RestSwaggerReader.java |  3 +-
 .../src/main/webapp/WEB-INF/web.xml             |  6 ++-
 3 files changed, 48 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/112c58e5/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerApiDeclarationServlet.java
----------------------------------------------------------------------
diff --git a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerApiDeclarationServlet.java
b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerApiDeclarationServlet.java
index 6bc5e50..68d621b 100644
--- a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerApiDeclarationServlet.java
+++ b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerApiDeclarationServlet.java
@@ -30,6 +30,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
 import io.swagger.jaxrs.config.BeanConfig;
+import io.swagger.models.Contact;
+import io.swagger.models.Info;
+import io.swagger.models.License;
 import io.swagger.models.Swagger;
 import org.apache.camel.impl.DefaultClassResolver;
 import org.apache.camel.model.rest.RestDefinition;
@@ -68,20 +71,47 @@ public abstract class RestSwaggerApiDeclarationServlet extends HttpServlet
{
         if (s != null) {
             cors = "true".equalsIgnoreCase(s);
         }
+        s = config.getInitParameter("schemas");
+        if (s != null) {
+            String[] schemas = s.split(",");
+            swaggerConfig.setSchemes(schemas);
+        } else {
+            // assume http by default
+            swaggerConfig.setSchemes(new String[]{"http"});
+        }
 
+        String version = config.getInitParameter("api.version");
         String title = config.getInitParameter("api.title");
         String description = config.getInitParameter("api.description");
-        String termsOfServiceUrl = config.getInitParameter("api.termsOfServiceUrl");
-        String contact = config.getInitParameter("api.contact");
-        String license = config.getInitParameter("api.license");
-        String licenseUrl = config.getInitParameter("api.licenseUrl");
-
-        swaggerConfig.setTitle(title);
-        swaggerConfig.setDescription(description);
-        swaggerConfig.setTermsOfServiceUrl(termsOfServiceUrl);
-        swaggerConfig.setContact(contact);
-        swaggerConfig.setLicense(license);
-        swaggerConfig.setLicenseUrl(licenseUrl);
+        String termsOfService = config.getInitParameter("api.termsOfService");
+        String licenseName = config.getInitParameter("api.license.name");
+        String licenseUrl = config.getInitParameter("api.license.url");
+        String contactName = config.getInitParameter("api.contact.name");
+        String contactUrl = config.getInitParameter("api.contact.url");
+        String contactEmail = config.getInitParameter("api.contact.email");
+
+        Info info = new Info();
+        info.setVersion(version);
+        info.setTitle(title);
+        info.setDescription(description);
+        info.setTermsOfService(termsOfService);
+
+        if (licenseName != null || licenseUrl != null) {
+            License license = new License();
+            license.setName(licenseName);
+            license.setUrl(licenseUrl);
+            info.setLicense(license);
+        }
+
+        if (contactName != null || contactUrl != null || contactEmail != null) {
+            Contact contact = new Contact();
+            contact.setName(contactName);
+            contact.setUrl(contactUrl);
+            contact.setEmail(contactEmail);
+            info.setContact(contact);
+        }
+
+        swaggerConfig.setInfo(info);
     }
 
     public abstract List<RestDefinition> getRestDefinitions(String camelId) throws
Exception;

http://git-wip-us.apache.org/repos/asf/camel/blob/112c58e5/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerReader.java
----------------------------------------------------------------------
diff --git a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerReader.java
b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerReader.java
index 8f12dfe..1ad8c1f 100644
--- a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerReader.java
+++ b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerReader.java
@@ -66,7 +66,6 @@ public class RestSwaggerReader {
      */
     public Swagger read(RestDefinition rest, BeanConfig config, ClassResolver classResolver)
{
         Swagger swagger = new Swagger();
-        config.configure(swagger);
 
         List<VerbDefinition> verbs = new ArrayList<>(rest.getVerbs());
         // must sort the verbs by uri so we group them together when an uri has multiple
operations
@@ -209,6 +208,8 @@ public class RestSwaggerReader {
             swagger.path(opPath, path);
         }
 
+        // configure before returning
+        swagger = config.configure(swagger);
         return swagger;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/112c58e5/examples/camel-example-swagger-java/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-swagger-java/src/main/webapp/WEB-INF/web.xml b/examples/camel-example-swagger-java/src/main/webapp/WEB-INF/web.xml
index 17e049f..2979553 100755
--- a/examples/camel-example-swagger-java/src/main/webapp/WEB-INF/web.xml
+++ b/examples/camel-example-swagger-java/src/main/webapp/WEB-INF/web.xml
@@ -60,7 +60,7 @@
     </init-param>
     <init-param>
       <param-name>api.version</param-name>
-      <param-value>2.0</param-value>
+      <param-value>1.2.3</param-value>
     </init-param>
     <init-param>
       <param-name>api.title</param-name>
@@ -70,6 +70,10 @@
       <param-name>api.description</param-name>
       <param-value>Camel Rest Example with Swagger that provides an User REST service</param-value>
     </init-param>
+    <init-param>
+      <param-name>api.contact.name</param-name>
+      <param-value>The Apache Camel team</param-value>
+    </init-param>
     <load-on-startup>2</load-on-startup>
   </servlet>
 


Mime
View raw message