From 18b500218a1a989c53cf14a1acf634ad56b27fb6 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sun, 31 Mar 2019 16:15:09 +0800 Subject: [PATCH] [JS] fix NPE for null string and improve Travis config file (#2553) * fix NPE with null string * update travis for nodejs * update js samples --- .../languages/JavascriptClientCodegen.java | 22 ++++++++----------- .../main/resources/Javascript/es6/travis.yml | 4 +--- .../src/main/resources/Javascript/travis.yml | 4 +--- .../petstore/javascript-es6/.travis.yml | 4 +--- .../javascript-promise-es6/.travis.yml | 4 +--- .../petstore/javascript-promise/.travis.yml | 4 +--- .../client/petstore/javascript/.travis.yml | 4 +--- 7 files changed, 15 insertions(+), 31 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java index b985bed98c..23404c7814 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java @@ -205,7 +205,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo @Override public String getHelp() { - return "Generates a Javascript client library."; + return "Generates a JavaScript client library."; } @Override @@ -340,6 +340,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo supportingFiles.add(new SupportingFile("index.mustache", createPath(sourceFolder, invokerPackage), "index.js")); supportingFiles.add(new SupportingFile("ApiClient.mustache", createPath(sourceFolder, invokerPackage), "ApiClient.js")); + } @Override @@ -980,7 +981,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo if (hasOptionalParams) { argList.add("opts"); - } + } if (!usePromises) { argList.add("callback"); @@ -1124,17 +1125,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo return codegenModel; } - /* - private static String sanitizePackageName(String packageName) { // FIXME parameter should not be assigned. Also declare it as "final" - packageName = packageName.trim(); - packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_"); - if (Strings.isNullOrEmpty(packageName)) { - return "invalidPackageName"; - } - return packageName; - } - */ - @Override public String toEnumName(CodegenProperty property) { return sanitizeName(camelize(property.name)) + "Enum"; @@ -1166,12 +1156,18 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo @Override public String escapeQuotationMark(String input) { + if (input == null) { + return ""; + } // remove ', " to avoid code injection return input.replace("\"", "").replace("'", ""); } @Override public String escapeUnsafeCharacters(String input) { + if (input == null) { + return ""; + } return input.replace("*/", "*_/").replace("/*", "/_*"); } diff --git a/modules/openapi-generator/src/main/resources/Javascript/es6/travis.yml b/modules/openapi-generator/src/main/resources/Javascript/es6/travis.yml index e49f4692f7..0968f7a433 100644 --- a/modules/openapi-generator/src/main/resources/Javascript/es6/travis.yml +++ b/modules/openapi-generator/src/main/resources/Javascript/es6/travis.yml @@ -1,7 +1,5 @@ language: node_js +cache: npm node_js: - "6" - "6.1" - - "5" - - "5.11" - diff --git a/modules/openapi-generator/src/main/resources/Javascript/travis.yml b/modules/openapi-generator/src/main/resources/Javascript/travis.yml index e49f4692f7..1b1103e7bd 100644 --- a/modules/openapi-generator/src/main/resources/Javascript/travis.yml +++ b/modules/openapi-generator/src/main/resources/Javascript/travis.yml @@ -1,7 +1,5 @@ language: node_js +cache: npm node_js: - - "6" - - "6.1" - "5" - "5.11" - diff --git a/samples/client/petstore/javascript-es6/.travis.yml b/samples/client/petstore/javascript-es6/.travis.yml index e49f4692f7..0968f7a433 100644 --- a/samples/client/petstore/javascript-es6/.travis.yml +++ b/samples/client/petstore/javascript-es6/.travis.yml @@ -1,7 +1,5 @@ language: node_js +cache: npm node_js: - "6" - "6.1" - - "5" - - "5.11" - diff --git a/samples/client/petstore/javascript-promise-es6/.travis.yml b/samples/client/petstore/javascript-promise-es6/.travis.yml index e49f4692f7..0968f7a433 100644 --- a/samples/client/petstore/javascript-promise-es6/.travis.yml +++ b/samples/client/petstore/javascript-promise-es6/.travis.yml @@ -1,7 +1,5 @@ language: node_js +cache: npm node_js: - "6" - "6.1" - - "5" - - "5.11" - diff --git a/samples/client/petstore/javascript-promise/.travis.yml b/samples/client/petstore/javascript-promise/.travis.yml index e49f4692f7..1b1103e7bd 100644 --- a/samples/client/petstore/javascript-promise/.travis.yml +++ b/samples/client/petstore/javascript-promise/.travis.yml @@ -1,7 +1,5 @@ language: node_js +cache: npm node_js: - - "6" - - "6.1" - "5" - "5.11" - diff --git a/samples/client/petstore/javascript/.travis.yml b/samples/client/petstore/javascript/.travis.yml index e49f4692f7..1b1103e7bd 100644 --- a/samples/client/petstore/javascript/.travis.yml +++ b/samples/client/petstore/javascript/.travis.yml @@ -1,7 +1,5 @@ language: node_js +cache: npm node_js: - - "6" - - "6.1" - "5" - "5.11" -