/**
* @see https://github.com/wordnik/swagger-core/wiki/datatypes
*/
protected static SwaggerDataType convertToSwaggerType(SwaggerModel models, Class<?> type) {
if (Void.TYPE.equals(type)) {
return new SwaggerDataType("void");
} else if (Integer.TYPE.equals(type) || Integer.class.isAssignableFrom(type)) {
return new SwaggerDataType("integer", "int32");
} else if (Long.TYPE.equals(type) || Long.class.isAssignableFrom(type)) {
return new SwaggerDataType("integer", "int64");
} else if (Float.TYPE.equals(type) || Float.class.isAssignableFrom(type)) {
return new SwaggerDataType("number", "float");
} else if (Double.TYPE.equals(type) || Double.class.isAssignableFrom(type)) {
return new SwaggerDataType("number", "double");
} else if (Byte.TYPE.equals(type) || Byte.class.isAssignableFrom(type)) {
return new SwaggerDataType("string", "byte");
} else if (Boolean.TYPE.equals(type) || Boolean.class.isAssignableFrom(type)) {
return new SwaggerDataType("boolean");
} else if (Number.class.isAssignableFrom(type)) {
return new SwaggerDataType("number");
} else if (String.class.equals(type)) {
return new SwaggerDataType("string");
} else if (Date.class.equals(type)) {
return new SwaggerDataType("string", "date-time");
} else if (type.isEnum()) {
return new SwaggerDataType("string");
} else if (type.isArray() || Collection.class.isAssignableFrom(type)) {
return new SwaggerDataType("array");
} else {
// it's a custom type, we need to create a model for it (if it does not already exist)
String typeName = type.getName();
if (!models.containsKey(typeName)) {
// Reserve a spot for this type, avoids circular references to cause a StackOverflow, see AMDATUWEB-10...
models.put(typeName, null);
// Overwrite the item with the actual model definition...
models.put(typeName, convertToSwaggerModel(models, type));
}
return new SwaggerDataType(type.getName());
}
}