forked from loafle/openapi-generator-original
Gh-4044: Enabling ES6 in javascript client (#5593)
* gh-4044: Added useES6 as an option for javascript templates * gh-4044: Enabled ES6 in `javascript/api.mustache` * gh-4044: Enabled ES6 in `javascript/ApiClient.mustache` * gh-4044: Enabled ES6 in `javascript/enumClass.mustache` * gh-4044: Added useES6 cli option to `javascript` clients and updated the test cases * gh-4044: Enabled ES6 in `javascript/index.mustache` * gh-4044: Enabled ES6 in `javascript` model templates * `javascript/model.mustache` * `javascript/partial_model_generic.mustache` * `javascript/partial_model_enum_class.mustache` * `javascript/partial_model_inner_enum.mustache` * gh-4044: Separated `javascript-es6` templates to another folder * gh-4044: Updated `javascript-es6/index.mustache` * gh-4044: Enabled ES6 in `javascript-es6/api_doc.mustache` * gh-4044: Added required dependencies for ES6 * gh-4044: Updated Supportig files for ES6 and non ES6 * gh-4044: Added test scripts to verify `javascript` useEs6 option * gh-4044: Commented `javascript-es6` scripts due to the permission issues.
This commit is contained in:
@@ -13,7 +13,6 @@ import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.models.ArrayModel;
|
||||
import io.swagger.models.ComposedModel;
|
||||
import io.swagger.models.Info;
|
||||
import io.swagger.models.License;
|
||||
import io.swagger.models.Model;
|
||||
@@ -22,7 +21,6 @@ import io.swagger.models.Operation;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
import io.swagger.models.properties.ByteArrayProperty;
|
||||
import io.swagger.models.properties.DateProperty;
|
||||
import io.swagger.models.properties.DateTimeProperty;
|
||||
import io.swagger.models.properties.DoubleProperty;
|
||||
@@ -41,7 +39,6 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -60,6 +57,28 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
public static final String USE_INHERITANCE = "useInheritance";
|
||||
public static final String EMIT_MODEL_METHODS = "emitModelMethods";
|
||||
public static final String EMIT_JS_DOC = "emitJSDoc";
|
||||
public static final String USE_ES6 = "useES6";
|
||||
|
||||
final String[][] JAVASCRIPT_SUPPORTING_FILES = new String[][] {
|
||||
new String[] {"package.mustache", "package.json"},
|
||||
new String[] {"index.mustache", "src/index.js"},
|
||||
new String[] {"ApiClient.mustache", "src/ApiClient.js"},
|
||||
new String[] {"git_push.sh.mustache", "git_push.sh"},
|
||||
new String[] {"README.mustache", "README.md"},
|
||||
new String[] {"mocha.opts", "mocha.opts"},
|
||||
new String[] {"travis.yml", ".travis.yml"}
|
||||
};
|
||||
|
||||
final String[][] JAVASCRIPT_ES6_SUPPORTING_FILES = new String[][] {
|
||||
new String[] {"package.mustache", "package.json"},
|
||||
new String[] {"index.mustache", "src/index.js"},
|
||||
new String[] {"ApiClient.mustache", "src/ApiClient.js"},
|
||||
new String[] {"git_push.sh.mustache", "git_push.sh"},
|
||||
new String[] {"README.mustache", "README.md"},
|
||||
new String[] {"mocha.opts", "mocha.opts"},
|
||||
new String[] {"travis.yml", ".travis.yml"},
|
||||
new String[] {".babelrc.mustache", ".babelrc"}
|
||||
};
|
||||
|
||||
protected String projectName;
|
||||
protected String moduleName;
|
||||
@@ -77,6 +96,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
protected String modelDocPath = "docs/";
|
||||
protected String apiTestPath = "api/";
|
||||
protected String modelTestPath = "model/";
|
||||
protected boolean useES6;
|
||||
|
||||
public JavascriptClientCodegen() {
|
||||
super();
|
||||
@@ -174,6 +194,9 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, "hides the timestamp when files were generated")
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
cliOptions.add(new CliOption(USE_ES6,
|
||||
"use USE_ES6")
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -242,6 +265,9 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
if (additionalProperties.containsKey(EMIT_JS_DOC)) {
|
||||
setEmitJSDoc(convertPropertyToBooleanAndWriteBack(EMIT_JS_DOC));
|
||||
}
|
||||
if (additionalProperties.containsKey(USE_ES6)) {
|
||||
setUseES6(convertPropertyToBooleanAndWriteBack(USE_ES6));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -298,18 +324,20 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
additionalProperties.put(USE_INHERITANCE, supportsInheritance);
|
||||
additionalProperties.put(EMIT_MODEL_METHODS, emitModelMethods);
|
||||
additionalProperties.put(EMIT_JS_DOC, emitJSDoc);
|
||||
additionalProperties.put(USE_ES6, useES6);
|
||||
|
||||
// make api and model doc path available in mustache template
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
|
||||
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache", createPath(sourceFolder, invokerPackage), "index.js"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", createPath(sourceFolder, invokerPackage), "ApiClient.js"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("mocha.opts", "", "mocha.opts"));
|
||||
supportingFiles.add(new SupportingFile("travis.yml", "", ".travis.yml"));
|
||||
String[][] supportingTemplateFiles = JAVASCRIPT_SUPPORTING_FILES;
|
||||
if (useES6) {
|
||||
supportingTemplateFiles = JAVASCRIPT_ES6_SUPPORTING_FILES;
|
||||
}
|
||||
|
||||
for (String[] supportingTemplateFile :supportingTemplateFiles) {
|
||||
supportingFiles.add(new SupportingFile(supportingTemplateFile[0], "", supportingTemplateFile[1]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -399,6 +427,15 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
this.usePromises = usePromises;
|
||||
}
|
||||
|
||||
public void setUseES6(boolean useES6) {
|
||||
this.useES6 = useES6;
|
||||
if (useES6) {
|
||||
embeddedTemplateDir = templateDir = "Javascript-es6";
|
||||
} else {
|
||||
embeddedTemplateDir = templateDir = "Javascript";
|
||||
}
|
||||
}
|
||||
|
||||
public void setUseInheritance(boolean useInheritance) {
|
||||
this.supportsInheritance = useInheritance;
|
||||
this.supportsMixins = useInheritance;
|
||||
|
||||
Reference in New Issue
Block a user