use of com.webcohesion.enunciate.api.datatype.BaseType in project enunciate by stoicflame.
the class BaseDatatypeNameForMethod method exec.
public Object exec(List list) throws TemplateModelException {
if (list.size() < 1) {
throw new TemplateModelException("The datatypeNameFor method must have a parameter.");
}
TemplateModel from = (TemplateModel) list.get(0);
Object unwrapped = FreemarkerUtil.unwrap(from);
BaseType baseType = null;
if (unwrapped instanceof DataType) {
DataType dataType = (DataType) unwrapped;
baseType = dataType.getBaseType();
}
if (baseType == null) {
throw new TemplateModelException("No base data type name for: " + unwrapped);
}
switch(baseType) {
case bool:
return "boolean";
case number:
return "number";
case string:
return "string";
default:
return "object";
}
}
use of com.webcohesion.enunciate.api.datatype.BaseType in project enunciate by stoicflame.
the class ReferencedDatatypeNameForMethod method exec.
@SuppressWarnings("rawtypes")
public Object exec(List list) throws TemplateModelException {
if (list.size() < 1) {
throw new TemplateModelException("The datatypeNameFor method must have a parameter.");
}
TemplateModel from = (TemplateModel) list.get(0);
Object unwrapped = FreemarkerUtil.unwrap(from);
if (!DataTypeReference.class.isAssignableFrom(unwrapped.getClass())) {
throw new TemplateModelException("No referenced data type name for: " + unwrapped);
}
DataTypeReference reference = DataTypeReference.class.cast(unwrapped);
BaseType baseType = reference.getBaseType();
String format = reference.getBaseTypeFormat();
String defaultType = "file";
if (list.size() > 1) {
defaultType = FreemarkerUtil.unwrap((TemplateModel) list.get(1)).toString();
}
switch(baseType) {
case bool:
return "boolean";
case number:
if ("int32".equals(format) || "int64".equals(format)) {
return "integer";
} else {
return "number";
}
case string:
return "string";
default:
return defaultType;
}
}
Aggregations