JavaScript: fix constructFromObject for Array fields

Closes #1721
This commit is contained in:
xhh 2016-01-22 11:23:45 +08:00
parent 53abd8a8fb
commit 16e367bdc8
4 changed files with 6 additions and 50 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 + ";";
}
}
/**

View File

@ -324,19 +324,9 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
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) {
if (p instanceof RefProperty) {
RefProperty rp = (RefProperty) p;
return ".constructFromObject(data." + name + ");";
}
@ -344,7 +334,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
return super.toDefaultValueWithParam(name, p);
}
@Override
public String getSwaggerType(Property p) {
String swaggerType = super.getSwaggerType(p);

View File

@ -95,9 +95,9 @@ var StatusEnum = function StatusEnum() {
self.name = data.name;
self.photoUrls = new Array();
self.photoUrls = data.photoUrls;
self.tags = new Array();
self.tags = data.tags;
self.status = data.status;

View File

@ -40,6 +40,7 @@ describe('PetApi', function() {
expect(fetched).to.be.ok();
expect(fetched.id).to.be(pet.id);
expect(fetched.getPhotoUrls()).to.eql(pet.getPhotoUrls());
expect(fetched.getCategory()).to.be.ok();
expect(fetched.getCategory().getName()).to.be(pet.getCategory().getName());