updated samples

This commit is contained in:
Tony Tam
2015-02-05 11:35:13 -08:00
parent 2f16ee3b29
commit f7c6810757
38 changed files with 3025 additions and 24 deletions

View File

@@ -7,9 +7,14 @@ import com.wordnik.swagger.util.Json;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
public class DefaultCodegen {
Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class);
protected String outputFolder = "";
protected Set<String> defaultIncludes = new HashSet<String>();
protected Map<String, String> typeMapping = new HashMap<String, String>();
@@ -375,7 +380,7 @@ public class DefaultCodegen {
Property prop = impl.getProperties().get(key);
if(prop == null) {
System.out.println("null property for " + key);
LOGGER.warn("null property for " + key);
}
else {
CodegenProperty cp = fromProperty(key, prop);
@@ -422,7 +427,7 @@ public class DefaultCodegen {
public CodegenProperty fromProperty(String name, Property p) {
if(p == null) {
System.out.println("unexpected missing property for name " + null);
LOGGER.error("unexpected missing property for name " + null);
return null;
}
CodegenProperty property = CodegenModelFactory.newInstance(CodegenModelType.PROPERTY);
@@ -481,8 +486,7 @@ public class DefaultCodegen {
ArrayProperty ap = (ArrayProperty) p;
CodegenProperty cp = fromProperty("inner", ap.getItems());
if(cp == null) {
System.out.println("skipping invalid property:");
Json.prettyPrint(p);
LOGGER.warn("skipping invalid property " + Json.pretty(p));
}
else {
property.baseType = getSwaggerType(p);
@@ -540,7 +544,7 @@ public class DefaultCodegen {
}
}
operationId = builder.toString();
System.out.println("generated operationId " + operationId);
LOGGER.warn("generated operationId " + operationId);
}
op.path = path;
op.operationId = operationId;
@@ -741,7 +745,7 @@ public class DefaultCodegen {
if("array".equals(qp.getType())) {
Property inner = qp.getItems();
if(inner == null) {
System.out.println("warning! No inner type supplied for array parameter \"" + qp.getName() + "\", using String");
LOGGER.warn("warning! No inner type supplied for array parameter \"" + qp.getName() + "\", using String");
inner = new StringProperty().description("//TODO automatically added by swagger-codegen");
}
property = new ArrayProperty(inner);
@@ -753,7 +757,7 @@ public class DefaultCodegen {
else
property = PropertyBuilder.build(qp.getType(), qp.getFormat(), null);
if(property == null) {
System.out.println("warning! Property type \"" + qp.getType() + "\" not found for parameter \"" + param.getName() + "\", using String");
LOGGER.warn("warning! Property type \"" + qp.getType() + "\" not found for parameter \"" + param.getName() + "\", using String");
property = new StringProperty().description("//TODO automatically added by swagger-codegen. Type was " + qp.getType() + " but not supported");
}
CodegenProperty model = fromProperty(qp.getName(), property);

View File

@@ -10,8 +10,8 @@ import java.util.*;
import java.io.File;
public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConfig {
protected String invokerPackage = "com.wordnik.api";
protected String groupId = "com.wordnik";
protected String invokerPackage = "io.swagger.api";
protected String groupId = "io.swagger";
protected String artifactId = "swagger-server";
protected String artifactVersion = "1.0.0";
protected String sourceFolder = "src/main/java";
@@ -31,8 +31,8 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
modelTemplateFiles.put("model.mustache", ".java");
apiTemplateFiles.put("api.mustache", ".java");
templateDir = "JavaJaxRS";
apiPackage = "com.wordnik.api";
modelPackage = "com.wordnik.model";
apiPackage = "io.swagger.api";
modelPackage = "io.swagger.model";
additionalProperties.put("invokerPackage", invokerPackage);
additionalProperties.put("groupId", groupId);
@@ -66,6 +66,22 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
);
}
@Override
public String getTypeDeclaration(Property p) {
if(p instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) p;
Property inner = ap.getItems();
return getSwaggerType(p) + "<" + getTypeDeclaration(inner) + ">";
}
else if (p instanceof MapProperty) {
MapProperty mp = (MapProperty) p;
Property inner = mp.getAdditionalProperties();
return getTypeDeclaration(inner);
}
return super.getTypeDeclaration(p);
}
@Override
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
String basePath = resourcePath;