forked from loafle/openapi-generator-original
Merge pull request #1942 from xhh/javascript-fixes
[JavaScript] Fix initialization issues on array and nested model fields
This commit is contained in:
commit
a550eec389
@ -31,7 +31,7 @@ For a list of variables available in the template, please refer to this [page](h
|
|||||||
Code change should conform to the programming style guide of the respective langauages:
|
Code change should conform to the programming style guide of the respective langauages:
|
||||||
- C#: https://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx
|
- C#: https://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx
|
||||||
- Java: https://google.github.io/styleguide/javaguide.html
|
- Java: https://google.github.io/styleguide/javaguide.html
|
||||||
- JavaScript - https://github.com/airbnb/javascript
|
- JavaScript - https://github.com/airbnb/javascript/tree/master/es5
|
||||||
- ObjC: https://github.com/NYTimes/objective-c-style-guide
|
- ObjC: https://github.com/NYTimes/objective-c-style-guide
|
||||||
- PHP: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
|
- PHP: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
|
||||||
- Python: https://www.python.org/dev/peps/pep-0008/
|
- Python: https://www.python.org/dev/peps/pep-0008/
|
||||||
|
@ -624,41 +624,7 @@ public class DefaultCodegen {
|
|||||||
* @return string presentation of the default value of the property
|
* @return string presentation of the default value of the property
|
||||||
*/
|
*/
|
||||||
public String toDefaultValueWithParam(String name, Property p) {
|
public String toDefaultValueWithParam(String name, Property p) {
|
||||||
if (p instanceof StringProperty) {
|
|
||||||
return " = data." + name + ";";
|
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 + ";";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -279,7 +279,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelImport(String name) {
|
public String toModelImport(String name) {
|
||||||
return name;
|
return toModelName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -308,35 +308,17 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
return "[]";
|
return "[]";
|
||||||
} else if (p instanceof MapProperty) {
|
} else if (p instanceof MapProperty) {
|
||||||
return "{}";
|
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) {
|
} else if (p instanceof RefProperty) {
|
||||||
RefProperty rp = (RefProperty)p;
|
RefProperty rp = (RefProperty)p;
|
||||||
return "new " +rp.getSimpleRef() + "()";
|
return "new " + getTypeDeclaration(p) + "()";
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.toDefaultValue(p);
|
return super.toDefaultValue(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toDefaultValueWithParam(String name, Property p) {
|
public String toDefaultValueWithParam(String name, Property p) {
|
||||||
if (p instanceof ArrayProperty) {
|
if (p instanceof RefProperty) {
|
||||||
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;
|
RefProperty rp = (RefProperty) p;
|
||||||
return ".constructFromObject(data." + name + ");";
|
return ".constructFromObject(data." + name + ");";
|
||||||
}
|
}
|
||||||
@ -344,7 +326,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
return super.toDefaultValueWithParam(name, p);
|
return super.toDefaultValueWithParam(name, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSwaggerType(Property p) {
|
public String getSwaggerType(Property p) {
|
||||||
String swaggerType = super.getSwaggerType(p);
|
String swaggerType = super.getSwaggerType(p);
|
||||||
|
@ -95,9 +95,9 @@ var StatusEnum = function StatusEnum() {
|
|||||||
|
|
||||||
self.name = data.name;
|
self.name = data.name;
|
||||||
|
|
||||||
self.photoUrls = new Array();
|
self.photoUrls = data.photoUrls;
|
||||||
|
|
||||||
self.tags = new Array();
|
self.tags = data.tags;
|
||||||
|
|
||||||
self.status = data.status;
|
self.status = data.status;
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ describe('PetApi', function() {
|
|||||||
|
|
||||||
expect(fetched).to.be.ok();
|
expect(fetched).to.be.ok();
|
||||||
expect(fetched.id).to.be(pet.id);
|
expect(fetched.id).to.be(pet.id);
|
||||||
|
expect(fetched.getPhotoUrls()).to.eql(pet.getPhotoUrls());
|
||||||
expect(fetched.getCategory()).to.be.ok();
|
expect(fetched.getCategory()).to.be.ok();
|
||||||
expect(fetched.getCategory().getName()).to.be(pet.getCategory().getName());
|
expect(fetched.getCategory().getName()).to.be(pet.getCategory().getName());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user