forked from loafle/openapi-generator-original
typescript-angular2: ensuring that dates are strings and datetimes are Dates (#5417)
This commit is contained in:
parent
f7cbb2c0e6
commit
26fa547fd2
@ -42,7 +42,7 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
|
|||||||
modelTemplateFiles.put("model.mustache", ".ts");
|
modelTemplateFiles.put("model.mustache", ".ts");
|
||||||
apiTemplateFiles.put("api.service.mustache", ".ts");
|
apiTemplateFiles.put("api.service.mustache", ".ts");
|
||||||
languageSpecificPrimitives.add("Blob");
|
languageSpecificPrimitives.add("Blob");
|
||||||
typeMapping.put("Date","Date");
|
typeMapping.put("date","string");
|
||||||
typeMapping.put("file","Blob");
|
typeMapping.put("file","Blob");
|
||||||
apiPackage = "api";
|
apiPackage = "api";
|
||||||
modelPackage = "model";
|
modelPackage = "model";
|
||||||
|
@ -132,12 +132,7 @@ export class {{classname}} {
|
|||||||
queryParameters.set('{{baseName}}', <any>{{paramName}}.toISOString());
|
queryParameters.set('{{baseName}}', <any>{{paramName}}.toISOString());
|
||||||
{{/isDateTime}}
|
{{/isDateTime}}
|
||||||
{{^isDateTime}}
|
{{^isDateTime}}
|
||||||
{{#isDate}}
|
|
||||||
queryParameters.set('{{baseName}}', <any>{{paramName}}.toISOString());
|
|
||||||
{{/isDate}}
|
|
||||||
{{^isDate}}
|
|
||||||
queryParameters.set('{{baseName}}', <any>{{paramName}});
|
queryParameters.set('{{baseName}}', <any>{{paramName}});
|
||||||
{{/isDate}}
|
|
||||||
{{/isDateTime}}
|
{{/isDateTime}}
|
||||||
}
|
}
|
||||||
{{/isListContainer}}
|
{{/isListContainer}}
|
||||||
|
@ -14,6 +14,7 @@ import io.swagger.models.Model;
|
|||||||
import io.swagger.models.ModelImpl;
|
import io.swagger.models.ModelImpl;
|
||||||
import io.swagger.models.properties.ArrayProperty;
|
import io.swagger.models.properties.ArrayProperty;
|
||||||
import io.swagger.models.properties.DateTimeProperty;
|
import io.swagger.models.properties.DateTimeProperty;
|
||||||
|
import io.swagger.models.properties.DateProperty;
|
||||||
import io.swagger.models.properties.LongProperty;
|
import io.swagger.models.properties.LongProperty;
|
||||||
import io.swagger.models.properties.RefProperty;
|
import io.swagger.models.properties.RefProperty;
|
||||||
import io.swagger.models.properties.StringProperty;
|
import io.swagger.models.properties.StringProperty;
|
||||||
@ -28,6 +29,7 @@ public class TypeScriptAngular2ModelTest {
|
|||||||
.property("id", new LongProperty())
|
.property("id", new LongProperty())
|
||||||
.property("name", new StringProperty())
|
.property("name", new StringProperty())
|
||||||
.property("createdAt", new DateTimeProperty())
|
.property("createdAt", new DateTimeProperty())
|
||||||
|
.property("birthDate", new DateProperty())
|
||||||
.required("id")
|
.required("id")
|
||||||
.required("name");
|
.required("name");
|
||||||
final DefaultCodegen codegen = new TypeScriptAngular2ClientCodegen();
|
final DefaultCodegen codegen = new TypeScriptAngular2ClientCodegen();
|
||||||
@ -36,7 +38,7 @@ public class TypeScriptAngular2ModelTest {
|
|||||||
Assert.assertEquals(cm.name, "sample");
|
Assert.assertEquals(cm.name, "sample");
|
||||||
Assert.assertEquals(cm.classname, "Sample");
|
Assert.assertEquals(cm.classname, "Sample");
|
||||||
Assert.assertEquals(cm.description, "a sample model");
|
Assert.assertEquals(cm.description, "a sample model");
|
||||||
Assert.assertEquals(cm.vars.size(), 3);
|
Assert.assertEquals(cm.vars.size(), 4);
|
||||||
|
|
||||||
final CodegenProperty property1 = cm.vars.get(0);
|
final CodegenProperty property1 = cm.vars.get(0);
|
||||||
Assert.assertEquals(property1.baseName, "id");
|
Assert.assertEquals(property1.baseName, "id");
|
||||||
@ -63,10 +65,22 @@ public class TypeScriptAngular2ModelTest {
|
|||||||
Assert.assertEquals(property3.complexType, null);
|
Assert.assertEquals(property3.complexType, null);
|
||||||
Assert.assertEquals(property3.datatype, "Date");
|
Assert.assertEquals(property3.datatype, "Date");
|
||||||
Assert.assertEquals(property3.name, "createdAt");
|
Assert.assertEquals(property3.name, "createdAt");
|
||||||
|
Assert.assertEquals(property3.baseType, "Date");
|
||||||
Assert.assertEquals(property3.defaultValue, "null");
|
Assert.assertEquals(property3.defaultValue, "null");
|
||||||
Assert.assertFalse(property3.hasMore);
|
Assert.assertTrue(property3.hasMore);
|
||||||
Assert.assertFalse(property3.required);
|
Assert.assertFalse(property3.required);
|
||||||
Assert.assertTrue(property3.isNotContainer);
|
Assert.assertTrue(property3.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property4 = cm.vars.get(3);
|
||||||
|
Assert.assertEquals(property4.baseName, "birthDate");
|
||||||
|
Assert.assertEquals(property4.complexType, null);
|
||||||
|
Assert.assertEquals(property4.datatype, "string");
|
||||||
|
Assert.assertEquals(property4.name, "birthDate");
|
||||||
|
Assert.assertEquals(property4.baseType, "string");
|
||||||
|
Assert.assertEquals(property4.defaultValue, "null");
|
||||||
|
Assert.assertFalse(property4.hasMore);
|
||||||
|
Assert.assertFalse(property4.required);
|
||||||
|
Assert.assertTrue(property4.isNotContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(description = "convert a model with list property")
|
@Test(description = "convert a model with list property")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user