From 73bf589ad0e1e1f0219299316d6795d66723a4f2 Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 9 Dec 2016 15:18:55 +0800 Subject: [PATCH 1/2] add swagger codegen evangelist --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 7e3cd797b9..95e0bb1e6d 100644 --- a/README.md +++ b/README.md @@ -941,6 +941,12 @@ Swagger Codegen Evangelist shoulders one or more of the following responsibiliti If you want to be a Swagger Codegen Evangelist, please kindly apply by sending an email to wing328hk@gmail.com (@wing328) +### List of Swagger Codegen Evangelists + +- Cliffano Subagio (@cliffano from Australia joined on Dec 9, 2016) + - [Building An AEM API Clients Ecosystem](http://www.slideshare.net/cliffano/building-an-aem-api-clients-ecosystem) + - [Adobe Marketing Cloud Community Expo](http://blog.cliffano.com/2016/11/10/adobe-marketing-cloud-community-expo/) + # License information on Generated Code The Swagger Codegen project is intended as a benefit for users of the Swagger / Open API Specification. The project itself has the [License](#license) as specified. In addition, please understand the following points: From c3571b28a5be8baa1a37c6df434c931493b7b206 Mon Sep 17 00:00:00 2001 From: Jens Oberender Date: Fri, 9 Dec 2016 08:55:33 +0100 Subject: [PATCH 2/2] Some code cleanings of problems reported by SonarQube. (#4324) * Some code cleanings of problems reported by SonarQube. * Updated changes to the petshop sample. --- .../main/resources/Java/ApiClient.mustache | 16 ++++---- .../Java/libraries/jersey2/ApiClient.mustache | 41 ++++++++++--------- samples/client/petstore/java/feign/hello.txt | 1 - .../java/io/swagger/client/ApiClient.java | 16 ++++---- .../java/io/swagger/client/ApiClient.java | 41 ++++++++++--------- .../client/petstore/java/jersey2/hello.txt | 1 - .../java/io/swagger/client/ApiClient.java | 41 ++++++++++--------- .../client/petstore/java/retrofit/hello.txt | 1 - 8 files changed, 79 insertions(+), 79 deletions(-) delete mode 100644 samples/client/petstore/java/feign/hello.txt delete mode 100644 samples/client/petstore/java/jersey2/hello.txt delete mode 100644 samples/client/petstore/java/retrofit/hello.txt diff --git a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache index c34dd51dce..25aa9099ef 100644 --- a/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/ApiClient.mustache @@ -353,7 +353,7 @@ public class ApiClient { StringBuilder b = new StringBuilder(); for(Object o : (Collection)param) { if(b.length() > 0) { - b.append(","); + b.append(','); } b.append(String.valueOf(o)); } @@ -372,7 +372,7 @@ public class ApiClient { // preconditions if (name == null || name.isEmpty() || value == null) return params; - Collection valueCollection = null; + Collection valueCollection; if (value instanceof Collection) { valueCollection = (Collection) value; } else { @@ -385,10 +385,10 @@ public class ApiClient { } // get the collection format - collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv + String format = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv // create the params based on the collection format - if (collectionFormat.equals("multi")) { + if ("multi".equals(format)) { for (Object item : valueCollection) { params.add(new Pair(name, parameterToString(item))); } @@ -398,13 +398,13 @@ public class ApiClient { String delimiter = ","; - if (collectionFormat.equals("csv")) { + if ("csv".equals(format)) { delimiter = ","; - } else if (collectionFormat.equals("ssv")) { + } else if ("ssv".equals(format)) { delimiter = " "; - } else if (collectionFormat.equals("tsv")) { + } else if ("tsv".equals(format)) { delimiter = "\t"; - } else if (collectionFormat.equals("pipes")) { + } else if ("pipes".equals(format)) { delimiter = "|"; } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index 668b34a90a..b81cd18d37 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -329,7 +329,7 @@ public class ApiClient { StringBuilder b = new StringBuilder(); for(Object o : (Collection)param) { if(b.length() > 0) { - b.append(","); + b.append(','); } b.append(String.valueOf(o)); } @@ -348,7 +348,7 @@ public class ApiClient { // preconditions if (name == null || name.isEmpty() || value == null) return params; - Collection valueCollection = null; + Collection valueCollection; if (value instanceof Collection) { valueCollection = (Collection) value; } else { @@ -361,10 +361,10 @@ public class ApiClient { } // get the collection format - collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv + String format = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv // create the params based on the collection format - if (collectionFormat.equals("multi")) { + if ("multi".equals(format)) { for (Object item : valueCollection) { params.add(new Pair(name, parameterToString(item))); } @@ -374,13 +374,13 @@ public class ApiClient { String delimiter = ","; - if (collectionFormat.equals("csv")) { + if ("csv".equals(format)) { delimiter = ","; - } else if (collectionFormat.equals("ssv")) { + } else if ("ssv".equals(format)) { delimiter = " "; - } else if (collectionFormat.equals("tsv")) { + } else if ("tsv".equals(format)) { delimiter = "\t"; - } else if (collectionFormat.equals("pipes")) { + } else if ("pipes".equals(format)) { delimiter = "|"; } @@ -464,7 +464,7 @@ public class ApiClient { * Content-Type (only JSON is supported for now). */ public Entity serialize(Object obj, Map formParams, String contentType) throws ApiException { - Entity entity = null; + Entity entity; if (contentType.startsWith("multipart/form-data")) { MultiPart multiPart = new MultiPart(); for (Entry param: formParams.entrySet()) { @@ -495,6 +495,7 @@ public class ApiClient { /** * Deserialize response body to Java object according to the Content-Type. */ + @SuppressWarnings("unchecked") public T deserialize(Response response, GenericType returnType) throws ApiException { if (response == null || returnType == null) { return null; @@ -503,9 +504,8 @@ public class ApiClient { if ("byte[]".equals(returnType.toString())) { // Handle binary response (byte array). return (T) response.readEntity(byte[].class); - } else if (returnType.equals(File.class)) { + } else if (returnType.getRawType() == File.class) { // Handle file downloading. - @SuppressWarnings("unchecked") T file = (T) downloadFileFromResponse(response); return file; } @@ -551,13 +551,13 @@ public class ApiClient { filename = matcher.group(1); } - String prefix = null; + String prefix; String suffix = null; if (filename == null) { prefix = "download-"; suffix = ""; } else { - int pos = filename.lastIndexOf("."); + int pos = filename.lastIndexOf('.'); if (pos == -1) { prefix = filename + "-"; } else { @@ -607,16 +607,17 @@ public class ApiClient { Invocation.Builder invocationBuilder = target.request().accept(accept); - for (String key : headerParams.keySet()) { - String value = headerParams.get(key); + for (Entry entry : headerParams.entrySet()) { + String value = entry.getValue(); if (value != null) { - invocationBuilder = invocationBuilder.header(key, value); + invocationBuilder = invocationBuilder.header(entry.getKey(), value); } } - for (String key : defaultHeaderMap.keySet()) { + for (Entry entry : defaultHeaderMap.entrySet()) { + String key = entry.getKey(); if (!headerParams.containsKey(key)) { - String value = defaultHeaderMap.get(key); + String value = entry.getValue(); if (value != null) { invocationBuilder = invocationBuilder.header(key, value); } @@ -625,7 +626,7 @@ public class ApiClient { Entity entity = serialize(body, formParams, contentType); - Response response = null; + Response response; if ("GET".equals(method)) { response = invocationBuilder.get(); @@ -646,7 +647,7 @@ public class ApiClient { if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) { return null; - } else if (response.getStatusInfo().getFamily().equals(Status.Family.SUCCESSFUL)) { + } else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) { if (returnType == null) return null; else diff --git a/samples/client/petstore/java/feign/hello.txt b/samples/client/petstore/java/feign/hello.txt deleted file mode 100644 index 6769dd60bd..0000000000 --- a/samples/client/petstore/java/feign/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello world! \ No newline at end of file diff --git a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java index 841ae1112e..36792292bd 100644 --- a/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey1/src/main/java/io/swagger/client/ApiClient.java @@ -354,7 +354,7 @@ public class ApiClient { StringBuilder b = new StringBuilder(); for(Object o : (Collection)param) { if(b.length() > 0) { - b.append(","); + b.append(','); } b.append(String.valueOf(o)); } @@ -373,7 +373,7 @@ public class ApiClient { // preconditions if (name == null || name.isEmpty() || value == null) return params; - Collection valueCollection = null; + Collection valueCollection; if (value instanceof Collection) { valueCollection = (Collection) value; } else { @@ -386,10 +386,10 @@ public class ApiClient { } // get the collection format - collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv + String format = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv // create the params based on the collection format - if (collectionFormat.equals("multi")) { + if ("multi".equals(format)) { for (Object item : valueCollection) { params.add(new Pair(name, parameterToString(item))); } @@ -399,13 +399,13 @@ public class ApiClient { String delimiter = ","; - if (collectionFormat.equals("csv")) { + if ("csv".equals(format)) { delimiter = ","; - } else if (collectionFormat.equals("ssv")) { + } else if ("ssv".equals(format)) { delimiter = " "; - } else if (collectionFormat.equals("tsv")) { + } else if ("tsv".equals(format)) { delimiter = "\t"; - } else if (collectionFormat.equals("pipes")) { + } else if ("pipes".equals(format)) { delimiter = "|"; } diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java index 5eb7e89e13..adec2801d0 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java @@ -324,7 +324,7 @@ public class ApiClient { StringBuilder b = new StringBuilder(); for(Object o : (Collection)param) { if(b.length() > 0) { - b.append(","); + b.append(','); } b.append(String.valueOf(o)); } @@ -343,7 +343,7 @@ public class ApiClient { // preconditions if (name == null || name.isEmpty() || value == null) return params; - Collection valueCollection = null; + Collection valueCollection; if (value instanceof Collection) { valueCollection = (Collection) value; } else { @@ -356,10 +356,10 @@ public class ApiClient { } // get the collection format - collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv + String format = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv // create the params based on the collection format - if (collectionFormat.equals("multi")) { + if ("multi".equals(format)) { for (Object item : valueCollection) { params.add(new Pair(name, parameterToString(item))); } @@ -369,13 +369,13 @@ public class ApiClient { String delimiter = ","; - if (collectionFormat.equals("csv")) { + if ("csv".equals(format)) { delimiter = ","; - } else if (collectionFormat.equals("ssv")) { + } else if ("ssv".equals(format)) { delimiter = " "; - } else if (collectionFormat.equals("tsv")) { + } else if ("tsv".equals(format)) { delimiter = "\t"; - } else if (collectionFormat.equals("pipes")) { + } else if ("pipes".equals(format)) { delimiter = "|"; } @@ -459,7 +459,7 @@ public class ApiClient { * Content-Type (only JSON is supported for now). */ public Entity serialize(Object obj, Map formParams, String contentType) throws ApiException { - Entity entity = null; + Entity entity; if (contentType.startsWith("multipart/form-data")) { MultiPart multiPart = new MultiPart(); for (Entry param: formParams.entrySet()) { @@ -490,6 +490,7 @@ public class ApiClient { /** * Deserialize response body to Java object according to the Content-Type. */ + @SuppressWarnings("unchecked") public T deserialize(Response response, GenericType returnType) throws ApiException { if (response == null || returnType == null) { return null; @@ -498,9 +499,8 @@ public class ApiClient { if ("byte[]".equals(returnType.toString())) { // Handle binary response (byte array). return (T) response.readEntity(byte[].class); - } else if (returnType.equals(File.class)) { + } else if (returnType.getRawType() == File.class) { // Handle file downloading. - @SuppressWarnings("unchecked") T file = (T) downloadFileFromResponse(response); return file; } @@ -540,13 +540,13 @@ public class ApiClient { filename = matcher.group(1); } - String prefix = null; + String prefix; String suffix = null; if (filename == null) { prefix = "download-"; suffix = ""; } else { - int pos = filename.lastIndexOf("."); + int pos = filename.lastIndexOf('.'); if (pos == -1) { prefix = filename + "-"; } else { @@ -596,16 +596,17 @@ public class ApiClient { Invocation.Builder invocationBuilder = target.request().accept(accept); - for (String key : headerParams.keySet()) { - String value = headerParams.get(key); + for (Entry entry : headerParams.entrySet()) { + String value = entry.getValue(); if (value != null) { - invocationBuilder = invocationBuilder.header(key, value); + invocationBuilder = invocationBuilder.header(entry.getKey(), value); } } - for (String key : defaultHeaderMap.keySet()) { + for (Entry entry : defaultHeaderMap.entrySet()) { + String key = entry.getKey(); if (!headerParams.containsKey(key)) { - String value = defaultHeaderMap.get(key); + String value = entry.getValue(); if (value != null) { invocationBuilder = invocationBuilder.header(key, value); } @@ -614,7 +615,7 @@ public class ApiClient { Entity entity = serialize(body, formParams, contentType); - Response response = null; + Response response; if ("GET".equals(method)) { response = invocationBuilder.get(); @@ -635,7 +636,7 @@ public class ApiClient { if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) { return null; - } else if (response.getStatusInfo().getFamily().equals(Status.Family.SUCCESSFUL)) { + } else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) { if (returnType == null) return null; else diff --git a/samples/client/petstore/java/jersey2/hello.txt b/samples/client/petstore/java/jersey2/hello.txt deleted file mode 100644 index 6769dd60bd..0000000000 --- a/samples/client/petstore/java/jersey2/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello world! \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java index 5eb7e89e13..adec2801d0 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java @@ -324,7 +324,7 @@ public class ApiClient { StringBuilder b = new StringBuilder(); for(Object o : (Collection)param) { if(b.length() > 0) { - b.append(","); + b.append(','); } b.append(String.valueOf(o)); } @@ -343,7 +343,7 @@ public class ApiClient { // preconditions if (name == null || name.isEmpty() || value == null) return params; - Collection valueCollection = null; + Collection valueCollection; if (value instanceof Collection) { valueCollection = (Collection) value; } else { @@ -356,10 +356,10 @@ public class ApiClient { } // get the collection format - collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv + String format = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv // create the params based on the collection format - if (collectionFormat.equals("multi")) { + if ("multi".equals(format)) { for (Object item : valueCollection) { params.add(new Pair(name, parameterToString(item))); } @@ -369,13 +369,13 @@ public class ApiClient { String delimiter = ","; - if (collectionFormat.equals("csv")) { + if ("csv".equals(format)) { delimiter = ","; - } else if (collectionFormat.equals("ssv")) { + } else if ("ssv".equals(format)) { delimiter = " "; - } else if (collectionFormat.equals("tsv")) { + } else if ("tsv".equals(format)) { delimiter = "\t"; - } else if (collectionFormat.equals("pipes")) { + } else if ("pipes".equals(format)) { delimiter = "|"; } @@ -459,7 +459,7 @@ public class ApiClient { * Content-Type (only JSON is supported for now). */ public Entity serialize(Object obj, Map formParams, String contentType) throws ApiException { - Entity entity = null; + Entity entity; if (contentType.startsWith("multipart/form-data")) { MultiPart multiPart = new MultiPart(); for (Entry param: formParams.entrySet()) { @@ -490,6 +490,7 @@ public class ApiClient { /** * Deserialize response body to Java object according to the Content-Type. */ + @SuppressWarnings("unchecked") public T deserialize(Response response, GenericType returnType) throws ApiException { if (response == null || returnType == null) { return null; @@ -498,9 +499,8 @@ public class ApiClient { if ("byte[]".equals(returnType.toString())) { // Handle binary response (byte array). return (T) response.readEntity(byte[].class); - } else if (returnType.equals(File.class)) { + } else if (returnType.getRawType() == File.class) { // Handle file downloading. - @SuppressWarnings("unchecked") T file = (T) downloadFileFromResponse(response); return file; } @@ -540,13 +540,13 @@ public class ApiClient { filename = matcher.group(1); } - String prefix = null; + String prefix; String suffix = null; if (filename == null) { prefix = "download-"; suffix = ""; } else { - int pos = filename.lastIndexOf("."); + int pos = filename.lastIndexOf('.'); if (pos == -1) { prefix = filename + "-"; } else { @@ -596,16 +596,17 @@ public class ApiClient { Invocation.Builder invocationBuilder = target.request().accept(accept); - for (String key : headerParams.keySet()) { - String value = headerParams.get(key); + for (Entry entry : headerParams.entrySet()) { + String value = entry.getValue(); if (value != null) { - invocationBuilder = invocationBuilder.header(key, value); + invocationBuilder = invocationBuilder.header(entry.getKey(), value); } } - for (String key : defaultHeaderMap.keySet()) { + for (Entry entry : defaultHeaderMap.entrySet()) { + String key = entry.getKey(); if (!headerParams.containsKey(key)) { - String value = defaultHeaderMap.get(key); + String value = entry.getValue(); if (value != null) { invocationBuilder = invocationBuilder.header(key, value); } @@ -614,7 +615,7 @@ public class ApiClient { Entity entity = serialize(body, formParams, contentType); - Response response = null; + Response response; if ("GET".equals(method)) { response = invocationBuilder.get(); @@ -635,7 +636,7 @@ public class ApiClient { if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) { return null; - } else if (response.getStatusInfo().getFamily().equals(Status.Family.SUCCESSFUL)) { + } else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) { if (returnType == null) return null; else diff --git a/samples/client/petstore/java/retrofit/hello.txt b/samples/client/petstore/java/retrofit/hello.txt deleted file mode 100644 index 6769dd60bd..0000000000 --- a/samples/client/petstore/java/retrofit/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello world! \ No newline at end of file