Merge pull request #1942 from xhh/javascript-fixes

[JavaScript] Fix initialization issues on array and nested model fields
This commit is contained in:
wing328
2016-01-22 18:15:20 +08:00
5 changed files with 9 additions and 61 deletions

View File

@@ -624,41 +624,7 @@ public class DefaultCodegen {
* @return string presentation of the default value of the property
*/
public String toDefaultValueWithParam(String name, Property p) {
if (p instanceof StringProperty) {
return " = data." + name + ";";
} else if (p instanceof BooleanProperty) {
return " = data." + name + ";";
} else if (p instanceof DateProperty) {
return " = data." + name + ";";
} else if (p instanceof DateTimeProperty) {
return " = data." + name + ";";
} else if (p instanceof DoubleProperty) {
DoubleProperty dp = (DoubleProperty) p;
if (dp.getDefault() != null) {
return dp.getDefault().toString();
}
return " = data." + name + ";";
} else if (p instanceof FloatProperty) {
FloatProperty dp = (FloatProperty) p;
if (dp.getDefault() != null) {
return dp.getDefault().toString();
}
return " = data." + name + ";";
} else if (p instanceof IntegerProperty) {
IntegerProperty dp = (IntegerProperty) p;
if (dp.getDefault() != null) {
return dp.getDefault().toString();
}
return " = data." + name + ";";
} else if (p instanceof LongProperty) {
LongProperty dp = (LongProperty) p;
if (dp.getDefault() != null) {
return dp.getDefault().toString();
}
return " = data." + name + ";";
} else {
return " = data." + name + ";";
}
return " = data." + name + ";";
}
/**

View File

@@ -279,7 +279,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
@Override
public String toModelImport(String name) {
return name;
return toModelName(name);
}
@Override
@@ -308,43 +308,24 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
return "[]";
} else if (p instanceof MapProperty) {
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;
return "new " +rp.getSimpleRef() + "()";
return "new " + getTypeDeclaration(p) + "()";
}
return super.toDefaultValue(p);
}
@Override
public String toDefaultValueWithParam(String name, Property p) {
if (p instanceof ArrayProperty) {
return " = new Array();";
} else if (p instanceof MapProperty) {
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;
if (p instanceof RefProperty) {
RefProperty rp = (RefProperty) p;
return ".constructFromObject(data." + name + ");";
}
return super.toDefaultValueWithParam(name, p);
}
@Override
public String getSwaggerType(Property p) {
String swaggerType = super.getSwaggerType(p);