camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [01/11] camel git commit: Fixed CS. Break up to smaller methods.
Date Fri, 04 Mar 2016 14:00:34 GMT
Repository: camel
Updated Branches:
  refs/heads/master ab7d838b4 -> af8c3283a


Fixed CS. Break up to smaller methods.


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

Branch: refs/heads/master
Commit: b8e2604d92c9ef7454a67452a4154791433762a6
Parents: ab7d838
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Mar 4 13:51:57 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Mar 4 13:51:57 2016 +0100

----------------------------------------------------------------------
 .../apache/camel/swagger/RestSwaggerReader.java | 230 ++++++++++---------
 1 file changed, 119 insertions(+), 111 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b8e2604d/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 bc01e37..e3e65ef 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
@@ -151,6 +151,10 @@ public class RestSwaggerReader {
             appendModels(clazz, swagger);
         }
 
+        doParseVerbs(swagger, rest, camelContextId, verbs, pathAsTag);
+    }
+
+    private void doParseVerbs(Swagger swagger, RestDefinition rest, String camelContextId,
List<VerbDefinition> verbs, String pathAsTag) {
         // used during gathering of apis
         List<Path> paths = new ArrayList<>();
 
@@ -291,128 +295,132 @@ public class RestSwaggerReader {
             }
 
             // enrich with configured response messages from the rest-dsl
-            for (RestOperationResponseMsgDefinition msg : verb.getResponseMsgs()) {
-                Response response = null;
-                if (op.getResponses() != null) {
-                    response = op.getResponses().get(msg.getCode());
-                }
-                if (response == null) {
-                    response = new Response();
-                }
-                if (ObjectHelper.isNotEmpty(msg.getResponseModel())) {
-                    Property prop = modelTypeAsProperty(msg.getResponseModel(), swagger);
-                    response.setSchema(prop);
-                }
-                response.setDescription(msg.getMessage());
-
-                // add headers
-                if (msg.getHeaders() != null) {
-                    for (RestOperationResponseHeaderDefinition header : msg.getHeaders())
{
-                        String name = header.getName();
-                        String type = header.getDataType();
-                        if ("string".equals(type)) {
-                            StringProperty sp = new StringProperty();
-                            sp.setName(name);
-                            sp.setDescription(header.getDescription());
-                            if (header.getAllowableValues() != null) {
-                                sp.setEnum(header.getAllowableValues());
+            doParseResponseMessages(swagger, verb, op);
+
+            // add path
+            swagger.path(opPath, path);
+        }
+    }
+
+    private void doParseResponseMessages(Swagger swagger, VerbDefinition verb, Operation
op) {
+        for (RestOperationResponseMsgDefinition msg : verb.getResponseMsgs()) {
+            Response response = null;
+            if (op.getResponses() != null) {
+                response = op.getResponses().get(msg.getCode());
+            }
+            if (response == null) {
+                response = new Response();
+            }
+            if (ObjectHelper.isNotEmpty(msg.getResponseModel())) {
+                Property prop = modelTypeAsProperty(msg.getResponseModel(), swagger);
+                response.setSchema(prop);
+            }
+            response.setDescription(msg.getMessage());
+
+            // add headers
+            if (msg.getHeaders() != null) {
+                for (RestOperationResponseHeaderDefinition header : msg.getHeaders()) {
+                    String name = header.getName();
+                    String type = header.getDataType();
+                    if ("string".equals(type)) {
+                        StringProperty sp = new StringProperty();
+                        sp.setName(name);
+                        sp.setDescription(header.getDescription());
+                        if (header.getAllowableValues() != null) {
+                            sp.setEnum(header.getAllowableValues());
+                        }
+                        response.addHeader(name, sp);
+                    } else if ("int".equals(type) || "integer".equals(type)) {
+                        IntegerProperty ip = new IntegerProperty();
+                        ip.setName(name);
+                        ip.setDescription(header.getDescription());
+
+                        List<Integer> values;
+                        if (!header.getAllowableValues().isEmpty()) {
+                            values = new ArrayList<Integer>();
+                            for (String text : header.getAllowableValues()) {
+                                values.add(Integer.valueOf(text));
                             }
-                            response.addHeader(name, sp);
-                        } else if ("int".equals(type) || "integer".equals(type)) {
-                            IntegerProperty ip = new IntegerProperty();
-                            ip.setName(name);
-                            ip.setDescription(header.getDescription());
-
-                            List<Integer> values;
-                            if (!header.getAllowableValues().isEmpty()) {
-                                values = new ArrayList<Integer>();
-                                for (String text : header.getAllowableValues()) {
-                                    values.add(Integer.valueOf(text));
-                                }
-                                ip.setEnum(values);
+                            ip.setEnum(values);
+                        }
+                        response.addHeader(name, ip);
+                    } else if ("long".equals(type)) {
+                        LongProperty lp = new LongProperty();
+                        lp.setName(name);
+                        lp.setDescription(header.getDescription());
+
+                        List<Long> values;
+                        if (!header.getAllowableValues().isEmpty()) {
+                            values = new ArrayList<Long>();
+                            for (String text : header.getAllowableValues()) {
+                                values.add(Long.valueOf(text));
                             }
-                            response.addHeader(name, ip);
-                        } else if ("long".equals(type)) {
-                            LongProperty lp = new LongProperty();
-                            lp.setName(name);
-                            lp.setDescription(header.getDescription());
-
-                            List<Long> values;
-                            if (!header.getAllowableValues().isEmpty()) {
-                                values = new ArrayList<Long>();
-                                for (String text : header.getAllowableValues()) {
-                                    values.add(Long.valueOf(text));
-                                }
-                                lp.setEnum(values);
+                            lp.setEnum(values);
+                        }
+                        response.addHeader(name, lp);
+                    } else if ("float".equals(type)) {
+                        FloatProperty lp = new FloatProperty();
+                        lp.setName(name);
+                        lp.setDescription(header.getDescription());
+
+                        List<Float> values;
+                        if (!header.getAllowableValues().isEmpty()) {
+                            values = new ArrayList<Float>();
+                            for (String text : header.getAllowableValues()) {
+                                values.add(Float.valueOf(text));
                             }
-                            response.addHeader(name, lp);
-                        } else if ("float".equals(type)) {
-                            FloatProperty lp = new FloatProperty();
-                            lp.setName(name);
-                            lp.setDescription(header.getDescription());
-
-                            List<Float> values;
-                            if (!header.getAllowableValues().isEmpty()) {
-                                values = new ArrayList<Float>();
-                                for (String text : header.getAllowableValues()) {
-                                    values.add(Float.valueOf(text));
-                                }
-                                lp.setEnum(values);
+                            lp.setEnum(values);
+                        }
+                        response.addHeader(name, lp);
+                    } else if ("double".equals(type)) {
+                        DoubleProperty dp = new DoubleProperty();
+                        dp.setName(name);
+                        dp.setDescription(header.getDescription());
+
+                        List<Double> values;
+                        if (!header.getAllowableValues().isEmpty()) {
+                            values = new ArrayList<Double>();
+                            for (String text : header.getAllowableValues()) {
+                                values.add(Double.valueOf(text));
                             }
-                            response.addHeader(name, lp);
-                        } else if ("double".equals(type)) {
-                            DoubleProperty dp = new DoubleProperty();
-                            dp.setName(name);
-                            dp.setDescription(header.getDescription());
-
-                            List<Double> values;
-                            if (!header.getAllowableValues().isEmpty()) {
-                                values = new ArrayList<Double>();
-                                for (String text : header.getAllowableValues()) {
-                                    values.add(Double.valueOf(text));
-                                }
-                                dp.setEnum(values);
+                            dp.setEnum(values);
+                        }
+                        response.addHeader(name, dp);
+                    } else if ("boolean".equals(type)) {
+                        BooleanProperty bp = new BooleanProperty();
+                        bp.setName(name);
+                        bp.setDescription(header.getDescription());
+                        response.addHeader(name, bp);
+                    } else if ("array".equals(type)) {
+                        ArrayProperty ap = new ArrayProperty();
+                        ap.setName(name);
+                        ap.setDescription(header.getDescription());
+                        if (header.getArrayType() != null) {
+                            if (header.getArrayType().equalsIgnoreCase("string")) {
+                                ap.setItems(new StringProperty());
                             }
-                            response.addHeader(name, dp);
-                        } else if ("boolean".equals(type)) {
-                            BooleanProperty bp = new BooleanProperty();
-                            bp.setName(name);
-                            bp.setDescription(header.getDescription());
-                            response.addHeader(name, bp);
-                        } else if ("array".equals(type)) {
-                            ArrayProperty ap = new ArrayProperty();
-                            ap.setName(name);
-                            ap.setDescription(header.getDescription());
-                            if (header.getArrayType() != null) {
-                                if (header.getArrayType().equalsIgnoreCase("string")) {
-                                    ap.setItems(new StringProperty());
-                                }
-                                if (header.getArrayType().equalsIgnoreCase("int") || header.getArrayType().equalsIgnoreCase("integer"))
{
-                                    ap.setItems(new IntegerProperty());
-                                }
-                                if (header.getArrayType().equalsIgnoreCase("long")) {
-                                    ap.setItems(new LongProperty());
-                                }
-                                if (header.getArrayType().equalsIgnoreCase("float")) {
-                                    ap.setItems(new FloatProperty());
-                                }
-                                if (header.getArrayType().equalsIgnoreCase("double")) {
-                                    ap.setItems(new DoubleProperty());
-                                }
-                                if (header.getArrayType().equalsIgnoreCase("boolean")) {
-                                    ap.setItems(new BooleanProperty());
-                                }
+                            if (header.getArrayType().equalsIgnoreCase("int") || header.getArrayType().equalsIgnoreCase("integer"))
{
+                                ap.setItems(new IntegerProperty());
+                            }
+                            if (header.getArrayType().equalsIgnoreCase("long")) {
+                                ap.setItems(new LongProperty());
+                            }
+                            if (header.getArrayType().equalsIgnoreCase("float")) {
+                                ap.setItems(new FloatProperty());
+                            }
+                            if (header.getArrayType().equalsIgnoreCase("double")) {
+                                ap.setItems(new DoubleProperty());
+                            }
+                            if (header.getArrayType().equalsIgnoreCase("boolean")) {
+                                ap.setItems(new BooleanProperty());
                             }
-                            response.addHeader(name, ap);
                         }
+                        response.addHeader(name, ap);
                     }
                 }
-
-                op.addResponse(msg.getCode(), response);
             }
 
-            // add path
-            swagger.path(opPath, path);
+            op.addResponse(msg.getCode(), response);
         }
     }
 


Mime
View raw message