forked from loafle/openapi-generator-original
Merge pull request #1900 from hiveship/fix-java-warnings
fix java warnings
This commit is contained in:
@@ -14,6 +14,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
public abstract class AbstractGenerator {
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public File writeToFile(String filename, String contents) throws IOException {
|
||||
System.out.println("writing file " + filename);
|
||||
File output = new File(filename);
|
||||
@@ -48,10 +49,7 @@ public abstract class AbstractGenerator {
|
||||
try {
|
||||
InputStream is = this.getClass().getClassLoader().getResourceAsStream(getCPResourcePath(name));
|
||||
if (is == null) {
|
||||
is = new FileInputStream(new File(name));
|
||||
}
|
||||
if (is == null) {
|
||||
throw new RuntimeException("no file found");
|
||||
is = new FileInputStream(new File(name)); // May throw but never return a null value
|
||||
}
|
||||
return new InputStreamReader(is);
|
||||
} catch (Exception e) {
|
||||
@@ -96,6 +94,7 @@ public abstract class AbstractGenerator {
|
||||
return this.getClass().getClassLoader().getResource(getCPResourcePath(name)) != null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public String getCPResourcePath(String name) {
|
||||
if (!"/".equals(File.separator)) {
|
||||
return name.replaceAll(Pattern.quote(File.separator), "/");
|
||||
|
||||
@@ -5,13 +5,8 @@ import io.swagger.codegen.auth.AuthParser;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.auth.AuthorizationValue;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
public class ClientOptInput {
|
||||
private CodegenConfig config;
|
||||
private ClientOpts opts;
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Options;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -32,10 +31,9 @@ public class Codegen extends DefaultGenerator {
|
||||
"\n -DdebugOperations prints operations passed to the template engine" +
|
||||
"\n -DdebugSupportingFiles prints additional data passed to the template engine";
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void main(String[] args) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
Options options = new Options();
|
||||
options.addOption("h", "help", false, "shows this message");
|
||||
options.addOption("l", "lang", true, "client language to generate.\nAvailable languages include:\n\t[" + configString + "]");
|
||||
@@ -139,7 +137,7 @@ public class Codegen extends DefaultGenerator {
|
||||
// see if it's a class
|
||||
try {
|
||||
System.out.println("loading class " + name);
|
||||
Class customClass = Class.forName(name);
|
||||
Class<?> customClass = Class.forName(name);
|
||||
System.out.println("loaded");
|
||||
return (CodegenConfig) customClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class CodegenOperation {
|
||||
*
|
||||
* @return true if parameter exists, false otherwise
|
||||
*/
|
||||
private boolean nonempty(List<CodegenParameter> params) {
|
||||
private static boolean nonempty(List<CodegenParameter> params) {
|
||||
return params != null && params.size() > 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,50 @@ public class CodegenProperty {
|
||||
public CodegenProperty items;
|
||||
public Map<String, Object> vendorExtensions;
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((_enum == null) ? 0 : _enum.hashCode());
|
||||
result = prime * result + ((allowableValues == null) ? 0 : allowableValues.hashCode());
|
||||
result = prime * result + ((baseName == null) ? 0 : baseName.hashCode());
|
||||
result = prime * result + ((baseType == null) ? 0 : baseType.hashCode());
|
||||
result = prime * result + ((complexType == null) ? 0 : complexType.hashCode());
|
||||
result = prime * result + ((containerType == null) ? 0 : containerType.hashCode());
|
||||
result = prime * result + ((datatype == null) ? 0 : datatype.hashCode());
|
||||
result = prime * result + ((datatypeWithEnum == null) ? 0 : datatypeWithEnum.hashCode());
|
||||
result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
|
||||
result = prime * result + ((defaultValueWithParam == null) ? 0 : defaultValueWithParam.hashCode());
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((example == null) ? 0 : example.hashCode());
|
||||
result = prime * result + ((exclusiveMaximum == null) ? 0 : exclusiveMaximum.hashCode());
|
||||
result = prime * result + ((exclusiveMinimum == null) ? 0 : exclusiveMinimum.hashCode());
|
||||
result = prime * result + ((getter == null) ? 0 : getter.hashCode());
|
||||
result = prime * result + ((hasMore == null) ? 0 : hasMore.hashCode());
|
||||
result = prime * result + ((isContainer == null) ? 0 : isContainer.hashCode());
|
||||
result = prime * result + (isEnum ? 1231 : 1237);
|
||||
result = prime * result + ((isNotContainer == null) ? 0 : isNotContainer.hashCode());
|
||||
result = prime * result + ((isPrimitiveType == null) ? 0 : isPrimitiveType.hashCode());
|
||||
result = prime * result + ((isReadOnly == null) ? 0 : isReadOnly.hashCode());
|
||||
result = prime * result + ((items == null) ? 0 : items.hashCode());
|
||||
result = prime * result + ((jsonSchema == null) ? 0 : jsonSchema.hashCode());
|
||||
result = prime * result + ((max == null) ? 0 : max.hashCode());
|
||||
result = prime * result + ((maxLength == null) ? 0 : maxLength.hashCode());
|
||||
result = prime * result + ((maximum == null) ? 0 : maximum.hashCode());
|
||||
result = prime * result + ((min == null) ? 0 : min.hashCode());
|
||||
result = prime * result + ((minLength == null) ? 0 : minLength.hashCode());
|
||||
result = prime * result + ((minimum == null) ? 0 : minimum.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((pattern == null) ? 0 : pattern.hashCode());
|
||||
result = prime * result + ((required == null) ? 0 : required.hashCode());
|
||||
result = prime * result + ((secondaryParam == null) ? 0 : secondaryParam.hashCode());
|
||||
result = prime * result + ((setter == null) ? 0 : setter.hashCode());
|
||||
result = prime * result + ((unescapedDescription == null) ? 0 : unescapedDescription.hashCode());
|
||||
result = prime * result + ((vendorExtensions == null) ? 0 : vendorExtensions.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
|
||||
@@ -109,38 +109,48 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
// override with any special post-processing
|
||||
@SuppressWarnings("static-method")
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
return objs;
|
||||
}
|
||||
|
||||
// override with any special post-processing
|
||||
@SuppressWarnings("static-method")
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
return objs;
|
||||
}
|
||||
|
||||
// override with any special post-processing
|
||||
@SuppressWarnings("static-method")
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
return objs;
|
||||
}
|
||||
|
||||
// override to post-process any model properties
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property){}
|
||||
@SuppressWarnings("unused")
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property){
|
||||
}
|
||||
|
||||
// override to post-process any parameters
|
||||
public void postProcessParameter(CodegenParameter parameter){}
|
||||
@SuppressWarnings("unused")
|
||||
public void postProcessParameter(CodegenParameter parameter){
|
||||
}
|
||||
|
||||
//override with any special handling of the entire swagger spec
|
||||
@SuppressWarnings("unused")
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
}
|
||||
|
||||
// override with any special handling of the entire swagger spec
|
||||
@SuppressWarnings("unused")
|
||||
public void processSwagger(Swagger swagger) {
|
||||
}
|
||||
|
||||
// override with any special text escaping logic
|
||||
@SuppressWarnings("static-method")
|
||||
public String escapeText(String input) {
|
||||
if (input != null) {
|
||||
input = input.trim();
|
||||
if (input != null) {
|
||||
input = input.trim(); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
String output = input.replaceAll("\n", "\\\\n");
|
||||
output = output.replace("\r", "\\r");
|
||||
output = output.replace("\"", "\\\"");
|
||||
@@ -274,7 +284,7 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file name of the Api
|
||||
* Return the file name of the Api Test
|
||||
*
|
||||
* @param name the file name of the Api
|
||||
* @return the file name of the Api
|
||||
@@ -304,7 +314,7 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the capitalized file name of the model
|
||||
* Return the capitalized file name of the model test
|
||||
*
|
||||
* @param name the model name
|
||||
* @return the file name of the model
|
||||
@@ -322,13 +332,14 @@ public class DefaultCodegen {
|
||||
public String toModelTestFilename(String name) {
|
||||
return initialCaps(name) + "Test";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the operation ID (method name)
|
||||
*
|
||||
* @param operationId operation ID
|
||||
* @return the sanitized method name
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
@@ -361,7 +372,7 @@ public class DefaultCodegen {
|
||||
* @return the sanitized parameter name
|
||||
*/
|
||||
public String toParamName(String name) {
|
||||
name = removeNonNameElementToCamelCase(name);
|
||||
name = removeNonNameElementToCamelCase(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
if (reservedWords.contains(name)) {
|
||||
return escapeReservedWord(name);
|
||||
}
|
||||
@@ -374,6 +385,7 @@ public class DefaultCodegen {
|
||||
* @param property Codegen property object
|
||||
* @return the Enum name
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
return StringUtils.capitalize(property.name) + "Enum";
|
||||
}
|
||||
@@ -386,6 +398,7 @@ public class DefaultCodegen {
|
||||
*
|
||||
* throws Runtime exception as reserved word is not allowed (default behavior)
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String escapeReservedWord(String name) {
|
||||
throw new RuntimeException("reserved word " + name + " not allowed");
|
||||
}
|
||||
@@ -495,6 +508,7 @@ public class DefaultCodegen {
|
||||
* @param operation Swagger operation object
|
||||
* @return string presentation of the example path
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String generateExamplePath(String path, Operation operation) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(path);
|
||||
@@ -577,6 +591,7 @@ public class DefaultCodegen {
|
||||
* @param p Swagger property object
|
||||
* @return string presentation of the default value of the property
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof StringProperty) {
|
||||
return "null";
|
||||
@@ -623,6 +638,7 @@ public class DefaultCodegen {
|
||||
* @param p Swagger property object
|
||||
* @return string presentation of the default value of the property
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String toDefaultValueWithParam(String name, Property p) {
|
||||
return " = data." + name + ";";
|
||||
}
|
||||
@@ -632,6 +648,7 @@ public class DefaultCodegen {
|
||||
* @param p Swagger property object
|
||||
* @return string presentation of the type
|
||||
**/
|
||||
@SuppressWarnings("static-method")
|
||||
public String getSwaggerType(Property p) {
|
||||
String datatype = null;
|
||||
if (p instanceof StringProperty && "number".equals(p.getFormat())) {
|
||||
@@ -660,6 +677,8 @@ public class DefaultCodegen {
|
||||
datatype = "map";
|
||||
} else if (p instanceof DecimalProperty) {
|
||||
datatype = "number";
|
||||
} else if ( p instanceof UUIDProperty) {
|
||||
datatype = "UUID";
|
||||
} else if (p instanceof RefProperty) {
|
||||
try {
|
||||
RefProperty r = (RefProperty) p;
|
||||
@@ -686,6 +705,7 @@ public class DefaultCodegen {
|
||||
* @param name string to be snake-cased
|
||||
* @return snake-cased string
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String snakeCase(String name) {
|
||||
return (name.length() > 0) ? (Character.toLowerCase(name.charAt(0)) + name.substring(1)) : "";
|
||||
}
|
||||
@@ -696,6 +716,7 @@ public class DefaultCodegen {
|
||||
* @param name string to be capitalized
|
||||
* @return capitalized string
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String initialCaps(String name) {
|
||||
return StringUtils.capitalize(name);
|
||||
}
|
||||
@@ -706,6 +727,7 @@ public class DefaultCodegen {
|
||||
* @param name name
|
||||
* @return a string presentation of the type
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String getTypeDeclaration(String name) {
|
||||
return name;
|
||||
}
|
||||
@@ -1111,7 +1133,7 @@ public class DefaultCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
private Response findMethodResponse(Map<String, Response> responses) {
|
||||
private static Response findMethodResponse(Map<String, Response> responses) {
|
||||
|
||||
String code = null;
|
||||
for (String responseCode : responses.keySet()) {
|
||||
@@ -1584,7 +1606,6 @@ public class DefaultCodegen {
|
||||
// to use the built-in model parsing, we unwrap the ArrayModel
|
||||
// and get a single property from it
|
||||
ArrayModel impl = (ArrayModel) model;
|
||||
CodegenModel cm = fromModel(bp.getName(), impl);
|
||||
// get the single property
|
||||
ArrayProperty ap = new ArrayProperty().items(impl.getItems());
|
||||
ap.setRequired(param.getRequired());
|
||||
@@ -1625,6 +1646,7 @@ public class DefaultCodegen {
|
||||
* @param schemes a map of Swagger SecuritySchemeDefinition object
|
||||
* @return a list of Codegen Security objects
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public List<CodegenSecurity> fromSecurity(Map<String, SecuritySchemeDefinition> schemes) {
|
||||
if (schemes == null) {
|
||||
return Collections.emptyList();
|
||||
@@ -1731,6 +1753,7 @@ public class DefaultCodegen {
|
||||
&& !languageSpecificPrimitives.contains(type);
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected List<Map<String, Object>> toExamples(Map<String, Object> examples) {
|
||||
if (examples == null) {
|
||||
return null;
|
||||
@@ -1754,7 +1777,7 @@ public class DefaultCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
private List<CodegenParameter> addHasMore(List<CodegenParameter> objs) {
|
||||
private static List<CodegenParameter> addHasMore(List<CodegenParameter> objs) {
|
||||
if (objs != null) {
|
||||
for (int i = 0; i < objs.size(); i++) {
|
||||
if (i > 0) {
|
||||
@@ -1768,7 +1791,7 @@ public class DefaultCodegen {
|
||||
return objs;
|
||||
}
|
||||
|
||||
private Map<String, Object> addHasMore(Map<String, Object> objs) {
|
||||
private static Map<String, Object> addHasMore(Map<String, Object> objs) {
|
||||
if (objs != null) {
|
||||
for (int i = 0; i < objs.size() - 1; i++) {
|
||||
if (i > 0) {
|
||||
@@ -1791,6 +1814,7 @@ public class DefaultCodegen {
|
||||
* @param co Codegen Operation object
|
||||
* @param operations map of Codegen operations
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
List<CodegenOperation> opList = operations.get(tag);
|
||||
if (opList == null) {
|
||||
@@ -1815,8 +1839,6 @@ public class DefaultCodegen {
|
||||
co.baseName = tag;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void addParentContainer(CodegenModel m, String name, Property property) {
|
||||
final CodegenProperty tmp = fromProperty(name, property);
|
||||
addImport(m, tmp.complexType);
|
||||
@@ -1845,7 +1867,7 @@ public class DefaultCodegen {
|
||||
String secondPattern = "([a-z\\d])([A-Z])";
|
||||
String replacementPattern = "$1_$2";
|
||||
// Replace package separator with slash.
|
||||
word = word.replaceAll("\\.", "/");
|
||||
word = word.replaceAll("\\.", "/"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
// Replace $ with two underscores for inner classes.
|
||||
word = word.replaceAll("\\$", "__");
|
||||
// Replace capital letter with _ plus lowercase letter.
|
||||
@@ -1862,6 +1884,7 @@ public class DefaultCodegen {
|
||||
* @param word The word
|
||||
* @return The dashized version of the word, e.g. "my-name"
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
protected String dashize(String word) {
|
||||
return underscore(word).replaceAll("[_ ]", "-");
|
||||
}
|
||||
@@ -1876,7 +1899,7 @@ public class DefaultCodegen {
|
||||
* @param name The base name
|
||||
* @return The next name for the base name
|
||||
*/
|
||||
private String generateNextName(String name) {
|
||||
private static String generateNextName(String name) {
|
||||
Pattern pattern = Pattern.compile("\\d+\\z");
|
||||
Matcher matcher = pattern.matcher(name);
|
||||
if (matcher.find()) {
|
||||
@@ -1941,9 +1964,10 @@ public class DefaultCodegen {
|
||||
* @param name string to be camelize
|
||||
* @return camelized string
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String removeNonNameElementToCamelCase(String name) {
|
||||
String nonNameElementPattern = "[-_:;#]";
|
||||
name = StringUtils.join(Lists.transform(Lists.newArrayList(name.split(nonNameElementPattern)), new Function<String, String>() {
|
||||
name = StringUtils.join(Lists.transform(Lists.newArrayList(name.split(nonNameElementPattern)), new Function<String, String>() { // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
@Nullable
|
||||
@Override
|
||||
public String apply(String input) {
|
||||
@@ -1980,7 +2004,7 @@ public class DefaultCodegen {
|
||||
Pattern p = Pattern.compile("\\/(.?)");
|
||||
Matcher m = p.matcher(word);
|
||||
while (m.find()) {
|
||||
word = m.replaceFirst("." + m.group(1)/*.toUpperCase()*/);
|
||||
word = m.replaceFirst("." + m.group(1)/*.toUpperCase()*/); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
m = p.matcher(word);
|
||||
}
|
||||
|
||||
@@ -2084,6 +2108,7 @@ public class DefaultCodegen {
|
||||
return library;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected CliOption buildLibraryCliOption(Map<String, String> supportedLibraries) {
|
||||
StringBuilder sb = new StringBuilder("library template (sub-template) to use:");
|
||||
for (String lib : supportedLibraries.keySet()) {
|
||||
@@ -2098,6 +2123,7 @@ public class DefaultCodegen {
|
||||
* @param name string to be sanitize
|
||||
* @return sanitized string
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String sanitizeName(String name) {
|
||||
// NOTE: performance wise, we should have written with 2 replaceAll to replace desired
|
||||
// character with _ or empty character. Below aims to spell out different cases we've
|
||||
@@ -2111,7 +2137,7 @@ public class DefaultCodegen {
|
||||
}
|
||||
|
||||
// input[] => input
|
||||
name = name.replaceAll("\\[\\]", "");
|
||||
name = name.replaceAll("\\[\\]", ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// input[a][b] => input_a_b
|
||||
name = name.replaceAll("\\[", "_");
|
||||
@@ -2133,6 +2159,5 @@ public class DefaultCodegen {
|
||||
// remove everything else other than word, number and _
|
||||
// $php_variable => php_variable
|
||||
return name.replaceAll("[^a-zA-Z0-9_]", "");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.apache.commons.lang3.StringUtils.capitalize;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
|
||||
|
||||
public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
|
||||
protected Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
|
||||
|
||||
protected CodegenConfig config;
|
||||
protected ClientOptInput opts;
|
||||
@@ -438,18 +438,12 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
File outputFile = new File(outputFilename);
|
||||
OutputStream out = new FileOutputStream(outputFile, false);
|
||||
if (in != null && out != null) {
|
||||
if (in != null) {
|
||||
System.out.println("writing file " + outputFile);
|
||||
IOUtils.copy(in, out);
|
||||
} else {
|
||||
if (in == null) {
|
||||
System.out.println("can't open " + templateFile + " for input");
|
||||
}
|
||||
if (out == null) {
|
||||
System.out.println("can't open " + outputFile + " for output");
|
||||
}
|
||||
System.out.println("can't open " + templateFile + " for input"); // FIXME: use LOGGER instead of standart output
|
||||
}
|
||||
|
||||
files.add(outputFile);
|
||||
}
|
||||
}
|
||||
@@ -458,13 +452,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config.processSwagger(swagger);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
private void processMimeTypes(List<String> mimeTypeList, Map<String, Object> operation, String source) {
|
||||
private static void processMimeTypes(List<String> mimeTypeList, Map<String, Object> operation, String source) {
|
||||
if (mimeTypeList != null && mimeTypeList.size() > 0) {
|
||||
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
|
||||
int count = 0;
|
||||
@@ -485,7 +477,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> sortModelsByInheritance(final Map<String, Model> definitions) {
|
||||
private static List<String> sortModelsByInheritance(final Map<String, Model> definitions) {
|
||||
List<String> sortedModelKeys = new ArrayList<String>(definitions.keySet());
|
||||
Comparator<String> cmp = new Comparator<String>() {
|
||||
@Override
|
||||
@@ -655,10 +647,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
}
|
||||
|
||||
private String generateParameterId(Parameter parameter) {
|
||||
private static String generateParameterId(Parameter parameter) {
|
||||
return parameter.getName() + ":" + parameter.getIn();
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String sanitizeTag(String tag) {
|
||||
// remove spaces and make strong case
|
||||
String[] parts = tag.split(" ");
|
||||
@@ -671,6 +664,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
return buf.toString().replaceAll("[^a-zA-Z ]", "");
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public Map<String, Object> processOperations(CodegenConfig config, String tag, List<CodegenOperation> ops) {
|
||||
Map<String, Object> operations = new HashMap<String, Object>();
|
||||
Map<String, Object> objs = new HashMap<String, Object>();
|
||||
@@ -731,6 +725,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
return operations;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public Map<String, Object> processModels(CodegenConfig config, Map<String, Model> definitions, Map<String, Model> allDefinitions) {
|
||||
Map<String, Object> objs = new HashMap<String, Object>();
|
||||
objs.put("package", config.modelPackage());
|
||||
@@ -750,7 +745,6 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
|
||||
Set<String> importSet = new TreeSet<String>();
|
||||
for (String nextImport : allImports) {
|
||||
Map<String, String> im = new HashMap<String, String>();
|
||||
String mapping = config.importMapping().get(nextImport);
|
||||
if (mapping == null) {
|
||||
mapping = config.toModelImport(nextImport);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package io.swagger.codegen;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.operations.Mod;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.parameters.RefParameter;
|
||||
import io.swagger.models.properties.*;
|
||||
import io.swagger.util.Json;
|
||||
|
||||
@@ -174,9 +172,7 @@ public class InlineModelResolver {
|
||||
m.setItems(new RefProperty(existing));
|
||||
}
|
||||
}
|
||||
} else if (model instanceof ComposedModel) {
|
||||
ComposedModel m = (ComposedModel) model;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,7 +195,7 @@ public class InlineModelResolver {
|
||||
public String uniqueName(String key) {
|
||||
int count = 0;
|
||||
boolean done = false;
|
||||
key = key.replaceAll("[^a-z_\\.A-Z0-9 ]", "");
|
||||
key = key.replaceAll("[^a-z_\\.A-Z0-9 ]", ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
while (!done) {
|
||||
String name = key;
|
||||
if (count > 0) {
|
||||
@@ -295,53 +291,26 @@ public class InlineModelResolver {
|
||||
}
|
||||
}
|
||||
|
||||
public Model modelFromProperty(ArrayProperty object, String path) {
|
||||
String access = object.getAccess();
|
||||
@SuppressWarnings("static-method")
|
||||
public Model modelFromProperty(ArrayProperty object, @SuppressWarnings("unused") String path) {
|
||||
String description = object.getDescription();
|
||||
String example = object.getExample();
|
||||
String name = object.getName();
|
||||
Integer position = object.getPosition();
|
||||
Boolean readOnly = object.getReadOnly();
|
||||
Boolean required = object.getRequired();
|
||||
String title = object.getTitle();
|
||||
Map<String, Object> extensions = object.getVendorExtensions();
|
||||
Xml xml = object.getXml();
|
||||
|
||||
// object.getItems()
|
||||
// Map<String, Property> properties = object.getProperties();
|
||||
|
||||
Property inner = object.getItems();
|
||||
if (inner instanceof ObjectProperty) {
|
||||
ArrayModel model = new ArrayModel();
|
||||
model.setDescription(description);
|
||||
model.setExample(example);
|
||||
// model.setName(name);
|
||||
// model.setXml(xml);
|
||||
|
||||
model.setItems(object.getItems());
|
||||
return model;
|
||||
}
|
||||
|
||||
// if(properties != null) {
|
||||
// flattenProperties(properties, path);
|
||||
// model.setProperties(properties);
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Model modelFromProperty(ObjectProperty object, String path) {
|
||||
String access = object.getAccess();
|
||||
String description = object.getDescription();
|
||||
String example = object.getExample();
|
||||
String name = object.getName();
|
||||
Integer position = object.getPosition();
|
||||
Boolean readOnly = object.getReadOnly();
|
||||
Boolean required = object.getRequired();
|
||||
String title = object.getTitle();
|
||||
Map<String, Object> extensions = object.getVendorExtensions();
|
||||
Xml xml = object.getXml();
|
||||
|
||||
Map<String, Property> properties = object.getProperties();
|
||||
|
||||
ModelImpl model = new ModelImpl();
|
||||
@@ -358,17 +327,10 @@ public class InlineModelResolver {
|
||||
return model;
|
||||
}
|
||||
|
||||
public Model modelFromProperty(MapProperty object, String path) {
|
||||
String access = object.getAccess();
|
||||
@SuppressWarnings("static-method")
|
||||
public Model modelFromProperty(MapProperty object, @SuppressWarnings("unused") String path) {
|
||||
String description = object.getDescription();
|
||||
String example = object.getExample();
|
||||
String name = object.getName();
|
||||
Integer position = object.getPosition();
|
||||
Boolean readOnly = object.getReadOnly();
|
||||
Boolean required = object.getRequired();
|
||||
String title = object.getTitle();
|
||||
Map<String, Object> extensions = object.getVendorExtensions();
|
||||
Xml xml = object.getXml();
|
||||
|
||||
ArrayModel model = new ArrayModel();
|
||||
model.setDescription(description);
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.swagger.codegen;
|
||||
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
import io.swagger.models.Swagger;
|
||||
import org.apache.commons.cli.BasicParser;
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.CommandLineParser;
|
||||
@@ -57,8 +56,6 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
}
|
||||
|
||||
protected void generate(String[] args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String targetLanguage = null;
|
||||
String outputFolder = null;
|
||||
String name = null;
|
||||
String targetPackage = "io.swagger.codegen";
|
||||
@@ -71,12 +68,9 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
options.addOption("n", "name", true, "the human-readable name of the generator");
|
||||
options.addOption("p", "package", true, "the package to put the main class into (defaults to io.swagger.codegen");
|
||||
|
||||
ClientOptInput clientOptInput = new ClientOptInput();
|
||||
Swagger swagger = null;
|
||||
CommandLine cmd = null;
|
||||
try {
|
||||
CommandLineParser parser = new BasicParser();
|
||||
|
||||
cmd = parser.parse(options, args);
|
||||
if (cmd.hasOption("h")) {
|
||||
usage(options);
|
||||
@@ -85,12 +79,11 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
if (cmd.hasOption("n")) {
|
||||
name = cmd.getOptionValue("n");
|
||||
} else {
|
||||
System.out.println("name is required");
|
||||
System.out.println("name is required"); //FIXME replace by LOGGER
|
||||
usage(options);
|
||||
return;
|
||||
}
|
||||
if (cmd.hasOption("l")) {
|
||||
targetLanguage = cmd.getOptionValue("l");
|
||||
}
|
||||
if (cmd.hasOption("p")) {
|
||||
targetPackage = cmd.getOptionValue("p");
|
||||
@@ -98,7 +91,7 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
if (cmd.hasOption("o")) {
|
||||
outputFolder = cmd.getOptionValue("o");
|
||||
} else {
|
||||
System.out.println("output folder is required");
|
||||
System.out.println("output folder is required"); // FIXME replace by LOGGER
|
||||
usage(options);
|
||||
return;
|
||||
}
|
||||
@@ -161,8 +154,6 @@ public class MetaGenerator extends AbstractGenerator {
|
||||
public Reader getTemplate(String name) {
|
||||
return getTemplateReader(templateDir + File.separator + name + ".mustache");
|
||||
}
|
||||
|
||||
;
|
||||
})
|
||||
.defaultValue("")
|
||||
.compile(template);
|
||||
|
||||
@@ -11,6 +11,7 @@ public class SupportingFile {
|
||||
this.destinationFilename = destinationFilename;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("SupportingFile:").append("\n");
|
||||
|
||||
@@ -18,7 +18,7 @@ public class AuthParser {
|
||||
for (String part : parts) {
|
||||
String[] kvPair = part.split(":");
|
||||
if (kvPair.length == 2) {
|
||||
auths.add(new AuthorizationValue(URLDecoder.decode(kvPair[0]), URLDecoder.decode(kvPair[1]), "header"));
|
||||
auths.add(new AuthorizationValue(URLDecoder.decode(kvPair[0]), URLDecoder.decode(kvPair[1]), "header")); // FIXME replace the deprecated method by decode(string, encoding). Which encoding is used ? Default UTF-8 ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ExampleGenerator {
|
||||
if (examples == null) {
|
||||
if (mediaTypes == null) {
|
||||
// assume application/json for this
|
||||
mediaTypes = Arrays.asList("application/json");
|
||||
mediaTypes = Arrays.asList("application/json"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
}
|
||||
for (String mediaType : mediaTypes) {
|
||||
Map<String, String> kv = new HashMap<String, String>();
|
||||
@@ -127,7 +127,7 @@ public class ExampleGenerator {
|
||||
return resolveModelToExample(simpleName, mediaType, model, processedModels);
|
||||
}
|
||||
} else if (property instanceof UUIDProperty) {
|
||||
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
||||
return "046b6c7f-0b8a-43b9-b35d-6489e6daee91";
|
||||
}
|
||||
|
||||
return "";
|
||||
@@ -142,16 +142,14 @@ public class ExampleGenerator {
|
||||
ModelImpl impl = (ModelImpl) model;
|
||||
Map<String, Object> values = new HashMap<String, Object>();
|
||||
|
||||
if (impl != null && impl.getProperties() != null) {
|
||||
if (impl.getProperties() != null) {
|
||||
for (String propertyName : impl.getProperties().keySet()) {
|
||||
Property property = impl.getProperties().get(propertyName);
|
||||
values.put(propertyName, resolvePropertyToExample(mediaType, property, processedModels));
|
||||
}
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class XmlExampleGenerator {
|
||||
public XmlExampleGenerator(Map<String, Model> examples) {
|
||||
this.examples = examples;
|
||||
if (examples == null) {
|
||||
examples = new HashMap<String, Model>();
|
||||
this.examples = new HashMap<String, Model>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +74,6 @@ public class XmlExampleGenerator {
|
||||
Map<String, Property> elements = new LinkedHashMap<String, Property>();
|
||||
|
||||
String name = modelName;
|
||||
String namespace;
|
||||
String prefix;
|
||||
Boolean wrapped;
|
||||
|
||||
Xml xml = model.getXml();
|
||||
if (xml != null) {
|
||||
if (xml.getName() != null) {
|
||||
@@ -117,6 +113,7 @@ public class XmlExampleGenerator {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String quote(String string) {
|
||||
return "\"" + string + "\"";
|
||||
}
|
||||
@@ -211,14 +208,17 @@ public class XmlExampleGenerator {
|
||||
return "not implemented " + property;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String openTag(String name) {
|
||||
return "<" + name + ">";
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String closeTag(String name) {
|
||||
return "</" + name + ">";
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String indent(int indent) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (int i = 0; i < indent; i++) {
|
||||
|
||||
@@ -9,10 +9,6 @@ import java.io.File;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
public AbstractTypeScriptClientCodegen() {
|
||||
super();
|
||||
@@ -56,6 +52,11 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
// mapped to String as a workaround
|
||||
typeMapping.put("binary", "string");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
@@ -75,7 +76,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$"))
|
||||
|
||||
@@ -63,7 +63,9 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
* unmarshalling problems and any other RuntimeException will be considered as ApiErrors.
|
||||
*/
|
||||
protected boolean onlyOneSuccess = true;
|
||||
Logger LOGGER = LoggerFactory.getLogger(AkkaScalaClientCodegen.class);
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
protected Logger LOGGER = LoggerFactory.getLogger(AkkaScalaClientCodegen.class);
|
||||
|
||||
public AkkaScalaClientCodegen() {
|
||||
super();
|
||||
|
||||
@@ -7,7 +7,6 @@ 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.BooleanProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
|
||||
@@ -151,7 +150,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
|
||||
@@ -23,8 +23,6 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String invokerPackage = "io.swagger.client";
|
||||
protected String groupId = "io.swagger";
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@SuppressWarnings({ "unused", "hiding" })
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class);
|
||||
protected boolean optionalAssemblyInfoFlag = true;
|
||||
protected boolean optionalMethodArgumentFlag = true;
|
||||
@@ -229,7 +230,7 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
|
||||
@@ -172,7 +172,7 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
name = name.replaceAll("[^a-zA-Z0-9_-]+", "");
|
||||
name = name.replaceAll("[^a-zA-Z0-9_-]+", ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
name = dashize(name);
|
||||
return name;
|
||||
}
|
||||
@@ -196,6 +196,7 @@ public class ClojureClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
return operations;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
protected String namespaceToFolder(String ns) {
|
||||
return ns.replace(".", File.separator).replace("-", "_");
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
|
||||
@@ -171,7 +171,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all uppper case, do nothing
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
@@ -221,15 +221,10 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toDefaultValue(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "{}";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "[]";
|
||||
}
|
||||
|
||||
return super.toDefaultValue(p);
|
||||
}
|
||||
|
||||
|
||||
@@ -193,14 +193,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
return getSwaggerType(p);
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
|
||||
if (p instanceof ArrayProperty || p instanceof MapProperty) {
|
||||
return getSwaggerType(p);
|
||||
}
|
||||
return super.getTypeDeclaration(p);
|
||||
@@ -256,12 +249,8 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
return "0";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "new Dictionary()";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "new Array()";
|
||||
} else {
|
||||
return "null";
|
||||
@@ -271,8 +260,8 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
|
||||
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();
|
||||
@@ -323,7 +312,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
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 camelize(name) + "Api";
|
||||
@@ -376,7 +365,4 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public void setSourceFolder(String sourceFolder) {
|
||||
this.sourceFolder = sourceFolder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> getOperations(Map<String, Object> objs) {
|
||||
private static List<Map<String, Object>> getOperations(Map<String, Object> objs) {
|
||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
|
||||
Map<String, Object> apiInfo = (Map<String, Object>) objs.get("apiInfo");
|
||||
List<Map<String, Object>> apis = (List<Map<String, Object>>) apiInfo.get("apis");
|
||||
@@ -259,7 +259,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||
private static List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||
Multimap<String, CodegenOperation> opsByPath = ArrayListMultimap.create();
|
||||
|
||||
for (CodegenOperation op : ops) {
|
||||
@@ -304,7 +304,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
operationId = super.toOperationId(operationId);
|
||||
operationId = super.toOperationId(operationId); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
// Use the part after the last dot, e.g.
|
||||
// controllers.defaultController.addPet => addPet
|
||||
operationId = operationId.replaceAll(".*\\.", "");
|
||||
|
||||
@@ -5,8 +5,6 @@ import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.properties.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@SuppressWarnings("hiding")
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavaClientCodegen.class);
|
||||
public static final String FULL_JAVA_UTIL = "fullJavaUtil";
|
||||
public static final String DEFAULT_LIBRARY = "<default>";
|
||||
@@ -322,7 +323,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
if("_".equals(name)) {
|
||||
name = "_u";
|
||||
@@ -353,7 +354,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
@@ -647,7 +648,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private String getAccept(Operation operation) {
|
||||
private static String getAccept(Operation operation) {
|
||||
String accepts = null;
|
||||
String defaultContentType = "application/json";
|
||||
if (operation.getProduces() != null && !operation.getProduces().isEmpty()) {
|
||||
@@ -678,14 +679,14 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return super.needToImport(type) && type.indexOf(".") < 0;
|
||||
}
|
||||
|
||||
private String findCommonPrefixOfVars(List<String> vars) {
|
||||
private static String findCommonPrefixOfVars(List<String> vars) {
|
||||
String prefix = StringUtils.getCommonPrefix(vars.toArray(new String[vars.size()]));
|
||||
// exclude trailing characters that should be part of a valid variable
|
||||
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
|
||||
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
|
||||
}
|
||||
|
||||
private String toEnumVarName(String value) {
|
||||
private static String toEnumVarName(String value) {
|
||||
String var = value.replaceAll("\\W+", "_").toUpperCase();
|
||||
if (var.matches("\\d.*")) {
|
||||
return "_" + var;
|
||||
@@ -694,7 +695,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
private CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
// This generator uses inline classes to define enums, which breaks when
|
||||
// dealing with models that have subTypes. To clean this up, we will analyze
|
||||
// the parent and child models, look for enums that match, and remove
|
||||
@@ -778,8 +779,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.serializableModel = serializableModel;
|
||||
}
|
||||
|
||||
private String sanitizePackageName(String packageName) {
|
||||
packageName = packageName.trim();
|
||||
private static String sanitizePackageName(String packageName) {
|
||||
packageName = packageName.trim(); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_");
|
||||
if(Strings.isNullOrEmpty(packageName)) {
|
||||
return "invalidPackageName";
|
||||
|
||||
@@ -11,7 +11,7 @@ import io.swagger.util.Yaml;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class JavaInflectorServerCodegen extends JavaClientCodegen implements CodegenConfig {
|
||||
public class JavaInflectorServerCodegen extends JavaClientCodegen {
|
||||
protected String title = "Swagger Inflector";
|
||||
|
||||
public JavaInflectorServerCodegen() {
|
||||
@@ -175,7 +175,7 @@ public class JavaInflectorServerCodegen extends JavaClientCodegen implements Cod
|
||||
if (name.length() == 0) {
|
||||
return "DefaultController";
|
||||
}
|
||||
name = name.replaceAll("[^a-zA-Z0-9]+", "_");
|
||||
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";
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.LongProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
import io.swagger.models.properties.RefProperty;
|
||||
@@ -32,6 +31,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class JavascriptClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@SuppressWarnings("hiding")
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JavascriptClientCodegen.class);
|
||||
|
||||
private static final String PROJECT_NAME = "projectName";
|
||||
@@ -228,7 +228,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME parameter should not be assigned. Also declare it as "final"
|
||||
|
||||
if("_".equals(name)) {
|
||||
name = "_u";
|
||||
@@ -259,7 +259,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME parameter should not be assigned. Also declare it as "final"
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
@@ -290,8 +290,8 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
Property inner = ap.getItems();
|
||||
// ArrayProperty ap = (ArrayProperty) p;
|
||||
// Property inner = ap.getItems();
|
||||
return getSwaggerType(p); // TODO: + "/* <" + getTypeDeclaration(inner) + "> */";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty) p;
|
||||
@@ -309,7 +309,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
} else if (p instanceof MapProperty) {
|
||||
return "{}";
|
||||
} else if (p instanceof RefProperty) {
|
||||
RefProperty rp = (RefProperty)p;
|
||||
return "new " + getTypeDeclaration(p) + "()";
|
||||
}
|
||||
|
||||
@@ -319,7 +318,6 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
@Override
|
||||
public String toDefaultValueWithParam(String name, Property p) {
|
||||
if (p instanceof RefProperty) {
|
||||
RefProperty rp = (RefProperty) p;
|
||||
return ".constructFromObject(data." + name + ");";
|
||||
}
|
||||
|
||||
@@ -366,7 +364,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
if (allDefinitions != null && codegenModel != null && codegenModel.parent != null && codegenModel.hasEnums) {
|
||||
final Model parentModel = allDefinitions.get(toModelName(codegenModel.parent));
|
||||
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
|
||||
codegenModel = this.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
codegenModel = JavascriptClientCodegen.reconcileInlineEnums(codegenModel, parentCodegenModel);
|
||||
}
|
||||
|
||||
return codegenModel;
|
||||
@@ -449,14 +447,14 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
&& !languageSpecificPrimitives.contains(type);
|
||||
}
|
||||
|
||||
private String findCommonPrefixOfVars(List<String> vars) {
|
||||
private static String findCommonPrefixOfVars(List<String> vars) {
|
||||
String prefix = StringUtils.getCommonPrefix(vars.toArray(new String[vars.size()]));
|
||||
// exclude trailing characters that should be part of a valid variable
|
||||
// e.g. ["status-on", "status-off"] => "status-" (not "status-o")
|
||||
return prefix.replaceAll("[a-zA-Z0-9]+\\z", "");
|
||||
}
|
||||
|
||||
private String toEnumVarName(String value) {
|
||||
private static String toEnumVarName(String value) {
|
||||
String var = value.replaceAll("\\W+", "_").toUpperCase();
|
||||
if (var.matches("\\d.*")) {
|
||||
return "_" + var;
|
||||
@@ -465,7 +463,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
}
|
||||
|
||||
private CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
private static CodegenModel reconcileInlineEnums(CodegenModel codegenModel, CodegenModel parentCodegenModel) {
|
||||
// This generator uses inline classes to define enums, which breaks when
|
||||
// dealing with models that have subTypes. To clean this up, we will analyze
|
||||
// the parent and child models, look for enums that match, and remove
|
||||
@@ -513,7 +511,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
private String sanitizePackageName(String packageName) {
|
||||
private static String sanitizePackageName(String packageName) { // FIXME parameter should not be assigned. Also declare it as "final"
|
||||
packageName = packageName.trim();
|
||||
packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_");
|
||||
if(Strings.isNullOrEmpty(packageName)) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import io.swagger.models.Swagger;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConfig {
|
||||
public class JaxRSServerCodegen extends JavaClientCodegen {
|
||||
protected String title = "Swagger Server";
|
||||
protected String implFolder = "src/main/java";
|
||||
|
||||
@@ -74,11 +74,7 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
if(additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
|
||||
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
|
||||
}
|
||||
|
||||
// if("jersey2".equals(getLibrary())) {
|
||||
// embeddedTemplateDir = templateDir = "JavaJaxRS" + File.separator + "jersey2";
|
||||
// }
|
||||
|
||||
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
@@ -157,7 +153,7 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
}
|
||||
}
|
||||
this.additionalProperties.put("serverPort", port);
|
||||
if(swagger != null && swagger.getPaths() != null) {
|
||||
if(swagger.getPaths() != null) {
|
||||
for(String pathname : swagger.getPaths().keySet()) {
|
||||
Path path = swagger.getPath(pathname);
|
||||
if(path.getOperations() != null) {
|
||||
@@ -233,7 +229,7 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf
|
||||
if (name.length() == 0) {
|
||||
return "DefaultApi";
|
||||
}
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name);
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<Map<String, Object>> getOperations(Map<String, Object> objs) {
|
||||
private static List<Map<String, Object>> getOperations(Map<String, Object> objs) {
|
||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
|
||||
Map<String, Object> apiInfo = (Map<String, Object>) objs.get("apiInfo");
|
||||
List<Map<String, Object>> apis = (List<Map<String, Object>>) apiInfo.get("apis");
|
||||
@@ -222,7 +222,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||
private static List<Map<String, Object>> sortOperationsByPath(List<CodegenOperation> ops) {
|
||||
Multimap<String, CodegenOperation> opsByPath = ArrayListMultimap.create();
|
||||
|
||||
for (CodegenOperation op : ops) {
|
||||
|
||||
@@ -219,12 +219,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return instantiationTypes.get("map");
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return instantiationTypes.get("array");
|
||||
} else {
|
||||
return null;
|
||||
@@ -312,7 +308,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
type = type.replaceAll("[^0-9a-zA-Z_]", "_");
|
||||
type = type.replaceAll("[^0-9a-zA-Z_]", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// language build-in classes
|
||||
if (typeMapping.keySet().contains(type) ||
|
||||
@@ -372,7 +368,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// if it's all upper case, do noting
|
||||
if (name.matches("^[A-Z_]$")) {
|
||||
@@ -409,6 +405,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public String escapeSpecialWord(String name) {
|
||||
return "var_" + name;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
import io.swagger.models.properties.MapProperty;
|
||||
import io.swagger.models.properties.Property;
|
||||
|
||||
@@ -185,14 +184,13 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String toVarName(String name) {
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
name = underscore(name);
|
||||
name = underscore(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// parameter name starting with number won't compile
|
||||
// need to escape it by appending _ at the beginning
|
||||
if (name.matches("^\\d.*")) {
|
||||
name = "_" + name;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -223,7 +221,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// e.g. phone_number_api.rb => PhoneNumberApi.rb
|
||||
return camelize(name) + "Api";
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@SuppressWarnings("hiding")
|
||||
static Logger LOGGER = LoggerFactory.getLogger(PhpClientCodegen.class);
|
||||
|
||||
public static final String VARIABLE_NAMING_CONVENTION = "variableNamingConvention";
|
||||
@@ -119,9 +120,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
public String toPackagePath(String packageName, String basePath) {
|
||||
packageName = packageName.replace(invokerPackage, "");
|
||||
packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
if (basePath != null && basePath.length() > 0) {
|
||||
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar;
|
||||
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
}
|
||||
|
||||
String regFirstPathSeparator;
|
||||
@@ -326,7 +327,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
if ("camelCase".equals(variableNamingConvention)) {
|
||||
// return the name in camelCase style
|
||||
@@ -356,7 +357,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// Note: backslash ("\\") is allowed for e.g. "\\DateTime"
|
||||
name = name.replaceAll("[^\\w\\\\]+", "_");
|
||||
name = name.replaceAll("[^\\w\\\\]+", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// remove dollar sign
|
||||
name = name.replaceAll("$", "");
|
||||
|
||||
@@ -179,7 +179,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// remove dollar sign
|
||||
name = name.replaceAll("$", "");
|
||||
@@ -212,7 +212,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// remove dollar sign
|
||||
name = name.replaceAll("$", "");
|
||||
@@ -294,6 +294,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
* (PEP 0008) Python packages should also have short, all-lowercase names,
|
||||
* although the use of underscores is discouraged.
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String generatePackageName(String packageName) {
|
||||
return underscore(packageName.replaceAll("[^\\w]+", ""));
|
||||
}
|
||||
|
||||
@@ -186,7 +186,6 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("api_error.mustache", gemFolder, "api_error.rb"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", gemFolder, "configuration.rb"));
|
||||
supportingFiles.add(new SupportingFile("version.mustache", gemFolder, "version.rb"));
|
||||
String modelFolder = gemFolder + File.separator + modelPackage.replace("/", File.separator);
|
||||
}
|
||||
|
||||
|
||||
@@ -208,6 +207,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
/**
|
||||
* Generate Ruby module name from the gem name, e.g. use "SwaggerClient" for "swagger_client".
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String generateModuleName(String gemName) {
|
||||
return camelize(gemName.replaceAll("[^\\w]+", "_"));
|
||||
}
|
||||
@@ -215,6 +215,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
/**
|
||||
* Generate Ruby gem name from the module name, e.g. use "swagger_client" for "SwaggerClient".
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
public String generateGemName(String moduleName) {
|
||||
return underscore(moduleName.replaceAll("[^\\w]+", ""));
|
||||
}
|
||||
@@ -306,7 +307,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // 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_]*$")) {
|
||||
@@ -333,7 +334,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
@@ -360,7 +361,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
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) + "_api";
|
||||
|
||||
@@ -165,7 +165,7 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public String toVarName(String name) {
|
||||
// return the name in underscore style
|
||||
// PhoneNumber => phone_number
|
||||
name = underscore(name);
|
||||
name = underscore(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
// parameter name starting with number won't compile
|
||||
// need to escape it by appending _ at the beginning
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.swagger.codegen.languages;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenConfig;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
@@ -18,8 +17,6 @@ import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String gemName;
|
||||
protected String moduleName;
|
||||
@@ -149,7 +146,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
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_]*$")) {
|
||||
@@ -201,7 +198,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_");
|
||||
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) + "_api";
|
||||
|
||||
@@ -180,8 +180,7 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
|
||||
|
||||
@Override
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
name = sanitizeName(name);
|
||||
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
if ("camelCase".equals(variableNamingConvention)) {
|
||||
// return the name in camelCase style
|
||||
|
||||
@@ -6,7 +6,7 @@ import io.swagger.models.Operation;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class SpringMVCServerCodegen extends JavaClientCodegen implements CodegenConfig {
|
||||
public class SpringMVCServerCodegen extends JavaClientCodegen {
|
||||
public static final String CONFIG_PACKAGE = "configPackage";
|
||||
protected String title = "Petstore Server";
|
||||
protected String configPackage = "";
|
||||
|
||||
@@ -270,6 +270,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return codegenProperty;
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-method")
|
||||
public String toSwiftyEnumName(String value) {
|
||||
// Prevent from breaking properly cased identifier
|
||||
if (value.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) {
|
||||
@@ -289,7 +290,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) {
|
||||
path = normalizePath(path);
|
||||
path = normalizePath(path); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
parameters = Lists.newArrayList(Iterators.filter(parameters.iterator(), new Predicate<Parameter>() {
|
||||
@Override
|
||||
|
||||
@@ -131,12 +131,8 @@ public class TizenClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toInstantiationType(Property p) {
|
||||
if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return instantiationTypes.get("map");
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return instantiationTypes.get("array");
|
||||
} else {
|
||||
return null;
|
||||
@@ -220,12 +216,8 @@ public class TizenClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
} else if (p instanceof DecimalProperty) {
|
||||
return "new Long()";
|
||||
} else if (p instanceof MapProperty) {
|
||||
MapProperty ap = (MapProperty) p;
|
||||
String inner = getSwaggerType(ap.getAdditionalProperties());
|
||||
return "new HashMap()";
|
||||
} else if (p instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) p;
|
||||
String inner = getSwaggerType(ap.getItems());
|
||||
return "new ArrayList()";
|
||||
}
|
||||
// else
|
||||
|
||||
Reference in New Issue
Block a user