forked from loafle/openapi-generator-original
Merge branch 'master' into java-docs
Conflicts: modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java samples/client/petstore/java/default/pom.xml samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Animal.java samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Cat.java samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Dog.java samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Name.java samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Name.java samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Cat.java samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Dog.java samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Name.java samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/StringUtil.java samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Model200Response.java samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/ModelReturn.java samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/model/Name.java samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/StringUtil.java samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/Model200Response.java samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/ModelReturn.java samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/model/Name.java samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/StringUtil.java samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/Model200Response.java samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/ModelReturn.java samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/model/Name.java
This commit is contained in:
@@ -15,7 +15,7 @@ public class CodegenOperation {
|
||||
isListContainer, isMultipart, hasMore = Boolean.TRUE,
|
||||
isResponseBinary = Boolean.FALSE, hasReference = Boolean.FALSE;
|
||||
public String path, operationId, returnType, httpMethod, returnBaseType,
|
||||
returnContainer, summary, notes, baseName, defaultResponse, discriminator;
|
||||
returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse, discriminator;
|
||||
public List<Map<String, String>> consumes, produces;
|
||||
public CodegenParameter bodyParam;
|
||||
public List<CodegenParameter> allParams = new ArrayList<CodegenParameter>();
|
||||
|
||||
@@ -9,7 +9,7 @@ public class CodegenParameter {
|
||||
public Boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
|
||||
isCookieParam, isBodyParam, hasMore, isContainer,
|
||||
secondaryParam, isCollectionFormatMulti, isPrimitiveType;
|
||||
public String baseName, paramName, dataType, datatypeWithEnum, collectionFormat, description, baseType, defaultValue;
|
||||
public String baseName, paramName, dataType, datatypeWithEnum, collectionFormat, description, unescapedDescription, baseType, defaultValue;
|
||||
public String example; // example value (x-example)
|
||||
public String jsonSchema;
|
||||
public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime;
|
||||
|
||||
@@ -32,6 +32,7 @@ public class CodegenProperty {
|
||||
public Boolean exclusiveMinimum;
|
||||
public Boolean exclusiveMaximum;
|
||||
public Boolean hasMore, required, secondaryParam;
|
||||
public Boolean hasMoreNonReadOnly; // for model constructor, true if next properyt is not readonly
|
||||
public Boolean isPrimitiveType, isContainer, isNotContainer;
|
||||
public Boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime;
|
||||
public Boolean isListContainer, isMapContainer;
|
||||
@@ -63,6 +64,7 @@ public class CodegenProperty {
|
||||
result = prime * result + ((exclusiveMinimum == null) ? 0 : exclusiveMinimum.hashCode());
|
||||
result = prime * result + ((getter == null) ? 0 : getter.hashCode());
|
||||
result = prime * result + ((hasMore == null) ? 0 : hasMore.hashCode());
|
||||
result = prime * result + ((hasMoreNonReadOnly == null) ? 0 : hasMoreNonReadOnly.hashCode());
|
||||
result = prime * result + ((isContainer == null) ? 0 : isContainer.hashCode());
|
||||
result = prime * result + (isEnum ? 1231 : 1237);
|
||||
result = prime * result + ((isNotContainer == null) ? 0 : isNotContainer.hashCode());
|
||||
|
||||
@@ -2,55 +2,22 @@ package io.swagger.codegen;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import io.swagger.codegen.examples.ExampleGenerator;
|
||||
import io.swagger.models.ArrayModel;
|
||||
import io.swagger.models.ComposedModel;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.RefModel;
|
||||
import io.swagger.models.Response;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.auth.ApiKeyAuthDefinition;
|
||||
import io.swagger.models.auth.BasicAuthDefinition;
|
||||
import io.swagger.models.auth.In;
|
||||
import io.swagger.models.auth.OAuth2Definition;
|
||||
import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.CookieParameter;
|
||||
import io.swagger.models.parameters.FormParameter;
|
||||
import io.swagger.models.parameters.HeaderParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.parameters.PathParameter;
|
||||
import io.swagger.models.parameters.QueryParameter;
|
||||
import io.swagger.models.parameters.SerializableParameter;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.auth.*;
|
||||
import io.swagger.models.parameters.*;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.models.properties.PropertyBuilder.PropertyId;
|
||||
import io.swagger.util.Json;
|
||||
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -203,11 +170,7 @@ public class DefaultCodegen {
|
||||
@SuppressWarnings("static-method")
|
||||
public String escapeText(String input) {
|
||||
if (input != null) {
|
||||
input = input.trim(); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
String output = input.replaceAll("\n", "\\\\n");
|
||||
output = output.replace("\r", "\\r");
|
||||
output = output.replace("\"", "\\\"");
|
||||
return output;
|
||||
return StringEscapeUtils.escapeJava(input).replace("\\/", "/");
|
||||
}
|
||||
return input;
|
||||
}
|
||||
@@ -1162,6 +1125,24 @@ public class DefaultCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
if (p instanceof BaseIntegerProperty) {
|
||||
BaseIntegerProperty sp = (BaseIntegerProperty) p;
|
||||
property.isInteger = true;
|
||||
/*if (sp.getEnum() != null) {
|
||||
List<Integer> _enum = sp.getEnum();
|
||||
property._enum = new ArrayList<String>();
|
||||
for(Integer i : _enum) {
|
||||
property._enum.add(i.toString());
|
||||
}
|
||||
property.isEnum = true;
|
||||
|
||||
// legacy support
|
||||
Map<String, Object> allowableValues = new HashMap<String, Object>();
|
||||
allowableValues.put("values", _enum);
|
||||
property.allowableValues = allowableValues;
|
||||
}*/
|
||||
}
|
||||
|
||||
if (p instanceof IntegerProperty) {
|
||||
IntegerProperty sp = (IntegerProperty) p;
|
||||
property.isInteger = true;
|
||||
@@ -1210,6 +1191,24 @@ public class DefaultCodegen {
|
||||
property.isByteArray = true;
|
||||
}
|
||||
|
||||
if (p instanceof DecimalProperty) {
|
||||
DecimalProperty sp = (DecimalProperty) p;
|
||||
property.isFloat = true;
|
||||
/*if (sp.getEnum() != null) {
|
||||
List<Double> _enum = sp.getEnum();
|
||||
property._enum = new ArrayList<String>();
|
||||
for(Double i : _enum) {
|
||||
property._enum.add(i.toString());
|
||||
}
|
||||
property.isEnum = true;
|
||||
|
||||
// legacy support
|
||||
Map<String, Object> allowableValues = new HashMap<String, Object>();
|
||||
allowableValues.put("values", _enum);
|
||||
property.allowableValues = allowableValues;
|
||||
}*/
|
||||
}
|
||||
|
||||
if (p instanceof DoubleProperty) {
|
||||
DoubleProperty sp = (DoubleProperty) p;
|
||||
property.isDouble = true;
|
||||
@@ -1398,6 +1397,7 @@ public class DefaultCodegen {
|
||||
op.path = path;
|
||||
op.operationId = toOperationId(operationId);
|
||||
op.summary = escapeText(operation.getSummary());
|
||||
op.unescapedNotes = operation.getDescription();
|
||||
op.notes = escapeText(operation.getDescription());
|
||||
op.tags = operation.getTags();
|
||||
op.hasConsumes = false;
|
||||
@@ -1579,33 +1579,20 @@ public class DefaultCodegen {
|
||||
|
||||
|
||||
allParams.add(p);
|
||||
// Issue #2561 (neilotoole) : Moved setting of is<Type>Param flags
|
||||
// from here to fromParameter().
|
||||
if (param instanceof QueryParameter) {
|
||||
p.isQueryParam = new Boolean(true);
|
||||
queryParams.add(p.copy());
|
||||
} else if (param instanceof PathParameter) {
|
||||
p.required = true;
|
||||
p.isPathParam = new Boolean(true);
|
||||
pathParams.add(p.copy());
|
||||
} else if (param instanceof HeaderParameter) {
|
||||
p.isHeaderParam = new Boolean(true);
|
||||
headerParams.add(p.copy());
|
||||
} else if (param instanceof CookieParameter) {
|
||||
p.isCookieParam = new Boolean(true);
|
||||
cookieParams.add(p.copy());
|
||||
} else if (param instanceof BodyParameter) {
|
||||
p.isBodyParam = new Boolean(true);
|
||||
p.isBinary = p.dataType.toLowerCase().startsWith("byte");
|
||||
bodyParam = p;
|
||||
bodyParams.add(p.copy());
|
||||
} else if (param instanceof FormParameter) {
|
||||
if ("file".equalsIgnoreCase(((FormParameter) param).getType())) {
|
||||
p.isFile = true;
|
||||
} else if("file".equals(p.baseType)){
|
||||
p.isFile = true;
|
||||
} else {
|
||||
p.notFile = true;
|
||||
}
|
||||
p.isFormParam = new Boolean(true);
|
||||
formParams.add(p.copy());
|
||||
}
|
||||
if (p.required == null || !p.required) {
|
||||
@@ -1720,6 +1707,7 @@ public class DefaultCodegen {
|
||||
CodegenParameter p = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
|
||||
p.baseName = param.getName();
|
||||
p.description = escapeText(param.getDescription());
|
||||
p.unescapedDescription = param.getDescription();
|
||||
if (param.getRequired()) {
|
||||
p.required = param.getRequired();
|
||||
}
|
||||
@@ -1933,6 +1921,33 @@ public class DefaultCodegen {
|
||||
// should be overridden by lang codegen
|
||||
setParameterExampleValue(p);
|
||||
|
||||
// Issue #2561 (neilotoole) : Set the is<TYPE>Param flags.
|
||||
// This code has been moved to here from #fromOperation
|
||||
// because these values should be set before calling #postProcessParameter.
|
||||
// See: https://github.com/swagger-api/swagger-codegen/issues/2561
|
||||
if (param instanceof QueryParameter) {
|
||||
p.isQueryParam = true;
|
||||
} else if (param instanceof PathParameter) {
|
||||
p.required = true;
|
||||
p.isPathParam = true;
|
||||
} else if (param instanceof HeaderParameter) {
|
||||
p.isHeaderParam = true;
|
||||
} else if (param instanceof CookieParameter) {
|
||||
p.isCookieParam = true;
|
||||
} else if (param instanceof BodyParameter) {
|
||||
p.isBodyParam = true;
|
||||
p.isBinary = p.dataType.toLowerCase().startsWith("byte");
|
||||
} else if (param instanceof FormParameter) {
|
||||
if ("file".equalsIgnoreCase(((FormParameter) param).getType())) {
|
||||
p.isFile = true;
|
||||
} else if("file".equals(p.baseType)){
|
||||
p.isFile = true;
|
||||
} else {
|
||||
p.notFile = true;
|
||||
}
|
||||
p.isFormParam = true;
|
||||
}
|
||||
|
||||
postProcessParameter(p);
|
||||
return p;
|
||||
}
|
||||
@@ -2257,9 +2272,12 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
private void addVars(CodegenModel m, List<CodegenProperty> vars, Map<String, Property> properties, Set<String> mandatory) {
|
||||
final int totalCount = properties.size();
|
||||
int count = 0;
|
||||
for (Map.Entry<String, Property> entry : properties.entrySet()) {
|
||||
// convert set to list so that we can access the next entry in the loop
|
||||
List<Map.Entry<String, Property>> propertyList = new ArrayList<Map.Entry<String, Property>>(properties.entrySet());
|
||||
final int totalCount = propertyList.size();
|
||||
for (int i = 0; i < totalCount; i++) {
|
||||
Map.Entry<String, Property> entry = propertyList.get(i);
|
||||
|
||||
final String key = entry.getKey();
|
||||
final Property prop = entry.getValue();
|
||||
|
||||
@@ -2273,13 +2291,19 @@ public class DefaultCodegen {
|
||||
// m.hasEnums to be set incorrectly if allProperties has enumerations but properties does not.
|
||||
m.hasEnums = true;
|
||||
}
|
||||
count++;
|
||||
if (count != totalCount) {
|
||||
|
||||
if (i+1 != totalCount) {
|
||||
cp.hasMore = true;
|
||||
// check the next entry to see if it's read only
|
||||
if (!Boolean.TRUE.equals(propertyList.get(i+1).getValue().getReadOnly())) {
|
||||
cp.hasMoreNonReadOnly = true; // next entry is not ready only
|
||||
}
|
||||
}
|
||||
|
||||
if (cp.isContainer != null) {
|
||||
addImport(m, typeMapping.get("array"));
|
||||
}
|
||||
|
||||
addImport(m, cp.baseType);
|
||||
addImport(m, cp.complexType);
|
||||
vars.add(cp);
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.swagger.models.auth.SecuritySchemeDefinition;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -16,7 +17,6 @@ import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
protected Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
|
||||
|
||||
@@ -148,7 +148,14 @@ public class CodegenConfigurator {
|
||||
}
|
||||
|
||||
public CodegenConfigurator setTemplateDir(String templateDir) {
|
||||
this.templateDir = new File(templateDir).getAbsolutePath();
|
||||
File f = new File(templateDir);
|
||||
|
||||
// check to see if the folder exists
|
||||
if (!(f != null && f.exists() && f.isDirectory())) {
|
||||
throw new IllegalArgumentException("Template directory " + templateDir + " does not exist.");
|
||||
}
|
||||
|
||||
this.templateDir = f.getAbsolutePath();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
"Int64",
|
||||
"Float",
|
||||
"Guid",
|
||||
"Stream", // not really a primitive, we include it to avoid model import
|
||||
"System.IO.Stream", // not really a primitive, we include it to avoid model import
|
||||
"Object")
|
||||
);
|
||||
|
||||
@@ -101,6 +101,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("binary", "byte[]");
|
||||
typeMapping.put("bytearray", "byte[]");
|
||||
typeMapping.put("boolean", "bool?");
|
||||
typeMapping.put("integer", "int?");
|
||||
typeMapping.put("float", "float?");
|
||||
@@ -109,7 +110,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
typeMapping.put("number", "double?");
|
||||
typeMapping.put("datetime", "DateTime?");
|
||||
typeMapping.put("date", "DateTime?");
|
||||
typeMapping.put("file", "Stream");
|
||||
typeMapping.put("file", "System.IO.Stream");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("list", "List");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.codegen.CodegenResponse;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.models.Operation;
|
||||
@@ -95,6 +96,25 @@ public abstract class AbstractJavaJAXRSServerCodegen extends JavaClientCodegen
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for ( CodegenOperation operation : ops ) {
|
||||
boolean isMultipartPost = false;
|
||||
List<Map<String, String>> consumes = operation.consumes;
|
||||
if(consumes != null) {
|
||||
for(Map<String, String> consume : consumes) {
|
||||
String mt = consume.get("mediaType");
|
||||
if(mt != null) {
|
||||
if(mt.startsWith("multipart/form-data")) {
|
||||
isMultipartPost = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(CodegenParameter parameter : operation.allParams) {
|
||||
if(isMultipartPost) {
|
||||
parameter.vendorExtensions.put("x-multipart", "true");
|
||||
}
|
||||
}
|
||||
|
||||
List<CodegenResponse> responses = operation.responses;
|
||||
if ( responses != null ) {
|
||||
for ( CodegenResponse resp : responses ) {
|
||||
|
||||
@@ -59,6 +59,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
typeMapping.put("ByteArray", "string");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PROPERTY_NAMING, CodegenConstants.MODEL_PROPERTY_NAMING_DESC).defaultValue("camelCase"));
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Scala client library base on Akka/Spray.";
|
||||
return "Generates a Scala client library (beta) base on Akka/Spray.";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.models.Model;
|
||||
@@ -34,6 +35,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class);
|
||||
private static final String NET45 = "v4.5";
|
||||
private static final String NET35 = "v3.5";
|
||||
private static final String UWP = "uwp";
|
||||
private static final String DATA_TYPE_WITH_ENUM_EXTENSION = "plainDatatypeWithEnum";
|
||||
|
||||
protected String packageGuid = "{" + java.util.UUID.randomUUID().toString().toUpperCase() + "}";
|
||||
@@ -44,10 +46,13 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
protected String packageCopyright = "No Copyright";
|
||||
protected String clientPackage = "IO.Swagger.Client";
|
||||
protected String localVariablePrefix = "";
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
|
||||
protected String targetFramework = NET45;
|
||||
protected String targetFrameworkNuget = "net45";
|
||||
protected boolean supportsAsync = Boolean.TRUE;
|
||||
protected boolean supportsUWP = Boolean.FALSE;
|
||||
|
||||
|
||||
protected final Map<String, String> frameworks;
|
||||
@@ -60,6 +65,9 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
modelTestTemplateFiles.put("model_test.mustache", ".cs");
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".cs");
|
||||
|
||||
modelDocTemplateFiles.put("model_doc.mustache", ".md");
|
||||
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||
|
||||
// C# client default
|
||||
setSourceFolder("src" + File.separator + "main" + File.separator + "csharp");
|
||||
|
||||
@@ -89,6 +97,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
frameworks = new ImmutableMap.Builder<String, String>()
|
||||
.put(NET35, ".NET Framework 3.5 compatible")
|
||||
.put(NET45, ".NET Framework 4.5+ compatible")
|
||||
.put(UWP, "Universal Windows Platform - beta support")
|
||||
.build();
|
||||
framework.defaultValue(this.targetFramework);
|
||||
framework.setEnum(frameworks);
|
||||
@@ -156,6 +165,13 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
if(additionalProperties.containsKey("supportsAsync")){
|
||||
additionalProperties.remove("supportsAsync");
|
||||
}
|
||||
} else if (UWP.equals(this.targetFramework)){
|
||||
setTargetFrameworkNuget("uwp");
|
||||
setSupportsAsync(Boolean.TRUE);
|
||||
setSupportsUWP(Boolean.TRUE);
|
||||
additionalProperties.put("supportsAsync", this.supportsUWP);
|
||||
additionalProperties.put("supportsUWP", this.supportsAsync);
|
||||
|
||||
} else {
|
||||
setTargetFrameworkNuget("net45");
|
||||
setSupportsAsync(Boolean.TRUE);
|
||||
@@ -209,17 +225,19 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
supportingFiles.add(new SupportingFile("compile.mustache", "", "compile.bat"));
|
||||
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "compile-mono.sh"));
|
||||
supportingFiles.add(new SupportingFile("packages.config.mustache", "vendor" + java.io.File.separator, "packages.config"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
|
||||
|
||||
if (optionalAssemblyInfoFlag) {
|
||||
supportingFiles.add(new SupportingFile("AssemblyInfo.mustache", packageFolder + File.separator + "Properties", "AssemblyInfo.cs"));
|
||||
}
|
||||
if (optionalProjectFileFlag) {
|
||||
supportingFiles.add(new SupportingFile("Project.mustache", packageFolder, clientPackage + ".csproj"));
|
||||
}
|
||||
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -290,20 +308,20 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objMap) {
|
||||
Map<String, Object> objs = super.postProcessModels(objMap);
|
||||
|
||||
Map<String, Object> objs = super.postProcessModels(objMap);
|
||||
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
Map<String, Object> allowableValues = var.allowableValues;
|
||||
|
||||
|
||||
// handle ArrayProperty
|
||||
if (var.items != null) {
|
||||
allowableValues = var.items.allowableValues;
|
||||
}
|
||||
|
||||
|
||||
if (allowableValues == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -339,12 +357,12 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
if (var.datatypeWithEnum != null) {
|
||||
var.vendorExtensions.put(DATA_TYPE_WITH_ENUM_EXTENSION, var.datatypeWithEnum.substring(0, var.datatypeWithEnum.length() - 1));
|
||||
}
|
||||
|
||||
|
||||
if (var.defaultValue != null) {
|
||||
String enumName = null;
|
||||
|
||||
|
||||
for (Map<String, String> enumVar : enumVars) {
|
||||
|
||||
|
||||
if (var.defaultValue.replace("\"", "").equals(enumVar.get("value"))) {
|
||||
enumName = enumVar.get("name");
|
||||
break;
|
||||
@@ -403,7 +421,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(removedChildEnum) {
|
||||
// If we removed an entry from this model's vars, we need to ensure hasMore is updated
|
||||
int count = 0, numVars = codegenProperties.size();
|
||||
@@ -453,4 +471,24 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
public void setSupportsAsync(Boolean supportsAsync){
|
||||
this.supportsAsync = supportsAsync;
|
||||
}
|
||||
|
||||
public void setSupportsUWP(Boolean supportsUWP){
|
||||
this.supportsUWP = supportsUWP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelDocFilename(String name) {
|
||||
return toModelFilename(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiDocFileFolder() {
|
||||
return (outputFolder + "/" + apiDocPath).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelDocFileFolder() {
|
||||
return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float",
|
||||
"Stream", // not really a primitive, we include it to avoid model import
|
||||
"System.IO.Stream", // not really a primitive, we include it to avoid model import
|
||||
"Object")
|
||||
);
|
||||
instantiationTypes.put("array", "List");
|
||||
@@ -76,7 +76,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
typeMapping.put("number", "double?");
|
||||
typeMapping.put("datetime", "DateTime?");
|
||||
typeMapping.put("date", "DateTime?");
|
||||
typeMapping.put("file", "Stream");
|
||||
typeMapping.put("file", "System.IO.Stream");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("list", "List");
|
||||
typeMapping.put("map", "Dictionary");
|
||||
|
||||
@@ -52,9 +52,8 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"bool",
|
||||
"num",
|
||||
"int",
|
||||
"float")
|
||||
"double")
|
||||
);
|
||||
instantiationTypes.put("array", "List");
|
||||
instantiationTypes.put("map", "Map");
|
||||
@@ -66,11 +65,11 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("int", "int");
|
||||
typeMapping.put("float", "num");
|
||||
typeMapping.put("float", "double");
|
||||
typeMapping.put("long", "int");
|
||||
typeMapping.put("short", "int");
|
||||
typeMapping.put("char", "String");
|
||||
typeMapping.put("double", "num");
|
||||
typeMapping.put("double", "double");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("integer", "int");
|
||||
typeMapping.put("Date", "DateTime");
|
||||
|
||||
@@ -25,6 +25,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
public static final String CONTROLLER_PACKAGE = "controllerPackage";
|
||||
public static final String DEFAULT_CONTROLLER = "defaultController";
|
||||
public static final String SUPPORT_PYTHON2= "supportPython2";
|
||||
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected int serverPort = 8080;
|
||||
@@ -105,11 +106,17 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
"",
|
||||
"README.md")
|
||||
);
|
||||
supportingFiles.add(new SupportingFile("__init__.mustache",
|
||||
"",
|
||||
"__init__.py")
|
||||
);
|
||||
|
||||
cliOptions.add(new CliOption(CONTROLLER_PACKAGE, "controller package").
|
||||
defaultValue("controllers"));
|
||||
cliOptions.add(new CliOption(DEFAULT_CONTROLLER, "default controller").
|
||||
defaultValue("default_controller"));
|
||||
cliOptions.add(new CliOption(SUPPORT_PYTHON2, "support python2").
|
||||
defaultValue("false"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,6 +131,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
this.controllerPackage = "controllers";
|
||||
additionalProperties.put(CONTROLLER_PACKAGE, this.controllerPackage);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(DEFAULT_CONTROLLER)) {
|
||||
this.defaultController = additionalProperties.get(DEFAULT_CONTROLLER).toString();
|
||||
}
|
||||
@@ -132,11 +140,19 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
additionalProperties.put(DEFAULT_CONTROLLER, this.defaultController);
|
||||
}
|
||||
|
||||
if (Boolean.TRUE.equals(additionalProperties.get(SUPPORT_PYTHON2))) {
|
||||
additionalProperties.put(SUPPORT_PYTHON2, Boolean.TRUE);
|
||||
}
|
||||
|
||||
if(!new java.io.File(controllerPackage + File.separator + defaultController + ".py").exists()) {
|
||||
supportingFiles.add(new SupportingFile("controller.mustache",
|
||||
controllerPackage,
|
||||
defaultController + ".py")
|
||||
);
|
||||
supportingFiles.add(new SupportingFile("__init__.mustache",
|
||||
controllerPackage,
|
||||
"__init__.py")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.swagger.codegen.*;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@@ -18,6 +19,8 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
protected String packageName = "swagger";
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
@@ -36,6 +39,10 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
outputFolder = "generated-code/go";
|
||||
modelTemplateFiles.put("model.mustache", ".go");
|
||||
apiTemplateFiles.put("api.mustache", ".go");
|
||||
|
||||
modelDocTemplateFiles.put("model_doc.mustache", ".md");
|
||||
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||
|
||||
templateDir = "go";
|
||||
|
||||
setReservedWordsLowerCase(
|
||||
@@ -79,11 +86,12 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "int32");
|
||||
typeMapping.put("long", "int64");
|
||||
typeMapping.put("number", "float32");
|
||||
typeMapping.put("float", "float32");
|
||||
typeMapping.put("double", "float64");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("string", "string");
|
||||
typeMapping.put("Date", "time.Time");
|
||||
typeMapping.put("date", "time.Time");
|
||||
typeMapping.put("DateTime", "time.Time");
|
||||
typeMapping.put("password", "string");
|
||||
typeMapping.put("File", "*os.File");
|
||||
@@ -91,6 +99,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// map binary to string as a workaround
|
||||
// the correct solution is to use []byte
|
||||
typeMapping.put("binary", "string");
|
||||
typeMapping.put("ByteArray", "string");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
importMapping.put("time.Time", "time");
|
||||
@@ -101,7 +110,6 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
.defaultValue("swagger"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Go package version.")
|
||||
.defaultValue("1.0.0"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,6 +132,9 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
|
||||
modelPackage = packageName;
|
||||
apiPackage = packageName;
|
||||
@@ -131,6 +142,9 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.go"));
|
||||
supportingFiles.add(new SupportingFile("api_client.mustache", "", "api_client.go"));
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,11 +168,11 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + packageName;
|
||||
return outputFolder + File.separator;
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + packageName;
|
||||
return outputFolder + File.separator;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -194,6 +208,13 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(toModelFilename(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
if (!StringUtils.isEmpty(modelNamePrefix)) {
|
||||
name = modelNamePrefix + "_" + name;
|
||||
}
|
||||
@@ -210,17 +231,68 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = "model_" + name; // e.g. return => ModelReturn (after camelize)
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
return underscore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// should be the same as the model name
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// e.g. PetApi.go => pet_api.go
|
||||
return underscore(name) + "_api";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Overrides postProcessParameter to add a vendor extension "x-exportParamName".
|
||||
* This is useful when paramName starts with a lowercase letter, but we need that
|
||||
* param to be exportable (starts with an Uppercase letter).
|
||||
*
|
||||
* @param parameter CodegenParameter object to be processed.
|
||||
*/
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter){
|
||||
|
||||
// Give the base class a chance to process
|
||||
super.postProcessParameter(parameter);
|
||||
|
||||
char firstChar = parameter.paramName.charAt(0);
|
||||
|
||||
if (Character.isUpperCase(firstChar)) {
|
||||
// First char is already uppercase, just use paramName.
|
||||
parameter.vendorExtensions.put("x-exportParamName", parameter.paramName);
|
||||
|
||||
}
|
||||
|
||||
// It's a lowercase first char, let's convert it to uppercase
|
||||
StringBuilder sb = new StringBuilder(parameter.paramName);
|
||||
sb.setCharAt(0, Character.toUpperCase(firstChar));
|
||||
parameter.vendorExtensions.put("x-exportParamName", sb.toString());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String apiDocFileFolder() {
|
||||
return (outputFolder + "/" + apiDocPath).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelDocFileFolder() {
|
||||
return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelDocFilename(String name) {
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiDocFilename(String name) {
|
||||
return toApiName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if(p instanceof ArrayProperty) {
|
||||
@@ -332,5 +404,4 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setPackageVersion(String packageVersion) {
|
||||
this.packageVersion = packageVersion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,345 +1,514 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Swagger;
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class HaskellServantCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// source folder where to write the files
|
||||
protected String sourceFolder = "src";
|
||||
protected String apiVersion = "0.0.1";
|
||||
// source folder where to write the files
|
||||
protected String sourceFolder = "src";
|
||||
protected String apiVersion = "0.0.1";
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the generator
|
||||
* to select the library with the -l flag.
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
public String getName() {
|
||||
return "haskell-servant";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
public String getHelp() {
|
||||
return "Generates a HaskellServantCodegen library.";
|
||||
}
|
||||
|
||||
public HaskellServantCodegen() {
|
||||
super();
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/HaskellServantCodegen";
|
||||
// How to encode special characters like $
|
||||
// They are translated to words like "Dollar" and prefixed with '
|
||||
// Then translated back during JSON encoding and decoding
|
||||
private Map<Character, String> specialCharReplacements = new HashMap<Character, String>();
|
||||
|
||||
/**
|
||||
* Models. You can write model files using the modelTemplateFiles map.
|
||||
* if you want to create one template for file, you can do so here.
|
||||
* for multiple files for model, just put another entry in the `modelTemplateFiles` with
|
||||
* a different extension
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
modelTemplateFiles.put(
|
||||
"model.mustache", // the template to use
|
||||
".hs"); // the extension for each file to write
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Api classes. You can write classes for each Api file with the apiTemplateFiles map.
|
||||
* as with models, add multiple entries with different extensions for multiple files per
|
||||
* class
|
||||
* Configures a friendly name for the generator. This will be used by the generator
|
||||
* to select the library with the -l flag.
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
apiTemplateFiles.put(
|
||||
"api.mustache", // the template to use
|
||||
".hs"); // the extension for each file to write
|
||||
public String getName() {
|
||||
return "haskell";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
public String getHelp() {
|
||||
return "Generates a Haskell server and client library.";
|
||||
}
|
||||
|
||||
public HaskellServantCodegen() {
|
||||
super();
|
||||
|
||||
// Initialize special characters
|
||||
specialCharReplacements.put('$', "Dollar");
|
||||
specialCharReplacements.put('^', "Caret");
|
||||
specialCharReplacements.put('|', "Pipe");
|
||||
specialCharReplacements.put('=', "Equal");
|
||||
specialCharReplacements.put('*', "Star");
|
||||
specialCharReplacements.put('-', "Dash");
|
||||
specialCharReplacements.put('&', "Ampersand");
|
||||
specialCharReplacements.put('%', "Percent");
|
||||
specialCharReplacements.put('#', "Hash");
|
||||
specialCharReplacements.put('@', "At");
|
||||
specialCharReplacements.put('!', "Exclamation");
|
||||
specialCharReplacements.put('+', "Plus");
|
||||
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/haskell-servant";
|
||||
|
||||
/*
|
||||
* Template Location. This is the location which templates will be read from. The generator
|
||||
* will use the resource stream to attempt to read the templates.
|
||||
*/
|
||||
embeddedTemplateDir = templateDir = "haskell-servant";
|
||||
embeddedTemplateDir = templateDir = "haskell-servant";
|
||||
|
||||
/**
|
||||
/*
|
||||
* Api Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
apiPackage = "Api";
|
||||
apiPackage = "API";
|
||||
|
||||
/**
|
||||
/*
|
||||
* Model Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
modelPackage = "Model";
|
||||
modelPackage = "Types";
|
||||
|
||||
/**
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
// from https://wiki.haskell.org/Keywords
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"as", "case", "of",
|
||||
"class", "data", // "data family", "data instance",
|
||||
"default", "deriving", // "deriving instance",
|
||||
"do",
|
||||
"forall", "foreign", "hiding",
|
||||
"id",
|
||||
"if", "then", "else",
|
||||
"import", "infix", "infixl", "infixr",
|
||||
"instance", "let", "in",
|
||||
"mdo", "module", "newtype",
|
||||
"proc", "qualified", "rec",
|
||||
"type", // "type family", "type instance",
|
||||
"where"
|
||||
)
|
||||
);
|
||||
// Haskell keywords and reserved function names, taken mostly from https://wiki.haskell.org/Keywords
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// Keywords
|
||||
"as", "case", "of",
|
||||
"class", "data", "family",
|
||||
"default", "deriving",
|
||||
"do", "forall", "foreign", "hiding",
|
||||
"if", "then", "else",
|
||||
"import", "infix", "infixl", "infixr",
|
||||
"instance", "let", "in",
|
||||
"mdo", "module", "newtype",
|
||||
"proc", "qualified", "rec",
|
||||
"type", "where"
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
/*
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
|
||||
/**
|
||||
/*
|
||||
* Supporting Files. You can write single files for the generator with the
|
||||
* entire object tree available. If the input file has a suffix of `.mustache
|
||||
* it will be processed by the template engine. Otherwise, it will be copied
|
||||
*/
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("stack.mustache", "", "stack.yaml"));
|
||||
supportingFiles.add(new SupportingFile("haskell-servant-codegen.mustache", "", "haskell-servant-codegen.cabal"));
|
||||
supportingFiles.add(new SupportingFile("Setup.mustache", "", "Setup.hs"));
|
||||
supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
|
||||
supportingFiles.add(new SupportingFile("Apis.mustache", "lib", "Apis.hs"));
|
||||
supportingFiles.add(new SupportingFile("Utils.mustache", "lib", "Utils.hs"));
|
||||
supportingFiles.add(new SupportingFile("Client.mustache", "client", "Main.hs"));
|
||||
supportingFiles.add(new SupportingFile("Server.mustache", "server", "Main.hs"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("stack.mustache", "", "stack.yaml"));
|
||||
supportingFiles.add(new SupportingFile("Setup.mustache", "", "Setup.hs"));
|
||||
|
||||
/**
|
||||
/*
|
||||
* Language Specific Primitives. These types will not trigger imports by
|
||||
* the client generator
|
||||
*/
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"Bool",
|
||||
"String",
|
||||
"Int",
|
||||
"Integer",
|
||||
"Float",
|
||||
"Char",
|
||||
"Double",
|
||||
"List",
|
||||
"FilePath"
|
||||
)
|
||||
);
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"Bool",
|
||||
"String",
|
||||
"Int",
|
||||
"Integer",
|
||||
"Float",
|
||||
"Char",
|
||||
"Double",
|
||||
"List",
|
||||
"FilePath"
|
||||
)
|
||||
);
|
||||
|
||||
typeMapping.clear();
|
||||
// typeMapping.put("enum", "NSString");
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("set", "Set");
|
||||
typeMapping.put("boolean", "Bool");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("int", "Int");
|
||||
typeMapping.put("long", "Integer");
|
||||
typeMapping.put("float", "Float");
|
||||
// typeMapping.put("byte", "Byte");
|
||||
typeMapping.put("short", "Int");
|
||||
typeMapping.put("char", "Char");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("DateTime", "Integer");
|
||||
// typeMapping.put("object", "Map");
|
||||
typeMapping.put("file", "FilePath");
|
||||
typeMapping.clear();
|
||||
typeMapping.put("array", "List");
|
||||
typeMapping.put("set", "Set");
|
||||
typeMapping.put("boolean", "Bool");
|
||||
typeMapping.put("string", "Text");
|
||||
typeMapping.put("int", "Int");
|
||||
typeMapping.put("long", "Integer");
|
||||
typeMapping.put("short", "Int");
|
||||
typeMapping.put("char", "Char");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("double", "Double");
|
||||
typeMapping.put("DateTime", "Integer");
|
||||
typeMapping.put("file", "FilePath");
|
||||
typeMapping.put("number", "Double");
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("any", "Value");
|
||||
|
||||
importMapping.clear();
|
||||
importMapping.put("Map", "qualified Data.Map as Map");
|
||||
importMapping.clear();
|
||||
importMapping.put("Map", "qualified Data.Map as Map");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
}
|
||||
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||
* those terms here. This logic is only called if a variable matches the reseved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return name + "_";
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separatorChar + "lib" + File.separatorChar + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write api files. You can use the apiPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separatorChar + "lib" + File.separatorChar + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||
* types. There is typically special handling for different property types
|
||||
*
|
||||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if(p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
}
|
||||
else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
return "Map.Map String " + getTypeDeclaration(inner);
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - swagger type conversion. This is used to map swagger types in a `Property` into
|
||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||
*
|
||||
* @return a string value of the type or complex model for this property
|
||||
* @see io.swagger.models.properties.Property
|
||||
*/
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
String type = null;
|
||||
if(typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if(languageSpecificPrimitives.contains(type))
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||
* those terms here. This logic is only called if a variable matches the reseved words
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return name + "_";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
// From the title, compute a reasonable name for the package and the API
|
||||
String title = swagger.getInfo().getTitle();
|
||||
|
||||
// Drop any API suffix
|
||||
if(title == null) {
|
||||
title = "Swagger";
|
||||
} else {
|
||||
title = title.trim();
|
||||
if (title.toUpperCase().endsWith("API")) {
|
||||
title = title.substring(0, title.length() - 3);
|
||||
}
|
||||
}
|
||||
|
||||
String[] words = title.split(" ");
|
||||
|
||||
// The package name is made by appending the lowercased words of the title interspersed with dashes
|
||||
List<String> wordsLower = new ArrayList<String>();
|
||||
for (String word : words) {
|
||||
wordsLower.add(word.toLowerCase());
|
||||
}
|
||||
String cabalName = joinStrings("-", wordsLower);
|
||||
|
||||
// The API name is made by appending the capitalized words of the title
|
||||
List<String> wordsCaps = new ArrayList<String>();
|
||||
for (String word : words) {
|
||||
wordsCaps.add(word.substring(0, 1).toUpperCase() + word.substring(1));
|
||||
}
|
||||
String apiName = joinStrings("", wordsCaps);
|
||||
|
||||
// Set the filenames to write for the API
|
||||
supportingFiles.add(new SupportingFile("haskell-servant-codegen.mustache", "", cabalName + ".cabal"));
|
||||
supportingFiles.add(new SupportingFile("API.mustache", "lib/" + apiName, "API.hs"));
|
||||
supportingFiles.add(new SupportingFile("Types.mustache", "lib/" + apiName, "Types.hs"));
|
||||
|
||||
|
||||
additionalProperties.put("title", apiName);
|
||||
additionalProperties.put("titleLower", apiName.substring(0, 1).toLowerCase() + apiName.substring(1));
|
||||
additionalProperties.put("package", cabalName);
|
||||
|
||||
// Due to the way servant resolves types, we need a high context stack limit
|
||||
additionalProperties.put("contextStackLimit", swagger.getPaths().size() * 2 + 300);
|
||||
|
||||
List<Map<String, Object>> replacements = new ArrayList<>();
|
||||
Object[] replacementChars = specialCharReplacements.keySet().toArray();
|
||||
for(int i = 0; i < replacementChars.length; i++) {
|
||||
Character c = (Character) replacementChars[i];
|
||||
Map<String, Object> o = new HashMap<>();
|
||||
o.put("char", Character.toString(c));
|
||||
o.put("replacement", "'" + specialCharReplacements.get(c));
|
||||
o.put("hasMore", i != replacementChars.length - 1);
|
||||
replacements.add(o);
|
||||
}
|
||||
additionalProperties.put("specialCharReplacements", replacements);
|
||||
|
||||
super.preprocessSwagger(swagger);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||
* types. There is typically special handling for different property types
|
||||
*
|
||||
* @return a string value used as the `dataType` field for model templates, `returnType` for api templates
|
||||
*/
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return "[" + getTypeDeclaration(inner) + "]";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
return "Map.Map String " + getTypeDeclaration(inner);
|
||||
}
|
||||
return fixModelChars(super.getTypeDeclaration(p));
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - swagger type conversion. This is used to map swagger types in a `Property` into
|
||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||
*
|
||||
* @return a string value of the type or complex model for this property
|
||||
* @see io.swagger.models.properties.Property
|
||||
*/
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if (languageSpecificPrimitives.contains(type))
|
||||
return toModelName(type);
|
||||
} else if(swaggerType == "object") {
|
||||
type = "Value";
|
||||
} else if(typeMapping.containsValue(swaggerType)) {
|
||||
type = swaggerType + "_";
|
||||
} else {
|
||||
type = swaggerType;
|
||||
}
|
||||
return toModelName(type);
|
||||
}
|
||||
else
|
||||
type = swaggerType;
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
private String capturePath(String path, List<CodegenParameter> pathParams) {
|
||||
for (CodegenParameter p : pathParams) {
|
||||
String pName = "{"+p.baseName+"}";
|
||||
if (path.indexOf(pName) >= 0) {
|
||||
path = path.replace(pName, "Capture " + "\""+p.baseName+"\" " + p.dataType);
|
||||
}
|
||||
@Override
|
||||
public String toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
Property additionalProperties2 = ap.getAdditionalProperties();
|
||||
String type = additionalProperties2.getType();
|
||||
if (null == type) {
|
||||
LOGGER.error("No Type defined for Additional Property " + additionalProperties2 + "\n" //
|
||||
+ "\tIn Property: " + p);
|
||||
}
|
||||
String inner = getSwaggerType(additionalProperties2);
|
||||
return "(Map.Map Text " + inner + ")";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
// Return only the inner type; the wrapping with QueryList is done
|
||||
// somewhere else, where we have access to the collection format.
|
||||
return inner;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private String queryPath(String path, List<CodegenParameter> queryParams) {
|
||||
for (CodegenParameter p : queryParams) {
|
||||
path += " :> QueryParam \"" + p.baseName + "\" " + p.dataType;
|
||||
|
||||
// Intersperse a separator string between a list of strings, like String.join.
|
||||
private String joinStrings(String sep, List<String> ss) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : ss) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(sep);
|
||||
}
|
||||
sb.append(s);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private String bodyPath(String path, List<CodegenParameter> bodyParams) {
|
||||
for (CodegenParameter p : bodyParams) {
|
||||
path += " :> ReqBody '[JSON] " + p.dataType;
|
||||
// Convert an HTTP path to a Servant route, including captured parameters.
|
||||
// For example, the path /api/jobs/info/{id}/last would become:
|
||||
// "api" :> "jobs" :> "info" :> Capture "id" IdType :> "last"
|
||||
// IdType is provided by the capture params.
|
||||
private List<String> pathToServantRoute(String path, List<CodegenParameter> pathParams) {
|
||||
// Map the capture params by their names.
|
||||
HashMap<String, String> captureTypes = new HashMap<String, String>();
|
||||
for (CodegenParameter param : pathParams) {
|
||||
captureTypes.put(param.baseName, param.dataType);
|
||||
}
|
||||
|
||||
// Cut off the leading slash, if it is present.
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
|
||||
// Convert the path into a list of servant route components.
|
||||
List<String> pathComponents = new ArrayList<String>();
|
||||
for (String piece : path.split("/")) {
|
||||
if (piece.startsWith("{") && piece.endsWith("}")) {
|
||||
String name = piece.substring(1, piece.length() - 1);
|
||||
pathComponents.add("Capture \"" + name + "\" " + captureTypes.get(name));
|
||||
} else {
|
||||
pathComponents.add("\"" + piece + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
// Intersperse the servant route pieces with :> to construct the final API type
|
||||
return pathComponents;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private String formPath(String path, List<CodegenParameter> formParams) {
|
||||
String names = "Form";
|
||||
for (CodegenParameter p : formParams) {
|
||||
if(p.dataType.equals("FilePath")){
|
||||
// file data processing
|
||||
}
|
||||
names += p.baseName;
|
||||
// Extract the arguments that are passed in the route path parameters
|
||||
private List<String> pathToClientType(String path, List<CodegenParameter> pathParams) {
|
||||
// Map the capture params by their names.
|
||||
HashMap<String, String> captureTypes = new HashMap<String, String>();
|
||||
for (CodegenParameter param : pathParams) {
|
||||
captureTypes.put(param.baseName, param.dataType);
|
||||
}
|
||||
|
||||
// Cut off the leading slash, if it is present.
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
|
||||
// Convert the path into a list of servant route components.
|
||||
List<String> type = new ArrayList<String>();
|
||||
for (String piece : path.split("/")) {
|
||||
if (piece.startsWith("{") && piece.endsWith("}")) {
|
||||
String name = piece.substring(1, piece.length() - 1);
|
||||
type.add(captureTypes.get(name));
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
if(formParams.size() > 0){
|
||||
path += " :> ReqBody '[FormUrlEncoded] " + names;
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) {
|
||||
CodegenOperation op = super.fromOperation(resourcePath, httpMethod, operation, definitions, swagger);
|
||||
|
||||
List<String> path = pathToServantRoute(op.path, op.pathParams);
|
||||
List<String> type = pathToClientType(op.path, op.pathParams);
|
||||
|
||||
// Query parameters appended to routes
|
||||
for (CodegenParameter param : op.queryParams) {
|
||||
String paramType = param.dataType;
|
||||
if(param.isListContainer != null && param.isListContainer) {
|
||||
paramType = makeQueryListType(paramType, param.collectionFormat);
|
||||
}
|
||||
path.add("QueryParam \"" + param.baseName + "\" " + paramType);
|
||||
type.add("Maybe " + param.dataType);
|
||||
}
|
||||
|
||||
// Either body or form data parameters appended to route
|
||||
// As far as I know, you cannot have two ReqBody routes.
|
||||
// Is it possible to have body params AND have form params?
|
||||
String bodyType = null;
|
||||
if (op.getHasBodyParam()) {
|
||||
for (CodegenParameter param : op.bodyParams) {
|
||||
path.add("ReqBody '[JSON] " + param.dataType);
|
||||
bodyType = param.dataType;
|
||||
}
|
||||
} else if(op.getHasFormParams()) {
|
||||
// Use the FormX data type, where X is the conglomerate of all things being passed
|
||||
String formName = "Form" + camelize(op.operationId);
|
||||
bodyType = formName;
|
||||
path.add("ReqBody '[FormUrlEncoded] " + formName);
|
||||
}
|
||||
if(bodyType != null) {
|
||||
type.add(bodyType);
|
||||
}
|
||||
|
||||
// Special headers appended to route
|
||||
for (CodegenParameter param : op.headerParams) {
|
||||
path.add("Header \"" + param.baseName + "\" " + param.dataType);
|
||||
|
||||
String paramType = param.dataType;
|
||||
if(param.isListContainer != null && param.isListContainer) {
|
||||
paramType = makeQueryListType(paramType, param.collectionFormat);
|
||||
}
|
||||
type.add("Maybe " + paramType);
|
||||
}
|
||||
|
||||
// Add the HTTP method and return type
|
||||
String returnType = op.returnType;
|
||||
if (returnType == null || returnType.equals("null")) {
|
||||
returnType = "()";
|
||||
}
|
||||
if (returnType.indexOf(" ") >= 0) {
|
||||
returnType = "(" + returnType + ")";
|
||||
}
|
||||
path.add("Verb '" + op.httpMethod.toUpperCase() + " 200 '[JSON] " + returnType);
|
||||
type.add("m " + returnType);
|
||||
|
||||
op.vendorExtensions.put("x-routeType", joinStrings(" :> ", path));
|
||||
op.vendorExtensions.put("x-clientType", joinStrings(" -> ", type));
|
||||
op.vendorExtensions.put("x-formName", "Form" + camelize(op.operationId));
|
||||
for(CodegenParameter param : op.formParams) {
|
||||
param.vendorExtensions.put("x-formPrefix", camelize(op.operationId, true));
|
||||
}
|
||||
return op;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private String headerPath(String path, List<CodegenParameter> headerParams) {
|
||||
for (CodegenParameter p : headerParams) {
|
||||
path += " :> Header \"" + p.baseName + "\" " + p.dataType;
|
||||
private String makeQueryListType(String type, String collectionFormat) {
|
||||
type = type.substring(1, type.length() - 1);
|
||||
switch(collectionFormat) {
|
||||
case "csv": return "(QueryList 'CommaSeparated (" + type + "))";
|
||||
case "tsv": return "(QueryList 'TabSeparated (" + type + "))";
|
||||
case "ssv": return "(QueryList 'SpaceSeparated (" + type + "))";
|
||||
case "pipes": return "(QueryList 'PipeSeparated (" + type + "))";
|
||||
case "multi": return "(QueryList 'MultiParamArray (" + type + "))";
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
private String filterReturnType(String rt) {
|
||||
if (rt == null || rt.equals("null")) {
|
||||
return "()";
|
||||
} else if (rt.indexOf(" ") >= 0) {
|
||||
return "(" + rt + ")";
|
||||
private String fixOperatorChars(String string) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (char c : string.toCharArray()) {
|
||||
if (specialCharReplacements.containsKey(c)) {
|
||||
sb.append("'");
|
||||
sb.append(specialCharReplacements.get(c));
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
return rt;
|
||||
}
|
||||
|
||||
private String addReturnPath(String path, String httpMethod, String returnType) {
|
||||
return path + " :> " + upperCaseFirst(httpMethod) + " '[JSON] " + filterReturnType(returnType);
|
||||
}
|
||||
|
||||
private String joinStrings(String sep, List<String> ss) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : ss) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(sep);
|
||||
}
|
||||
sb.append(s);
|
||||
// Remove characters from a string that do not belong in a model classname
|
||||
private String fixModelChars(String string) {
|
||||
return string.replace(".", "").replace("-", "");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String replacePathSplitter(String path) {
|
||||
String[] ps = path.replaceFirst("/", "").split("/", 0);
|
||||
List<String> rs = new ArrayList<String>();
|
||||
for (String p : ps) {
|
||||
if (p.indexOf("{") < 0) {
|
||||
rs.add("\"" + p + "\"");
|
||||
} else {
|
||||
rs.add(p);
|
||||
}
|
||||
// Override fromModel to create the appropriate model namings
|
||||
@Override
|
||||
public CodegenModel fromModel(String name, Model mod, Map<String, Model> allDefinitions) {
|
||||
CodegenModel model = super.fromModel(name, mod, allDefinitions);
|
||||
|
||||
// Clean up the class name to remove invalid characters
|
||||
model.classname = fixModelChars(model.classname);
|
||||
if(typeMapping.containsValue(model.classname)) {
|
||||
model.classname += "_";
|
||||
}
|
||||
|
||||
// From the model name, compute the prefix for the fields.
|
||||
String prefix = camelize(model.classname, true);
|
||||
for(CodegenProperty prop : model.vars) {
|
||||
prop.name = prefix + camelize(fixOperatorChars(prop.name));
|
||||
}
|
||||
|
||||
// Create newtypes for things with non-object types
|
||||
String dataOrNewtype = "data";
|
||||
String modelType = ((ModelImpl) mod).getType();
|
||||
if(modelType != "object" && typeMapping.containsKey(modelType)) {
|
||||
String newtype = typeMapping.get(modelType);
|
||||
model.vendorExtensions.put("x-customNewtype", newtype);
|
||||
}
|
||||
|
||||
// Provide the prefix as a vendor extension, so that it can be used in the ToJSON and FromJSON instances.
|
||||
model.vendorExtensions.put("x-prefix", prefix);
|
||||
model.vendorExtensions.put("x-data", dataOrNewtype);
|
||||
|
||||
return model;
|
||||
}
|
||||
return joinStrings(" :> ", rs);
|
||||
}
|
||||
|
||||
private String upperCaseFirst(String str) {
|
||||
char[] array = str.toLowerCase().toCharArray();
|
||||
array[0] = Character.toUpperCase(array[0]);
|
||||
return new String(array);
|
||||
}
|
||||
|
||||
private String parseScheme(String basePath) {
|
||||
return "Http";
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger){
|
||||
CodegenOperation op = super.fromOperation(resourcePath, httpMethod, operation, definitions, swagger);
|
||||
String path = op.path;
|
||||
op.nickname = addReturnPath(headerPath(formPath(bodyPath(queryPath(capturePath(replacePathSplitter(path), op.pathParams), op.queryParams), op.bodyParams), op.formParams), op.headerParams), op.httpMethod, op.returnType);
|
||||
return op;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
|
||||
CodegenParameter p = super.fromParameter(param, imports);
|
||||
p.vendorExtensions.put("x-formParamName", camelize(p.baseName));
|
||||
p.dataType = fixModelChars(p.dataType);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected Boolean serializableModel = false;
|
||||
protected boolean serializeBigDecimalAsString = false;
|
||||
protected boolean useRxJava = false;
|
||||
protected boolean hideGenerationTimestamp = false;
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
|
||||
@@ -101,6 +102,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
.SERIALIZE_BIG_DECIMAL_AS_STRING_DESC));
|
||||
cliOptions.add(CliOption.newBoolean(FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA, "Whether to use the RxJava adapter with the retrofit2 library."));
|
||||
cliOptions.add(new CliOption("hideGenerationTimestamp", "hides the timestamp when files were generated"));
|
||||
|
||||
supportedLibraries.put(DEFAULT_LIBRARY, "HTTP client: Jersey client 1.18. JSON processing: Jackson 2.4.2");
|
||||
supportedLibraries.put("feign", "HTTP client: Netflix Feign 8.1.1");
|
||||
|
||||
@@ -6,11 +6,8 @@ import io.swagger.models.Operation;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
{
|
||||
|
||||
public JavaJerseyServerCodegen()
|
||||
{
|
||||
public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
public JavaJerseyServerCodegen() {
|
||||
super();
|
||||
|
||||
sourceFolder = "src/gen/java";
|
||||
@@ -43,6 +40,7 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
Map<String, String> supportedLibraries = new LinkedHashMap<String, String>();
|
||||
|
||||
supportedLibraries.put(DEFAULT_LIBRARY, "Jersey core 1.18.1");
|
||||
supportedLibraries.put("jersey2", "Jersey core 2.x");
|
||||
library.setEnum(supportedLibraries);
|
||||
|
||||
cliOptions.add(library);
|
||||
@@ -85,6 +83,9 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
supportingFiles.add(new SupportingFile("ApiOriginFilter.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiOriginFilter.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiResponseMessage.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiResponseMessage.java"));
|
||||
supportingFiles.add(new SupportingFile("NotFoundException.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "NotFoundException.java"));
|
||||
supportingFiles.add(new SupportingFile("jacksonJsonProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JacksonJsonProvider.java"));
|
||||
writeOptional(outputFolder, new SupportingFile("bootstrap.mustache", (implFolder + '/' + apiPackage).replace(".", "/"), "Bootstrap.java"));
|
||||
|
||||
writeOptional(outputFolder, new SupportingFile("web.mustache", ("src/main/webapp/WEB-INF"), "web.xml"));
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "StringUtil.java"));
|
||||
|
||||
@@ -92,6 +93,24 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
setDateLibrary(additionalProperties.get("dateLibrary").toString());
|
||||
additionalProperties.put(dateLibrary, "true");
|
||||
}
|
||||
if(DEFAULT_LIBRARY.equals(library) || library == null) {
|
||||
if(templateDir.startsWith(JAXRS_TEMPLATE_DIRECTORY_NAME)) {
|
||||
// set to the default location
|
||||
templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "jersey1_18";
|
||||
}
|
||||
else {
|
||||
templateDir += File.separator + "jersey1_18";
|
||||
}
|
||||
}
|
||||
if("jersey2".equals(library)) {
|
||||
if(templateDir.startsWith(JAXRS_TEMPLATE_DIRECTORY_NAME)) {
|
||||
// set to the default location
|
||||
templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "jersey2";
|
||||
}
|
||||
else {
|
||||
templateDir += File.separator + "jersey2";
|
||||
}
|
||||
}
|
||||
|
||||
if ( "joda".equals(dateLibrary) ) {
|
||||
supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java"));
|
||||
@@ -128,5 +147,9 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
}
|
||||
opList.add(co);
|
||||
co.baseName = basePath;
|
||||
}
|
||||
}
|
||||
|
||||
public void hideGenerationTimestamp(boolean hideGenerationTimestamp) {
|
||||
this.hideGenerationTimestamp = hideGenerationTimestamp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
typeMapping.put("float", "Number");
|
||||
typeMapping.put("number", "Number");
|
||||
typeMapping.put("DateTime", "Date"); // Should this be dateTime?
|
||||
typeMapping.put("Date", "Date"); // Should this be date?
|
||||
typeMapping.put("date", "Date"); // Should this be date?
|
||||
typeMapping.put("long", "Integer");
|
||||
typeMapping.put("short", "Integer");
|
||||
typeMapping.put("char", "String");
|
||||
|
||||
@@ -79,7 +79,7 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Javascript AngularJS client library annotated with Google Closure Compiler annotations" +
|
||||
return "Generates a Javascript AngularJS client library (beta) annotated with Google Closure Compiler annotations" +
|
||||
"(https://developers.google.com/closure/compiler/docs/js-for-compiler?hl=en)";
|
||||
}
|
||||
|
||||
|
||||
@@ -278,7 +278,9 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
if(operation.getOperationId() == null) {
|
||||
operation.setOperationId(getOrGenerateOperationId(operation, pathname, method.toString()));
|
||||
}
|
||||
operation.getVendorExtensions().put("x-swagger-router-controller", toApiName(tag));
|
||||
if(operation.getVendorExtensions().get("x-swagger-router-controller") == null) {
|
||||
operation.getVendorExtensions().put("x-swagger-router-controller", sanitizeTag(tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
@@ -36,6 +37,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String license = "MIT";
|
||||
protected String gitRepoURL = "https://github.com/swagger-api/swagger-codegen";
|
||||
protected String[] specialWords = {"new", "copy"};
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
|
||||
public ObjcClientCodegen() {
|
||||
super();
|
||||
@@ -46,6 +49,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
apiTemplateFiles.put("api-header.mustache", ".h");
|
||||
apiTemplateFiles.put("api-body.mustache", ".m");
|
||||
embeddedTemplateDir = templateDir = "objc";
|
||||
modelDocTemplateFiles.put("model_doc.mustache", ".md");
|
||||
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||
|
||||
defaultIncludes.clear();
|
||||
defaultIncludes.add("bool");
|
||||
@@ -90,7 +95,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "NSString");
|
||||
|
||||
typeMapping.put("ByteArray", "NSString");
|
||||
|
||||
// ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
|
||||
setReservedWordsLowerCase(
|
||||
@@ -199,6 +204,10 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
additionalProperties.put(GIT_REPO_URL, gitRepoURL);
|
||||
additionalProperties.put(LICENSE, license);
|
||||
|
||||
// make api and model doc path available in mustache template
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
|
||||
String swaggerFolder = podName;
|
||||
|
||||
modelPackage = swaggerFolder;
|
||||
@@ -388,6 +397,26 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiDocFileFolder() {
|
||||
return (outputFolder + "/" + apiDocPath).replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelDocFileFolder() {
|
||||
return (outputFolder + "/" + modelDocPath).replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelDocFilename(String name) {
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiDocFilename(String name) {
|
||||
return toApiName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separatorChar + apiPackage();
|
||||
@@ -562,4 +591,75 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParameterExampleValue(CodegenParameter p) {
|
||||
String example;
|
||||
|
||||
if (p.defaultValue == null) {
|
||||
example = p.example;
|
||||
} else {
|
||||
example = p.defaultValue;
|
||||
}
|
||||
|
||||
String type = p.baseType;
|
||||
if (type == null) {
|
||||
type = p.dataType;
|
||||
}
|
||||
|
||||
if ("NSString*".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = p.paramName + "_example";
|
||||
}
|
||||
example = "@\"" + escapeText(example) + "\"";
|
||||
} else if ("NSNumber*".equals(type)) {
|
||||
if (example == null) {
|
||||
example = "56";
|
||||
}
|
||||
example = "@" + example;
|
||||
/* OBJC uses NSNumber to represent both int, long, double and float
|
||||
} else if ("Float".equalsIgnoreCase(type) || "Double".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = "3.4";
|
||||
} */
|
||||
} else if ("BOOLEAN".equalsIgnoreCase(type) || "bool".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = "True";
|
||||
}
|
||||
} else if ("NSURL*".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = "/path/to/file";
|
||||
}
|
||||
//[NSURL fileURLWithPath:@"path/to/file"]
|
||||
example = "[NSURL fileURLWithPath:@\"" + escapeText(example) + "\"]";
|
||||
/*} else if ("NSDate".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = "2013-10-20";
|
||||
}
|
||||
example = "'" + escapeText(example) + "'";*/
|
||||
} else if ("NSDate*".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = "2013-10-20T19:20:30+01:00";
|
||||
}
|
||||
example = "@\"" + escapeText(example) + "\"";
|
||||
} else if (!languageSpecificPrimitives.contains(type)) {
|
||||
// type is a model class, e.g. User
|
||||
type = type.replace("*", "");
|
||||
// e.g. [[SWGPet alloc] init
|
||||
example = "[[" + type + " alloc] init]";
|
||||
} else {
|
||||
LOGGER.warn("Type " + type + " not handled properly in setParameterExampleValue");
|
||||
}
|
||||
|
||||
if (example == null) {
|
||||
example = "NULL";
|
||||
} else if (Boolean.TRUE.equals(p.isListContainer)) {
|
||||
example = "@[" + example + "]";
|
||||
} else if (Boolean.TRUE.equals(p.isMapContainer)) {
|
||||
example = "@{@\"key\" : " + example + "}";
|
||||
}
|
||||
|
||||
p.example = example;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
typeMapping.put("ByteArray", "string");
|
||||
|
||||
cliOptions.clear();
|
||||
cliOptions.add(new CliOption(MODULE_NAME, "Perl module name (convention: CamelCase or Long::Module).").defaultValue("SwaggerClient"));
|
||||
|
||||
@@ -96,6 +96,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("integer", "int");
|
||||
typeMapping.put("long", "int");
|
||||
typeMapping.put("number", "float");
|
||||
typeMapping.put("float", "float");
|
||||
typeMapping.put("double", "double");
|
||||
typeMapping.put("string", "string");
|
||||
@@ -109,6 +110,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("list", "array");
|
||||
typeMapping.put("object", "object");
|
||||
typeMapping.put("binary", "string");
|
||||
typeMapping.put("ByteArray", "string");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.swagger.codegen.languages;
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
@@ -17,6 +18,8 @@ import org.apache.commons.lang.StringUtils;
|
||||
public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String packageName;
|
||||
protected String packageVersion;
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
|
||||
public PythonClientCodegen() {
|
||||
super();
|
||||
@@ -28,6 +31,9 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
apiTemplateFiles.put("api.mustache", ".py");
|
||||
embeddedTemplateDir = templateDir = "python";
|
||||
|
||||
modelDocTemplateFiles.put("model_doc.mustache", ".md");
|
||||
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||
|
||||
languageSpecificPrimitives.clear();
|
||||
languageSpecificPrimitives.add("int");
|
||||
languageSpecificPrimitives.add("float");
|
||||
@@ -36,6 +42,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
languageSpecificPrimitives.add("str");
|
||||
languageSpecificPrimitives.add("datetime");
|
||||
languageSpecificPrimitives.add("date");
|
||||
languageSpecificPrimitives.add("object");
|
||||
|
||||
typeMapping.clear();
|
||||
typeMapping.put("integer", "int");
|
||||
@@ -54,6 +61,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "str");
|
||||
typeMapping.put("ByteArray", "str");
|
||||
|
||||
// from https://docs.python.org/release/2.5.4/ref/keywords.html
|
||||
setReservedWordsLowerCase(
|
||||
@@ -97,6 +105,10 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||
|
||||
// make api and model doc path available in mustache template
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
|
||||
String swaggerFolder = packageName;
|
||||
|
||||
modelPackage = swaggerFolder + File.separatorChar + "models";
|
||||
@@ -138,6 +150,27 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiDocFileFolder() {
|
||||
return (outputFolder + "/" + apiDocPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelDocFileFolder() {
|
||||
return (outputFolder + "/" + modelDocPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelDocFilename(String name) {
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiDocFilename(String name) {
|
||||
return toApiName(name);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separatorChar + apiPackage().replace('.', File.separatorChar);
|
||||
@@ -388,4 +421,70 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParameterExampleValue(CodegenParameter p) {
|
||||
String example;
|
||||
|
||||
if (p.defaultValue == null) {
|
||||
example = p.example;
|
||||
} else {
|
||||
example = p.defaultValue;
|
||||
}
|
||||
|
||||
String type = p.baseType;
|
||||
if (type == null) {
|
||||
type = p.dataType;
|
||||
}
|
||||
|
||||
if ("String".equalsIgnoreCase(type) || "str".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = p.paramName + "_example";
|
||||
}
|
||||
example = "'" + escapeText(example) + "'";
|
||||
} else if ("Integer".equals(type) || "int".equals(type)) {
|
||||
if (example == null) {
|
||||
example = "56";
|
||||
}
|
||||
} else if ("Float".equalsIgnoreCase(type) || "Double".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = "3.4";
|
||||
}
|
||||
} else if ("BOOLEAN".equalsIgnoreCase(type) || "bool".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = "True";
|
||||
}
|
||||
} else if ("file".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = "/path/to/file";
|
||||
}
|
||||
example = "'" + escapeText(example) + "'";
|
||||
} else if ("Date".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = "2013-10-20";
|
||||
}
|
||||
example = "'" + escapeText(example) + "'";
|
||||
} else if ("DateTime".equalsIgnoreCase(type)) {
|
||||
if (example == null) {
|
||||
example = "2013-10-20T19:20:30+01:00";
|
||||
}
|
||||
example = "'" + escapeText(example) + "'";
|
||||
} else if (!languageSpecificPrimitives.contains(type)) {
|
||||
// type is a model class, e.g. User
|
||||
example = this.packageName + "." + type + "()";
|
||||
} else {
|
||||
LOGGER.warn("Type " + type + " not handled properly in setParameterExampleValue");
|
||||
}
|
||||
|
||||
if (example == null) {
|
||||
example = "NULL";
|
||||
} else if (Boolean.TRUE.equals(p.isListContainer)) {
|
||||
example = "[" + example + "]";
|
||||
} else if (Boolean.TRUE.equals(p.isMapContainer)) {
|
||||
example = "{'key': " + example + "}";
|
||||
}
|
||||
|
||||
p.example = example;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -116,6 +116,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("file", "File");
|
||||
typeMapping.put("binary", "String");
|
||||
typeMapping.put("ByteArray", "String");
|
||||
|
||||
// remove modelPackage and apiPackage added by default
|
||||
Iterator<CliOption> itr = cliOptions.iterator();
|
||||
|
||||
@@ -101,6 +101,7 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "String");
|
||||
typeMapping.put("ByteArray", "String");
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
|
||||
@@ -32,18 +32,6 @@ public class SpringMVCServerCodegen extends JavaClientCodegen {
|
||||
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
|
||||
additionalProperties.put(CONFIG_PACKAGE, configPackage);
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"byte[]",
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float")
|
||||
);
|
||||
|
||||
cliOptions.add(new CliOption(CONFIG_PACKAGE, "configuration package for generated code"));
|
||||
|
||||
supportedLibraries.clear();
|
||||
|
||||
@@ -74,6 +74,8 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"Int",
|
||||
"Int32",
|
||||
"Int64",
|
||||
"Float",
|
||||
"Double",
|
||||
"Bool",
|
||||
@@ -93,9 +95,10 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
"Empty",
|
||||
"AnyObject")
|
||||
);
|
||||
setReservedWordsLowerCase(
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"class", "break", "as", "associativity", "deinit", "case", "dynamicType", "convenience", "enum", "continue",
|
||||
"Int", "Int32", "Int64", "Int64", "Float", "Double", "Bool", "Void", "String", "Character", "AnyObject",
|
||||
"class", "Class", "break", "as", "associativity", "deinit", "case", "dynamicType", "convenience", "enum", "continue",
|
||||
"false", "dynamic", "extension", "default", "is", "didSet", "func", "do", "nil", "final", "import", "else",
|
||||
"self", "get", "init", "fallthrough", "Self", "infix", "internal", "for", "super", "inout", "let", "if",
|
||||
"true", "lazy", "operator", "in", "COLUMN", "left", "private", "return", "FILE", "mutating", "protocol",
|
||||
@@ -115,10 +118,10 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("char", "Character");
|
||||
typeMapping.put("short", "Int");
|
||||
typeMapping.put("int", "Int");
|
||||
typeMapping.put("long", "Int");
|
||||
typeMapping.put("integer", "Int");
|
||||
typeMapping.put("Integer", "Int");
|
||||
typeMapping.put("int", "Int32");
|
||||
typeMapping.put("long", "Int64");
|
||||
typeMapping.put("integer", "Int32");
|
||||
typeMapping.put("Integer", "Int32");
|
||||
typeMapping.put("float", "Float");
|
||||
typeMapping.put("number", "Double");
|
||||
typeMapping.put("double", "Double");
|
||||
@@ -127,6 +130,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "String");
|
||||
typeMapping.put("ByteArray", "String");
|
||||
|
||||
importMapping = new HashMap<String, String>();
|
||||
|
||||
@@ -200,6 +204,11 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isReservedWord(String word) {
|
||||
return word != null && reservedWords.contains(word); //don't lowercase as super does
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name; // add an underscore to the name
|
||||
@@ -331,10 +340,9 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// Ensure that the enum type doesn't match a reserved word or
|
||||
// the variable name doesn't match the generated enum type or the
|
||||
// Swift compiler will generate an error
|
||||
if (isReservedWord(codegenProperty.datatypeWithEnum) ||
|
||||
name.equals(codegenProperty.datatypeWithEnum)) {
|
||||
codegenProperty.datatypeWithEnum = escapeReservedWord(codegenProperty.datatypeWithEnum);
|
||||
}
|
||||
if (isReservedWord(codegenProperty.datatypeWithEnum) || name.equals(codegenProperty.datatypeWithEnum)) {
|
||||
codegenProperty.datatypeWithEnum = codegenProperty.datatypeWithEnum + "Enum";
|
||||
}
|
||||
}
|
||||
return codegenProperty;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user