added better enum support

This commit is contained in:
Tony Tam 2015-02-15 22:05:45 -08:00
parent ffe5353987
commit 3b501f4134
4 changed files with 14 additions and 8 deletions

View File

@ -3,7 +3,7 @@ package com.wordnik.swagger.codegen;
import java.util.*;
public class CodegenProperty {
public String baseName, complexType, getter, setter, description, datatype,
public String baseName, complexType, getter, setter, description, datatype, datatypeWithEnum,
name, min, max, defaultValue, baseType, containerType;
/** maxLength validation for strings, see http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.2.1 */

View File

@ -480,9 +480,14 @@ public class DefaultCodegen {
}
}
property.datatype = property.isEnum
? StringUtils.capitalize(property.name) + "Enum"
: getTypeDeclaration(p);
property.datatype = getTypeDeclaration(p);
// this can cause issues for clients which don't support enums
if(property.isEnum)
property.datatypeWithEnum = StringUtils.capitalize(property.name) + "Enum";
else
property.datatypeWithEnum = property.datatype;
property.baseType = getSwaggerType(p);
if(p instanceof ArrayProperty) {

View File

@ -317,14 +317,14 @@ public Map<String, Object> processOperations(CodegenConfig config, String tag, L
operations.put("operations", objs);
operations.put("package", config.apiPackage());
Set<String> allImports = new HashSet<String>();
Set<String> allImports = new LinkedHashSet<String>();
for(CodegenOperation op: ops) {
allImports.addAll(op.imports);
}
List<Map<String, String>> imports = new ArrayList<Map<String, String>>();
for(String i: allImports) {
Map<String, String> im = new HashMap<String, String>();
Map<String, String> im = new LinkedHashMap<String, String>();
String m = config.importMapping().get(i);
if(m == null)
m = config.toModelImport(i);
@ -344,7 +344,7 @@ public Map<String, Object> processOperations(CodegenConfig config, String tag, L
objs.put("package", config.modelPackage());
List<Object> models = new ArrayList<Object>();
List<Object> model = new ArrayList<Object>();
Set<String> allImports = new HashSet<String>();
Set<String> allImports = new LinkedHashSet<String>();
for(String key: definitions.keySet()) {
Model mm = definitions.get(key);
CodegenModel cm = config.fromModel(key, mm);
@ -357,7 +357,7 @@ public Map<String, Object> processOperations(CodegenConfig config, String tag, L
List<Map<String, String>> imports = new ArrayList<Map<String, String>>();
for(String i: allImports) {
Map<String, String> im = new HashMap<String, String>();
Map<String, String> im = new LinkedHashMap<String, String>();
String m = config.importMapping().get(i);
if(m == null)
m = config.toModelImport(i);

View File

@ -24,6 +24,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
public PhpClientCodegen() {
super();
modelPackage = "models";
outputFolder = "generated-code/php";
modelTemplateFiles.put("model.mustache", ".php");
apiTemplateFiles.put("api.mustache", ".php");