forked from loafle/openapi-generator-original
Added support for arrays and also warning for objects with null properties
This commit is contained in:
@@ -31,6 +31,7 @@ public class FieldDefinition {
|
||||
private boolean hasMapResponse;
|
||||
private boolean hasSetResponse;
|
||||
private boolean hasDateResponse;
|
||||
private boolean hasArrayResponse;
|
||||
|
||||
private boolean hasPrimitiveType;
|
||||
|
||||
@@ -58,6 +59,14 @@ public class FieldDefinition {
|
||||
this.hasSetResponse = hasSetResponse;
|
||||
}
|
||||
|
||||
public boolean isHasArrayResponse() {
|
||||
return hasArrayResponse;
|
||||
}
|
||||
|
||||
public void setHasArrayResponse(boolean hasArrayResponse) {
|
||||
this.hasArrayResponse = hasArrayResponse;
|
||||
}
|
||||
|
||||
public boolean isHasPrimitiveType() {
|
||||
return hasPrimitiveType;
|
||||
}
|
||||
@@ -77,7 +86,9 @@ public class FieldDefinition {
|
||||
hasSetResponse = true;
|
||||
}else if(returnType.startsWith("Map")){
|
||||
hasMapResponse = true;
|
||||
}
|
||||
}else if(returnType.startsWith("Array")){
|
||||
hasArrayResponse = true;
|
||||
}
|
||||
this.returnType = returnType;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* User: ramesh
|
||||
@@ -54,7 +56,9 @@ public class LibraryCodeGenerator {
|
||||
protected DataTypeMappingProvider dataTypeMappingProvider;
|
||||
protected RulesProvider codeGenRulesProvider;
|
||||
protected NamingPolicyProvider nameGenerator;
|
||||
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(LibraryCodeGenerator.class);
|
||||
|
||||
public LibraryCodeGenerator(){}
|
||||
|
||||
public LibraryCodeGenerator(String configPath){
|
||||
@@ -159,24 +163,28 @@ public class LibraryCodeGenerator {
|
||||
if(!generatedClassNames.contains(model.getName()) && !this.getCodeGenRulesProvider().isModelIgnored(model.getName())){
|
||||
List<String> imports = new ArrayList<String>();
|
||||
imports.addAll(this.config.getDefaultModelImports());
|
||||
for(ModelField param : model.getFields()){
|
||||
for(String importDef : param.getFieldDefinition(this.getDataTypeMappingProvider(), config, nameGenerator).getImportDefinitions()){
|
||||
if(!imports.contains(importDef)){
|
||||
imports.add(importDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
StringTemplate template = templateGroup.getInstanceOf(MODEL_OBJECT_TEMPLATE);
|
||||
template.setAttribute("model", model);
|
||||
template.setAttribute("fields", model.getFields());
|
||||
template.setAttribute("imports", imports);
|
||||
template.setAttribute("annotationPackageName", languageConfig.getAnnotationPackageName());
|
||||
template.setAttribute("extends", config.getDefaultModelBaseClass());
|
||||
template.setAttribute("className", model.getGenratedClassName());
|
||||
template.setAttribute(PACKAGE_NAME, config.getModelPackageName());
|
||||
File aFile = new File(languageConfig.getModelClassLocation()+model.getGenratedClassName()+languageConfig.getClassFileExtension());
|
||||
writeFile(aFile, template.toString(), "Model class");
|
||||
generatedClassNames.add(model.getName());
|
||||
if(null == model.getFields() || model.getFields().size() == 0){
|
||||
logger.warn("Model " + model.getName() + " doesn't have any properties");
|
||||
} else {
|
||||
for(ModelField param : model.getFields()){
|
||||
for(String importDef : param.getFieldDefinition(this.getDataTypeMappingProvider(), config, nameGenerator).getImportDefinitions()){
|
||||
if(!imports.contains(importDef)){
|
||||
imports.add(importDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
StringTemplate template = templateGroup.getInstanceOf(MODEL_OBJECT_TEMPLATE);
|
||||
template.setAttribute("model", model);
|
||||
template.setAttribute("fields", model.getFields());
|
||||
template.setAttribute("imports", imports);
|
||||
template.setAttribute("annotationPackageName", languageConfig.getAnnotationPackageName());
|
||||
template.setAttribute("extends", config.getDefaultModelBaseClass());
|
||||
template.setAttribute("className", model.getGenratedClassName());
|
||||
template.setAttribute(PACKAGE_NAME, config.getModelPackageName());
|
||||
File aFile = new File(languageConfig.getModelClassLocation()+model.getGenratedClassName()+languageConfig.getClassFileExtension());
|
||||
writeFile(aFile, template.toString(), "Model class");
|
||||
generatedClassNames.add(model.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +67,17 @@ public interface DataTypeMappingProvider {
|
||||
*/
|
||||
public String getSetReturnTypeSignature(String typeClass);
|
||||
|
||||
|
||||
/**
|
||||
* Signature that should be used when returning array of given object type.
|
||||
*
|
||||
* Example: in java this output will look as <Code> Array<User> </Code> for methods that returns a set of user objects
|
||||
* @param typeClass of class that the set object contains.
|
||||
* @return
|
||||
*/
|
||||
public String getArrayReturnTypeSignature(String typeClass);
|
||||
|
||||
|
||||
/**
|
||||
* Initialization need for list objects. Example. If it is java list the initialization will look as
|
||||
*
|
||||
@@ -103,6 +114,18 @@ public interface DataTypeMappingProvider {
|
||||
*/
|
||||
public String generateSetInitialization(String typeClass);
|
||||
|
||||
/**
|
||||
* Initialization need for Array objects. Example. If it is Java Array initialization will look as
|
||||
*
|
||||
* <Code>
|
||||
* new ObjectName[]()
|
||||
* </Code>
|
||||
*
|
||||
* @param typeClass
|
||||
* @return
|
||||
*/
|
||||
public String generateArrayInitialization(String typeClass);
|
||||
|
||||
/**
|
||||
* Sets variable initialization.
|
||||
*
|
||||
@@ -145,18 +168,18 @@ public interface DataTypeMappingProvider {
|
||||
public List<String> getMapIncludes();
|
||||
|
||||
/**
|
||||
* Gets list of items that needs to be included when referring set objects in model or resource classes.
|
||||
* Gets list of to needs to be included when referring set objects in model or resource classes.
|
||||
*
|
||||
* Example: in java while using sets we use an interface of <Code>Set</Code> and implementation of
|
||||
* <Code>HashSet</Code>. So the the implementation of this method in java
|
||||
* Example: in java while using sets we use an interface of <Code>Array</Code> and implementation of
|
||||
* <Code>Arry</Code>. So the the implementation of this method in java
|
||||
* language will be:
|
||||
* <Code>
|
||||
* List<String> imports = new ArrayList<String>();
|
||||
imports.add("java.util.Set");
|
||||
imports.add("java.util.HashSet");
|
||||
imports.add("java.lang.Array");
|
||||
* </Code>
|
||||
* @return
|
||||
*/
|
||||
|
||||
public List<String> getSetIncludes();
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,6 +33,10 @@ public class As3DataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
primitiveValueMap.put("Float", "Number");
|
||||
primitiveValueMap.put("Date", "Date");
|
||||
primitiveValueMap.put("date", "Date");
|
||||
primitiveValueMap.put("byte", "byte");
|
||||
primitiveValueMap.put("Byte", "byte");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static Map<String, String> primitiveObjectMap = new HashMap<String, String>();
|
||||
@@ -52,6 +56,8 @@ public class As3DataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
primitiveObjectMap.put("Float", "Number");
|
||||
primitiveObjectMap.put("Date", "Date");
|
||||
primitiveObjectMap.put("date", "Date");
|
||||
primitiveObjectMap.put("byte", "byte");
|
||||
|
||||
}
|
||||
|
||||
private NamingPolicyProvider nameGenerator = new CamelCaseNamingPolicyProvider();
|
||||
@@ -99,6 +105,10 @@ public class As3DataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
return "Array";
|
||||
}
|
||||
|
||||
public String getArrayReturnTypeSignature(String typeClass) {
|
||||
return "Array";
|
||||
}
|
||||
|
||||
public String generateListInitialization(String typeClass) {
|
||||
return " new Array()";
|
||||
}
|
||||
@@ -109,6 +119,11 @@ public class As3DataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
|
||||
public String generateSetInitialization(String typeClass) {
|
||||
return " new Array()";
|
||||
|
||||
}
|
||||
|
||||
public String generateArrayInitialization(String typeClass) {
|
||||
return " new Array()";
|
||||
}
|
||||
|
||||
public List<String> getListIncludes() {
|
||||
@@ -150,7 +165,10 @@ public class As3DataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
}else if (type.startsWith("Set[")) {
|
||||
classShortName = type.substring(4, type.length()-1);
|
||||
classShortName = getObjectType(classShortName, true);
|
||||
}else if (type.equals("ok")) {
|
||||
}else if (type.startsWith("Array[")) {
|
||||
classShortName = type.substring(6, type.length()-1);
|
||||
classShortName = getObjectType(classShortName, true);
|
||||
}else if (type.equals("ok")) {
|
||||
classShortName = "void";
|
||||
}else{
|
||||
classShortName = getObjectType(type, true);
|
||||
@@ -175,7 +193,7 @@ public class As3DataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
return "void";
|
||||
}
|
||||
String classShortName = "";
|
||||
if(type.startsWith("List[") || type.startsWith("Map[") || type.startsWith("Set[")){
|
||||
if(type.startsWith("List[") || type.startsWith("Map[") || type.startsWith("Set[") || type.startsWith("Array[") ){
|
||||
classShortName = "Array";
|
||||
}else{
|
||||
classShortName = getObjectType(type, true);
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.wordnik.swagger.codegen.config.NamingPolicyProvider;
|
||||
public class CamelCaseNamingPolicyProvider implements NamingPolicyProvider {
|
||||
|
||||
public static String INPUT_OBJECT_SUFFIX = "Input";
|
||||
|
||||
/**
|
||||
* gets the name of class that is responsible for tracking current library version
|
||||
* @return
|
||||
|
||||
@@ -47,6 +47,8 @@ public class JavaDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
primitiveValueMap.put("Float", "float");
|
||||
primitiveValueMap.put("Date", "Date");
|
||||
primitiveValueMap.put("date", "Date");
|
||||
primitiveValueMap.put("Byte", "byte");
|
||||
|
||||
}
|
||||
|
||||
public static Map<String, String> primitiveObjectMap = new HashMap<String, String>();
|
||||
@@ -70,6 +72,8 @@ public class JavaDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
primitiveObjectMap.put("Date", "Date");
|
||||
primitiveObjectMap.put("date", "Date");
|
||||
primitiveObjectMap.put("java.util.Date", "Date");
|
||||
primitiveObjectMap.put("byte", "byte");
|
||||
|
||||
}
|
||||
|
||||
private NamingPolicyProvider nameGenerator = new CamelCaseNamingPolicyProvider();
|
||||
@@ -93,6 +97,10 @@ public class JavaDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
return "Set<"+nameGenerator.applyClassNamingPolicy(typeClass)+">";
|
||||
}
|
||||
|
||||
public String getArrayReturnTypeSignature(String typeClass) {
|
||||
return nameGenerator.applyClassNamingPolicy(typeClass)+"[]";
|
||||
}
|
||||
|
||||
public String generateListInitialization(String typeClass) {
|
||||
return " new ArrayList<"+nameGenerator.applyClassNamingPolicy(typeClass)+">()";
|
||||
}
|
||||
@@ -105,6 +113,10 @@ public class JavaDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
return " new HashSet<"+nameGenerator.applyClassNamingPolicy(typeClass)+">()";
|
||||
}
|
||||
|
||||
public String generateArrayInitialization(String typeClass) {
|
||||
return " null";
|
||||
}
|
||||
|
||||
public List<String> getListIncludes() {
|
||||
List<String> imports = new ArrayList<String>();
|
||||
imports.add("java.util.List");
|
||||
@@ -150,7 +162,10 @@ public class JavaDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
}else if (type.startsWith("Set[")) {
|
||||
classShortName = type.substring(4, type.length()-1);
|
||||
classShortName = getClassType(classShortName, true);
|
||||
}else if (type.equalsIgnoreCase("ok")) {
|
||||
}else if (type.startsWith("Array[")) {
|
||||
classShortName = type.substring(6, type.length()-1);
|
||||
classShortName = getClassType(classShortName, true);
|
||||
}else if (type.equalsIgnoreCase("ok")) {
|
||||
classShortName = "void";
|
||||
}else{
|
||||
classShortName = getClassType(type, true);
|
||||
@@ -191,7 +206,10 @@ public class JavaDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
}else if (type.startsWith("Set[")) {
|
||||
classShortName = type.substring(4, type.length()-1);
|
||||
classShortName = "Set<"+ getClassName(classShortName, true) +">";
|
||||
}else{
|
||||
}else if (type.startsWith("Array[")) {
|
||||
classShortName = type.substring(6, type.length()-1);
|
||||
classShortName = getClassName(classShortName, true) +"[]";
|
||||
}else{
|
||||
classShortName = getClassName(type, true);
|
||||
}
|
||||
return classShortName;
|
||||
|
||||
@@ -33,6 +33,8 @@ public class JSDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
primitiveValueMap.put("Float", "Number");
|
||||
primitiveValueMap.put("Date", "Date");
|
||||
primitiveValueMap.put("date", "Date");
|
||||
primitiveValueMap.put("byte", "byte");
|
||||
|
||||
}
|
||||
|
||||
public static Map<String, String> primitiveObjectMap = new HashMap<String, String>();
|
||||
@@ -52,6 +54,8 @@ public class JSDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
primitiveObjectMap.put("Float", "Number");
|
||||
primitiveObjectMap.put("Date", "Date");
|
||||
primitiveObjectMap.put("date", "Date");
|
||||
primitiveObjectMap.put("byte", "Byte");
|
||||
|
||||
}
|
||||
|
||||
private NamingPolicyProvider nameGenerator = new CamelCaseNamingPolicyProvider();
|
||||
@@ -99,6 +103,11 @@ public class JSDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
return "Array";
|
||||
}
|
||||
|
||||
public String getArrayReturnTypeSignature(String typeClass) {
|
||||
return "Array";
|
||||
}
|
||||
|
||||
|
||||
public String generateListInitialization(String typeClass) {
|
||||
return " new Array()";
|
||||
}
|
||||
@@ -111,6 +120,10 @@ public class JSDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
return " new Array()";
|
||||
}
|
||||
|
||||
public String generateArrayInitialization(String typeClass) {
|
||||
return " new Array()";
|
||||
}
|
||||
|
||||
public List<String> getListIncludes() {
|
||||
List<String> imports = new ArrayList<String>();
|
||||
return imports;
|
||||
@@ -149,7 +162,10 @@ public class JSDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
}else if (type.startsWith("Set[")) {
|
||||
classShortName = type.substring(4, type.length()-1);
|
||||
classShortName = getObjectType(classShortName, true);
|
||||
}else if (type.equals("ok")) {
|
||||
}else if (type.startsWith("Array[")) {
|
||||
classShortName = type.substring(6, type.length()-1);
|
||||
classShortName = getObjectType(classShortName, true);
|
||||
}else if (type.equals("ok")) {
|
||||
classShortName = "void";
|
||||
}else{
|
||||
classShortName = getObjectType(type, true);
|
||||
@@ -174,7 +190,7 @@ public class JSDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
return "void";
|
||||
}
|
||||
String classShortName = "";
|
||||
if(type.startsWith("List[") || type.startsWith("Map[") || type.startsWith("Set[")){
|
||||
if(type.startsWith("List[") || type.startsWith("Map[") || type.startsWith("Set[") || type.startsWith("Array[")){
|
||||
classShortName = "Array";
|
||||
}else{
|
||||
classShortName = getObjectType(type, true);
|
||||
|
||||
@@ -49,6 +49,9 @@ public class PHPDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
primitiveValueMap.put("date", "string");
|
||||
primitiveValueMap.put("Double", "float");
|
||||
primitiveValueMap.put("double", "float");
|
||||
primitiveValueMap.put("byte", "byte");
|
||||
primitiveValueMap.put("Byte", "byte");
|
||||
|
||||
}
|
||||
|
||||
public static Map<String, String> primitiveObjectMap = new HashMap<String, String>();
|
||||
@@ -75,6 +78,8 @@ public class PHPDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
primitiveObjectMap.put("Date", "string");
|
||||
primitiveObjectMap.put("date", "string");
|
||||
primitiveObjectMap.put("java.util.Date", "string");
|
||||
primitiveObjectMap.put("Byte", "byte");
|
||||
|
||||
}
|
||||
|
||||
private NamingPolicyProvider nameGenerator = new CamelCaseNamingPolicyProvider();
|
||||
@@ -102,6 +107,10 @@ public class PHPDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
return "array<"+nameGenerator.applyClassNamingPolicy(typeClass)+">";
|
||||
}
|
||||
|
||||
public String getArrayReturnTypeSignature(String typeClass) {
|
||||
return "array<"+nameGenerator.applyClassNamingPolicy(typeClass)+">";
|
||||
}
|
||||
|
||||
public String generateListInitialization(String typeClass) {
|
||||
return " array()";
|
||||
}
|
||||
@@ -114,6 +123,10 @@ public class PHPDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
return " array()";
|
||||
}
|
||||
|
||||
public String generateArrayInitialization(String typeClass) {
|
||||
return " array()";
|
||||
}
|
||||
|
||||
public List<String> getListIncludes() {
|
||||
List<String> imports = new ArrayList<String>();
|
||||
return imports;
|
||||
|
||||
@@ -49,6 +49,9 @@ public class PythonDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
primitiveValueMap.put("date", "str");
|
||||
primitiveValueMap.put("Double", "float");
|
||||
primitiveValueMap.put("double", "float");
|
||||
primitiveValueMap.put("Byte", "byte");
|
||||
primitiveValueMap.put("byte", "byte");
|
||||
|
||||
}
|
||||
|
||||
public static Map<String, String> primitiveObjectMap = new HashMap<String, String>();
|
||||
@@ -75,6 +78,8 @@ public class PythonDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
primitiveObjectMap.put("Date", "str");
|
||||
primitiveObjectMap.put("date", "str");
|
||||
primitiveObjectMap.put("java.util.Date", "str");
|
||||
primitiveObjectMap.put("byte", "Byte");
|
||||
|
||||
}
|
||||
|
||||
private NamingPolicyProvider nameGenerator = new CamelCaseNamingPolicyProvider();
|
||||
@@ -102,6 +107,10 @@ public class PythonDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
return "set<"+nameGenerator.applyClassNamingPolicy(typeClass)+">";
|
||||
}
|
||||
|
||||
public String getArrayReturnTypeSignature(String typeClass) {
|
||||
return getListReturnTypeSignature(typeClass);
|
||||
}
|
||||
|
||||
public String generateListInitialization(String typeClass) {
|
||||
return " list()";
|
||||
}
|
||||
@@ -110,6 +119,10 @@ public class PythonDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
return " dict()";
|
||||
}
|
||||
|
||||
public String generateArrayInitialization(String typeClass) {
|
||||
return " list()";
|
||||
}
|
||||
|
||||
public String generateSetInitialization(String typeClass) {
|
||||
return " set()";
|
||||
}
|
||||
@@ -152,7 +165,10 @@ public class PythonDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
}else if (type.startsWith("Set[")) {
|
||||
classShortName = type.substring(4, type.length()-1);
|
||||
classShortName = getClassType(classShortName, true);
|
||||
}else if (type.equalsIgnoreCase("ok")) {
|
||||
}else if (type.startsWith("Array[")) {
|
||||
classShortName = type.substring(6, type.length()-1);
|
||||
classShortName = getClassType(classShortName, true);
|
||||
}else if (type.equalsIgnoreCase("ok")) {
|
||||
classShortName = "void";
|
||||
}else{
|
||||
classShortName = getClassType(type, true);
|
||||
@@ -193,7 +209,10 @@ public class PythonDataTypeMappingProvider implements DataTypeMappingProvider {
|
||||
}else if (type.startsWith("Set[")) {
|
||||
classShortName = type.substring(4, type.length()-1);
|
||||
classShortName = "set<"+ getClassName(classShortName, true) +">";
|
||||
}else{
|
||||
}else if (type.startsWith("Array[")) {
|
||||
classShortName = type.substring(6, type.length()-1);
|
||||
classShortName = "list<"+ getClassName(classShortName, true) +">";
|
||||
}else{
|
||||
classShortName = getClassName(type, true);
|
||||
}
|
||||
return classShortName;
|
||||
|
||||
@@ -57,6 +57,7 @@ object RubyDataTypeMappingProvider {
|
||||
"java.lang.Float" -> "Float",
|
||||
"Date" -> "Date",
|
||||
"date" -> "Date",
|
||||
"byte" -> "Byte",
|
||||
"java.util.Date" -> "Date")
|
||||
}
|
||||
|
||||
@@ -74,6 +75,10 @@ class RubyDataTypeMappingProvider extends DataTypeMappingProvider {
|
||||
return "List[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||
}
|
||||
|
||||
def getArrayReturnTypeSignature(typeClass: String): String = {
|
||||
return "List[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||
}
|
||||
|
||||
def getMapReturnTypeSignature(typeClass: String): String = {
|
||||
return "Map[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||
}
|
||||
@@ -96,6 +101,10 @@ class RubyDataTypeMappingProvider extends DataTypeMappingProvider {
|
||||
return " new HashSet[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||
}
|
||||
|
||||
def generateArrayInitialization(typeClass: String): String = {
|
||||
return generateListInitialization(typeClass)
|
||||
}
|
||||
|
||||
def getListIncludes(): java.util.List[String] = {
|
||||
List("scala.collection.mutable.ListBuffer")
|
||||
}
|
||||
@@ -130,6 +139,9 @@ class RubyDataTypeMappingProvider extends DataTypeMappingProvider {
|
||||
} else if (inputType.startsWith("Set[")) {
|
||||
classShortName = inputType.substring(4, inputType.length() - 1)
|
||||
classShortName = getClassType(classShortName, true)
|
||||
} else if (inputType.startsWith("Array[")) {
|
||||
classShortName = inputType.substring(6, inputType.length() - 1)
|
||||
classShortName = getClassType(classShortName, true)
|
||||
} else if (inputType.equalsIgnoreCase("ok")) {
|
||||
classShortName = ""
|
||||
} else {
|
||||
@@ -171,7 +183,11 @@ class RubyDataTypeMappingProvider extends DataTypeMappingProvider {
|
||||
} else if (input.startsWith("Set[")) {
|
||||
classShortName = input.substring(4, input.length() - 1);
|
||||
classShortName = "Set[" + getClassName(classShortName, true) + "]";
|
||||
} else {
|
||||
}else if (input.startsWith("Array[")) {
|
||||
classShortName = input.substring(6, input.length() - 1);
|
||||
classShortName = "List[" + getClassName(classShortName, true) + "]";
|
||||
}
|
||||
else {
|
||||
classShortName = getClassName(input, true);
|
||||
}
|
||||
classShortName
|
||||
|
||||
@@ -37,7 +37,9 @@ object ScalaDataTypeMappingProvider {
|
||||
"float" -> "float",
|
||||
"Float" -> "float",
|
||||
"Date" -> "Date",
|
||||
"date" -> "Date")
|
||||
"date" -> "Date",
|
||||
"byte" -> "Byte",
|
||||
"Byte" -> "Byte")
|
||||
|
||||
val primitiveObjectMap = Map("string" -> "String",
|
||||
"String" -> "String",
|
||||
@@ -57,6 +59,7 @@ object ScalaDataTypeMappingProvider {
|
||||
"java.lang.Float" -> "Float",
|
||||
"Date" -> "Date",
|
||||
"date" -> "Date",
|
||||
"byte" -> "Byte",
|
||||
"java.util.Date" -> "Date")
|
||||
}
|
||||
|
||||
@@ -81,7 +84,11 @@ class ScalaDataTypeMappingProvider extends DataTypeMappingProvider {
|
||||
def getSetReturnTypeSignature(typeClass: String): String = {
|
||||
return "Set[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||
}
|
||||
|
||||
|
||||
def getArrayReturnTypeSignature(typeClass: String): String = {
|
||||
return "Array["+nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||
}
|
||||
|
||||
def generateVariableInitialization(typeClass:String):String = "=_"
|
||||
|
||||
def generateListInitialization(typeClass: String): String = {
|
||||
@@ -96,6 +103,10 @@ class ScalaDataTypeMappingProvider extends DataTypeMappingProvider {
|
||||
return " new HashSet[" + nameGenerator.applyClassNamingPolicy(typeClass) + "]";
|
||||
}
|
||||
|
||||
def generateArrayInitialization(typeClass: String): String = {
|
||||
return " null ";
|
||||
}
|
||||
|
||||
def getListIncludes(): java.util.List[String] = {
|
||||
List("scala.collection.mutable.ListBuffer")
|
||||
}
|
||||
@@ -130,7 +141,10 @@ class ScalaDataTypeMappingProvider extends DataTypeMappingProvider {
|
||||
} else if (inputType.startsWith("Set[")) {
|
||||
classShortName = inputType.substring(4, inputType.length() - 1)
|
||||
classShortName = getClassType(classShortName, true)
|
||||
} else if (inputType.equalsIgnoreCase("ok")) {
|
||||
}else if (inputType.startsWith("Array[")) {
|
||||
classShortName = inputType.substring(6, inputType.length() - 1)
|
||||
classShortName = getClassType(classShortName, true)
|
||||
}else if (inputType.equalsIgnoreCase("ok")) {
|
||||
classShortName = ""
|
||||
} else {
|
||||
classShortName = getClassType(inputType, true)
|
||||
@@ -171,6 +185,9 @@ class ScalaDataTypeMappingProvider extends DataTypeMappingProvider {
|
||||
} else if (input.startsWith("Set[")) {
|
||||
classShortName = input.substring(4, input.length() - 1);
|
||||
classShortName = "Set[" + getClassName(classShortName, true) + "]";
|
||||
} else if (input.startsWith("Array[")) {
|
||||
classShortName = input.substring(6, input.length() - 1);
|
||||
classShortName = getClassName(classShortName, true) + "[]";
|
||||
} else {
|
||||
classShortName = getClassName(input, true);
|
||||
}
|
||||
|
||||
@@ -190,7 +190,22 @@ public class ModelField {
|
||||
fieldDefinition.setName(this.getName());
|
||||
}
|
||||
|
||||
}else if (type.startsWith("Map[")) {
|
||||
}else if(type.startsWith("Array[")){
|
||||
fieldDefinition.getImportDefinitions().addAll(dataTypeMapper.getSetIncludes());
|
||||
String entryType = type.substring(6, type.length()-1);
|
||||
entryType = dataTypeMapper.getClassType(entryType, true);
|
||||
fieldDefinition.setHasPrimitiveType(dataTypeMapper.isPrimitiveType(entryType));
|
||||
fieldDefinition.setHasArrayResponse(true);
|
||||
String returnType = dataTypeMapper.getArrayReturnTypeSignature(entryType);
|
||||
fieldDefinition.setReturnType(returnType);
|
||||
fieldDefinition.setInitialization(" = " + dataTypeMapper.generateArrayInitialization(entryType));
|
||||
if(this.getWrapperName() != null){
|
||||
fieldDefinition.setName(this.getWrapperName());
|
||||
}else{
|
||||
fieldDefinition.setName(this.getName());
|
||||
}
|
||||
|
||||
}else if (type.startsWith("Map[")) {
|
||||
fieldDefinition.getImportDefinitions().addAll(dataTypeMapper.getMapIncludes());
|
||||
String keyClass, entryClass = "";
|
||||
String entryType = type.substring(4, type.length()-1);
|
||||
|
||||
Reference in New Issue
Block a user