camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-7800: camel-swagger-java - work in progress
Date Fri, 18 Sep 2015 09:42:26 GMT
Repository: camel
Updated Branches:
  refs/heads/swagger 03c407c94 -> f298fad1d


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/f298fad1
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f298fad1
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f298fad1

Branch: refs/heads/swagger
Commit: f298fad1de3cc066d9dcf0dbcd0ace3ee70d56d9
Parents: 03c407c
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Sep 18 11:25:39 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Sep 18 11:43:42 2015 +0200

----------------------------------------------------------------------
 .../swagger/DefaultCamelSwaggerServlet.java     |   4 +-
 .../camel/swagger/RestModelConverters.java      |  41 ++
 .../RestSwaggerApiDeclarationServlet.java       |   5 +-
 .../apache/camel/swagger/RestSwaggerReader.java | 125 +++++-
 .../swagger/RestSwaggerReaderModelTest.java     |  94 +++++
 .../camel/swagger/RestSwaggerReaderTest.java    |   3 +-
 .../java/org/apache/camel/swagger/User.java     |  53 +++
 examples/camel-example-swagger-java/pom.xml     | 382 ++++++++++---------
 .../org/apache/camel/example/rest/User.java     |   1 -
 .../src/main/resources/camel-config-xml.xml     |   2 +-
 10 files changed, 500 insertions(+), 210 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f298fad1/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/DefaultCamelSwaggerServlet.java
----------------------------------------------------------------------
diff --git a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/DefaultCamelSwaggerServlet.java
b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/DefaultCamelSwaggerServlet.java
index 12d79aa..2a68868 100644
--- a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/DefaultCamelSwaggerServlet.java
+++ b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/DefaultCamelSwaggerServlet.java
@@ -42,7 +42,7 @@ public class DefaultCamelSwaggerServlet extends RestSwaggerApiDeclarationServlet
                 id = id.substring(1, id.length() - 1);
             }
             if (camelId == null || camelId.equals(id)) {
-                // filter out older Camel versions as this requires Camel 2.15 or better
+                // filter out older Camel versions as this requires Camel 2.15 or better
(rest-dsl)
                 String version = (String) server.getAttribute(on, "CamelVersion");
                 if (CamelVersionHelper.isGE("2.15.0", version)) {
                     found = on;
@@ -75,7 +75,7 @@ public class DefaultCamelSwaggerServlet extends RestSwaggerApiDeclarationServlet
                 id = id.substring(1, id.length() - 1);
             }
 
-            // filter out older Camel versions as this requires Camel 2.15 or better
+            // filter out older Camel versions as this requires Camel 2.15 or better (rest-dsl)
             String version = (String) server.getAttribute(on, "CamelVersion");
             if (CamelVersionHelper.isGE("2.15.0", version)) {
                 answer.add(id);

http://git-wip-us.apache.org/repos/asf/camel/blob/f298fad1/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestModelConverters.java
----------------------------------------------------------------------
diff --git a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestModelConverters.java
b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestModelConverters.java
new file mode 100644
index 0000000..ed5b705
--- /dev/null
+++ b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestModelConverters.java
@@ -0,0 +1,41 @@
+/**
+ * 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.camel.swagger;
+
+import java.util.Map;
+
+import io.swagger.converter.ModelConverters;
+import io.swagger.models.Model;
+import io.swagger.models.properties.StringProperty;
+
+/**
+ * A Camel extended {@link ModelConverters} where we appending vendor extensions
+ * to include the java class name of the model classes.
+ */
+public class RestModelConverters extends ModelConverters {
+
+    public Map<String, Model> readClass(Class clazz) {
+        String name = clazz.getName();
+        Map<String, Model> resolved = super.read(clazz);
+        if (resolved != null) {
+            for (Model model : resolved.values()) {
+                model.getVendorExtensions().put("x-className", new StringProperty(name));
+            }
+        }
+        return resolved;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f298fad1/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 ceb5af2..6bc5e50 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
@@ -31,6 +31,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
 import io.swagger.jaxrs.config.BeanConfig;
 import io.swagger.models.Swagger;
+import org.apache.camel.impl.DefaultClassResolver;
 import org.apache.camel.model.rest.RestDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -123,7 +124,7 @@ public abstract class RestSwaggerApiDeclarationServlet extends HttpServlet
{
                 }
             }
         } catch (Exception e) {
-            LOG.warn("Error rendering swagger due " + e.getMessage());
+            LOG.warn("Error rendering swagger due " + e.getMessage(), e);
         }
     }
 
@@ -142,7 +143,7 @@ public abstract class RestSwaggerApiDeclarationServlet extends HttpServlet
{
             // TODO: combine the rests
 
             for (RestDefinition rest : rests) {
-                Swagger swagger = reader.read(rest, swaggerConfig);
+                Swagger swagger = reader.read(rest, swaggerConfig, new DefaultClassResolver());
 
                 ObjectMapper mapper = new ObjectMapper();
                 mapper.enable(SerializationFeature.INDENT_OUTPUT);

http://git-wip-us.apache.org/repos/asf/camel/blob/f298fad1/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 e6172af..e664529 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
@@ -19,10 +19,15 @@ package org.apache.camel.swagger;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
 
 import io.swagger.jaxrs.config.BeanConfig;
+import io.swagger.models.Model;
+import io.swagger.models.ModelImpl;
 import io.swagger.models.Operation;
 import io.swagger.models.Path;
 import io.swagger.models.Response;
@@ -34,15 +39,30 @@ import io.swagger.models.parameters.Parameter;
 import io.swagger.models.parameters.PathParameter;
 import io.swagger.models.parameters.QueryParameter;
 import io.swagger.models.parameters.SerializableParameter;
+import io.swagger.models.properties.ArrayProperty;
+import io.swagger.models.properties.RefProperty;
+import io.swagger.models.properties.StringProperty;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.model.rest.RestOperationParamDefinition;
 import org.apache.camel.model.rest.RestOperationResponseMsgDefinition;
 import org.apache.camel.model.rest.RestParamType;
 import org.apache.camel.model.rest.VerbDefinition;
+import org.apache.camel.spi.ClassResolver;
 
+/**
+ * A Camel REST-DSL swagger reader that parse the rest-dsl into a swagger model representation.
+ */
 public class RestSwaggerReader {
 
-    public Swagger read(RestDefinition rest, BeanConfig config) {
+    /**
+     * Read the REST-DSL definition and parse that as a Swagger model representation
+     *
+     * @param rest              the rest-dsl
+     * @param config            the swagger configuration
+     * @param classResolver     class resolver to use
+     * @return the swagger model
+     */
+    public Swagger read(RestDefinition rest, BeanConfig config, ClassResolver classResolver)
{
         Swagger swagger = new Swagger();
         config.configure(swagger);
 
@@ -50,6 +70,31 @@ public class RestSwaggerReader {
         // must sort the verbs by uri so we group them together when an uri has multiple
operations
         Collections.sort(verbs, new VerbOrdering());
 
+        // gather all types in use
+        Set<String> types = new LinkedHashSet<>();
+        for (VerbDefinition verb : verbs) {
+            String type = verb.getType();
+            if (type != null) {
+                if (type.endsWith("[]")) {
+                    type = type.substring(0, type.length() - 2);
+                }
+                types.add(type);
+            }
+            type = verb.getOutType();
+            if (type != null) {
+                if (type.endsWith("[]")) {
+                    type = type.substring(0, type.length() - 2);
+                }
+                types.add(type);
+            }
+        }
+
+        // use annotation scanner to find models (annotated classes)
+        for (String type : types) {
+            Class<?> clazz = classResolver.resolveClass(type);
+            appendModels(clazz, swagger);
+        }
+
         // used during gathering of apis
         List<Path> paths = new ArrayList<>();
 
@@ -71,21 +116,26 @@ public class RestSwaggerReader {
             }
             path = path.set(method, op);
 
-            // TODO: add the type / outType stuff with array and model detection
-
-            if (verb.getConsumes() != null) {
-                op.consumes(verb.getConsumes());
-            } else if (rest.getConsumes() != null) {
-                op.consumes(rest.getConsumes());
+            String consumes = verb.getConsumes() != null ? verb.getConsumes() : rest.getConsumes();
+            if (consumes != null) {
+                String[] parts = consumes.split(",");
+                for (String part : parts) {
+                    op.addConsumes(part);
+                }
             }
-            if (verb.getProduces() != null) {
-                op.produces(verb.getProduces());
-            } else if (rest.getProduces() != null) {
-                op.produces(rest.getProduces());
+
+            String produces = verb.getProduces() != null ? verb.getProduces() : rest.getProduces();
+            if (produces != null) {
+                String[] parts = produces.split(",");
+                for (String part : parts) {
+                    op.addProduces(part);
+                }
             }
+
             if (verb.getDescriptionText() != null) {
                 op.summary(verb.getDescriptionText());
             }
+
             for (RestOperationParamDefinition param : verb.getParams()) {
                 Parameter parameter = null;
                 if (param.getType().equals(RestParamType.body)) {
@@ -108,12 +158,47 @@ public class RestSwaggerReader {
 
                     if (parameter instanceof SerializableParameter) {
                         SerializableParameter sp = (SerializableParameter) parameter;
-                        sp.setType(param.getDataType());
+
+                        // TODO: like response object with type refer to model
+                        if (param.getDataType() != null) {
+                            sp.setType(param.getDataType());
+                        } else if (verb.getType() != null) {
+                            boolean array = verb.getType().endsWith("[]");
+                            if (array) {
+                                sp.setType("array");
+                            } else {
+                                sp.setType(verb.getType());
+                            }
+                        }
                     }
 
                     op.addParameter(parameter);
                 }
             }
+
+            if (verb.getOutType() != null) {
+                Response response = new Response();
+                boolean array = verb.getOutType().endsWith("[]");
+                String type = array ? verb.getOutType().substring(0, verb.getOutType().length()
- 2) : verb.getOutType();
+                // lookup in models to use key instead of FQN
+
+                for (Model model : swagger.getDefinitions().values()) {
+                    StringProperty modelType = (StringProperty) model.getVendorExtensions().get("x-className");
+                    if (modelType != null && type.equals(modelType.getFormat()))
{
+                        type = ((ModelImpl) model).getName();
+                        break;
+                    }
+                }
+
+                if (array) {
+                    response.setSchema(new ArrayProperty(new RefProperty(type)));
+                } else {
+                    response.setSchema(new RefProperty(type));
+                }
+                response.setDescription("Output type");
+                op.addResponse("200", response);
+            }
+
             for (RestOperationResponseMsgDefinition msg : verb.getResponseMsgs()) {
                 Response response = new Response();
                 response.setDescription(msg.getMessage());
@@ -123,13 +208,27 @@ public class RestSwaggerReader {
             // add path
             swagger.path(opPath, path);
 
-            // TODO: add model parser for swagger annotations in the model/schema
         }
 
         return swagger;
     }
 
     /**
+     * If the class is annotated with swagger annotations its parsed into a Swagger model
representation
+     * which is added to swagger
+     *
+     * @param clazz   the class such as pojo with swagger annotation
+     * @param swagger the swagger model
+     */
+    private void appendModels(Class clazz, Swagger swagger) {
+        RestModelConverters converters = new RestModelConverters();
+        final Map<String, Model> models = converters.readClass(clazz);
+        for (Map.Entry<String, Model> entry : models.entrySet()) {
+            swagger.model(entry.getKey(), entry.getValue());
+        }
+    }
+
+    /**
      * To sort the rest operations
      */
     private static class VerbOrdering implements Comparator<VerbDefinition> {

http://git-wip-us.apache.org/repos/asf/camel/blob/f298fad1/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderModelTest.java
----------------------------------------------------------------------
diff --git a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderModelTest.java
b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderModelTest.java
new file mode 100644
index 0000000..d899613
--- /dev/null
+++ b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderModelTest.java
@@ -0,0 +1,94 @@
+/**
+ * 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.camel.swagger;
+
+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.Swagger;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultClassResolver;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.model.rest.RestParamType;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class RestSwaggerReaderModelTest extends CamelTestSupport {
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("dummy-rest", new DummyRestConsumerFactory());
+        return jndi;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // this user REST service is json only
+                rest("/user").description("User rest service")
+                    .consumes("application/json").produces("application/json")
+
+                    .get("/{id}").description("Find user by id").outType(User.class)
+                        .param().name("id").type(RestParamType.path).description("The id
of the user to get").dataType("integer").endParam()
+                        .to("bean:userService?method=getUser(${header.id})")
+
+                    .put().description("Updates or create a user").type(User.class)
+                        .param().name("body").type(RestParamType.body).description("The user
to update or create").endParam()
+                        .to("bean:userService?method=updateUser")
+
+                    .get("/findAll").description("Find all users").outTypeList(User.class)
+                        .to("bean:userService?method=listUsers");
+            }
+        };
+    }
+
+    @Test
+    public void testReaderRead() throws Exception {
+        RestDefinition rest = context.getRestDefinitions().get(0);
+        assertNotNull(rest);
+
+        BeanConfig config = new BeanConfig();
+        config.setHost("localhost:8080");
+        config.setSchemes(new String[]{"http"});
+        config.setBasePath("/api");
+        RestSwaggerReader reader = new RestSwaggerReader();
+
+        Swagger swagger = reader.read(rest, config, new DefaultClassResolver());
+        assertNotNull(swagger);
+
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.enable(SerializationFeature.INDENT_OUTPUT);
+        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+        String json = mapper.writeValueAsString(swagger);
+
+        log.info(json);
+
+        assertTrue(json.contains("\"host\" : \"localhost:8080\""));
+        assertTrue(json.contains("\"description\" : \"Output type\""));
+        assertTrue(json.contains("\"$ref\" : \"#/definitions/User\""));
+        assertTrue(json.contains("\"x-className\""));
+        assertTrue(json.contains("\"format\" : \"org.apache.camel.swagger.User\""));
+
+        context.stop();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f298fad1/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderTest.java
----------------------------------------------------------------------
diff --git a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderTest.java
b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderTest.java
index baefb8f..b7c9de3 100644
--- a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderTest.java
+++ b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderTest.java
@@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
 import io.swagger.jaxrs.config.BeanConfig;
 import io.swagger.models.Swagger;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultClassResolver;
 import org.apache.camel.impl.JndiRegistry;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.model.rest.RestParamType;
@@ -68,7 +69,7 @@ public class RestSwaggerReaderTest extends CamelTestSupport {
         config.setBasePath("/api");
         RestSwaggerReader reader = new RestSwaggerReader();
 
-        Swagger swagger = reader.read(rest, config);
+        Swagger swagger = reader.read(rest, config, new DefaultClassResolver());
         assertNotNull(swagger);
 
         ObjectMapper mapper = new ObjectMapper();

http://git-wip-us.apache.org/repos/asf/camel/blob/f298fad1/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/User.java
----------------------------------------------------------------------
diff --git a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/User.java
b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/User.java
new file mode 100644
index 0000000..17c68a0
--- /dev/null
+++ b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/User.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.camel.swagger;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel(description = "Represents an user of the system")
+public class User {
+
+    private int id;
+    private String name;
+
+    public User() {
+    }
+
+    public User(int id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    @ApiModelProperty(value = "The id of the user", required = true)
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    @ApiModelProperty(value = "The name of the user", required = true)
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/f298fad1/examples/camel-example-swagger-java/pom.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-swagger-java/pom.xml b/examples/camel-example-swagger-java/pom.xml
index 1218033..09b0ba7 100755
--- a/examples/camel-example-swagger-java/pom.xml
+++ b/examples/camel-example-swagger-java/pom.xml
@@ -15,195 +15,197 @@
     See the License for the specific language governing permissions and
     limitations under the License.
 -->
-<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>
-
-    <parent>
-        <groupId>org.apache.camel</groupId>
-        <artifactId>examples</artifactId>
-        <version>2.16-SNAPSHOT</version>
-    </parent>
-
-    <artifactId>camel-example-swagger-java</artifactId>
-    <name>Camel :: Example :: Swagger Java</name>
-    <description>An example using REST DSL and Swagger Java with Apache Tomcat</description>
-    <packaging>war</packaging>
-
-    <properties>
-        <swagger-ui.version>2.1.2</swagger-ui.version>
-        <logback-version>1.1.3</logback-version>
-        <swagger.url>https://github.com/swagger-api/swagger-ui/archive</swagger.url>
-        <destDir>target/swagger-ui</destDir>
-    </properties>
-
-    <dependencies>
-
-        <!-- camel -->
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-spring</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-servlet</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-metrics</artifactId>
-        </dependency>
-
-        <!-- swagger api -->
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-swagger-java</artifactId>
-        </dependency>
-
-        <!-- use for json binding -->
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-jackson</artifactId>
-        </dependency>
-
-        <!-- we need spring web -->
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-web</artifactId>
-        </dependency>
-
-        <!-- logging -->
-        <dependency>
-            <groupId>log4j</groupId>
-            <artifactId>log4j</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-log4j12</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-classic</artifactId>
-            <version>${logback-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-core</artifactId>
-            <version>${logback-version}</version>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <!-- we do not want version in the WAR name -->
-        <finalName>${project.artifactId}</finalName>
-
-        <plugins>
-            <!-- Step 1. - Download Swagger UI project from GitHub -->
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>wagon-maven-plugin</artifactId>
-                <version>1.0</version>
-                <executions>
-                    <execution>
-                        <phase>process-resources</phase>
-                        <goals>
-                            <goal>download-single</goal>
-                        </goals>
-                        <configuration>
-                            <url>${swagger.url}</url>
-                            <fromFile>v${swagger-ui.version}.tar.gz</fromFile>
-                            <toFile>${project.build.directory}/swagger-ui-${swagger-ui.version}.tar.gz</toFile>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-
-            <!-- Step 2. -  Decompress content and move it to target/swagger-ui folder
-->
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-antrun-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <phase>process-resources</phase>
-                        <goals>
-                            <goal>run</goal>
-                        </goals>
-                        <configuration>
-                            <target>
-                                <echo message="Decompress archive" />
-                                <gunzip src="${project.build.directory}/swagger-ui-${swagger-ui.version}.tar.gz"
/>
-                                <untar src="${project.build.directory}/swagger-ui-${swagger-ui.version}.tar"
dest="${project.build.directory}" />
-                                <echo message="moving resources" />
-                                <move todir="${destDir}" overwrite="yes">
-                                    <fileset dir="${project.build.directory}/swagger-ui-${swagger-ui.version}/dist"
/>
-                                </move>
-                            </target>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-
-            <!-- Step 3. Copy Web Resources to target/classes but also to target/swagger-ui
-->
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-resources-plugin</artifactId>
-                <executions>
-                    <execution>
-                        <id>copy-resources</id>
-                        <phase>generate-resources</phase>
-                        <goals>
-                            <goal>copy-resources</goal>
-                        </goals>
-                        <configuration>
-                            <outputDirectory>${basedir}/target/classes/</outputDirectory>
-                            <resources>
-                                <resource>
-                                    <directory>src/main/webapp</directory>
-                                    <filtering>false</filtering>
-                                </resource>
-                                <!-- Copy swagger-ui resources to classes directory to
be able to use it with mvn jetty:run -->
-                                <resource>
-                                    <directory>${destDir}</directory>
-                                    <filtering>false</filtering>
-                                </resource>
-                            </resources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-
-            <!-- Step 4. Add Swagger-ui Resources to the WAR -->
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-war-plugin</artifactId>
-                <configuration>
-                    <webResources>
-                        <resource>
-                            <directory>target/swagger-ui/</directory>
-                            <includes>
-                                <include>**/*.*</include>
-                            </includes>
-                        </resource>
-                    </webResources>
-                </configuration>
-            </plugin>
-
-            <!-- allows running this example with mvn:jetty-run -->
-            <plugin>
-                <groupId>org.eclipse.jetty</groupId>
-                <artifactId>jetty-maven-plugin</artifactId>
-                <version>${jetty9-version}</version>
-                <configuration>
-                    <webAppSourceDirectory>target/classes</webAppSourceDirectory>
-                	<webApp>
-                		<contextPath>/${project.artifactId}</contextPath>
-                	</webApp>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
+<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>
+
+  <parent>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>examples</artifactId>
+    <version>2.16-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-example-swagger-java</artifactId>
+  <name>Camel :: Example :: Swagger Java</name>
+  <description>An example using REST DSL and Swagger Java with Apache Tomcat</description>
+  <packaging>war</packaging>
+
+  <properties>
+    <swagger-ui.version>2.1.2</swagger-ui.version>
+    <logback-version>1.1.3</logback-version>
+    <swagger.url>https://github.com/swagger-api/swagger-ui/archive</swagger.url>
+    <destDir>target/swagger-ui</destDir>
+  </properties>
+
+  <dependencies>
+
+    <!-- camel -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-servlet</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-metrics</artifactId>
+    </dependency>
+
+    <!-- swagger api -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-swagger-java</artifactId>
+    </dependency>
+
+    <!-- use for json binding -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-jackson</artifactId>
+    </dependency>
+
+    <!-- we need spring web -->
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-web</artifactId>
+    </dependency>
+
+    <!-- logging -->
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>ch.qos.logback</groupId>
+      <artifactId>logback-classic</artifactId>
+      <version>${logback-version}</version>
+    </dependency>
+    <dependency>
+      <groupId>ch.qos.logback</groupId>
+      <artifactId>logback-core</artifactId>
+      <version>${logback-version}</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <!-- we do not want version in the WAR name -->
+    <finalName>${project.artifactId}</finalName>
+
+    <plugins>
+      <!-- Step 1. - Download Swagger UI project from GitHub -->
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>wagon-maven-plugin</artifactId>
+        <version>1.0</version>
+        <executions>
+          <execution>
+            <phase>process-resources</phase>
+            <goals>
+              <goal>download-single</goal>
+            </goals>
+            <configuration>
+              <url>${swagger.url}</url>
+              <fromFile>v${swagger-ui.version}.tar.gz</fromFile>
+              <toFile>${project.build.directory}/swagger-ui-${swagger-ui.version}.tar.gz</toFile>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+      <!-- Step 2. -  Decompress content and move it to target/swagger-ui folder -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>process-resources</phase>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <configuration>
+              <target>
+                <echo message="Decompress archive"/>
+                <gunzip src="${project.build.directory}/swagger-ui-${swagger-ui.version}.tar.gz"/>
+                <untar src="${project.build.directory}/swagger-ui-${swagger-ui.version}.tar"
+                       dest="${project.build.directory}"/>
+                <echo message="moving resources"/>
+                <move todir="${destDir}" overwrite="yes">
+                  <fileset dir="${project.build.directory}/swagger-ui-${swagger-ui.version}/dist"/>
+                </move>
+              </target>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+      <!-- Step 3. Copy Web Resources to target/classes but also to target/swagger-ui
-->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>copy-resources</id>
+            <phase>generate-resources</phase>
+            <goals>
+              <goal>copy-resources</goal>
+            </goals>
+            <configuration>
+              <outputDirectory>${basedir}/target/classes/</outputDirectory>
+              <resources>
+                <resource>
+                  <directory>src/main/webapp</directory>
+                  <filtering>false</filtering>
+                </resource>
+                <!-- Copy swagger-ui resources to classes directory to be able to use
it with mvn jetty:run -->
+                <resource>
+                  <directory>${destDir}</directory>
+                  <filtering>false</filtering>
+                </resource>
+              </resources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+      <!-- Step 4. Add Swagger-ui Resources to the WAR -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-war-plugin</artifactId>
+        <configuration>
+          <webResources>
+            <resource>
+              <directory>target/swagger-ui/</directory>
+              <includes>
+                <include>**/*.*</include>
+              </includes>
+            </resource>
+          </webResources>
+        </configuration>
+      </plugin>
+
+      <!-- allows running this example with mvn:jetty-run -->
+      <plugin>
+        <groupId>org.eclipse.jetty</groupId>
+        <artifactId>jetty-maven-plugin</artifactId>
+        <version>${jetty9-version}</version>
+        <configuration>
+          <webAppSourceDirectory>target/classes</webAppSourceDirectory>
+          <webApp>
+            <contextPath>/${project.artifactId}</contextPath>
+          </webApp>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
 
 </project>

http://git-wip-us.apache.org/repos/asf/camel/blob/f298fad1/examples/camel-example-swagger-java/src/main/java/org/apache/camel/example/rest/User.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-swagger-java/src/main/java/org/apache/camel/example/rest/User.java
b/examples/camel-example-swagger-java/src/main/java/org/apache/camel/example/rest/User.java
index a1c6b87..09c0391 100644
--- a/examples/camel-example-swagger-java/src/main/java/org/apache/camel/example/rest/User.java
+++ b/examples/camel-example-swagger-java/src/main/java/org/apache/camel/example/rest/User.java
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.example.rest;
 
-
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/f298fad1/examples/camel-example-swagger-java/src/main/resources/camel-config-xml.xml
----------------------------------------------------------------------
diff --git a/examples/camel-example-swagger-java/src/main/resources/camel-config-xml.xml b/examples/camel-example-swagger-java/src/main/resources/camel-config-xml.xml
index cd6fdf0..8ec9b0b 100755
--- a/examples/camel-example-swagger-java/src/main/resources/camel-config-xml.xml
+++ b/examples/camel-example-swagger-java/src/main/resources/camel-config-xml.xml
@@ -49,7 +49,7 @@
       <!-- this is a rest GET to view an user by the given id -->
       <get uri="/{id}" outType="org.apache.camel.example.rest.User">
         <description>Find user by id</description>
-        <param name="id" type="path" description="The id of the user to get" dataType="int"/>
+        <param name="id" type="path" description="The id of the user to get" dataType="integer"/>
         <to uri="bean:userService?method=getUser(${header.id})"/>
       </get>
 


Mime
View raw message