Add TypeScript default value mappers (#6828)

Fixes #6765.
This commit is contained in:
Erik Timmers
2017-11-02 10:16:30 +01:00
committed by wing328
parent e8635632a4
commit 980dd7c6ab
5 changed files with 75 additions and 23 deletions

View File

@@ -18,11 +18,20 @@ import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.CodegenType;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.BooleanProperty;
import io.swagger.models.properties.DateProperty;
import io.swagger.models.properties.DateTimeProperty;
import io.swagger.models.properties.DoubleProperty;
import io.swagger.models.properties.FileProperty;
import io.swagger.models.properties.FloatProperty;
import io.swagger.models.properties.IntegerProperty;
import io.swagger.models.properties.LongProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.StringProperty;
public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig {
private static final String UNDEFINED_VALUE = "undefined";
protected String modelPropertyNaming= "camelCase";
protected Boolean supportsES6 = true;
@@ -221,6 +230,49 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
return super.getTypeDeclaration(p);
}
@Override
public String toDefaultValue(Property p) {
if (p instanceof StringProperty) {
StringProperty sp = (StringProperty) p;
if (sp.getDefault() != null) {
return "\"" + sp.getDefault() + "\"";
}
return UNDEFINED_VALUE;
} else if (p instanceof BooleanProperty) {
return UNDEFINED_VALUE;
} else if (p instanceof DateProperty) {
return UNDEFINED_VALUE;
} else if (p instanceof DateTimeProperty) {
return UNDEFINED_VALUE;
} else if (p instanceof DoubleProperty) {
DoubleProperty dp = (DoubleProperty) p;
if (dp.getDefault() != null) {
return dp.getDefault().toString();
}
return UNDEFINED_VALUE;
} else if (p instanceof FloatProperty) {
FloatProperty fp = (FloatProperty) p;
if (fp.getDefault() != null) {
return fp.getDefault().toString();
}
return UNDEFINED_VALUE;
} else if (p instanceof IntegerProperty) {
IntegerProperty ip = (IntegerProperty) p;
if (ip.getDefault() != null) {
return ip.getDefault().toString();
}
return UNDEFINED_VALUE;
} else if (p instanceof LongProperty) {
LongProperty lp = (LongProperty) p;
if (lp.getDefault() != null) {
return lp.getDefault().toString();
}
return UNDEFINED_VALUE;
} else {
return UNDEFINED_VALUE;
}
}
@Override
public String getSwaggerType(Property p) {
String swaggerType = super.getSwaggerType(p);