forked from loafle/openapi-generator-original
Merge branch 'master' into ruby-binary
Conflicts: samples/client/petstore/ruby/lib/petstore/api/pet_api.rb
This commit is contained in:
@@ -7,11 +7,16 @@ import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ConfigParser {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigParser.class);
|
||||
|
||||
public static Config read(String location) {
|
||||
|
||||
System.out.println("reading config from " + location);
|
||||
LOGGER.info("reading config from " + location);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@@ -27,11 +32,11 @@ public class ConfigParser {
|
||||
if (optionNode.getValue().isValueNode()) {
|
||||
config.setOption(optionNode.getKey(), optionNode.getValue().asText());
|
||||
} else {
|
||||
System.out.println("omitting non-value node " + optionNode.getKey());
|
||||
LOGGER.warn("omitting non-value node " + optionNode.getKey());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
LOGGER.error(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,18 @@ import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class AbstractGenerator {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGenerator.class);
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public File writeToFile(String filename, String contents) throws IOException {
|
||||
System.out.println("writing file " + filename);
|
||||
LOGGER.info("writing file " + filename);
|
||||
File output = new File(filename);
|
||||
|
||||
if (output.getParent() != null && !new File(output.getParent()).exists()) {
|
||||
@@ -37,10 +42,10 @@ public abstract class AbstractGenerator {
|
||||
if (reader == null) {
|
||||
throw new RuntimeException("no file found");
|
||||
}
|
||||
java.util.Scanner s = new java.util.Scanner(reader).useDelimiter("\\A");
|
||||
Scanner s = new Scanner(reader).useDelimiter("\\A");
|
||||
return s.hasNext() ? s.next() : "";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage());
|
||||
}
|
||||
throw new RuntimeException("can't load template " + name);
|
||||
}
|
||||
@@ -53,7 +58,7 @@ public abstract class AbstractGenerator {
|
||||
}
|
||||
return new InputStreamReader(is);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage());
|
||||
}
|
||||
throw new RuntimeException("can't load template " + name);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import config.Config;
|
||||
import config.ConfigParser;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
import org.apache.commons.cli.BasicParser;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Options;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -17,12 +7,28 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import org.apache.commons.cli.BasicParser;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import config.Config;
|
||||
import config.ConfigParser;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.parser.SwaggerParser;
|
||||
|
||||
/**
|
||||
* @deprecated use instead {@link io.swagger.codegen.DefaultGenerator}
|
||||
* or cli interface from https://github.com/swagger-api/swagger-codegen/pull/547
|
||||
*/
|
||||
@Deprecated
|
||||
public class Codegen extends DefaultGenerator {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Codegen.class);
|
||||
|
||||
static Map<String, CodegenConfig> configs = new HashMap<String, CodegenConfig>();
|
||||
static String configString;
|
||||
static String debugInfoOptions = "\nThe following additional debug options are available for all codegen targets:" +
|
||||
@@ -111,7 +117,7 @@ public class Codegen extends DefaultGenerator {
|
||||
.swagger(swagger);
|
||||
new Codegen().opts(clientOptInput).generate();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,9 +142,9 @@ public class Codegen extends DefaultGenerator {
|
||||
} else {
|
||||
// see if it's a class
|
||||
try {
|
||||
System.out.println("loading class " + name);
|
||||
LOGGER.debug("loading class " + name);
|
||||
Class<?> customClass = Class.forName(name);
|
||||
System.out.println("loaded");
|
||||
LOGGER.debug("loaded");
|
||||
return (CodegenConfig) customClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("can't load class " + name);
|
||||
|
||||
@@ -62,10 +62,21 @@ public class CodegenConstants {
|
||||
public static final String OPTIONAL_ASSEMBLY_INFO = "optionalAssemblyInfo";
|
||||
public static final String OPTIONAL_ASSEMBLY_INFO_DESC = "Generate AssemblyInfo.cs (Default: true).";
|
||||
|
||||
public static final String USE_COLLECTION = "useCollection";
|
||||
public static final String USE_COLLECTION_DESC = "Deserialize array types to Collection<T> instead of List<T>.";
|
||||
|
||||
public static final String RETURN_ICOLLECTION = "returnICollection";
|
||||
public static final String RETURN_ICOLLECTION_DESC = "Return ICollection<T> instead of the concrete type.";
|
||||
|
||||
public static final String OPTIONAL_PROJECT_FILE = "optionalProjectFile";
|
||||
public static final String OPTIONAL_PROJECT_FILE_DESC = "Generate {PackageName}.csproj (Default: false).";
|
||||
|
||||
public static final String OPTIONAL_PROJECT_GUID = "packageGuid";
|
||||
public static final String OPTIONAL_PROJECT_GUID_DESC = "The GUID that will be associated with the C# project";
|
||||
|
||||
public static final String MODEL_PROPERTY_NAMING = "modelPropertyNaming";
|
||||
public static final String MODEL_PROPERTY_NAMING_DESC = "Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name";
|
||||
|
||||
public static enum MODEL_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case, original}
|
||||
|
||||
}
|
||||
|
||||
@@ -689,7 +689,7 @@ public class DefaultCodegen {
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Error obtaining the datatype from RefProperty:" + p + ". Datatype default to Object");
|
||||
datatype = "Object";
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
} else {
|
||||
if (p != null) {
|
||||
@@ -1090,7 +1090,7 @@ public class DefaultCodegen {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
CodegenProperty cp = fromProperty(property.name, ap.getItems());
|
||||
if (cp == null) {
|
||||
LOGGER.warn("skipping invalid property " + Json.pretty(p));
|
||||
LOGGER.warn("skipping invalid property " + Json.pretty(p));
|
||||
} else {
|
||||
property.baseType = getSwaggerType(p);
|
||||
if (!languageSpecificPrimitives.contains(cp.baseType)) {
|
||||
|
||||
@@ -240,7 +240,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
if (System.getProperty("debugModels") != null) {
|
||||
System.out.println("############ Model info ############");
|
||||
LOGGER.info("############ Model info ############");
|
||||
Json.prettyPrint(allModels);
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
if (System.getProperty("debugOperations") != null) {
|
||||
System.out.println("############ Operation info ############");
|
||||
LOGGER.info("############ Operation info ############");
|
||||
Json.prettyPrint(allOperations);
|
||||
}
|
||||
|
||||
@@ -379,7 +379,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
config.postProcessSupportingFileData(bundle);
|
||||
|
||||
if (System.getProperty("debugSupportingFiles") != null) {
|
||||
System.out.println("############ Supporting file info ############");
|
||||
LOGGER.info("############ Supporting file info ############");
|
||||
Json.prettyPrint(bundle);
|
||||
}
|
||||
|
||||
@@ -439,10 +439,12 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
File outputFile = new File(outputFilename);
|
||||
OutputStream out = new FileOutputStream(outputFile, false);
|
||||
if (in != null) {
|
||||
System.out.println("writing file " + outputFile);
|
||||
LOGGER.info("writing file " + outputFile);
|
||||
IOUtils.copy(in, out);
|
||||
} else {
|
||||
System.out.println("can't open " + templateFile + " for input"); // FIXME: use LOGGER instead of standart output
|
||||
if (in == null) {
|
||||
LOGGER.error("can't open " + templateFile + " for input");
|
||||
}
|
||||
}
|
||||
files.add(outputFile);
|
||||
}
|
||||
@@ -550,7 +552,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
public void processOperation(String resourcePath, String httpMethod, Operation operation, Map<String, List<CodegenOperation>> operations, Path path) {
|
||||
if (operation != null) {
|
||||
if (System.getProperty("debugOperations") != null) {
|
||||
LOGGER.debug("processOperation: resourcePath= " + resourcePath + "\t;" + httpMethod + " " + operation + "\n");
|
||||
LOGGER.info("processOperation: resourcePath= " + resourcePath + "\t;" + httpMethod + " " + operation
|
||||
+ "\n");
|
||||
}
|
||||
List<String> tags = operation.getTags();
|
||||
if (tags == null) {
|
||||
|
||||
@@ -8,8 +8,11 @@ import org.apache.commons.cli.CommandLineParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -24,6 +27,9 @@ import java.util.ServiceLoader;
|
||||
*/
|
||||
@Deprecated
|
||||
public class MetaGenerator extends AbstractGenerator {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MetaGenerator.class);
|
||||
|
||||
static Map<String, CodegenConfig> configs = new HashMap<String, CodegenConfig>();
|
||||
static String configString;
|
||||
|
||||
@@ -99,7 +105,7 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
usage(options);
|
||||
return;
|
||||
}
|
||||
System.out.println("writing to folder " + outputFolder);
|
||||
LOGGER.info("writing to folder " + outputFolder);
|
||||
File outputFolderLocation = new File(outputFolder);
|
||||
if (!outputFolderLocation.exists()) {
|
||||
outputFolderLocation.mkdirs();
|
||||
@@ -163,11 +169,11 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
} else {
|
||||
String template = readTemplate(templateDir + File.separator + support.templateFile);
|
||||
FileUtils.writeStringToFile(new File(outputFilename), template);
|
||||
System.out.println("copying file to " + outputFilename);
|
||||
LOGGER.info("copying file to " + outputFilename);
|
||||
files.add(new File(outputFilename));
|
||||
}
|
||||
} catch (java.io.IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,16 @@ import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import config.ConfigParser;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
public class AuthParser {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AuthParser.class);
|
||||
|
||||
public static List<AuthorizationValue> parse(String urlEncodedAuthStr) {
|
||||
List<AuthorizationValue> auths = new ArrayList<AuthorizationValue>();
|
||||
@@ -38,7 +45,7 @@ public class AuthParser {
|
||||
.append(URLEncoder.encode(v.getValue(), "UTF-8"));
|
||||
} catch (Exception e) {
|
||||
// continue
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return b.toString();
|
||||
|
||||
@@ -36,7 +36,7 @@ import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
*/
|
||||
public class CodegenConfigurator {
|
||||
|
||||
public static final Logger LOG = LoggerFactory.getLogger(CodegenConfigurator.class);
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(CodegenConfigurator.class);
|
||||
|
||||
private String lang;
|
||||
private String inputSpec;
|
||||
@@ -349,7 +349,7 @@ public class CodegenConfigurator {
|
||||
if (!verbose) {
|
||||
return;
|
||||
}
|
||||
LOG.info("\nVERBOSE MODE: ON. Additional debug options are injected" +
|
||||
LOGGER.info("\nVERBOSE MODE: ON. Additional debug options are injected" +
|
||||
"\n - [debugSwagger] prints the swagger specification as interpreted by the codegen" +
|
||||
"\n - [debugModels] prints models passed to the template engine" +
|
||||
"\n - [debugOperations] prints operations passed to the template engine" +
|
||||
@@ -392,7 +392,7 @@ public class CodegenConfigurator {
|
||||
try {
|
||||
return Json.mapper().readValue(new File(configFile), CodegenConfigurator.class);
|
||||
} catch (IOException e) {
|
||||
LOG.error("Unable to deserialize config file: " + configFile, e);
|
||||
LOGGER.error("Unable to deserialize config file: " + configFile, e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
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;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
|
||||
public abstract class AbstractJavaJAXRSServerCodegen extends JavaClientCodegen
|
||||
{
|
||||
/**
|
||||
* Name of the sub-directory in "src/main/resource" where to find the
|
||||
* Mustache template for the JAX-RS Codegen.
|
||||
*/
|
||||
protected static final String JAXRS_TEMPLATE_DIRECTORY_NAME = "JavaJaxRS";
|
||||
protected String implFolder = "src/main/java";
|
||||
protected String title = "Swagger Server";
|
||||
|
||||
public AbstractJavaJAXRSServerCodegen()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
// ================
|
||||
// ABSTRACT METHODS
|
||||
// ================
|
||||
|
||||
@Override
|
||||
public abstract String getHelp();
|
||||
|
||||
@Override
|
||||
public abstract String getName();
|
||||
|
||||
// ===============
|
||||
// COMMONS METHODS
|
||||
// ===============
|
||||
|
||||
@Override
|
||||
public CodegenType getTag()
|
||||
{
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger)
|
||||
{
|
||||
if ( "/".equals(swagger.getBasePath()) ) {
|
||||
swagger.setBasePath("");
|
||||
}
|
||||
|
||||
String host = swagger.getHost();
|
||||
String port = "8080"; // Default value for a JEE Server
|
||||
if ( host != null ) {
|
||||
String[] parts = host.split(":");
|
||||
if ( parts.length > 1 ) {
|
||||
port = parts[1];
|
||||
}
|
||||
}
|
||||
this.additionalProperties.put("serverPort", port);
|
||||
if ( swagger.getPaths() != null ) {
|
||||
for ( String pathname : swagger.getPaths().keySet() ) {
|
||||
Path path = swagger.getPath(pathname);
|
||||
if ( path.getOperations() != null ) {
|
||||
for ( Operation operation : path.getOperations() ) {
|
||||
if ( operation.getTags() != null ) {
|
||||
List<Map<String, String>> tags = new ArrayList<Map<String, String>>();
|
||||
for ( String tag : operation.getTags() ) {
|
||||
Map<String, String> value = new HashMap<String, String>();
|
||||
value.put("tag", tag);
|
||||
value.put("hasMore", "true");
|
||||
tags.add(value);
|
||||
}
|
||||
if ( tags.size() > 0 ) {
|
||||
tags.get(tags.size() - 1).remove("hasMore");
|
||||
}
|
||||
if ( operation.getTags().size() > 0 ) {
|
||||
String tag = operation.getTags().get(0);
|
||||
operation.setTags(Arrays.asList(tag));
|
||||
}
|
||||
operation.setVendorExtension("x-tags", tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
if ( operations != null ) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for ( CodegenOperation operation : ops ) {
|
||||
List<CodegenResponse> responses = operation.responses;
|
||||
if ( responses != null ) {
|
||||
for ( CodegenResponse resp : responses ) {
|
||||
if ( "0".equals(resp.code) ) {
|
||||
resp.code = "200";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( operation.returnType == null ) {
|
||||
operation.returnType = "void";
|
||||
} else if ( operation.returnType.startsWith("List") ) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if ( end > 0 ) {
|
||||
operation.returnType = rt.substring("List<".length(), end).trim();
|
||||
operation.returnContainer = "List";
|
||||
}
|
||||
} else if ( operation.returnType.startsWith("Map") ) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if ( end > 0 ) {
|
||||
operation.returnType = rt.substring("Map<".length(), end).split(",")[1].trim();
|
||||
operation.returnContainer = "Map";
|
||||
}
|
||||
} else if ( operation.returnType.startsWith("Set") ) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if ( end > 0 ) {
|
||||
operation.returnType = rt.substring("Set<".length(), end).trim();
|
||||
operation.returnContainer = "Set";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(final String name)
|
||||
{
|
||||
String computed = name;
|
||||
if ( computed.length() == 0 ) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
computed = sanitizeName(computed);
|
||||
return camelize(computed) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag)
|
||||
{
|
||||
String result = super.apiFilename(templateName, tag);
|
||||
|
||||
if ( templateName.endsWith("Impl.mustache") ) {
|
||||
int ix = result.lastIndexOf('/');
|
||||
result = result.substring(0, ix) + "/impl" + result.substring(ix, result.length() - 5) + "ServiceImpl.java";
|
||||
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
|
||||
} else if ( templateName.endsWith("Factory.mustache") ) {
|
||||
int ix = result.lastIndexOf('/');
|
||||
result = result.substring(0, ix) + "/factories" + result.substring(ix, result.length() - 5) + "ServiceFactory.java";
|
||||
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
|
||||
} else if ( templateName.endsWith("Service.mustache") ) {
|
||||
int ix = result.lastIndexOf('.');
|
||||
result = result.substring(0, ix) + "Service.java";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String implFileFolder(String output)
|
||||
{
|
||||
return outputFolder + "/" + output + "/" + apiPackage().replace('.', '/');
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(String filename)
|
||||
{
|
||||
return super.shouldOverwrite(filename) && !filename.endsWith("ServiceImpl.java") && !filename.endsWith("ServiceFactory.java");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
protected String modelPropertyNaming= "camelCase";
|
||||
|
||||
public AbstractTypeScriptClientCodegen() {
|
||||
super();
|
||||
supportsInheritance = true;
|
||||
@@ -50,8 +52,21 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
typeMapping.put("DateTime", "Date");
|
||||
//TODO binary should be mapped to byte array
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
typeMapping.put("binary", "string");
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.MODEL_PROPERTY_NAMING, CodegenConstants.MODEL_PROPERTY_NAMING_DESC).defaultValue("camelCase"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
if (additionalProperties.containsKey(CodegenConstants.MODEL_PROPERTY_NAMING)) {
|
||||
setModelPropertyNaming((String) additionalProperties.get(CodegenConstants.MODEL_PROPERTY_NAMING));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
@@ -74,7 +89,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
public String toParamName(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'.
|
||||
|
||||
@@ -94,9 +109,9 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
public String toVarName(String name) {
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
return getNameUsingModelPropertyNaming(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,19 +161,47 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
// append _ at the beginning, e.g. _return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
return escapeReservedWord(camelize(sanitizeName(operationId), true));
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
// append _ at the beginning, e.g. _return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
return escapeReservedWord(camelize(sanitizeName(operationId), true));
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId), true);
|
||||
}
|
||||
|
||||
public void setModelPropertyNaming(String naming) {
|
||||
if ("original".equals(naming) || "camelCase".equals(naming) ||
|
||||
"PascalCase".equals(naming) || "snake_case".equals(naming)) {
|
||||
this.modelPropertyNaming = naming;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid model property naming '" +
|
||||
naming + "'. Must be 'original', 'camelCase', " +
|
||||
"'PascalCase' or 'snake_case'");
|
||||
}
|
||||
}
|
||||
|
||||
public String getModelPropertyNaming() {
|
||||
return this.modelPropertyNaming;
|
||||
}
|
||||
|
||||
public String getNameUsingModelPropertyNaming(String name) {
|
||||
switch (CodegenConstants.MODEL_PROPERTY_NAMING_TYPE.valueOf(getModelPropertyNaming())) {
|
||||
case original: return name;
|
||||
case camelCase: return camelize(name, true);
|
||||
case PascalCase: return camelize(name);
|
||||
case snake_case: return underscore(name);
|
||||
default: throw new IllegalArgumentException("Invalid model property naming '" +
|
||||
name + "'. Must be 'original', 'camelCase', " +
|
||||
"'PascalCase' or 'snake_case'");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.codegen.CliOption;
|
||||
|
||||
@@ -28,6 +29,8 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
protected boolean optionalProjectFileFlag = false;
|
||||
protected boolean optionalMethodArgumentFlag = true;
|
||||
protected boolean useDateTimeOffsetFlag = false;
|
||||
protected boolean useCollection = false;
|
||||
protected boolean returnICollection = false;
|
||||
protected String packageGuid = "{" + java.util.UUID.randomUUID().toString().toUpperCase() + "}";
|
||||
protected String packageTitle = "Swagger Library";
|
||||
protected String packageProductName = "SwaggerLibrary";
|
||||
@@ -77,6 +80,8 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"long?",
|
||||
"float?",
|
||||
"byte[]",
|
||||
"ICollection",
|
||||
"Collection",
|
||||
"List",
|
||||
"Dictionary",
|
||||
"DateTime?",
|
||||
@@ -90,7 +95,9 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
"Stream", // not really a primitive, we include it to avoid model import
|
||||
"Object")
|
||||
);
|
||||
|
||||
instantiationTypes.put("array", "List");
|
||||
instantiationTypes.put("list", "List");
|
||||
instantiationTypes.put("map", "Dictionary");
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
@@ -122,6 +129,11 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
CodegenConstants.OPTIONAL_ASSEMBLY_INFO_DESC).defaultValue(Boolean.TRUE.toString()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC).defaultValue(sourceFolder));
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.USE_DATETIME_OFFSET, CodegenConstants.USE_DATETIME_OFFSET_DESC));
|
||||
|
||||
cliOptions.add( CliOption.newBoolean(CodegenConstants.USE_COLLECTION, CodegenConstants.USE_COLLECTION_DESC)
|
||||
.defaultValue(Boolean.FALSE.toString()) );
|
||||
cliOptions.add( CliOption.newBoolean(CodegenConstants.RETURN_ICOLLECTION, CodegenConstants.RETURN_ICOLLECTION_DESC)
|
||||
.defaultValue(Boolean.FALSE.toString()) );
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.OPTIONAL_PROJECT_FILE,
|
||||
CodegenConstants.OPTIONAL_PROJECT_FILE_DESC).defaultValue(Boolean.FALSE.toString()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.OPTIONAL_PROJECT_GUID, CodegenConstants.OPTIONAL_PROJECT_GUID_DESC));
|
||||
@@ -192,6 +204,15 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
setOptionalAssemblyInfoFlag(Boolean.valueOf(additionalProperties
|
||||
.get(CodegenConstants.OPTIONAL_ASSEMBLY_INFO).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.USE_COLLECTION)){
|
||||
setUseCollection(Boolean.valueOf(additionalProperties.get(CodegenConstants.USE_COLLECTION).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.RETURN_ICOLLECTION)){
|
||||
setReturnICollection(Boolean.valueOf(additionalProperties.get(CodegenConstants.RETURN_ICOLLECTION).toString()));
|
||||
}
|
||||
|
||||
|
||||
String packageFolder = sourceFolder + File.separator + packageName.replace(".", java.io.File.separator);
|
||||
String clientPackageDir = sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator);
|
||||
@@ -321,6 +342,32 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
super.postProcessOperations(objs);
|
||||
if(objs != null) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
if (operations != null) {
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation operation : ops) {
|
||||
if (operation.returnType != null) {
|
||||
operation.returnContainer = operation.returnType;
|
||||
if( this.returnICollection && (
|
||||
operation.returnType.startsWith("List")||
|
||||
operation.returnType.startsWith("Collection")) ) {
|
||||
// NOTE: ICollection works for both List<T> and Collection<T>
|
||||
int genericStart = operation.returnType.indexOf("<");
|
||||
if(genericStart > 0) {
|
||||
operation.returnType = "ICollection" + operation.returnType.substring(genericStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
@@ -379,6 +426,21 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
this.optionalMethodArgumentFlag = flag;
|
||||
}
|
||||
|
||||
public void setReturnICollection(boolean returnICollection) {
|
||||
this.returnICollection = returnICollection;
|
||||
}
|
||||
|
||||
public void setUseCollection(boolean useCollection) {
|
||||
this.useCollection = useCollection;
|
||||
if(useCollection){
|
||||
typeMapping.put("array", "Collection");
|
||||
typeMapping.put("list", "Collection");
|
||||
|
||||
instantiationTypes.put("array", "Collection");
|
||||
instantiationTypes.put("list", "Collection");
|
||||
}
|
||||
}
|
||||
|
||||
public void useDateTimeOffset(boolean flag) {
|
||||
this.useDateTimeOffsetFlag = flag;
|
||||
if (flag)
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import config.ConfigParser;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.HttpMethod;
|
||||
import io.swagger.models.Operation;
|
||||
@@ -14,7 +16,13 @@ import io.swagger.util.Yaml;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FlaskConnexionCodegen.class);
|
||||
|
||||
public static final String CONTROLLER_PACKAGE = "controllerPackage";
|
||||
public static final String DEFAULT_CONTROLLER = "defaultController";
|
||||
|
||||
@@ -289,7 +297,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
try {
|
||||
objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
for (Map<String, Object> operations : getOperations(objs)) {
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.models.Operation;
|
||||
|
||||
public class JavaCXFServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
{
|
||||
public JavaCXFServerCodegen()
|
||||
{
|
||||
super();
|
||||
|
||||
sourceFolder = "src/gen/java";
|
||||
invokerPackage = "io.swagger.api";
|
||||
artifactId = "swagger-jaxrs-server";
|
||||
outputFolder = "generated-code/JavaJaxRS-CXF";
|
||||
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
apiPackage = "io.swagger.api";
|
||||
modelPackage = "io.swagger.model";
|
||||
|
||||
additionalProperties.put("title", title);
|
||||
|
||||
super.embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "cxf";
|
||||
|
||||
for ( int i = 0; i < cliOptions.size(); i++ ) {
|
||||
if ( CodegenConstants.LIBRARY.equals(cliOptions.get(i).getOpt()) ) {
|
||||
cliOptions.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts()
|
||||
{
|
||||
super.processOpts();
|
||||
sourceFolder = "gen" + File.separator + "java";
|
||||
|
||||
modelTemplateFiles.clear();
|
||||
modelTemplateFiles.put("entityModel.mustache", ".java");
|
||||
|
||||
supportingFiles.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "jaxrs-cxf";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
super.addOperationToGroup(tag, resourcePath, operation, co, operations);
|
||||
co.subresourceOperation = !co.path.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp()
|
||||
{
|
||||
return "Generates a Java JAXRS Server application based on Apache CXF framework.";
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,45 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import io.swagger.codegen.*;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
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.FormParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
import io.swagger.models.properties.DoubleProperty;
|
||||
import io.swagger.models.properties.FloatProperty;
|
||||
import io.swagger.models.properties.IntegerProperty;
|
||||
import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.StringProperty;
|
||||
|
||||
public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@SuppressWarnings("hiding")
|
||||
@@ -22,6 +47,10 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public static final String FULL_JAVA_UTIL = "fullJavaUtil";
|
||||
public static final String DEFAULT_LIBRARY = "<default>";
|
||||
public static final String DATE_LIBRARY = "dateLibrary";
|
||||
public static final String USE_RX_JAVA = "useRxJava";
|
||||
|
||||
public static final String RETROFIT_1 = "retrofit";
|
||||
public static final String RETROFIT_2 = "retrofit2";
|
||||
|
||||
protected String dateLibrary = "default";
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
@@ -35,6 +64,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String javaUtilPrefix = "";
|
||||
protected Boolean serializableModel = false;
|
||||
protected boolean serializeBigDecimalAsString = false;
|
||||
protected boolean useRxJava = false;
|
||||
|
||||
public JavaClientCodegen() {
|
||||
super();
|
||||
@@ -88,13 +118,15 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, CodegenConstants
|
||||
.SERIALIZE_BIG_DECIMAL_AS_STRING_DESC));
|
||||
cliOptions.add(CliOption.newBoolean(FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA, "Whether to use the RxJava adapter with the retrofit2 library."));
|
||||
|
||||
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)");
|
||||
supportedLibraries.put("retrofit2", "HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta2)");
|
||||
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.0-beta2). Enable the RxJava adapter using '-DuseRxJava=true'.");
|
||||
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
library.setDefault(DEFAULT_LIBRARY);
|
||||
library.setEnum(supportedLibraries);
|
||||
@@ -183,6 +215,10 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (additionalProperties.containsKey(FULL_JAVA_UTIL)) {
|
||||
this.setFullJavaUtil(Boolean.valueOf(additionalProperties.get(FULL_JAVA_UTIL).toString()));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_RX_JAVA)) {
|
||||
this.setUseRxJava(Boolean.valueOf(additionalProperties.get(USE_RX_JAVA).toString()));
|
||||
}
|
||||
if (fullJavaUtil) {
|
||||
javaUtilPrefix = "java.util.";
|
||||
}
|
||||
@@ -240,7 +276,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));
|
||||
|
||||
if (!("feign".equals(getLibrary()) || "retrofit".equals(getLibrary()) || "retrofit2".equals(getLibrary()))) {
|
||||
if (!("feign".equals(getLibrary()) || usesAnyRetrofitLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("apiException.mustache", invokerFolder, "ApiException.java"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", invokerFolder, "Configuration.java"));
|
||||
supportingFiles.add(new SupportingFile("Pair.mustache", invokerFolder, "Pair.java"));
|
||||
@@ -257,7 +293,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("ProgressResponseBody.mustache", invokerFolder, "ProgressResponseBody.java"));
|
||||
// "build.sbt" is for development with SBT
|
||||
supportingFiles.add(new SupportingFile("build.sbt.mustache", "", "build.sbt"));
|
||||
} else if ("retrofit".equals(getLibrary()) || "retrofit2".equals(getLibrary())) {
|
||||
} else if (usesAnyRetrofitLibrary()) {
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java"));
|
||||
supportingFiles.add(new SupportingFile("CollectionFormats.mustache", invokerFolder, "CollectionFormats.java"));
|
||||
} else if("jersey2".equals(getLibrary())) {
|
||||
@@ -285,6 +321,14 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean usesAnyRetrofitLibrary() {
|
||||
return getLibrary() != null && getLibrary().contains(RETROFIT_1);
|
||||
}
|
||||
|
||||
private boolean usesRetrofit2Library() {
|
||||
return getLibrary() != null && getLibrary().contains(RETROFIT_2);
|
||||
}
|
||||
|
||||
private void sanitizeConfig() {
|
||||
// Sanitize any config options here. We also have to update the additionalProperties because
|
||||
// the whole additionalProperties object is injected into the main object passed to the mustache layer
|
||||
@@ -493,7 +537,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parentSchema != null && codegenModel.hasEnums) {
|
||||
final Model parentModel = allDefinitions.get(codegenModel.parentSchema);
|
||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
codegenModel = JavaClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
}
|
||||
|
||||
return codegenModel;
|
||||
@@ -598,7 +642,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
if("retrofit".equals(getLibrary()) || "retrofit2".equals(getLibrary())) {
|
||||
if(usesAnyRetrofitLibrary()) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
if (operations != null) {
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
@@ -614,7 +658,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (operation.returnType == null) {
|
||||
operation.returnType = "Void";
|
||||
}
|
||||
if ("retrofit2".equals(getLibrary()) && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/"))
|
||||
if (usesRetrofit2Library() && StringUtils.isNotEmpty(operation.path) && operation.path.startsWith("/"))
|
||||
operation.path = operation.path.substring(1);
|
||||
}
|
||||
}
|
||||
@@ -792,6 +836,10 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.fullJavaUtil = fullJavaUtil;
|
||||
}
|
||||
|
||||
public void setUseRxJava(boolean useRxJava) {
|
||||
this.useRxJava = useRxJava;
|
||||
}
|
||||
|
||||
public void setDateLibrary(String library) {
|
||||
this.dateLibrary = library;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,13 @@ import io.swagger.util.Yaml;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class JavaInflectorServerCodegen extends JavaClientCodegen {
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class JavaInflectorServerCodegen extends JavaClientCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaInflectorServerCodegen.class);
|
||||
|
||||
protected String title = "Swagger Inflector";
|
||||
|
||||
public JavaInflectorServerCodegen() {
|
||||
@@ -164,7 +170,7 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen {
|
||||
try {
|
||||
objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Operation;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen
|
||||
{
|
||||
|
||||
public JavaJerseyServerCodegen()
|
||||
{
|
||||
super();
|
||||
|
||||
sourceFolder = "src/gen/java";
|
||||
invokerPackage = "io.swagger.api";
|
||||
artifactId = "swagger-jaxrs-server";
|
||||
outputFolder = "generated-code/JavaJaxRS-Jersey";
|
||||
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
apiTemplateFiles.put("apiService.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceFactory.mustache", ".java");
|
||||
apiPackage = "io.swagger.api";
|
||||
modelPackage = "io.swagger.model";
|
||||
|
||||
additionalProperties.put("title", title);
|
||||
|
||||
embeddedTemplateDir = templateDir = JAXRS_TEMPLATE_DIRECTORY_NAME + File.separator + "jersey1_18";
|
||||
|
||||
for ( int i = 0; i < cliOptions.size(); i++ ) {
|
||||
if ( CodegenConstants.LIBRARY.equals(cliOptions.get(i).getOpt()) ) {
|
||||
cliOptions.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
library.setDefault(DEFAULT_LIBRARY);
|
||||
|
||||
Map<String, String> supportedLibraries = new LinkedHashMap<String, String>();
|
||||
|
||||
supportedLibraries.put(DEFAULT_LIBRARY, "Jersey core 1.18.1");
|
||||
library.setEnum(supportedLibraries);
|
||||
|
||||
cliOptions.add(library);
|
||||
cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "jaxrs"; // TODO should be renamed as "jaxrs-jersey"
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp()
|
||||
{
|
||||
return "Generates a Java JAXRS Server application based on Jersey framework.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts()
|
||||
{
|
||||
super.processOpts();
|
||||
|
||||
if ( additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER) ) {
|
||||
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
|
||||
}
|
||||
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(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"));
|
||||
supportingFiles.add(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") ) {
|
||||
setDateLibrary(additionalProperties.get("dateLibrary").toString());
|
||||
additionalProperties.put(dateLibrary, "true");
|
||||
}
|
||||
|
||||
if ( "joda".equals(dateLibrary) ) {
|
||||
supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java"));
|
||||
supportingFiles.add(new SupportingFile("JodaLocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaLocalDateProvider.java"));
|
||||
} else if ( "java8".equals(dateLibrary) ) {
|
||||
supportingFiles.add(new SupportingFile("LocalDateTimeProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateTimeProvider.java"));
|
||||
supportingFiles.add(new SupportingFile("LocalDateProvider.mustache", (sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateProvider.java"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
String basePath = resourcePath;
|
||||
if (basePath.startsWith("/")) {
|
||||
basePath = basePath.substring(1);
|
||||
}
|
||||
int pos = basePath.indexOf("/");
|
||||
if (pos > 0) {
|
||||
basePath = basePath.substring(0, pos);
|
||||
}
|
||||
|
||||
if (basePath == "") {
|
||||
basePath = "default";
|
||||
} else {
|
||||
if (co.path.startsWith("/" + basePath)) {
|
||||
co.path = co.path.substring(("/" + basePath).length());
|
||||
}
|
||||
co.subresourceOperation = !co.path.isEmpty();
|
||||
}
|
||||
List<CodegenOperation> opList = operations.get(basePath);
|
||||
if (opList == null) {
|
||||
opList = new ArrayList<CodegenOperation>();
|
||||
operations.put(basePath, opList);
|
||||
}
|
||||
opList.add(co);
|
||||
co.baseName = basePath;
|
||||
}
|
||||
}
|
||||
@@ -419,25 +419,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
if("retrofit".equals(getLibrary())) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
if (operations != null) {
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation operation : ops) {
|
||||
if (operation.hasConsumes == Boolean.TRUE) {
|
||||
Map<String, String> firstType = operation.consumes.get(0);
|
||||
if (firstType != null) {
|
||||
if ("multipart/form-data".equals(firstType.get("mediaType"))) {
|
||||
operation.isMultipart = Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation.returnType == null) {
|
||||
operation.returnType = "Void";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,267 +0,0 @@
|
||||
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 java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class JaxRSServerCodegen extends JavaClientCodegen {
|
||||
protected String title = "Swagger Server";
|
||||
protected String implFolder = "src/main/java";
|
||||
|
||||
public JaxRSServerCodegen() {
|
||||
super();
|
||||
|
||||
sourceFolder = "src/gen/java";
|
||||
invokerPackage = "io.swagger.api";
|
||||
artifactId = "swagger-jaxrs-server";
|
||||
|
||||
outputFolder = "generated-code/javaJaxRS";
|
||||
modelTemplateFiles.put("model.mustache", ".java");
|
||||
apiTemplateFiles.put("api.mustache", ".java");
|
||||
apiTemplateFiles.put("apiService.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceImpl.mustache", ".java");
|
||||
apiTemplateFiles.put("apiServiceFactory.mustache", ".java");
|
||||
apiPackage = "io.swagger.api";
|
||||
modelPackage = "io.swagger.model";
|
||||
|
||||
additionalProperties.put("title", title);
|
||||
|
||||
embeddedTemplateDir = templateDir = "JavaJaxRS" + File.separator + "jersey1_18";
|
||||
|
||||
for(int i = 0; i < cliOptions.size(); i++) {
|
||||
if(CodegenConstants.LIBRARY.equals(cliOptions.get(i).getOpt())) {
|
||||
cliOptions.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
library.setDefault(DEFAULT_LIBRARY);
|
||||
|
||||
Map<String, String> supportedLibraries = new LinkedHashMap<String, String>();
|
||||
|
||||
supportedLibraries.put(DEFAULT_LIBRARY, "Jersey core 1.18.1");
|
||||
// supportedLibraries.put("jersey2", "Jersey2 core library 2.x");
|
||||
library.setEnum(supportedLibraries);
|
||||
|
||||
cliOptions.add(library);
|
||||
cliOptions.add(new CliOption(CodegenConstants.IMPL_FOLDER, CodegenConstants.IMPL_FOLDER_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "jaxrs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Java JAXRS Server application.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if(additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
|
||||
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
|
||||
}
|
||||
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(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"));
|
||||
supportingFiles.add(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")) {
|
||||
setDateLibrary(additionalProperties.get("dateLibrary").toString());
|
||||
additionalProperties.put(dateLibrary, "true");
|
||||
}
|
||||
|
||||
if("joda".equals(dateLibrary)) {
|
||||
supportingFiles.add(new SupportingFile("JodaDateTimeProvider.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaDateTimeProvider.java"));
|
||||
supportingFiles.add(new SupportingFile("JodaLocalDateProvider.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "JodaLocalDateProvider.java"));
|
||||
}
|
||||
else if ("java8".equals(dateLibrary)) {
|
||||
supportingFiles.add(new SupportingFile("LocalDateTimeProvider.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateTimeProvider.java"));
|
||||
supportingFiles.add(new SupportingFile("LocalDateProvider.mustache",
|
||||
(sourceFolder + '/' + apiPackage).replace(".", "/"), "LocalDateProvider.java"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
String basePath = resourcePath;
|
||||
if (basePath.startsWith("/")) {
|
||||
basePath = basePath.substring(1);
|
||||
}
|
||||
int pos = basePath.indexOf("/");
|
||||
if (pos > 0) {
|
||||
basePath = basePath.substring(0, pos);
|
||||
}
|
||||
|
||||
if (basePath == "") {
|
||||
basePath = "default";
|
||||
} else {
|
||||
if (co.path.startsWith("/" + basePath)) {
|
||||
co.path = co.path.substring(("/" + basePath).length());
|
||||
}
|
||||
co.subresourceOperation = !co.path.isEmpty();
|
||||
}
|
||||
List<CodegenOperation> opList = operations.get(basePath);
|
||||
if (opList == null) {
|
||||
opList = new ArrayList<CodegenOperation>();
|
||||
operations.put(basePath, opList);
|
||||
}
|
||||
opList.add(co);
|
||||
co.baseName = basePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
if("/".equals(swagger.getBasePath())) {
|
||||
swagger.setBasePath("");
|
||||
}
|
||||
|
||||
String host = swagger.getHost();
|
||||
String port = "8080";
|
||||
if(host != null) {
|
||||
String[] parts = host.split(":");
|
||||
if(parts.length > 1) {
|
||||
port = parts[1];
|
||||
}
|
||||
}
|
||||
this.additionalProperties.put("serverPort", port);
|
||||
if(swagger.getPaths() != null) {
|
||||
for(String pathname : swagger.getPaths().keySet()) {
|
||||
Path path = swagger.getPath(pathname);
|
||||
if(path.getOperations() != null) {
|
||||
for(Operation operation : path.getOperations()) {
|
||||
if(operation.getTags() != null) {
|
||||
List<Map<String, String>> tags = new ArrayList<Map<String, String>>();
|
||||
for(String tag : operation.getTags()) {
|
||||
Map<String, String> value = new HashMap<String, String>();
|
||||
value.put("tag", tag);
|
||||
value.put("hasMore", "true");
|
||||
tags.add(value);
|
||||
}
|
||||
if(tags.size() > 0) {
|
||||
tags.get(tags.size() - 1).remove("hasMore");
|
||||
}
|
||||
if(operation.getTags().size() > 0) {
|
||||
String tag = operation.getTags().get(0);
|
||||
operation.setTags(Arrays.asList(tag));
|
||||
}
|
||||
operation.setVendorExtension("x-tags", tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
if (operations != null) {
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation operation : ops) {
|
||||
List<CodegenResponse> responses = operation.responses;
|
||||
if (responses != null) {
|
||||
for (CodegenResponse resp : responses) {
|
||||
if ("0".equals(resp.code)) {
|
||||
resp.code = "200";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (operation.returnType == null) {
|
||||
operation.returnType = "Void";
|
||||
} else if (operation.returnType.startsWith("List")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("List<".length(), end).trim();
|
||||
operation.returnContainer = "List";
|
||||
}
|
||||
} else if (operation.returnType.startsWith("Map")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("Map<".length(), end).split(",")[1].trim();
|
||||
operation.returnContainer = "Map";
|
||||
}
|
||||
} else if (operation.returnType.startsWith("Set")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("Set<".length(), end).trim();
|
||||
operation.returnContainer = "Set";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
name = sanitizeName(name);
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
|
||||
String result = super.apiFilename(templateName, tag);
|
||||
|
||||
if (templateName.endsWith("Impl.mustache")) {
|
||||
int ix = result.lastIndexOf('/');
|
||||
result = result.substring(0, ix) + "/impl" + result.substring(ix, result.length() - 5) + "ServiceImpl.java";
|
||||
|
||||
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
|
||||
} else if (templateName.endsWith("Factory.mustache")) {
|
||||
int ix = result.lastIndexOf('/');
|
||||
result = result.substring(0, ix) + "/factories" + result.substring(ix, result.length() - 5) + "ServiceFactory.java";
|
||||
|
||||
result = result.replace(apiFileFolder(), implFileFolder(implFolder));
|
||||
} else if (templateName.endsWith("Service.mustache")) {
|
||||
int ix = result.lastIndexOf('.');
|
||||
result = result.substring(0, ix) + "Service.java";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private String implFileFolder(String output) {
|
||||
return outputFolder + "/" + output + "/" + apiPackage().replace('.', '/');
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(String filename) {
|
||||
return super.shouldOverwrite(filename) && !filename.endsWith("ServiceImpl.java") && !filename.endsWith("ServiceFactory.java");
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,13 @@ import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSServerCodegen.class);
|
||||
|
||||
protected String apiVersion = "1.0.0";
|
||||
protected int serverPort = 8080;
|
||||
protected String projectName = "swagger-server";
|
||||
@@ -284,7 +290,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
});
|
||||
objs.put("swagger-yaml", Yaml.mapper().registerModule(module).writeValueAsString(swagger));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
for (Map<String, Object> operations : getOperations(objs)) {
|
||||
|
||||
@@ -29,6 +29,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String gemName;
|
||||
protected String moduleName;
|
||||
protected String gemVersion = "1.0.0";
|
||||
protected String specFolder = "spec";
|
||||
protected String libFolder = "lib";
|
||||
protected String gemLicense = "Apache-2.0";
|
||||
protected String gemHomepage = "http://swagger.io";
|
||||
@@ -47,6 +48,9 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
apiTemplateFiles.put("api.mustache", ".rb");
|
||||
embeddedTemplateDir = templateDir = "ruby";
|
||||
|
||||
modelTestTemplateFiles.put("model_test.mustache", ".rb");
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".rb");
|
||||
|
||||
typeMapping.clear();
|
||||
languageSpecificPrimitives.clear();
|
||||
|
||||
@@ -236,6 +240,16 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return outputFolder + File.separator + libFolder + File.separator + gemName + File.separator + modelPackage.replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apiTestFileFolder() {
|
||||
return outputFolder + File.separator + specFolder + File.separator + apiPackage.replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelTestFileFolder() {
|
||||
return outputFolder + File.separator + specFolder + File.separator + modelPackage.replace("/", File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
@@ -368,6 +382,16 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return underscore(name) + "_api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiTestFilename(String name) {
|
||||
return toApiName(name) + "_spec";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelTestFilename(String name) {
|
||||
return toModelName(name) + "_spec";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
|
||||
@@ -17,7 +17,14 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SinatraServerCodegen.class);
|
||||
|
||||
protected String gemName;
|
||||
protected String moduleName;
|
||||
protected String gemVersion = "1.0.0";
|
||||
@@ -230,7 +237,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
try {
|
||||
objs.put("swagger-yaml", Yaml.mapper().writeValueAsString(swagger));
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SwaggerGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SwaggerGenerator.class);
|
||||
|
||||
public SwaggerGenerator() {
|
||||
super();
|
||||
embeddedTemplateDir = templateDir = "swagger";
|
||||
@@ -41,9 +47,9 @@ public class SwaggerGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
try {
|
||||
String outputFile = outputFolder + File.separator + "swagger.json";
|
||||
FileUtils.writeStringToFile(new File(outputFile), swaggerString);
|
||||
System.out.println("wrote file to " + outputFile);
|
||||
LOGGER.debug("wrote file to " + outputFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,22 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.util.Yaml;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SwaggerYamlGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SwaggerYamlGenerator.class);
|
||||
|
||||
public SwaggerYamlGenerator() {
|
||||
super();
|
||||
embeddedTemplateDir = templateDir = "swagger";
|
||||
@@ -40,9 +46,9 @@ public class SwaggerYamlGenerator extends DefaultCodegen implements CodegenConfi
|
||||
String swaggerString = Yaml.mapper().writeValueAsString(swagger);
|
||||
String outputFile = outputFolder + File.separator + "swagger.yaml";
|
||||
FileUtils.writeStringToFile(new File(outputFile), swaggerString);
|
||||
System.out.println("wrote file to " + outputFile);
|
||||
LOGGER.debug("wrote file to " + outputFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package io.swagger.codegen.utils;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
public class OptionUtils {
|
||||
|
||||
public static List<Pair<String, String>> parseCommaSeparatedTuples(String input) {
|
||||
|
||||
List<Pair<String, String>> results = new ArrayList<Pair<String, String>>();
|
||||
|
||||
final List<String> tuples = splitCommaSeparatedList(input);
|
||||
|
||||
for (String tuple : tuples) {
|
||||
int ix = tuple.indexOf('=');
|
||||
if (ix > 0 && ix < tuple.length() - 1) {
|
||||
final Pair<String, String> pair = Pair.of(tuple.substring(0, ix), tuple.substring(ix + 1));
|
||||
results.add(pair);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public static List<String> splitCommaSeparatedList(String input) {
|
||||
|
||||
List<String> results = new ArrayList<String>();
|
||||
|
||||
if(input != null && !input.isEmpty()) {
|
||||
for (String value : input.split(",")) {
|
||||
if(isNotEmpty(value))
|
||||
results.add(value);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user