forked from loafle/openapi-generator-original
Merge branch 'master' into issue-1357
This commit is contained in:
@@ -41,7 +41,7 @@ public class CodegenConstants {
|
||||
public static final String SORT_PARAMS_BY_REQUIRED_FLAG_DESC = "Sort method arguments to place required parameters before optional parameters.";
|
||||
|
||||
public static final String ENSURE_UNIQUE_PARAMS = "ensureUniqueParams";
|
||||
public static final String ENSURE_UNIQUE_PARAMS_DESC = "Whether to ensure parameter names are unique in an operation (rename parameters that are not). Default: true";
|
||||
public static final String ENSURE_UNIQUE_PARAMS_DESC = "Whether to ensure parameter names are unique in an operation (rename parameters that are not).";
|
||||
|
||||
public static final String PACKAGE_NAME = "packageName";
|
||||
public static final String PACKAGE_VERSION = "packageVersion";
|
||||
|
||||
@@ -448,7 +448,8 @@ public class DefaultCodegen {
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG,
|
||||
CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC).defaultValue("true"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants.ENSURE_UNIQUE_PARAMS_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ENSURE_UNIQUE_PARAMS, CodegenConstants.ENSURE_UNIQUE_PARAMS_DESC)
|
||||
.defaultValue("true"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1826,6 +1827,16 @@ public class DefaultCodegen {
|
||||
return word;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashize the given word.
|
||||
*
|
||||
* @param word The word
|
||||
* @return The dashized version of the word, e.g. "my-name"
|
||||
*/
|
||||
protected String dashize(String word) {
|
||||
return underscore(word).replaceAll("[_ ]", "-");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the next name for the given name, i.e. append "2" to the base name if not ending with a number,
|
||||
* otherwise increase the number by 1. For example:
|
||||
|
||||
@@ -199,8 +199,4 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
protected String namespaceToFolder(String ns) {
|
||||
return ns.replace(".", File.separator).replace("-", "_");
|
||||
}
|
||||
|
||||
protected String dashize(String s) {
|
||||
return underscore(s).replaceAll("[_ ]", "-");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.properties.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
public class JMeterCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
// source folder where to write the files
|
||||
protected String sourceFolder = "";
|
||||
protected String apiVersion = "1.0.0";
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 "jmeter";
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 JMeter .jmx file.";
|
||||
}
|
||||
|
||||
public JMeterCodegen() {
|
||||
super();
|
||||
|
||||
// set the output folder here
|
||||
outputFolder = "generated-code/JMeterCodegen";
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
apiTemplateFiles.put(
|
||||
"api.mustache", // the template to use
|
||||
".jmx"); // the extension for each file to write
|
||||
|
||||
apiTemplateFiles.put("testdata-localhost.mustache", ".csv");
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
templateDir = "JMeter";
|
||||
|
||||
/**
|
||||
* Api Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
apiPackage = "";
|
||||
|
||||
/**
|
||||
* Model Package. Optional, if needed, this can be used in templates
|
||||
*/
|
||||
modelPackage = "";
|
||||
|
||||
/**
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
reservedWords = new HashSet<String> (
|
||||
Arrays.asList(
|
||||
"sample1", // replace with static values
|
||||
"sample2")
|
||||
);
|
||||
|
||||
/**
|
||||
* Additional Properties. These values can be passed to the templates and
|
||||
* are available in models, apis, and supporting files
|
||||
*/
|
||||
additionalProperties.put("apiVersion", apiVersion);
|
||||
|
||||
// supportingFiles.add(new SupportingFile("testdata-localhost.mustache", "input", "testdata-localhost.csv"));
|
||||
}
|
||||
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
if (swagger != null && swagger.getPaths() != null) {
|
||||
for (String pathname : swagger.getPaths().keySet()) {
|
||||
Path path = swagger.getPath(pathname);
|
||||
if (path.getOperations() != null) {
|
||||
for (Operation operation : path.getOperations()) {
|
||||
String pathWithDollars = pathname.replaceAll("\\{", "\\$\\{");
|
||||
operation.setVendorExtension("x-path", pathWithDollars);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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; // add an underscore to the name
|
||||
}
|
||||
|
||||
/**
|
||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||
* instantiated
|
||||
*/
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + "/" + 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 + "/" + sourceFolder + "/" + 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 getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||
}
|
||||
else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
return getSwaggerType(p) + "[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))
|
||||
return toModelName(type);
|
||||
}
|
||||
else
|
||||
type = swaggerType;
|
||||
return toModelName(type);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,12 @@ import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.FormParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
import io.swagger.models.properties.DoubleProperty;
|
||||
@@ -98,6 +104,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
.defaultValue("false"));
|
||||
|
||||
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");
|
||||
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6");
|
||||
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1");
|
||||
supportedLibraries.put("retrofit", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
|
||||
@@ -215,15 +222,18 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
|
||||
|
||||
final String authFolder = (sourceFolder + '/' + invokerPackage + ".auth").replace(".", "/");
|
||||
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));
|
||||
if ("feign".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("FormAwareEncoder.mustache", invokerFolder, "FormAwareEncoder.java"));
|
||||
} else {
|
||||
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));
|
||||
}
|
||||
|
||||
if (!("retrofit".equals(getLibrary()) || "retrofit2".equals(getLibrary()))) {
|
||||
if (!("feign".equals(getLibrary()) || "retrofit".equals(getLibrary()) || "retrofit2".equals(getLibrary()))) {
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache", invokerFolder, "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", invokerFolder, "Configuration.java"));
|
||||
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
|
||||
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/Authentication.mustache", authFolder, "Authentication.java"));
|
||||
}
|
||||
@@ -233,6 +243,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// the "okhttp-gson" library template requires "ApiCallback.mustache" for async call
|
||||
supportingFiles.add(new SupportingFile("ApiCallback.mustache", invokerFolder, "ApiCallback.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java"));
|
||||
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
|
||||
supportingFiles.add(new SupportingFile("ProgressRequestBody.mustache", invokerFolder, "ProgressRequestBody.java"));
|
||||
supportingFiles.add(new SupportingFile("ProgressResponseBody.mustache", invokerFolder, "ProgressResponseBody.java"));
|
||||
// "build.sbt" is for development with SBT
|
||||
@@ -240,8 +251,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
} else if ("retrofit".equals(getLibrary()) || "retrofit2".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java"));
|
||||
supportingFiles.add(new SupportingFile("CollectionFormats.mustache", invokerFolder, "CollectionFormats.java"));
|
||||
} else {
|
||||
supportingFiles.add(new SupportingFile("TypeRef.mustache", invokerFolder, "TypeRef.java"));
|
||||
} else if("jersey2".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,6 +555,57 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return objs;
|
||||
}
|
||||
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
if (swagger != null && swagger.getPaths() != null) {
|
||||
for (String pathname : swagger.getPaths().keySet()) {
|
||||
Path path = swagger.getPath(pathname);
|
||||
if (path.getOperations() != null) {
|
||||
for (Operation operation : path.getOperations()) {
|
||||
boolean hasFormParameters = false;
|
||||
for (Parameter parameter : operation.getParameters()) {
|
||||
if (parameter instanceof FormParameter) {
|
||||
hasFormParameters = true;
|
||||
}
|
||||
}
|
||||
|
||||
String defaultContentType = hasFormParameters ? "application/x-www-form-urlencoded" : "application/json";
|
||||
String contentType = operation.getConsumes() == null || operation.getConsumes().isEmpty()
|
||||
? defaultContentType : operation.getConsumes().get(0);
|
||||
String accepts = getAccept(operation);
|
||||
operation.setVendorExtension("x-contentType", contentType);
|
||||
operation.setVendorExtension("x-accepts", accepts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getAccept(Operation operation) {
|
||||
String accepts = null;
|
||||
String defaultContentType = "application/json";
|
||||
if (operation.getProduces() != null && !operation.getProduces().isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String produces : operation.getProduces()) {
|
||||
if (defaultContentType.equalsIgnoreCase(produces)) {
|
||||
accepts = defaultContentType;
|
||||
break;
|
||||
} else {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(produces);
|
||||
}
|
||||
}
|
||||
if (accepts == null) {
|
||||
accepts = sb.toString();
|
||||
}
|
||||
} else {
|
||||
accepts = defaultContentType;
|
||||
}
|
||||
|
||||
return accepts;
|
||||
}
|
||||
|
||||
protected boolean needToImport(String type) {
|
||||
return super.needToImport(type) && type.indexOf(".") < 0;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
@@ -34,15 +34,19 @@ import org.slf4j.LoggerFactory;
|
||||
public class JavascriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavascriptClientCodegen.class);
|
||||
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
protected String artifactId = "swagger-java-client";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
private static final String PROJECT_NAME = "projectName";
|
||||
private static final String MODULE_NAME = "moduleName";
|
||||
private static final String PROJECT_DESCRIPTION = "projectDescription";
|
||||
private static final String PROJECT_VERSION = "projectVersion";
|
||||
private static final String PROJECT_LICENSE_NAME = "projectLicenseName";
|
||||
|
||||
protected String projectName = null;
|
||||
protected String moduleName = null;
|
||||
protected String projectDescription = null;
|
||||
protected String projectVersion = null;
|
||||
|
||||
protected String sourceFolder = "src";
|
||||
protected String localVariablePrefix = "";
|
||||
protected boolean fullJavaUtil = false;
|
||||
protected String javaUtilPrefix = "";
|
||||
protected Boolean serializableModel = false;
|
||||
|
||||
public JavascriptClientCodegen() {
|
||||
super();
|
||||
@@ -50,44 +54,48 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
modelTemplateFiles.put("model.mustache", ".js");
|
||||
apiTemplateFiles.put("api.mustache", ".js");
|
||||
templateDir = "Javascript";
|
||||
apiPackage = "scripts/rest/api";
|
||||
modelPackage = "scripts/rest/model";
|
||||
apiPackage = "api";
|
||||
modelPackage = "model";
|
||||
|
||||
// reference: http://www.w3schools.com/js/js_reserved.asp
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"abstract", "continue", "for", "new", "switch", "assert",
|
||||
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
|
||||
"this", "break", "double", "implements", "protected", "throw", "byte", "else",
|
||||
"import", "public", "throws", "case", "enum", "instanceof", "return", "transient",
|
||||
"catch", "extends", "int", "short", "try", "char", "final", "interface", "static",
|
||||
"void", "class", "finally", "long", "strictfp", "volatile", "const", "float",
|
||||
"native", "super", "while")
|
||||
"abstract", "arguments", "boolean", "break", "byte",
|
||||
"case", "catch", "char", "class", "const",
|
||||
"continue", "debugger", "default", "delete", "do",
|
||||
"double", "else", "enum", "eval", "export",
|
||||
"extends", "false", "final", "finally", "float",
|
||||
"for", "function", "goto", "if", "implements",
|
||||
"import", "in", "instanceof", "int", "interface",
|
||||
"let", "long", "native", "new", "null",
|
||||
"package", "private", "protected", "public", "return",
|
||||
"short", "static", "super", "switch", "synchronized",
|
||||
"this", "throw", "throws", "transient", "true",
|
||||
"try", "typeof", "var", "void", "volatile",
|
||||
"while", "with", "yield",
|
||||
"Array", "Date", "eval", "function", "hasOwnProperty",
|
||||
"Infinity", "isFinite", "isNaN", "isPrototypeOf",
|
||||
"Math", "NaN", "Number", "Object",
|
||||
"prototype", "String", "toString", "undefined", "valueOf")
|
||||
);
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
"String",
|
||||
"boolean",
|
||||
"Boolean",
|
||||
"Double",
|
||||
"Integer",
|
||||
"Long",
|
||||
"Float",
|
||||
"Object",
|
||||
"byte[]")
|
||||
Arrays.asList("String", "Boolean", "Integer", "Number", "Array", "Object", "Date", "File")
|
||||
);
|
||||
instantiationTypes.put("array", "Array");
|
||||
instantiationTypes.put("map", "HashMap");
|
||||
defaultIncludes = new HashSet<String>(languageSpecificPrimitives);
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.INVOKER_PACKAGE, CodegenConstants.INVOKER_PACKAGE_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.GROUP_ID, CodegenConstants.GROUP_ID_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_ID, CodegenConstants.ARTIFACT_ID_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC).defaultValue("src"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.LOCAL_VARIABLE_PREFIX, CodegenConstants.LOCAL_VARIABLE_PREFIX_DESC));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SERIALIZABLE_MODEL, CodegenConstants.SERIALIZABLE_MODEL_DESC));
|
||||
cliOptions.add(new CliOption("fullJavaUtil", "whether to use fully qualified name for classes under java.util (default to false)"));
|
||||
|
||||
cliOptions.add(new CliOption(PROJECT_NAME,
|
||||
"name of the project (Default: generated from info.title or \"swagger-js-client\")"));
|
||||
cliOptions.add(new CliOption(MODULE_NAME,
|
||||
"module name for AMD, Node or globals (Default: generated from <projectName>)"));
|
||||
cliOptions.add(new CliOption(PROJECT_DESCRIPTION,
|
||||
"description of the project (Default: using info.description or \"Client library of <projectName>\")"));
|
||||
cliOptions.add(new CliOption(PROJECT_VERSION,
|
||||
"version of the project (Default: using info.version or \"1.0.0\")"));
|
||||
cliOptions.add(new CliOption(PROJECT_LICENSE_NAME,
|
||||
"name of the license the project uses (Default: using info.license.name)"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,8 +117,94 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
typeMapping.put("array", "Array");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("array", "Array");
|
||||
typeMapping.put("List", "Array");
|
||||
typeMapping.put("map", "Object");
|
||||
typeMapping.put("object", "Object");
|
||||
typeMapping.put("boolean", "Boolean");
|
||||
typeMapping.put("char", "String");
|
||||
typeMapping.put("string", "String");
|
||||
typeMapping.put("short", "Integer");
|
||||
typeMapping.put("int", "Integer");
|
||||
typeMapping.put("integer", "Integer");
|
||||
typeMapping.put("long", "Integer");
|
||||
typeMapping.put("float", "Number");
|
||||
typeMapping.put("double", "Number");
|
||||
typeMapping.put("number", "Number");
|
||||
typeMapping.put("DateTime", "Date");
|
||||
|
||||
importMapping.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
super.preprocessSwagger(swagger);
|
||||
|
||||
if (additionalProperties.containsKey(PROJECT_NAME)) {
|
||||
projectName = ((String) additionalProperties.get(PROJECT_NAME));
|
||||
}
|
||||
if (additionalProperties.containsKey(MODULE_NAME)) {
|
||||
moduleName = ((String) additionalProperties.get(MODULE_NAME));
|
||||
}
|
||||
if (additionalProperties.containsKey(PROJECT_DESCRIPTION)) {
|
||||
projectDescription = ((String) additionalProperties.get(PROJECT_DESCRIPTION));
|
||||
}
|
||||
if (additionalProperties.containsKey(PROJECT_VERSION)) {
|
||||
projectVersion = ((String) additionalProperties.get(PROJECT_VERSION));
|
||||
}
|
||||
if (additionalProperties.containsKey(CodegenConstants.LOCAL_VARIABLE_PREFIX)) {
|
||||
localVariablePrefix = (String) additionalProperties.get(CodegenConstants.LOCAL_VARIABLE_PREFIX);
|
||||
}
|
||||
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
|
||||
sourceFolder = (String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER);
|
||||
}
|
||||
|
||||
if (swagger.getInfo() != null) {
|
||||
Info info = swagger.getInfo();
|
||||
if (projectName == null && info.getTitle() != null) {
|
||||
// when projectName is not specified, generate it from info.title
|
||||
projectName = dashize(info.getTitle());
|
||||
}
|
||||
if (projectVersion == null) {
|
||||
// when projectVersion is not specified, use info.version
|
||||
projectVersion = info.getVersion();
|
||||
}
|
||||
if (projectDescription == null) {
|
||||
// when projectDescription is not specified, use info.description
|
||||
projectDescription = info.getDescription();
|
||||
}
|
||||
if (info.getLicense() != null) {
|
||||
License license = info.getLicense();
|
||||
if (additionalProperties.get(PROJECT_LICENSE_NAME) == null) {
|
||||
additionalProperties.put(PROJECT_LICENSE_NAME, license.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// default values
|
||||
if (projectName == null) {
|
||||
projectName = "swagger-js-client";
|
||||
}
|
||||
if (moduleName == null) {
|
||||
moduleName = camelize(underscore(projectName));
|
||||
}
|
||||
if (projectVersion == null) {
|
||||
projectVersion = "1.0.0";
|
||||
}
|
||||
if (projectDescription == null) {
|
||||
projectDescription = "Client library of " + projectName;
|
||||
}
|
||||
|
||||
additionalProperties.put(PROJECT_NAME, projectName);
|
||||
additionalProperties.put(MODULE_NAME, moduleName);
|
||||
additionalProperties.put(PROJECT_DESCRIPTION, escapeText(projectDescription));
|
||||
additionalProperties.put(PROJECT_VERSION, projectVersion);
|
||||
additionalProperties.put(CodegenConstants.LOCAL_VARIABLE_PREFIX, localVariablePrefix);
|
||||
additionalProperties.put(CodegenConstants.SOURCE_FOLDER, sourceFolder);
|
||||
|
||||
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("index.mustache", sourceFolder, "index.js"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -180,6 +274,16 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiImport(String name) {
|
||||
return toApiName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
@@ -198,84 +302,42 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
final ArrayProperty ap = (ArrayProperty) p;
|
||||
final String pattern;
|
||||
//if (fullJavaUtil) {
|
||||
// pattern = "new ArrayList()";
|
||||
//} else {
|
||||
// pattern = "new ArrayList<%s>()";
|
||||
//}
|
||||
|
||||
pattern = "new Array()";
|
||||
return String.format(pattern, getTypeDeclaration(ap.getItems()));
|
||||
return "[]";
|
||||
} else if (p instanceof MapProperty) {
|
||||
final MapProperty ap = (MapProperty) p;
|
||||
final String pattern;
|
||||
if (fullJavaUtil) {
|
||||
pattern = "new java.util.HashMap<String, %s>()";
|
||||
} else {
|
||||
pattern = "new HashMap<String, %s>()";
|
||||
}
|
||||
return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties()));
|
||||
|
||||
return "{}";
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString()+"l";
|
||||
}
|
||||
return "null";
|
||||
|
||||
|
||||
// added for Javascript
|
||||
} else if (p instanceof RefProperty) {
|
||||
RefProperty rp = (RefProperty)p;
|
||||
System.out.println("rp: " + rp.getName() + rp.getAccess() + rp.getDescription() + rp.getExample() + rp.getFormat() + rp.getSimpleRef() + rp.getTitle() + rp.getType());
|
||||
|
||||
return "new " +rp.getSimpleRef() + "()";
|
||||
RefProperty rp = (RefProperty)p;
|
||||
return "new " +rp.getSimpleRef() + "()";
|
||||
}
|
||||
|
||||
System.out.println("property: " + p);
|
||||
|
||||
|
||||
return super.toDefaultValue(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toDefaultValueWithParam(String name, Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
final ArrayProperty ap = (ArrayProperty) p;
|
||||
final String pattern;
|
||||
// if (fullJavaUtil) {
|
||||
// pattern = "new java.util.ArrayList<%s>()";
|
||||
// } else {
|
||||
// pattern = "new ArrayList<%s>()" ;
|
||||
// }
|
||||
pattern = " = new Array()" ;
|
||||
|
||||
return String.format(pattern, getTypeDeclaration(ap.getItems()))+ ";";
|
||||
return " = new Array();";
|
||||
} else if (p instanceof MapProperty) {
|
||||
final MapProperty ap = (MapProperty) p;
|
||||
final String pattern;
|
||||
if (fullJavaUtil) {
|
||||
pattern = " = new java.util.HashMap<String, %s>()";
|
||||
} else {
|
||||
pattern = "new HashMap<String, %s>()";
|
||||
}
|
||||
return String.format(pattern, getTypeDeclaration(ap.getAdditionalProperties()))+ ";";
|
||||
|
||||
return " = {}";
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
return " = data." + name + ";";
|
||||
|
||||
|
||||
// added for Javascript
|
||||
} else if (p instanceof RefProperty) {
|
||||
RefProperty rp = (RefProperty)p;
|
||||
System.out.println("rp: " + rp.getName() + rp.getAccess() + rp.getDescription() + rp.getExample() + rp.getFormat() + rp.getSimpleRef() + rp.getTitle() + rp.getType());
|
||||
|
||||
return ".constructFromObject(data." + name + ");";
|
||||
RefProperty rp = (RefProperty)p;
|
||||
return ".constructFromObject(data." + name + ");";
|
||||
}
|
||||
|
||||
System.out.println("property: " + p);
|
||||
|
||||
|
||||
return super.toDefaultValueWithParam(name, p);
|
||||
}
|
||||
|
||||
@@ -286,7 +348,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(swaggerType)) {
|
||||
type = typeMapping.get(swaggerType);
|
||||
if (languageSpecificPrimitives.contains(type) || type.indexOf(".") >= 0) {
|
||||
if (!needToImport(type)) {
|
||||
return type;
|
||||
}
|
||||
} else {
|
||||
@@ -397,7 +459,8 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
|
||||
protected boolean needToImport(String type) {
|
||||
return super.needToImport(type) && type.indexOf(".") < 0;
|
||||
return !defaultIncludes.contains(type)
|
||||
&& !languageSpecificPrimitives.contains(type);
|
||||
}
|
||||
|
||||
private String findCommonPrefixOfVars(List<String> vars) {
|
||||
@@ -449,7 +512,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
@@ -464,39 +527,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
public void setInvokerPackage(String invokerPackage) {
|
||||
this.invokerPackage = invokerPackage;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public void setArtifactId(String artifactId) {
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
public void setArtifactVersion(String artifactVersion) {
|
||||
this.artifactVersion = artifactVersion;
|
||||
}
|
||||
|
||||
public void setSourceFolder(String sourceFolder) {
|
||||
this.sourceFolder = sourceFolder;
|
||||
}
|
||||
|
||||
public void setLocalVariablePrefix(String localVariablePrefix) {
|
||||
this.localVariablePrefix = localVariablePrefix;
|
||||
}
|
||||
|
||||
|
||||
public Boolean getSerializableModel() {
|
||||
return serializableModel;
|
||||
}
|
||||
|
||||
public void setSerializableModel(Boolean serializableModel) {
|
||||
this.serializableModel = serializableModel;
|
||||
}
|
||||
|
||||
private String sanitizePackageName(String packageName) {
|
||||
packageName = packageName.trim();
|
||||
packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_");
|
||||
|
||||
@@ -7,9 +7,7 @@ import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@@ -343,11 +341,6 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separatorChar + apiPackage();
|
||||
@@ -452,4 +445,55 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setLicense(String license) {
|
||||
this.license = license;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default value of the property
|
||||
*
|
||||
* @param p Swagger property object
|
||||
* @return string presentation of the default value of the property
|
||||
*/
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof StringProperty) {
|
||||
StringProperty dp = (StringProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return "@\"" + dp.getDefault().toString() + "\"";
|
||||
}
|
||||
} else if (p instanceof BooleanProperty) {
|
||||
BooleanProperty dp = (BooleanProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
if (dp.getDefault().toString().equalsIgnoreCase("false"))
|
||||
return "@0";
|
||||
else
|
||||
return "@1";
|
||||
}
|
||||
} else if (p instanceof DateProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DateTimeProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DoubleProperty) {
|
||||
DoubleProperty dp = (DoubleProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return "@" + dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof FloatProperty) {
|
||||
FloatProperty dp = (FloatProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return "@" + dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof IntegerProperty) {
|
||||
IntegerProperty dp = (IntegerProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return "@" + dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return "@" + dp.getDefault().toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.RefProperty;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@@ -276,10 +273,6 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return toModelName(type);
|
||||
}
|
||||
|
||||
public String toDefaultValue(Property p) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
public void setInvokerPackage(String invokerPackage) {
|
||||
this.invokerPackage = invokerPackage;
|
||||
}
|
||||
@@ -377,4 +370,51 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default value of the property
|
||||
*
|
||||
* @param p Swagger property object
|
||||
* @return string presentation of the default value of the property
|
||||
*/
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof StringProperty) {
|
||||
StringProperty dp = (StringProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return "'" + dp.getDefault().toString() + "'";
|
||||
}
|
||||
} else if (p instanceof BooleanProperty) {
|
||||
BooleanProperty dp = (BooleanProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof DateProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DateTimeProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DoubleProperty) {
|
||||
DoubleProperty dp = (DoubleProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof FloatProperty) {
|
||||
FloatProperty dp = (FloatProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof IntegerProperty) {
|
||||
IntegerProperty dp = (IntegerProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@@ -166,10 +164,6 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return type;
|
||||
}
|
||||
|
||||
public String toDefaultValue(Property p) {
|
||||
return "None";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
@@ -291,4 +285,55 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public String generatePackageName(String packageName) {
|
||||
return underscore(packageName.replaceAll("[^\\w]+", ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the default value of the property
|
||||
*
|
||||
* @param p Swagger property object
|
||||
* @return string presentation of the default value of the property
|
||||
*/
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof StringProperty) {
|
||||
StringProperty dp = (StringProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return "'" + dp.getDefault().toString() + "'";
|
||||
}
|
||||
} else if (p instanceof BooleanProperty) {
|
||||
BooleanProperty dp = (BooleanProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
if (dp.getDefault().toString().equalsIgnoreCase("false"))
|
||||
return "False";
|
||||
else
|
||||
return "True";
|
||||
}
|
||||
} else if (p instanceof DateProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DateTimeProperty) {
|
||||
// TODO
|
||||
} else if (p instanceof DoubleProperty) {
|
||||
DoubleProperty dp = (DoubleProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof FloatProperty) {
|
||||
FloatProperty dp = (FloatProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof IntegerProperty) {
|
||||
IntegerProperty dp = (IntegerProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@@ -186,6 +184,43 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof IntegerProperty) {
|
||||
IntegerProperty dp = (IntegerProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof LongProperty) {
|
||||
LongProperty dp = (LongProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof DoubleProperty) {
|
||||
DoubleProperty dp = (DoubleProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof FloatProperty) {
|
||||
FloatProperty dp = (FloatProperty) p;
|
||||
if (dp.getDefault() != null) {
|
||||
return dp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof BooleanProperty) {
|
||||
BooleanProperty bp = (BooleanProperty) p;
|
||||
if (bp.getDefault() != null) {
|
||||
return bp.getDefault().toString();
|
||||
}
|
||||
} else if (p instanceof StringProperty) {
|
||||
StringProperty sp = (StringProperty) p;
|
||||
if (sp.getDefault() != null) {
|
||||
return "\"" + escapeText(sp.getDefault()) + "\"";
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSwaggerType(Property p) {
|
||||
String swaggerType = super.getSwaggerType(p);
|
||||
@@ -204,10 +239,6 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String toDefaultValue(Property p) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
@@ -8,10 +10,13 @@ import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.util.Yaml;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
@@ -73,6 +78,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
supportingFiles.add(new SupportingFile("config.ru", "", "config.ru"));
|
||||
supportingFiles.add(new SupportingFile("Gemfile", "", "Gemfile"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("swagger.mustache","","swagger.yaml"));
|
||||
}
|
||||
|
||||
public CodegenType getTag() {
|
||||
@@ -213,5 +219,17 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
return underscore(operationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
Swagger swagger = (Swagger)objs.get("swagger");
|
||||
if(swagger != null) {
|
||||
try {
|
||||
objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user