forked from loafle/openapi-generator-original
Merge branch 'master' of https://github.com/swagger-api/swagger-codegen into feature/integration-test
This commit is contained in:
@@ -33,7 +33,7 @@ public class CodegenModel {
|
||||
public Set<String> allMandatory;
|
||||
|
||||
public Set<String> imports = new TreeSet<String>();
|
||||
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum;
|
||||
public Boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired;
|
||||
public ExternalDocs externalDocs;
|
||||
|
||||
public Map<String, Object> vendorExtensions;
|
||||
|
||||
@@ -7,13 +7,16 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CodegenOperation {
|
||||
public final List<CodegenProperty> responseHeaders = new ArrayList<CodegenProperty>();
|
||||
public Boolean hasAuthMethods, hasConsumes, hasProduces, hasParams, hasOptionalParams,
|
||||
returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMapContainer,
|
||||
isListContainer, isMultipart, hasMore = Boolean.TRUE,
|
||||
isResponseBinary = Boolean.FALSE, hasReference = Boolean.FALSE;
|
||||
isResponseBinary = Boolean.FALSE, hasReference = Boolean.FALSE,
|
||||
isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
|
||||
isRestful;
|
||||
public String path, operationId, returnType, httpMethod, returnBaseType,
|
||||
returnContainer, summary, unescapedNotes, notes, baseName, defaultResponse, discriminator;
|
||||
public List<Map<String, String>> consumes, produces;
|
||||
@@ -88,6 +91,81 @@ public class CodegenOperation {
|
||||
return nonempty(formParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if act as Restful index method
|
||||
*
|
||||
* @return true if act as Restful index method, false otherwise
|
||||
*/
|
||||
public boolean isRestfulIndex() {
|
||||
return "GET".equals(httpMethod) && "".equals(pathWithoutBaseName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if act as Restful show method
|
||||
*
|
||||
* @return true if act as Restful show method, false otherwise
|
||||
*/
|
||||
public boolean isRestfulShow() {
|
||||
return "GET".equals(httpMethod) && isMemberPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if act as Restful create method
|
||||
*
|
||||
* @return true if act as Restful create method, false otherwise
|
||||
*/
|
||||
public boolean isRestfulCreate() {
|
||||
return "POST".equals(httpMethod) && "".equals(pathWithoutBaseName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if act as Restful update method
|
||||
*
|
||||
* @return true if act as Restful update method, false otherwise
|
||||
*/
|
||||
public boolean isRestfulUpdate() {
|
||||
return Arrays.asList("PUT", "PATCH").contains(httpMethod) && isMemberPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if act as Restful destroy method
|
||||
*
|
||||
* @return true if act as Restful destroy method, false otherwise
|
||||
*/
|
||||
public boolean isRestfulDestroy() {
|
||||
return "DELETE".equals(httpMethod) && isMemberPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Restful-style
|
||||
*
|
||||
* @return true if Restful-style, false otherwise
|
||||
*/
|
||||
public boolean isRestful() {
|
||||
return isRestfulIndex() || isRestfulShow() || isRestfulCreate() || isRestfulUpdate() || isRestfulDestroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the substring except baseName from path
|
||||
*
|
||||
* @return the substring
|
||||
*/
|
||||
private String pathWithoutBaseName() {
|
||||
return baseName != null ? path.replace("/" + baseName.toLowerCase(), "") : path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the path match format /xxx/:id
|
||||
*
|
||||
* @return true if path act as member
|
||||
*/
|
||||
private boolean isMemberPath() {
|
||||
if (pathParams.size() != 1) return false;
|
||||
|
||||
String id = pathParams.get(0).baseName;
|
||||
return ("/{" + id + "}").equals(pathWithoutBaseName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s(%s)", baseName, path);
|
||||
|
||||
@@ -1901,6 +1901,14 @@ public class DefaultCodegen {
|
||||
}
|
||||
op.externalDocs = operation.getExternalDocs();
|
||||
|
||||
// set Restful Flag
|
||||
op.isRestfulShow = op.isRestfulShow();
|
||||
op.isRestfulIndex = op.isRestfulIndex();
|
||||
op.isRestfulCreate = op.isRestfulCreate();
|
||||
op.isRestfulUpdate = op.isRestfulUpdate();
|
||||
op.isRestfulDestroy = op.isRestfulDestroy();
|
||||
op.isRestful = op.isRestful();
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
@@ -2519,6 +2527,7 @@ public class DefaultCodegen {
|
||||
private void addVars(CodegenModel m, Map<String, Property> properties, List<String> required,
|
||||
Map<String, Property> allProperties, List<String> allRequired) {
|
||||
|
||||
m.hasRequired = false;
|
||||
if (properties != null && !properties.isEmpty()) {
|
||||
m.hasVars = true;
|
||||
m.hasEnums = false;
|
||||
@@ -2557,6 +2566,7 @@ public class DefaultCodegen {
|
||||
} else {
|
||||
final CodegenProperty cp = fromProperty(key, prop);
|
||||
cp.required = mandatory.contains(key) ? true : null;
|
||||
m.hasRequired = Boolean.TRUE.equals(m.hasRequired) || Boolean.TRUE.equals(cp.required);
|
||||
if (cp.isEnum) {
|
||||
// FIXME: if supporting inheritance, when called a second time for allProperties it is possible for
|
||||
// m.hasEnums to be set incorrectly if allProperties has enumerations but properties does not.
|
||||
|
||||
@@ -89,8 +89,8 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
cliOptions.add(CliOption.newBoolean(USE_ANDROID_MAVEN_GRADLE_PLUGIN, "A flag to toggle android-maven gradle plugin.")
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
|
||||
supportedLibraries.put("<default>", "HTTP client: Apache HttpClient 4.3.6. JSON processing: Gson 2.3.1");
|
||||
supportedLibraries.put("volley", "HTTP client: Volley 1.0.19");
|
||||
supportedLibraries.put("volley", "HTTP client: Volley 1.0.19 (default)");
|
||||
supportedLibraries.put("httpclient", "HTTP client: Apache HttpClient 4.3.6. JSON processing: Gson 2.3.1. IMPORTANT: Android client using HttpClient is not actively maintained and will be depecreated in the next major release.");
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
library.setEnum(supportedLibraries);
|
||||
cliOptions.add(library);
|
||||
@@ -382,23 +382,26 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
additionalProperties.put( "modelDocPath", modelDocPath );
|
||||
|
||||
if (StringUtils.isEmpty(getLibrary())) {
|
||||
modelDocTemplateFiles.put( "model_doc.mustache", ".md" );
|
||||
apiDocTemplateFiles.put( "api_doc.mustache", ".md" );
|
||||
//supportingFiles.add(new SupportingFile("api_doc.mustache", apiDocPath, "api.md"));
|
||||
//supportingFiles.add(new SupportingFile("model_doc.mustache", modelDocPath, "model.md"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
addSupportingFilesForDefault();
|
||||
} else if ("volley".equals(getLibrary())) {
|
||||
modelDocTemplateFiles.put( "model_doc.mustache", ".md" );
|
||||
apiDocTemplateFiles.put( "api_doc.mustache", ".md" );
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
//supportingFiles.add(new SupportingFile("api_doc.mustache", apiDocPath, "api.md"));
|
||||
//supportingFiles.add(new SupportingFile("model_doc.mustache", modelDocPath, "model.md"));
|
||||
addSupportingFilesForVolley();
|
||||
setLibrary("volley"); // set volley as the default library
|
||||
}
|
||||
|
||||
// determine which file (mustache) to add based on library
|
||||
if ("volley".equals(getLibrary())) {
|
||||
addSupportingFilesForVolley();
|
||||
} else if ("httpclient".equals(getLibrary())) {
|
||||
addSupportingFilesForHttpClient();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid 'library' option specified: '" + getLibrary() + "'. Must be 'httpclient' or 'volley' (default)");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addSupportingFilesForDefault() {
|
||||
private void addSupportingFilesForHttpClient() {
|
||||
// documentation files
|
||||
modelDocTemplateFiles.put( "model_doc.mustache", ".md" );
|
||||
apiDocTemplateFiles.put( "api_doc.mustache", ".md" );
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
supportingFiles.add(new SupportingFile("build.mustache", "", "build.gradle"));
|
||||
@@ -418,6 +421,13 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
}
|
||||
|
||||
private void addSupportingFilesForVolley() {
|
||||
// documentation files
|
||||
modelDocTemplateFiles.put( "model_doc.mustache", ".md" );
|
||||
apiDocTemplateFiles.put( "api_doc.mustache", ".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"));
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
// supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
supportingFiles.add(new SupportingFile("build.mustache", "", "build.gradle"));
|
||||
|
||||
@@ -218,6 +218,8 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
binRelativePath += "vendor";
|
||||
additionalProperties.put("binRelativePath", binRelativePath);
|
||||
|
||||
supportingFiles.add(new SupportingFile("IApiAccessor.mustache",
|
||||
clientPackageDir, "IApiAccessor.cs"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache",
|
||||
clientPackageDir, "Configuration.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache",
|
||||
|
||||
@@ -107,12 +107,12 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
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");
|
||||
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_1, "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
|
||||
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.1). Enable the RxJava adapter using '-DuseRxJava=true'. (RxJava 1.1.2)");
|
||||
supportedLibraries.put(DEFAULT_LIBRARY, "HTTP client: Jersey client 1.19.1. JSON processing: Jackson 2.7.0");
|
||||
supportedLibraries.put("feign", "HTTP client: Netflix Feign 8.16.0. JSON processing: Jackson 2.7.0");
|
||||
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.22.2. JSON processing: Jackson 2.7.0");
|
||||
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.6.2");
|
||||
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
|
||||
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.2.0. JSON processing: Gson 2.6.1 (Retrofit 2.0.2). Enable the RxJava adapter using '-DuseRxJava=true'. (RxJava 1.1.3)");
|
||||
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
library.setDefault(DEFAULT_LIBRARY);
|
||||
|
||||
@@ -42,6 +42,9 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String[] specialWords = {"new", "copy"};
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
protected String modelFilesPath = "Model/";
|
||||
protected String coreFilesPath = "Core/";
|
||||
protected String apiFilesPath = "Api/";
|
||||
|
||||
protected Set<String> advancedMapingTypes = new HashSet<String>();
|
||||
|
||||
@@ -223,35 +226,38 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
|
||||
String swaggerFolder = podName;
|
||||
additionalProperties.put("modelFilesPath", modelFilesPath);
|
||||
additionalProperties.put("coreFilesPath", coreFilesPath);
|
||||
additionalProperties.put("apiFilesPath", apiFilesPath);
|
||||
|
||||
modelPackage = swaggerFolder;
|
||||
apiPackage = swaggerFolder;
|
||||
modelPackage = podName;
|
||||
apiPackage = podName;
|
||||
|
||||
supportingFiles.add(new SupportingFile("Object-header.mustache", swaggerFolder, classPrefix + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("Object-body.mustache", swaggerFolder, classPrefix + "Object.m"));
|
||||
supportingFiles.add(new SupportingFile("QueryParamCollection-header.mustache", swaggerFolder, classPrefix + "QueryParamCollection.h"));
|
||||
supportingFiles.add(new SupportingFile("QueryParamCollection-body.mustache", swaggerFolder, classPrefix + "QueryParamCollection.m"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient-header.mustache", swaggerFolder, classPrefix + "ApiClient.h"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient-body.mustache", swaggerFolder, classPrefix + "ApiClient.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONResponseSerializer-header.mustache", swaggerFolder, classPrefix + "JSONResponseSerializer.h"));
|
||||
supportingFiles.add(new SupportingFile("JSONResponseSerializer-body.mustache", swaggerFolder, classPrefix + "JSONResponseSerializer.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONRequestSerializer-body.mustache", swaggerFolder, classPrefix + "JSONRequestSerializer.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONRequestSerializer-header.mustache", swaggerFolder, classPrefix + "JSONRequestSerializer.h"));
|
||||
supportingFiles.add(new SupportingFile("ResponseDeserializer-body.mustache", swaggerFolder, classPrefix + "ResponseDeserializer.m"));
|
||||
supportingFiles.add(new SupportingFile("ResponseDeserializer-header.mustache", swaggerFolder, classPrefix + "ResponseDeserializer.h"));
|
||||
supportingFiles.add(new SupportingFile("Sanitizer-body.mustache", swaggerFolder, classPrefix + "Sanitizer.m"));
|
||||
supportingFiles.add(new SupportingFile("Sanitizer-header.mustache", swaggerFolder, classPrefix + "Sanitizer.h"));
|
||||
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.m", swaggerFolder, "JSONValueTransformer+ISO8601.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.h", swaggerFolder, "JSONValueTransformer+ISO8601.h"));
|
||||
supportingFiles.add(new SupportingFile("Configuration-body.mustache", swaggerFolder, classPrefix + "Configuration.m"));
|
||||
supportingFiles.add(new SupportingFile("Configuration-header.mustache", swaggerFolder, classPrefix + "Configuration.h"));
|
||||
supportingFiles.add(new SupportingFile("Object-header.mustache", coreFileFolder(), classPrefix + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("Object-body.mustache", coreFileFolder(), classPrefix + "Object.m"));
|
||||
supportingFiles.add(new SupportingFile("QueryParamCollection-header.mustache", coreFileFolder(), classPrefix + "QueryParamCollection.h"));
|
||||
supportingFiles.add(new SupportingFile("QueryParamCollection-body.mustache", coreFileFolder(), classPrefix + "QueryParamCollection.m"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient-header.mustache", coreFileFolder(), classPrefix + "ApiClient.h"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient-body.mustache", coreFileFolder(), classPrefix + "ApiClient.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONResponseSerializer-header.mustache", coreFileFolder(), classPrefix + "JSONResponseSerializer.h"));
|
||||
supportingFiles.add(new SupportingFile("JSONResponseSerializer-body.mustache", coreFileFolder(), classPrefix + "JSONResponseSerializer.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONRequestSerializer-body.mustache", coreFileFolder(), classPrefix + "JSONRequestSerializer.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONRequestSerializer-header.mustache", coreFileFolder(), classPrefix + "JSONRequestSerializer.h"));
|
||||
supportingFiles.add(new SupportingFile("ResponseDeserializer-body.mustache", coreFileFolder(), classPrefix + "ResponseDeserializer.m"));
|
||||
supportingFiles.add(new SupportingFile("ResponseDeserializer-header.mustache", coreFileFolder(), classPrefix + "ResponseDeserializer.h"));
|
||||
supportingFiles.add(new SupportingFile("Sanitizer-body.mustache", coreFileFolder(), classPrefix + "Sanitizer.m"));
|
||||
supportingFiles.add(new SupportingFile("Sanitizer-header.mustache", coreFileFolder(), classPrefix + "Sanitizer.h"));
|
||||
supportingFiles.add(new SupportingFile("Logger-body.mustache", coreFileFolder(), classPrefix + "Logger.m"));
|
||||
supportingFiles.add(new SupportingFile("Logger-header.mustache", coreFileFolder(), classPrefix + "Logger.h"));
|
||||
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.m", coreFileFolder(), "JSONValueTransformer+ISO8601.m"));
|
||||
supportingFiles.add(new SupportingFile("JSONValueTransformer+ISO8601.h", coreFileFolder(), "JSONValueTransformer+ISO8601.h"));
|
||||
supportingFiles.add(new SupportingFile("Configuration-body.mustache", coreFileFolder(), classPrefix + "Configuration.m"));
|
||||
supportingFiles.add(new SupportingFile("Configuration-header.mustache", coreFileFolder(), classPrefix + "Configuration.h"));
|
||||
supportingFiles.add(new SupportingFile("podspec.mustache", "", podName + ".podspec"));
|
||||
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"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -454,12 +460,16 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separatorChar + apiPackage();
|
||||
return (outputFolder + "/"+ apiPackage() + "/" + apiFilesPath).replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separatorChar + modelPackage();
|
||||
return (outputFolder + "/"+ modelPackage() + "/" + modelFilesPath).replace("/", File.separator);
|
||||
}
|
||||
|
||||
public String coreFileFolder() {
|
||||
return (apiPackage() + "/" + coreFilesPath).replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
@@ -13,6 +14,7 @@ import io.swagger.models.properties.*;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashSet;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -35,7 +37,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String composerVendorName = "swagger";
|
||||
protected String composerProjectName = "swagger-client";
|
||||
protected String packagePath = "SwaggerClient-php";
|
||||
protected String artifactVersion = "1.0.0";
|
||||
protected String artifactVersion = null;
|
||||
protected String srcBasePath = "lib";
|
||||
protected String testBasePath = "test";
|
||||
protected String docsBasePath = "docs";
|
||||
@@ -626,4 +628,14 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// process enum in models
|
||||
return postProcessModelsEnum(objs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation op : operationList) {
|
||||
op.vendorExtensions.put("x-testOperationId", camelize(op.operationId));
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
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.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.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Rails5ServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Rails5ServerCodegen.class);
|
||||
|
||||
protected String gemName;
|
||||
protected String moduleName;
|
||||
protected String gemVersion = "1.0.0";
|
||||
protected String appFolder = "app";
|
||||
protected String channelsFolder = appFolder + File.separator + "channels";
|
||||
protected String applicationCableFolder = channelsFolder + File.separator + "application_cable";
|
||||
protected String controllersFolder = appFolder + File.separator + "controllers";
|
||||
protected String jobsFolder = appFolder + File.separator + "jobs";
|
||||
protected String mailersFolder = appFolder + File.separator + "mailers";
|
||||
protected String modelsFolder = appFolder + File.separator + "models";
|
||||
protected String viewsFolder = appFolder + File.separator + "views";
|
||||
protected String layoutsFolder = viewsFolder + File.separator + "layouts";
|
||||
protected String binFolder = "bin";
|
||||
protected String configFolder = "config";
|
||||
protected String environmentsFolder = configFolder + File.separator + "config";
|
||||
protected String initializersFolder = configFolder + File.separator + "initializers";
|
||||
protected String localesFolder = configFolder + File.separator + "locales";
|
||||
protected String dbFolder = "db";
|
||||
protected String migrateFolder = dbFolder + File.separator + "migrate";
|
||||
protected String libFolder = "lib";
|
||||
protected String tasksFolder = libFolder + File.separator + "tasks";
|
||||
protected String logFolder = "log";
|
||||
protected String publicFolder = "public";
|
||||
protected String testFolder = "test";
|
||||
protected String tmpFolder = "tmp";
|
||||
protected String cacheFolder = tmpFolder + File.separator + "cache";
|
||||
protected String pidFolder = tmpFolder + File.separator + "pids";
|
||||
protected String socketsFolder = tmpFolder + File.separator + "sockets";
|
||||
protected String vendorFolder = "vendor";
|
||||
|
||||
public Rails5ServerCodegen() {
|
||||
super();
|
||||
apiPackage = "app/controllers";
|
||||
outputFolder = "generated-code" + File.separator + "rails5";
|
||||
|
||||
// no model
|
||||
modelTemplateFiles.clear();
|
||||
apiTemplateFiles.put("controller.mustache", ".rb");
|
||||
embeddedTemplateDir = templateDir = "rails5";
|
||||
|
||||
typeMapping.clear();
|
||||
languageSpecificPrimitives.clear();
|
||||
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__",
|
||||
"begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN",
|
||||
"break", "do", "false", "next", "rescue", "then", "when", "END", "case",
|
||||
"else", "for", "nil", "retry", "true", "while", "alias", "class", "elsif",
|
||||
"if", "not", "return", "undef", "yield")
|
||||
);
|
||||
|
||||
languageSpecificPrimitives.add("int");
|
||||
languageSpecificPrimitives.add("array");
|
||||
languageSpecificPrimitives.add("map");
|
||||
languageSpecificPrimitives.add("string");
|
||||
languageSpecificPrimitives.add("DateTime");
|
||||
|
||||
typeMapping.put("long", "int");
|
||||
typeMapping.put("integer", "int");
|
||||
typeMapping.put("Array", "array");
|
||||
typeMapping.put("String", "string");
|
||||
typeMapping.put("List", "array");
|
||||
typeMapping.put("map", "map");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
|
||||
// remove modelPackage and apiPackage added by default
|
||||
cliOptions.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
// use constant model/api package (folder path)
|
||||
//setModelPackage("models");
|
||||
setApiPackage("app/controllers");
|
||||
|
||||
supportingFiles.add(new SupportingFile("Gemfile", "", "Gemfile"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("Rakefile", "", "Rakefile"));
|
||||
supportingFiles.add(new SupportingFile("config.ru", "", "config.ru"));
|
||||
supportingFiles.add(new SupportingFile("channel.rb", applicationCableFolder, "channel.rb"));
|
||||
supportingFiles.add(new SupportingFile("connection.rb", applicationCableFolder, "connection.rb"));
|
||||
supportingFiles.add(new SupportingFile("application_controller.rb", controllersFolder, "application_controller.rb"));
|
||||
supportingFiles.add(new SupportingFile("application_job.rb", jobsFolder, "application_job.rb"));
|
||||
supportingFiles.add(new SupportingFile("application_mailer.rb", mailersFolder, "application_mailer.rb"));
|
||||
supportingFiles.add(new SupportingFile("application_record.rb", modelsFolder, "application_record.rb"));
|
||||
supportingFiles.add(new SupportingFile("mailer.html.erb", layoutsFolder, "mailer.html.erb"));
|
||||
supportingFiles.add(new SupportingFile("mailer.text.erb", layoutsFolder, "mailer.text.erb"));
|
||||
supportingFiles.add(new SupportingFile("bundle", binFolder, "bundle"));
|
||||
supportingFiles.add(new SupportingFile("rails", binFolder, "rails"));
|
||||
supportingFiles.add(new SupportingFile("rake", binFolder, "rake"));
|
||||
supportingFiles.add(new SupportingFile("setup", binFolder, "setup"));
|
||||
supportingFiles.add(new SupportingFile("update", binFolder, "update"));
|
||||
supportingFiles.add(new SupportingFile("development.rb", environmentsFolder, "development.rb"));
|
||||
supportingFiles.add(new SupportingFile("production.rb", environmentsFolder, "production.rb"));
|
||||
supportingFiles.add(new SupportingFile("active_record_belongs_to_required_by_default.rb", initializersFolder, "active_record_belongs_to_required_by_default.rb"));
|
||||
supportingFiles.add(new SupportingFile("application_controller_renderer.rb", initializersFolder, "application_controller_renderer.rb"));
|
||||
supportingFiles.add(new SupportingFile("backtrace_silencers.rb", initializersFolder, "backtrace_silencers.rb"));
|
||||
supportingFiles.add(new SupportingFile("callback_terminator.rb", initializersFolder, "callback_terminator.rb"));
|
||||
supportingFiles.add(new SupportingFile("cors.rb", initializersFolder, "cors.rb"));
|
||||
supportingFiles.add(new SupportingFile("filter_parameter_logging.rb", initializersFolder, "filter_parameter_logging.rb"));
|
||||
supportingFiles.add(new SupportingFile("inflections.rb", initializersFolder, "inflections.rb"));
|
||||
supportingFiles.add(new SupportingFile("mime_types.rb", initializersFolder, "mime_types.rb"));
|
||||
supportingFiles.add(new SupportingFile("ssl_options.rb", initializersFolder, "ssl_options.rb"));
|
||||
supportingFiles.add(new SupportingFile("to_time_preserves_timezone.rb", initializersFolder, "to_time_preserves_timezone.rb"));
|
||||
supportingFiles.add(new SupportingFile("en.yml", localesFolder, "en.yml"));
|
||||
supportingFiles.add(new SupportingFile("application.rb", configFolder, "application.rb"));
|
||||
supportingFiles.add(new SupportingFile("boot.rb", configFolder, "boot.rb"));
|
||||
supportingFiles.add(new SupportingFile("cable.yml", configFolder, "cable.yml"));
|
||||
supportingFiles.add(new SupportingFile("database.yml", configFolder, "database.yml"));
|
||||
supportingFiles.add(new SupportingFile("environment.rb", configFolder, "environment.rb"));
|
||||
supportingFiles.add(new SupportingFile("puma.rb", configFolder, "puma.rb"));
|
||||
supportingFiles.add(new SupportingFile("routes.mustache", configFolder, "routes.rb"));
|
||||
supportingFiles.add(new SupportingFile("secrets.yml", configFolder, "secrets.yml"));
|
||||
supportingFiles.add(new SupportingFile("spring.rb", configFolder, "spring.rb"));
|
||||
supportingFiles.add(new SupportingFile(".keep", migrateFolder, ".keep"));
|
||||
supportingFiles.add(new SupportingFile("schema.rb", dbFolder, "schema.rb"));
|
||||
supportingFiles.add(new SupportingFile("seeds.rb", dbFolder, "seeds.rb"));
|
||||
supportingFiles.add(new SupportingFile(".keep", tasksFolder, ".keep"));
|
||||
supportingFiles.add(new SupportingFile(".keep", logFolder, ".keep"));
|
||||
supportingFiles.add(new SupportingFile("404.html", publicFolder, "404.html"));
|
||||
supportingFiles.add(new SupportingFile("422.html", publicFolder, "422.html"));
|
||||
supportingFiles.add(new SupportingFile("500.html", publicFolder, "500.html"));
|
||||
supportingFiles.add(new SupportingFile("apple-touch-icon-precomposed.png", publicFolder, "apple-touch-icon-precomposed.png"));
|
||||
supportingFiles.add(new SupportingFile("apple-touch-icon.png", publicFolder, "apple-touch-icon.png"));
|
||||
supportingFiles.add(new SupportingFile("favicon.ico", publicFolder, "favicon.ico"));
|
||||
supportingFiles.add(new SupportingFile("robots.txt", publicFolder, "robots.txt"));
|
||||
supportingFiles.add(new SupportingFile("robots.txt", publicFolder, "robots.txt"));
|
||||
supportingFiles.add(new SupportingFile("test_helper.rb", testFolder, "test_helper.rb"));
|
||||
supportingFiles.add(new SupportingFile(".keep", cacheFolder, ".keep"));
|
||||
supportingFiles.add(new SupportingFile(".keep", pidFolder, ".keep"));
|
||||
supportingFiles.add(new SupportingFile(".keep", socketsFolder, ".keep"));
|
||||
supportingFiles.add(new SupportingFile("restart.txt", tmpFolder, "restart.txt"));
|
||||
supportingFiles.add(new SupportingFile(".keep", vendorFolder, ".keep"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "rails5";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Rails5 server library.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + File.separator + apiPackage.replace("/", File.separator);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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 type;
|
||||
}
|
||||
} else {
|
||||
type = swaggerType;
|
||||
}
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(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'.
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
|
||||
// camelize (lower first character) the variable name
|
||||
// petId => pet_id
|
||||
name = underscore(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
// underscore the model file name
|
||||
// PhoneNumber.rb => phone_number.rb
|
||||
return underscore(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
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. PhoneNumberApi.rb => phone_number_api.rb
|
||||
return underscore(name) + "_controllers";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "ApiController";
|
||||
}
|
||||
// e.g. phone_number_api => PhoneNumberApi
|
||||
return camelize(name) + "Controller";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
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) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -355,8 +355,8 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (value.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) {
|
||||
return value;
|
||||
}
|
||||
char[] separators = {'-', '_', ' '};
|
||||
return WordUtils.capitalizeFully(StringUtils.lowerCase(value), separators).replaceAll("[-_ ]", "");
|
||||
char[] separators = {'-', '_', ' ', ':'};
|
||||
return WordUtils.capitalizeFully(StringUtils.lowerCase(value), separators).replaceAll("[-_ :]", "");
|
||||
}
|
||||
|
||||
|
||||
@@ -502,6 +502,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String name, String datatype) {
|
||||
// TODO: this code is probably useless, because the var name is computed from the value in map.put("enum", toSwiftyEnumName(value));
|
||||
// number
|
||||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||
String varName = new String(name);
|
||||
@@ -525,8 +526,9 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String enumName = underscore(toModelName(property.name)).toUpperCase();
|
||||
String enumName = toModelName(property.name);
|
||||
|
||||
// TODO: toModelName already does something for names starting with number, so this code is probably never called
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
|
||||
@@ -26,7 +26,6 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
super.processOpts();
|
||||
supportingFiles.add(new SupportingFile("api.mustache", "", "api.ts"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("assign.ts", "", "assign.ts"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("package.json.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("typings.json.mustache", "", "typings.json"));
|
||||
|
||||
Reference in New Issue
Block a user