mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 19:33:55 +00:00
Case-insensitive checking on reserved words
This commit is contained in:
parent
6b6f0df985
commit
dd3a06560d
@ -121,7 +121,7 @@ public class DefaultCodegen {
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// override with any special post-processing
|
||||
@SuppressWarnings("static-method")
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
@ -157,7 +157,7 @@ public class DefaultCodegen {
|
||||
// override with any special text escaping logic
|
||||
@SuppressWarnings("static-method")
|
||||
public String escapeText(String input) {
|
||||
if (input != null) {
|
||||
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");
|
||||
@ -258,7 +258,7 @@ public class DefaultCodegen {
|
||||
public Map<String, Object> vendorExtensions() {
|
||||
return vendorExtensions;
|
||||
}
|
||||
|
||||
|
||||
public List<SupportingFile> supportingFiles() {
|
||||
return supportingFiles;
|
||||
}
|
||||
@ -297,7 +297,7 @@ public class DefaultCodegen {
|
||||
|
||||
/**
|
||||
* Return the file name of the Api Test
|
||||
*
|
||||
*
|
||||
* @param name the file name of the Api
|
||||
* @return the file name of the Api
|
||||
*/
|
||||
@ -307,7 +307,7 @@ public class DefaultCodegen {
|
||||
|
||||
/**
|
||||
* Return the file name of the Api Test
|
||||
*
|
||||
*
|
||||
* @param name the file name of the Api
|
||||
* @return the file name of the Api
|
||||
*/
|
||||
@ -317,7 +317,7 @@ public class DefaultCodegen {
|
||||
|
||||
/**
|
||||
* Return the variable name in the Api
|
||||
*
|
||||
*
|
||||
* @param name the varible name of the Api
|
||||
* @return the snake-cased variable name
|
||||
*/
|
||||
@ -327,7 +327,7 @@ public class DefaultCodegen {
|
||||
|
||||
/**
|
||||
* Return the capitalized file name of the model test
|
||||
*
|
||||
*
|
||||
* @param name the model name
|
||||
* @return the file name of the model
|
||||
*/
|
||||
@ -337,17 +337,17 @@ public class DefaultCodegen {
|
||||
|
||||
/**
|
||||
* Return the capitalized file name of the model test
|
||||
*
|
||||
*
|
||||
* @param name the model name
|
||||
* @return the file name of the model
|
||||
*/
|
||||
public String toModelTestFilename(String name) {
|
||||
return initialCaps(name) + "Test";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the operation ID (method name)
|
||||
*
|
||||
*
|
||||
* @param operationId operation ID
|
||||
* @return the sanitized method name
|
||||
*/
|
||||
@ -364,7 +364,7 @@ public class DefaultCodegen {
|
||||
/**
|
||||
* Return the variable name by removing invalid characters and proper escaping if
|
||||
* it's a reserved word.
|
||||
*
|
||||
*
|
||||
* @param name the variable name
|
||||
* @return the sanitized variable name
|
||||
*/
|
||||
@ -379,7 +379,7 @@ public class DefaultCodegen {
|
||||
/**
|
||||
* Return the parameter name by removing invalid characters and proper escaping if
|
||||
* it's a reserved word.
|
||||
*
|
||||
*
|
||||
* @param name Codegen property object
|
||||
* @return the sanitized parameter name
|
||||
*/
|
||||
@ -393,7 +393,7 @@ public class DefaultCodegen {
|
||||
|
||||
/**
|
||||
* Return the Enum name (e.g. StatusEnum given 'status')
|
||||
*
|
||||
*
|
||||
* @param property Codegen property object
|
||||
* @return the Enum name
|
||||
*/
|
||||
@ -401,10 +401,10 @@ public class DefaultCodegen {
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
return StringUtils.capitalize(property.name) + "Enum";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the escaped name of the reserved word
|
||||
*
|
||||
*
|
||||
* @param name the name to be escaped
|
||||
* @return the escaped reserved word
|
||||
*
|
||||
@ -417,7 +417,7 @@ public class DefaultCodegen {
|
||||
|
||||
/**
|
||||
* Return the fully-qualified "Model" name for import
|
||||
*
|
||||
*
|
||||
* @param name the name of the "Model"
|
||||
* @return the fully-qualified "Model" name for import
|
||||
*/
|
||||
@ -431,7 +431,7 @@ public class DefaultCodegen {
|
||||
|
||||
/**
|
||||
* Return the fully-qualified "Api" name for import
|
||||
*
|
||||
*
|
||||
* @param name the name of the "Api"
|
||||
* @return the fully-qualified "Api" name for import
|
||||
*/
|
||||
@ -442,7 +442,7 @@ public class DefaultCodegen {
|
||||
/**
|
||||
* Default constructor.
|
||||
* This method will map between Swagger type and language-specified type, as well as mapping
|
||||
* between Swagger type and the corresponding import statement for the language. This will
|
||||
* between Swagger type and the corresponding import statement for the language. This will
|
||||
* also add some language specified CLI options, if any.
|
||||
*
|
||||
*
|
||||
@ -603,7 +603,7 @@ public class DefaultCodegen {
|
||||
* @param p Swagger property object
|
||||
* @return string presentation of the example value of the property
|
||||
*/
|
||||
@SuppressWarnings("static-method")
|
||||
@SuppressWarnings("static-method")
|
||||
public String toExampleValue(Property p) {
|
||||
if(p.getExample() != null) {
|
||||
return p.getExample().toString();
|
||||
@ -689,7 +689,7 @@ public class DefaultCodegen {
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the property initialized from a data object
|
||||
* Useful for initialization with a plain object in Javascript
|
||||
@ -965,7 +965,7 @@ public class DefaultCodegen {
|
||||
return camelize(toVarName(name));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert Swagger Property object to Codegen Property object
|
||||
*
|
||||
@ -1032,7 +1032,7 @@ public class DefaultCodegen {
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (p instanceof IntegerProperty) {
|
||||
IntegerProperty sp = (IntegerProperty) p;
|
||||
property.isInteger = true;
|
||||
@ -1050,7 +1050,7 @@ public class DefaultCodegen {
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (p instanceof LongProperty) {
|
||||
LongProperty sp = (LongProperty) p;
|
||||
property.isLong = true;
|
||||
@ -1068,7 +1068,7 @@ public class DefaultCodegen {
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (p instanceof BooleanProperty) {
|
||||
property.isBoolean = true;
|
||||
}
|
||||
@ -1098,7 +1098,7 @@ public class DefaultCodegen {
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (p instanceof FloatProperty) {
|
||||
FloatProperty sp = (FloatProperty) p;
|
||||
property.isFloat = true;
|
||||
@ -1116,7 +1116,7 @@ public class DefaultCodegen {
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (p instanceof DateProperty) {
|
||||
DateProperty sp = (DateProperty) p;
|
||||
property.isDate = true;
|
||||
@ -1134,7 +1134,7 @@ public class DefaultCodegen {
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (p instanceof DateTimeProperty) {
|
||||
DateTimeProperty sp = (DateTimeProperty) p;
|
||||
property.isDateTime = true;
|
||||
@ -1229,7 +1229,7 @@ public class DefaultCodegen {
|
||||
}
|
||||
return responses.get(code);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert Swagger Operation object to Codegen Operation object (without providing a Swagger object)
|
||||
*
|
||||
@ -1242,7 +1242,7 @@ public class DefaultCodegen {
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
|
||||
return fromOperation(path, httpMethod, operation, definitions, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert Swagger Operation object to Codegen Operation object
|
||||
*
|
||||
@ -1277,11 +1277,11 @@ public class DefaultCodegen {
|
||||
// empty list, do nothing to override global setting
|
||||
}
|
||||
} else if (swagger != null && swagger.getConsumes() != null && swagger.getConsumes().size() > 0) {
|
||||
// use consumes defined globally
|
||||
// use consumes defined globally
|
||||
consumes = swagger.getConsumes();
|
||||
LOGGER.debug("No consumes defined in operation. Using global consumes (" + swagger.getConsumes() + ") for " + op.operationId);
|
||||
}
|
||||
|
||||
|
||||
// if "consumes" is defined (per operation or using global definition)
|
||||
if (consumes != null && consumes.size() > 0) {
|
||||
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
|
||||
@ -1310,11 +1310,11 @@ public class DefaultCodegen {
|
||||
// empty list, do nothing to override global setting
|
||||
}
|
||||
} else if (swagger != null && swagger.getProduces() != null && swagger.getProduces().size() > 0) {
|
||||
// use produces defined globally
|
||||
// use produces defined globally
|
||||
produces = swagger.getProduces();
|
||||
LOGGER.debug("No produces defined in operation. Using global produces (" + swagger.getProduces() + ") for " + op.operationId);
|
||||
}
|
||||
|
||||
|
||||
// if "produces" is defined (per operation or using global definition)
|
||||
if (produces != null && produces.size() > 0) {
|
||||
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
|
||||
@ -1556,7 +1556,7 @@ public class DefaultCodegen {
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert Swagger Parameter object to Codegen Parameter object
|
||||
*
|
||||
@ -1658,7 +1658,7 @@ public class DefaultCodegen {
|
||||
p.maxLength = qp.getMaxLength();
|
||||
p.minLength = qp.getMinLength();
|
||||
p.pattern = qp.getPattern();
|
||||
|
||||
|
||||
p.maximum = qp.getMaximum();
|
||||
p.exclusiveMaximum = qp.isExclusiveMaximum();
|
||||
p.minimum = qp.getMinimum();
|
||||
@ -1783,14 +1783,14 @@ public class DefaultCodegen {
|
||||
Map<String, Object> scope = new HashMap<String, Object>();
|
||||
scope.put("scope", scopeEntry.getKey());
|
||||
scope.put("description", scopeEntry.getValue());
|
||||
|
||||
|
||||
count += 1;
|
||||
if (count < numScopes) {
|
||||
scope.put("hasMore", "true");
|
||||
} else {
|
||||
scope.put("hasMore", null);
|
||||
}
|
||||
|
||||
|
||||
scopes.add(scope);
|
||||
}
|
||||
sec.scopes = scopes;
|
||||
@ -1803,6 +1803,17 @@ public class DefaultCodegen {
|
||||
return secs;
|
||||
}
|
||||
|
||||
protected void setReservedWordsLowerCase(List<String> words) {
|
||||
reservedWords = new HashSet<String>();
|
||||
for (String word : words) {
|
||||
reservedWords.add(word.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isReservedWord(String word) {
|
||||
return word != null && reservedWords.contains(word.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get operationId from the operation object, and if it's blank, generate a new one from the given parameters.
|
||||
*
|
||||
@ -2046,9 +2057,9 @@ public class DefaultCodegen {
|
||||
m.vars.add(cp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m.mandatory = mandatory;
|
||||
|
||||
|
||||
} else {
|
||||
m.emptyVars = true;
|
||||
m.hasVars = false;
|
||||
@ -2077,7 +2088,7 @@ public class DefaultCodegen {
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Camelize name (parameter, property, method, etc) with upper case for first letter
|
||||
* copied from Twitter elephant bird
|
||||
@ -2221,7 +2232,7 @@ public class DefaultCodegen {
|
||||
// character with _ or empty character. Below aims to spell out different cases we've
|
||||
// encountered so far and hopefully make it easier for others to add more special
|
||||
// cases in the future.
|
||||
|
||||
|
||||
// better error handling when map/array type is invalid
|
||||
if (name == null) {
|
||||
LOGGER.error("String to be sanitized is null. Default to ERROR_UNKNOWN");
|
||||
|
@ -44,7 +44,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
Arrays.asList("IDictionary")
|
||||
);
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names in API methods (endpoints)
|
||||
"path_", "pathParams", "queryParams", "headerParams", "formParams", "fileParams",
|
||||
@ -282,7 +282,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
@ -304,7 +304,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
name = camelize(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -329,7 +329,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -470,7 +470,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
name = sanitizeName(name);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,10 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
public AbstractTypeScriptClientCodegen() {
|
||||
super();
|
||||
supportsInheritance = true;
|
||||
reservedWords = new HashSet<String>(Arrays.asList(
|
||||
setReservedWordsLowerCase(Arrays.asList(
|
||||
// local variable names used in API methods (endpoints)
|
||||
"path", "queryParameters", "headerParams", "formParams", "useFormData", "deferred",
|
||||
"requestOptions",
|
||||
"requestOptions",
|
||||
// Typescript reserved words
|
||||
"abstract", "await", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield"));
|
||||
|
||||
@ -32,7 +32,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
"Float",
|
||||
"Object"));
|
||||
instantiationTypes.put("array", "Array");
|
||||
|
||||
|
||||
typeMapping = new HashMap<String, String>();
|
||||
typeMapping.put("Array", "Array");
|
||||
typeMapping.put("array", "Array");
|
||||
@ -67,7 +67,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
@ -102,7 +102,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*"))
|
||||
if (isReservedWord(name) || name.matches("^\\d.*"))
|
||||
name = escapeReservedWord(name);
|
||||
|
||||
return name;
|
||||
@ -117,7 +117,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name))
|
||||
if (isReservedWord(name))
|
||||
throw new RuntimeException(name
|
||||
+ " (reserved word) cannot be used as a model name");
|
||||
|
||||
@ -170,7 +170,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
// append _ at the beginning, e.g. _return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
return escapeReservedWord(camelize(sanitizeName(operationId), true));
|
||||
}
|
||||
|
||||
@ -178,12 +178,12 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
}
|
||||
|
||||
public void setModelPropertyNaming(String naming) {
|
||||
if ("original".equals(naming) || "camelCase".equals(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', " +
|
||||
throw new IllegalArgumentException("Invalid model property naming '" +
|
||||
naming + "'. Must be 'original', 'camelCase', " +
|
||||
"'PascalCase' or 'snake_case'");
|
||||
}
|
||||
}
|
||||
@ -198,9 +198,9 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
|
||||
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'");
|
||||
default: throw new IllegalArgumentException("Invalid model property naming '" +
|
||||
name + "'. Must be 'original', 'camelCase', " +
|
||||
"'PascalCase' or 'snake_case'");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
* unmarshalling problems and any other RuntimeException will be considered as ApiErrors.
|
||||
*/
|
||||
protected boolean onlyOneSuccess = true;
|
||||
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
protected Logger LOGGER = LoggerFactory.getLogger(AkkaScalaClientCodegen.class);
|
||||
|
||||
@ -76,7 +76,7 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
apiPackage = mainPackage + ".api";
|
||||
modelPackage = mainPackage + ".model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"abstract", "case", "catch", "class", "def", "do", "else", "extends",
|
||||
"false", "final", "finally", "for", "forSome", "if", "implicit",
|
||||
@ -276,7 +276,7 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
|
||||
if (capitalized) {
|
||||
identifier = StringUtils.capitalize(identifier);
|
||||
}
|
||||
if (identifier.matches("[a-zA-Z_$][\\w_$]+") && !reservedWords.contains(identifier)) {
|
||||
if (identifier.matches("[a-zA-Z_$][\\w_$]+") && !isReservedWord(identifier)) {
|
||||
return identifier;
|
||||
}
|
||||
return escapeReservedWord(identifier);
|
||||
|
@ -42,7 +42,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names used in API methods (endpoints)
|
||||
"postBody", "path", "queryParams", "headerParams", "formParams",
|
||||
@ -165,7 +165,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -185,7 +185,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
name = camelize(sanitizeName(name));
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
String modelName = "Object" + name;
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
@ -210,7 +210,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
|
@ -23,11 +23,9 @@ public class AspNet5ServerCodegen extends AbstractCSharpCodegen {
|
||||
apiTemplateFiles.put("controller.mustache", ".cs");
|
||||
|
||||
// contextually reserved words
|
||||
reservedWords.add("var");
|
||||
reservedWords.add("async");
|
||||
reservedWords.add("await");
|
||||
reservedWords.add("dynamic");
|
||||
reservedWords.add("yield");
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList("var", "async", "await", "dynamic", "yield")
|
||||
);
|
||||
|
||||
cliOptions.clear();
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names used in API methods (endpoints)
|
||||
"config", "path", "contentTypes", "contentType", "queryParams", "headerParams",
|
||||
|
@ -31,12 +31,12 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
apiPackage = "IO.Swagger.Api";
|
||||
modelPackage = "IO.Swagger.Model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names in API methods (endpoints)
|
||||
"path", "queryParams", "headerParams", "formParams", "fileParams", "postBody",
|
||||
"authSettings", "response", "StatusCode",
|
||||
// C# reserved word
|
||||
// C# reserved word
|
||||
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while")
|
||||
);
|
||||
|
||||
@ -114,7 +114,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
} else {
|
||||
additionalProperties.put(CLIENT_PACKAGE, clientPackage);
|
||||
}
|
||||
|
||||
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache",
|
||||
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "Configuration.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache",
|
||||
@ -184,7 +184,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
name = camelize(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -206,7 +206,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
name = sanitizeName(name);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
apiPackage = "lib.api";
|
||||
modelPackage = "lib.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"abstract", "as", "assert", "async", "async*", "await",
|
||||
"break", "case", "catch", "class", "const", "continue",
|
||||
@ -183,7 +183,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@ -261,7 +261,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
|
@ -70,8 +70,8 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
importMapping = new HashMap<String, String>();
|
||||
importMapping.put("File", "flash.filesystem.File");
|
||||
|
||||
// from
|
||||
reservedWords = new HashSet<String>(Arrays.asList("add", "for", "lt", "tellTarget", "and",
|
||||
// from
|
||||
setReservedWordsLowerCase(Arrays.asList("add", "for", "lt", "tellTarget", "and",
|
||||
"function", "ne", "this", "break", "ge", "new", "typeof", "continue", "gt", "not",
|
||||
"var", "delete", "if", "on", "void", "do", "ifFrameLoaded", "onClipEvent", "while",
|
||||
"else", "in", "or", "with", "eq", "le", "return"));
|
||||
@ -261,7 +261,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
public String toVarName(String name) {
|
||||
// replace - with _ e.g. created-at => created_at
|
||||
name = name.replaceAll("-", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (name.matches("^[A-Z_]*$")) {
|
||||
name = name.toLowerCase();
|
||||
@ -272,7 +272,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
name = camelize(dropDots(name), true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -288,7 +288,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@ -300,7 +300,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@ -343,7 +343,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ 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";
|
||||
@ -73,7 +73,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
embeddedTemplateDir = templateDir = "flaskConnexion";
|
||||
|
||||
// from https://docs.python.org/release/2.5.4/ref/keywords.html
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"and", "del", "from", "not", "while", "as", "elif", "global", "or", "with",
|
||||
"assert", "else", "if", "pass", "yield", "break", "except", "import",
|
||||
|
@ -38,7 +38,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
apiTemplateFiles.put("api.mustache", ".go");
|
||||
templateDir = "go";
|
||||
|
||||
reservedWords = new HashSet<String> (
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"break", "default", "func", "interface", "select",
|
||||
"case", "defer", "go", "map", "struct",
|
||||
@ -100,7 +100,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
.defaultValue("swagger"));
|
||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Go package version.")
|
||||
.defaultValue("1.0.0"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,7 +128,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
apiPackage = packageName;
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
@ -158,7 +158,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = camelize(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if(reservedWords.contains(name) || name.matches("^\\d.*"))
|
||||
if(isReservedWord(name) || name.matches("^\\d.*"))
|
||||
name = escapeReservedWord(name);
|
||||
|
||||
return name;
|
||||
@ -173,7 +173,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if(reservedWords.contains(name))
|
||||
if(isReservedWord(name))
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
|
||||
// camelize the model name
|
||||
@ -220,7 +220,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if(reservedWords.contains(operationId))
|
||||
if(isReservedWord(operationId))
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
|
||||
return camelize(operationId);
|
||||
|
@ -17,7 +17,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
/**
|
||||
* Configures the type of generator.
|
||||
*
|
||||
*
|
||||
* @return the CodegenType for this generator
|
||||
* @see io.swagger.codegen.CodegenType
|
||||
*/
|
||||
@ -28,7 +28,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
/**
|
||||
* Configures a friendly name for the generator. This will be used by the generator
|
||||
* to select the library with the -l flag.
|
||||
*
|
||||
*
|
||||
* @return the friendly name for the generator
|
||||
*/
|
||||
public String getName() {
|
||||
@ -38,7 +38,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
/**
|
||||
* Returns human-friendly help for the generator. Provide the consumer with help
|
||||
* tips, parameters here
|
||||
*
|
||||
*
|
||||
* @return A string value for the help message
|
||||
*/
|
||||
public String getHelp() {
|
||||
@ -90,7 +90,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
// from https://wiki.haskell.org/Keywords
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"as", "case", "of",
|
||||
"class", "data", // "data family", "data instance",
|
||||
@ -174,7 +174,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
/**
|
||||
* Escapes a reserved word as defined in the `reservedWords` array. Handle escaping
|
||||
* those terms here. This logic is only called if a variable matches the reseved words
|
||||
*
|
||||
*
|
||||
* @return the escaped term
|
||||
*/
|
||||
@Override
|
||||
@ -221,7 +221,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional - swagger type conversion. This is used to map swagger types in a `Property` into
|
||||
* Optional - swagger type conversion. This is used to map swagger types in a `Property` into
|
||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||
*
|
||||
* @return a string value of the type or complex model for this property
|
||||
@ -244,7 +244,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
private String capturePath(String path, List<CodegenParameter> pathParams) {
|
||||
for (CodegenParameter p : pathParams) {
|
||||
String pName = "{"+p.baseName+"}";
|
||||
if (path.indexOf(pName) >= 0) {
|
||||
if (path.indexOf(pName) >= 0) {
|
||||
path = path.replace(pName, "Capture " + "\""+p.baseName+"\" " + p.dataType);
|
||||
}
|
||||
}
|
||||
@ -270,7 +270,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
for (CodegenParameter p : formParams) {
|
||||
if(p.dataType.equals("FilePath")){
|
||||
// file data processing
|
||||
}
|
||||
}
|
||||
names += p.baseName;
|
||||
}
|
||||
if(formParams.size() > 0){
|
||||
@ -315,7 +315,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
|
||||
String[] ps = path.replaceFirst("/", "").split("/", 0);
|
||||
List<String> rs = new ArrayList<String>();
|
||||
for (String p : ps) {
|
||||
if (p.indexOf("{") < 0) {
|
||||
if (p.indexOf("{") < 0) {
|
||||
rs.add("\"" + p + "\"");
|
||||
} else {
|
||||
rs.add(p);
|
||||
|
@ -52,20 +52,20 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
// used as internal variables, can collide with parameter names
|
||||
"path", "queryParams", "headerParams", "formParams", "postBody", "accepts", "accept", "contentTypes",
|
||||
"contentType", "authNames",
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// used as internal variables, can collide with parameter names
|
||||
"path", "queryParams", "headerParams", "formParams", "postBody", "accepts", "accept", "contentTypes",
|
||||
"contentType", "authNames",
|
||||
|
||||
// language reserved words
|
||||
"abstract", "continue", "for", "new", "switch", "assert",
|
||||
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
|
||||
"this", "break", "double", "implements", "protected", "throw", "byte", "else",
|
||||
"import", "public", "throws", "case", "enum", "instanceof", "return", "transient",
|
||||
"catch", "extends", "int", "short", "try", "char", "final", "interface", "static",
|
||||
"void", "class", "finally", "long", "strictfp", "volatile", "const", "float",
|
||||
"native", "super", "while")
|
||||
// language reserved words
|
||||
"abstract", "continue", "for", "new", "switch", "assert",
|
||||
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
|
||||
"this", "break", "double", "implements", "protected", "throw", "byte", "else",
|
||||
"import", "public", "throws", "case", "enum", "instanceof", "return", "transient",
|
||||
"catch", "extends", "int", "short", "try", "char", "final", "interface", "static",
|
||||
"void", "class", "finally", "long", "strictfp", "volatile", "const", "float",
|
||||
"native", "super", "while")
|
||||
);
|
||||
|
||||
languageSpecificPrimitives = new HashSet<String>(
|
||||
@ -362,7 +362,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -384,7 +384,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = camelize(name);
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
String modelName = "Object" + name;
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
@ -508,7 +508,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
operationId = camelize(sanitizeName(operationId), true);
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = camelize("call_" + operationId, true);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
|
@ -75,7 +75,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
modelPackage = "model";
|
||||
|
||||
// reference: http://www.w3schools.com/js/js_reserved.asp
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"abstract", "arguments", "boolean", "break", "byte",
|
||||
"case", "catch", "char", "class", "const",
|
||||
@ -276,7 +276,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
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)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@ -420,7 +420,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
operationId = escapeReservedWord(operationId);
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
||||
super();
|
||||
|
||||
supportsInheritance = false;
|
||||
reservedWords = new HashSet<String>(Arrays.asList("abstract",
|
||||
setReservedWordsLowerCase(Arrays.asList("abstract",
|
||||
"continue", "for", "new", "switch", "assert", "default", "if",
|
||||
"package", "synchronized", "do", "goto", "private",
|
||||
"this", "break", "double", "implements", "protected", "throw",
|
||||
@ -114,7 +114,7 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*"))
|
||||
if (isReservedWord(name) || name.matches("^\\d.*"))
|
||||
name = escapeReservedWord(name);
|
||||
|
||||
return name;
|
||||
@ -129,7 +129,7 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name))
|
||||
if (isReservedWord(name))
|
||||
throw new RuntimeException(name
|
||||
+ " (reserved word) cannot be used as a model name");
|
||||
|
||||
|
@ -21,7 +21,7 @@ import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSServerCodegen.class);
|
||||
|
||||
protected String apiVersion = "1.0.0";
|
||||
@ -60,7 +60,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
/**
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"break", "case", "class", "catch", "const", "continue", "debugger",
|
||||
"default", "delete", "do", "else", "export", "extends", "finally",
|
||||
@ -251,7 +251,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
}
|
||||
this.additionalProperties.put("serverPort", port);
|
||||
|
||||
|
||||
if (swagger.getInfo() != null) {
|
||||
Info info = swagger.getInfo();
|
||||
if (info.getTitle() != null) {
|
||||
|
@ -39,7 +39,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
public ObjcClientCodegen() {
|
||||
super();
|
||||
|
||||
|
||||
outputFolder = "generated-code" + File.separator + "objc";
|
||||
modelTemplateFiles.put("model-header.mustache", ".h");
|
||||
modelTemplateFiles.put("model-body.mustache", ".m");
|
||||
@ -60,7 +60,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
defaultIncludes.add("NSDictionary");
|
||||
defaultIncludes.add("NSMutableArray");
|
||||
defaultIncludes.add("NSMutableDictionary");
|
||||
|
||||
|
||||
languageSpecificPrimitives.clear();
|
||||
languageSpecificPrimitives.add("NSNumber");
|
||||
languageSpecificPrimitives.add("NSString");
|
||||
@ -93,8 +93,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
|
||||
// ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
|
||||
reservedWords = new HashSet<String>(
|
||||
Arrays.asList(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names in API methods (endpoints)
|
||||
"resourcePath", "pathParams", "queryParams", "headerParams",
|
||||
"responseContentType", "requestContentType", "authSettings",
|
||||
@ -174,19 +174,19 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (additionalProperties.containsKey(CLASS_PREFIX)) {
|
||||
setClassPrefix((String) additionalProperties.get(CLASS_PREFIX));
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey(AUTHOR_NAME)) {
|
||||
setAuthorName((String) additionalProperties.get(AUTHOR_NAME));
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey(AUTHOR_EMAIL)) {
|
||||
setAuthorEmail((String) additionalProperties.get(AUTHOR_EMAIL));
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey(GIT_REPO_URL)) {
|
||||
setGitRepoURL((String) additionalProperties.get(GIT_REPO_URL));
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey(LICENSE)) {
|
||||
setLicense((String) additionalProperties.get(LICENSE));
|
||||
}
|
||||
@ -392,7 +392,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = camelize(name, true);
|
||||
|
||||
// for reserved word or word starting with number, prepend `_`
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -424,7 +424,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
@ -442,19 +442,19 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setPodVersion(String podVersion) {
|
||||
this.podVersion = podVersion;
|
||||
}
|
||||
|
||||
|
||||
public void setAuthorEmail(String authorEmail) {
|
||||
this.authorEmail = authorEmail;
|
||||
}
|
||||
|
||||
|
||||
public void setAuthorName(String authorName) {
|
||||
this.authorName = authorName;
|
||||
}
|
||||
|
||||
|
||||
public void setGitRepoURL(String gitRepoURL) {
|
||||
this.gitRepoURL = gitRepoURL;
|
||||
}
|
||||
|
||||
|
||||
public void setLicense(String license) {
|
||||
this.license = license;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
embeddedTemplateDir = templateDir = "perl";
|
||||
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"else", "lock", "qw",
|
||||
"__END__", "elsif", "lt", "qx",
|
||||
@ -219,7 +219,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
escapeReservedWord(name); // e.g. return => _return
|
||||
}
|
||||
|
||||
@ -272,7 +272,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore("call_" + operationId));
|
||||
return underscore("call_" + operationId);
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
modelPackage = invokerPackage + "\\Model";
|
||||
testPackage = invokerPackage + "\\Tests";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variables used in api methods (endpoints)
|
||||
"resourcePath", "method", "httpBody", "queryParams", "headerParams",
|
||||
@ -178,13 +178,13 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
} else {
|
||||
additionalProperties.put(SRC_BASE_PATH, srcBasePath);
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
||||
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
|
||||
}
|
||||
|
||||
|
||||
if (!additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
|
||||
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
|
||||
}
|
||||
@ -192,19 +192,19 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (!additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
|
||||
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey(COMPOSER_PROJECT_NAME)) {
|
||||
this.setComposerProjectName((String) additionalProperties.get(COMPOSER_PROJECT_NAME));
|
||||
} else {
|
||||
additionalProperties.put(COMPOSER_PROJECT_NAME, composerProjectName);
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey(COMPOSER_VENDOR_NAME)) {
|
||||
this.setComposerVendorName((String) additionalProperties.get(COMPOSER_VENDOR_NAME));
|
||||
} else {
|
||||
additionalProperties.put(COMPOSER_VENDOR_NAME, composerVendorName);
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) {
|
||||
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
|
||||
} else {
|
||||
@ -214,7 +214,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (additionalProperties.containsKey(VARIABLE_NAMING_CONVENTION)) {
|
||||
this.setParameterNamingConvention((String) additionalProperties.get(VARIABLE_NAMING_CONVENTION));
|
||||
}
|
||||
|
||||
|
||||
additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", toPackagePath(invokerPackage, srcBasePath), "Configuration.php"));
|
||||
@ -301,7 +301,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setInvokerPackage(String invokerPackage) {
|
||||
this.invokerPackage = invokerPackage;
|
||||
}
|
||||
|
||||
|
||||
public void setArtifactVersion(String artifactVersion) {
|
||||
this.artifactVersion = artifactVersion;
|
||||
}
|
||||
@ -313,7 +313,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setSrcBasePath(String srcBasePath) {
|
||||
this.srcBasePath = srcBasePath;
|
||||
}
|
||||
|
||||
|
||||
public void setParameterNamingConvention(String variableNamingConvention) {
|
||||
this.variableNamingConvention = variableNamingConvention;
|
||||
}
|
||||
@ -321,7 +321,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setComposerVendorName(String composerVendorName) {
|
||||
this.composerVendorName = composerVendorName;
|
||||
}
|
||||
|
||||
|
||||
public void setComposerProjectName(String composerProjectName) {
|
||||
this.composerProjectName = composerProjectName;
|
||||
}
|
||||
@ -365,7 +365,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = name.replaceAll("$", "");
|
||||
|
||||
// model name cannot use reserved keyword
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name));
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
@ -395,7 +395,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
typeMapping.put("binary", "str");
|
||||
|
||||
// from https://docs.python.org/release/2.5.4/ref/keywords.html
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable name used in API methods (endpoints)
|
||||
"all_params", "resource_path", "method", "path_params", "query_params",
|
||||
@ -197,7 +197,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
name = name.replaceAll("^_*", "");
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
name = name.replaceAll("$", "");
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@ -273,7 +273,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
|
||||
/**
|
||||
* Reserved words. Override this with reserved words specific to your language
|
||||
*/
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"sample1", // replace with static values
|
||||
"sample2")
|
||||
|
@ -58,7 +58,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.clear();
|
||||
languageSpecificPrimitives.clear();
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names used in API methods (endpoints)
|
||||
"path", "query_params", "header_params", "_header_accept", "_header_accept_result",
|
||||
@ -344,7 +344,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
name = underscore(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -362,7 +362,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
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)) {
|
||||
if (isReservedWord(name)) {
|
||||
String modelName = camelize("object_" + name);
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
|
||||
return modelName;
|
||||
@ -376,7 +376,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
String filename = underscore("object_" + name);
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + filename);
|
||||
return filename;
|
||||
@ -425,7 +425,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
String newOperationId = underscore("call_" + operationId);
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
|
||||
return newOperationId;
|
||||
|
@ -47,7 +47,7 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
apiPackage = "io.swagger.client.api";
|
||||
modelPackage = "io.swagger.client.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
// local variable names used in API methods (endpoints)
|
||||
"path", "contentTypes", "contentType", "queryParams", "headerParams",
|
||||
@ -235,7 +235,7 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class ScalatraServerCodegen extends DefaultCodegen implements CodegenConf
|
||||
apiPackage = "com.wordnik.client.api";
|
||||
modelPackage = "com.wordnik.client.model";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"abstract", "continue", "for", "new", "switch", "assert",
|
||||
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
|
||||
|
@ -37,7 +37,7 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
embeddedTemplateDir = templateDir = "silex";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"__halt_compiler", "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "final", "for", "foreach", "function", "global", "goto", "if", "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset", "list", "namespace", "new", "or", "print", "private", "protected", "public", "require", "require_once", "return", "static", "switch", "throw", "trait", "try", "unset", "use", "var", "while", "xor")
|
||||
);
|
||||
@ -185,7 +185,7 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
escapeReservedWord(name); // e.g. return => _return
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ 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;
|
||||
@ -43,7 +43,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
typeMapping.clear();
|
||||
languageSpecificPrimitives.clear();
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__",
|
||||
"begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN",
|
||||
@ -165,7 +165,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
name = underscore(name);
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
if (isReservedWord(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@ -193,7 +193,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toModelFilename(String name) {
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
}
|
||||
|
||||
@ -223,7 +223,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
|
||||
|
||||
embeddedTemplateDir = templateDir = "slim";
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"__halt_compiler", "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "final", "for", "foreach", "function", "global", "goto", "if", "implements", "include", "include_once", "instanceof", "insteadof", "interface", "isset", "list", "namespace", "new", "or", "print", "private", "protected", "public", "require", "require_once", "return", "static", "switch", "throw", "trait", "try", "unset", "use", "var", "while", "xor")
|
||||
);
|
||||
@ -210,7 +210,7 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// model name cannot use reserved keyword
|
||||
if (reservedWords.contains(name)) {
|
||||
if (isReservedWord(name)) {
|
||||
escapeReservedWord(name); // e.g. return => _return
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
"Empty",
|
||||
"AnyObject")
|
||||
);
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
Arrays.asList(
|
||||
"class", "break", "as", "associativity", "deinit", "case", "dynamicType", "convenience", "enum", "continue",
|
||||
"false", "dynamic", "extension", "default", "is", "didSet", "func", "do", "nil", "final", "import", "else",
|
||||
@ -267,7 +267,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// Ensure that the enum type doesn't match a reserved word or
|
||||
// the variable name doesn't match the generated enum type or the
|
||||
// Swift compiler will generate an error
|
||||
if (reservedWords.contains(codegenProperty.datatypeWithEnum) ||
|
||||
if (isReservedWord(codegenProperty.datatypeWithEnum) ||
|
||||
name.equals(codegenProperty.datatypeWithEnum)) {
|
||||
codegenProperty.datatypeWithEnum = escapeReservedWord(codegenProperty.datatypeWithEnum);
|
||||
}
|
||||
@ -301,7 +301,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class TizenClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
additionalProperties().put("prefix", PREFIX);
|
||||
|
||||
reservedWords = new HashSet<String>(
|
||||
setReservedWordsLowerCase(
|
||||
// VERIFY
|
||||
Arrays.asList(
|
||||
"void", "char", "short", "int", "void", "char", "short", "int",
|
||||
@ -273,7 +273,7 @@ public class TizenClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return$
|
||||
if (reservedWords.contains(operationId)) {
|
||||
if (isReservedWord(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user