mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 11:23:58 +00:00
Some clean-ups for the Javascript client codegen
This commit is contained in:
parent
89f269969d
commit
3f3e444ab1
@ -34,15 +34,8 @@ import org.slf4j.LoggerFactory;
|
||||
public class JavascriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavascriptClientCodegen.class);
|
||||
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-java-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String sourceFolder = "src";
|
||||
protected String localVariablePrefix = "";
|
||||
protected boolean fullJavaUtil = false;
|
||||
protected String javaUtilPrefix = "";
|
||||
protected Boolean serializableModel = false;
|
||||
|
||||
public JavascriptClientCodegen() {
|
||||
super();
|
||||
@ -80,14 +73,8 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
instantiationTypes.put("map", "HashMap");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.GROUP_ID, CodegenConstants.GROUP_ID_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, CodegenConstants.ARTIFACT_ID_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.LOCAL_VARIABLE_PREFIX, CodegenConstants.LOCAL_VARIABLE_PREFIX_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
|
||||
cliOptions.add(new CliOption("fullJavaUtil", "whether to use fully qualified name for classes under java.util (default to false)"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -108,9 +95,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
typeMapping.put("array", "Array");
|
||||
|
||||
typeMapping.put("array", "Array");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -198,84 +183,42 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
final ArrayProperty ap = (ArrayProperty) p;
|
||||
final String pattern;
|
||||
//if (fullJavaUtil) {
|
||||
// pattern = "new ArrayList()";
|
||||
//} else {
|
||||
// pattern = "new ArrayList<%s>()";
|
||||
//}
|
||||
|
||||
pattern = "new Array()";
|
||||
return String.format(pattern, getTypeDeclaration(ap.getItems()));
|
||||
return "[]";
|
||||
} else if (p instanceof MapProperty) {
|
||||
final MapProperty ap = (MapProperty) p;
|
||||
final String pattern;
|
||||
if (fullJavaUtil) {
|
||||
pattern = "new java.util.HashMap<String, %s>()";
|
||||
} else {
|
||||
pattern = "new HashMap<String, %s>()";
|
||||
}
|
||||
return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties()));
|
||||
|
||||
return "{}";
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString()+"l";
|
||||
}
|
||||
return "null";
|
||||
|
||||
|
||||
// added for Javascript
|
||||
} else if (p instanceof RefProperty) {
|
||||
RefProperty rp = (RefProperty)p;
|
||||
System.out.println("rp: " + rp.getName() + rp.getAccess() + rp.getDescription() + rp.getExample() + rp.getFormat() + rp.getSimpleRef() + rp.getTitle() + rp.getType());
|
||||
|
||||
return "new " +rp.getSimpleRef() + "()";
|
||||
return "new " +rp.getSimpleRef() + "()";
|
||||
}
|
||||
|
||||
System.out.println("property: " + p);
|
||||
|
||||
|
||||
return super.toDefaultValue(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toDefaultValueWithParam(String name, Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
final ArrayProperty ap = (ArrayProperty) p;
|
||||
final String pattern;
|
||||
// if (fullJavaUtil) {
|
||||
// pattern = "new java.util.ArrayList<%s>()";
|
||||
// } else {
|
||||
// pattern = "new ArrayList<%s>()" ;
|
||||
// }
|
||||
pattern = " = new Array()" ;
|
||||
|
||||
return String.format(pattern, getTypeDeclaration(ap.getItems()))+ ";";
|
||||
return " = new Array();";
|
||||
} else if (p instanceof MapProperty) {
|
||||
final MapProperty ap = (MapProperty) p;
|
||||
final String pattern;
|
||||
if (fullJavaUtil) {
|
||||
pattern = " = new java.util.HashMap<String, %s>()";
|
||||
} else {
|
||||
pattern = "new HashMap<String, %s>()";
|
||||
}
|
||||
return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties()))+ ";";
|
||||
|
||||
return " = {}";
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
return " = data." + name + ";";
|
||||
|
||||
|
||||
// added for Javascript
|
||||
} else if (p instanceof RefProperty) {
|
||||
RefProperty rp = (RefProperty)p;
|
||||
System.out.println("rp: " + rp.getName() + rp.getAccess() + rp.getDescription() + rp.getExample() + rp.getFormat() + rp.getSimpleRef() + rp.getTitle() + rp.getType());
|
||||
|
||||
return ".constructFromObject(data." + name + ");";
|
||||
return ".constructFromObject(data." + name + ");";
|
||||
}
|
||||
|
||||
System.out.println("property: " + p);
|
||||
|
||||
|
||||
return super.toDefaultValueWithParam(name, p);
|
||||
}
|
||||
|
||||
@ -449,7 +392,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(removedChildEnum) {
|
||||
// If we removed an entry from this model's vars, we need to ensure hasMore is updated
|
||||
int count = 0, numVars = codegenProperties.size();
|
||||
@ -464,22 +407,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
public void setInvokerPackage(String invokerPackage) {
|
||||
this.invokerPackage = invokerPackage;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public void setArtifactId(String artifactId) {
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public void setArtifactVersion(String artifactVersion) {
|
||||
this.artifactVersion = artifactVersion;
|
||||
}
|
||||
|
||||
public void setSourceFolder(String sourceFolder) {
|
||||
this.sourceFolder = sourceFolder;
|
||||
}
|
||||
@ -488,15 +415,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
this.localVariablePrefix = localVariablePrefix;
|
||||
}
|
||||
|
||||
|
||||
public Boolean getSerializableModel() {
|
||||
return serializableModel;
|
||||
}
|
||||
|
||||
public void setSerializableModel(Boolean serializableModel) {
|
||||
this.serializableModel = serializableModel;
|
||||
}
|
||||
|
||||
private String sanitizePackageName(String packageName) {
|
||||
packageName = packageName.trim();
|
||||
packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_");
|
||||
|
@ -1,7 +1,3 @@
|
||||
/*
|
||||
* {{>generatedAnnotation}}
|
||||
*/
|
||||
|
||||
//export module
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
define(['jquery'], function($) {
|
||||
|
@ -1 +0,0 @@
|
||||
@javax.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}")
|
@ -1,7 +1,3 @@
|
||||
/*
|
||||
* @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavascriptClientCodegen", date = "2015-12-09T16:07:21.000+07:00")
|
||||
*/
|
||||
|
||||
//export module
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
define(['jquery'], function($) {
|
||||
|
@ -1,7 +1,3 @@
|
||||
/*
|
||||
* @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavascriptClientCodegen", date = "2015-12-09T16:07:21.000+07:00")
|
||||
*/
|
||||
|
||||
//export module
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
define(['jquery'], function($) {
|
||||
|
@ -1,7 +1,3 @@
|
||||
/*
|
||||
* @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavascriptClientCodegen", date = "2015-12-09T16:07:21.000+07:00")
|
||||
*/
|
||||
|
||||
//export module
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
define(['jquery'], function($) {
|
||||
|
@ -66,7 +66,7 @@ var Pet = function Pet(photoUrls, name) {
|
||||
/**
|
||||
* datatype: Array
|
||||
**/
|
||||
self.tags = new Array();
|
||||
self.tags = [];
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
|
Loading…
Reference in New Issue
Block a user