mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
added folder to writeOptional
This commit is contained in:
parent
7c2d09d0e4
commit
fc56546d34
@ -2231,10 +2231,16 @@ public class DefaultCodegen {
|
||||
/**
|
||||
* only write if the file doesn't exist
|
||||
*
|
||||
* @param outputFolder
|
||||
* @param supportingFile
|
||||
*/
|
||||
public void writeOptional(SupportingFile supportingFile) {
|
||||
String folder = supportingFile.folder;
|
||||
public void writeOptional(String outputFolder, SupportingFile supportingFile) {
|
||||
String folder = "";
|
||||
|
||||
if(outputFolder != null && !"".equals(outputFolder)) {
|
||||
folder += outputFolder + File.separator;
|
||||
}
|
||||
folder += supportingFile.folder;
|
||||
if(!"".equals(folder)) {
|
||||
folder += File.separator + supportingFile.destinationFilename;
|
||||
}
|
||||
|
@ -1,11 +1,5 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenResponse;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
@ -13,6 +7,8 @@ import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractJavaJAXRSServerCodegen extends JavaClientCodegen
|
||||
{
|
||||
/**
|
||||
@ -49,8 +45,7 @@ public abstract class AbstractJavaJAXRSServerCodegen extends JavaClientCodegen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger)
|
||||
{
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
if ( "/".equals(swagger.getBasePath()) ) {
|
||||
swagger.setBasePath("");
|
||||
}
|
||||
@ -93,8 +88,7 @@ public abstract class AbstractJavaJAXRSServerCodegen extends JavaClientCodegen
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs)
|
||||
{
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
if ( operations != null ) {
|
||||
@ -139,8 +133,7 @@ public abstract class AbstractJavaJAXRSServerCodegen extends JavaClientCodegen
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(final String name)
|
||||
{
|
||||
public String toApiName(final String name) {
|
||||
String computed = name;
|
||||
if ( computed.length() == 0 ) {
|
||||
return "DefaultApi";
|
||||
@ -150,8 +143,7 @@ public abstract class AbstractJavaJAXRSServerCodegen extends JavaClientCodegen
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag)
|
||||
{
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String result = super.apiFilename(templateName, tag);
|
||||
|
||||
if ( templateName.endsWith("Impl.mustache") ) {
|
||||
@ -169,15 +161,12 @@ public abstract class AbstractJavaJAXRSServerCodegen extends JavaClientCodegen
|
||||
return result;
|
||||
}
|
||||
|
||||
private String implFileFolder(String output)
|
||||
{
|
||||
private String implFileFolder(String output) {
|
||||
return outputFolder + "/" + output + "/" + apiPackage().replace('.', '/');
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(String filename)
|
||||
{
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
return super.shouldOverwrite(filename) && !filename.endsWith("ServiceImpl.java") && !filename.endsWith("ServiceFactory.java");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -234,13 +234,13 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
importMapping.put("StringUtil", invokerPackage + ".StringUtil");
|
||||
|
||||
final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
||||
writeOptional(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(new SupportingFile("README.mustache", "", "README.md"));
|
||||
writeOptional(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
|
||||
writeOptional(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
writeOptional(new SupportingFile("gradle.properties.mustache", "", "gradle.properties"));
|
||||
writeOptional(new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
|
||||
writeOptional(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
|
||||
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
writeOptional(outputFolder, new SupportingFile("build.gradle.mustache", "", "build.gradle"));
|
||||
writeOptional(outputFolder, new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
|
||||
writeOptional(outputFolder, new SupportingFile("gradle.properties.mustache", "", "gradle.properties"));
|
||||
writeOptional(outputFolder, new SupportingFile("manifest.mustache", projectFolder, "AndroidManifest.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
|
||||
|
||||
final String authFolder = (sourceFolder + '/' + invokerPackage + ".auth").replace(".", "/");
|
||||
|
@ -18,11 +18,11 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaInflectorServerCodegen.class);
|
||||
|
||||
protected String title = "Swagger Inflector";
|
||||
|
||||
protected String implFolder = "src/main/java";
|
||||
public JavaInflectorServerCodegen() {
|
||||
super();
|
||||
|
||||
sourceFolder = "src/main/java";
|
||||
sourceFolder = "src/gen/java";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
embeddedTemplateDir = templateDir = "JavaInflector";
|
||||
@ -71,10 +71,10 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
super.processOpts();
|
||||
|
||||
supportingFiles.clear();
|
||||
writeOptional(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(new SupportingFile("README.mustache", "", "README.md"));
|
||||
writeOptional(new SupportingFile("web.mustache", "src/main/webapp/WEB-INF", "web.xml"));
|
||||
writeOptional(new SupportingFile("inflector.mustache", "", "inflector.yaml"));
|
||||
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
writeOptional(outputFolder, new SupportingFile("web.mustache", "src/main/webapp/WEB-INF", "web.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("inflector.mustache", "", "inflector.yaml"));
|
||||
supportingFiles.add(new SupportingFile("swagger.mustache",
|
||||
"src/main/swagger",
|
||||
"swagger.yaml")
|
||||
@ -161,6 +161,18 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
return objs;
|
||||
}
|
||||
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String result = super.apiFilename(templateName, tag);
|
||||
|
||||
if ( templateName.endsWith("api.mustache") ) {
|
||||
int ix = result.indexOf(sourceFolder);
|
||||
String beg = result.substring(0, ix);
|
||||
String end = result.substring(ix + sourceFolder.length());
|
||||
new java.io.File(beg + implFolder).mkdirs();
|
||||
result = beg + implFolder + end;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
@ -183,12 +195,4 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
name = name.replaceAll("[^a-zA-Z0-9]+", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
return camelize(name)+ "Controller";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
return super.shouldOverwrite(filename) &&
|
||||
!filename.endsWith("pom.xml") &&
|
||||
!filename.endsWith("README.md") &&
|
||||
!filename.endsWith("inflector.yaml");
|
||||
}
|
||||
}
|
||||
|
@ -79,13 +79,13 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
}
|
||||
|
||||
supportingFiles.clear();
|
||||
writeOptional(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(new SupportingFile("README.mustache", "", "README.md"));
|
||||
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiException.java"));
|
||||
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"));
|
||||
writeOptional(new SupportingFile("web.mustache", ("src/main/webapp/WEB-INF"), "web.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("web.mustache", ("src/main/webapp/WEB-INF"), "web.xml"));
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "StringUtil.java"));
|
||||
|
||||
if ( additionalProperties.containsKey("dateLibrary") ) {
|
||||
|
@ -89,10 +89,10 @@ public class JavaResteasyServerCodegen extends JavaClientCodegen implements Code
|
||||
}
|
||||
|
||||
supportingFiles.clear();
|
||||
writeOptional(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(new SupportingFile("gradle.mustache", "", "build.gradle"));
|
||||
writeOptional(new SupportingFile("settingsGradle.mustache", "", "settings.gradle"));
|
||||
writeOptional(new SupportingFile("README.mustache", "", "README.md"));
|
||||
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("gradle.mustache", "", "build.gradle"));
|
||||
writeOptional(outputFolder, new SupportingFile("settingsGradle.mustache", "", "settings.gradle"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("ApiException.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiOriginFilter.mustache",
|
||||
@ -101,11 +101,11 @@ public class JavaResteasyServerCodegen extends JavaClientCodegen implements Code
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "ApiResponseMessage.java"));
|
||||
supportingFiles.add(new SupportingFile("NotFoundException.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "NotFoundException.java"));
|
||||
writeOptional(new SupportingFile("web.mustache",
|
||||
writeOptional(outputFolder, new SupportingFile("web.mustache",
|
||||
("src/main/webapp/WEB-INF"), "web.xml"));
|
||||
writeOptional(new SupportingFile("jboss-web.mustache",
|
||||
writeOptional(outputFolder, new SupportingFile("jboss-web.mustache",
|
||||
("src/main/webapp/WEB-INF"), "jboss-web.xml"));
|
||||
writeOptional(new SupportingFile("RestApplication.mustache",
|
||||
writeOptional(outputFolder, new SupportingFile("RestApplication.mustache",
|
||||
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "RestApplication.java"));
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache",
|
||||
(sourceFolder + '/' + invokerPackage).replace(".", "/"), "StringUtil.java"));
|
||||
|
@ -89,18 +89,9 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"api",
|
||||
"swagger.yaml")
|
||||
);
|
||||
writeOptional(new SupportingFile("index.mustache",
|
||||
"",
|
||||
"index.js")
|
||||
);
|
||||
writeOptional(new SupportingFile("package.mustache",
|
||||
"",
|
||||
"package.json")
|
||||
);
|
||||
writeOptional(new SupportingFile("README.mustache",
|
||||
"",
|
||||
"README.md")
|
||||
);
|
||||
writeOptional(outputFolder, new SupportingFile("index.mustache", "", "index.js"));
|
||||
writeOptional(outputFolder, new SupportingFile("package.mustache", "", "package.json"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
if (System.getProperty("noservice") == null) {
|
||||
apiTemplateFiles.put(
|
||||
"service.mustache", // the template to use
|
||||
|
Loading…
Reference in New Issue
Block a user