Merge pull request #2242 from xhh/java-reserved-operation-id

Handle reserved operationId/modelName in Java/Android clients
This commit is contained in:
wing328 2016-02-26 17:03:10 +08:00
commit 04ede6dff5
39 changed files with 259 additions and 228 deletions

View File

@ -121,7 +121,7 @@ public class DefaultCodegen {
return objs; return objs;
} }
// override with any special post-processing // override with any special post-processing
@SuppressWarnings("static-method") @SuppressWarnings("static-method")
public Map<String, Object> postProcessOperations(Map<String, Object> objs) { public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
@ -157,7 +157,7 @@ public class DefaultCodegen {
// override with any special text escaping logic // override with any special text escaping logic
@SuppressWarnings("static-method") @SuppressWarnings("static-method")
public String escapeText(String input) { 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'. input = input.trim(); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
String output = input.replaceAll("\n", "\\\\n"); String output = input.replaceAll("\n", "\\\\n");
output = output.replace("\r", "\\r"); output = output.replace("\r", "\\r");
@ -258,7 +258,7 @@ public class DefaultCodegen {
public Map<String, Object> vendorExtensions() { public Map<String, Object> vendorExtensions() {
return vendorExtensions; return vendorExtensions;
} }
public List<SupportingFile> supportingFiles() { public List<SupportingFile> supportingFiles() {
return supportingFiles; return supportingFiles;
} }
@ -297,7 +297,7 @@ public class DefaultCodegen {
/** /**
* Return the file name of the Api Test * Return the file name of the Api Test
* *
* @param name the file name of the Api * @param name the file name of the Api
* @return 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 * Return the file name of the Api Test
* *
* @param name the file name of the Api * @param name the file name of the Api
* @return 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 * Return the variable name in the Api
* *
* @param name the varible name of the Api * @param name the varible name of the Api
* @return the snake-cased variable name * @return the snake-cased variable name
*/ */
@ -327,7 +327,7 @@ public class DefaultCodegen {
/** /**
* Return the capitalized file name of the model test * Return the capitalized file name of the model test
* *
* @param name the model name * @param name the model name
* @return the file name of the model * @return the file name of the model
*/ */
@ -337,17 +337,17 @@ public class DefaultCodegen {
/** /**
* Return the capitalized file name of the model test * Return the capitalized file name of the model test
* *
* @param name the model name * @param name the model name
* @return the file name of the model * @return the file name of the model
*/ */
public String toModelTestFilename(String name) { public String toModelTestFilename(String name) {
return initialCaps(name) + "Test"; return initialCaps(name) + "Test";
} }
/** /**
* Return the operation ID (method name) * Return the operation ID (method name)
* *
* @param operationId operation ID * @param operationId operation ID
* @return the sanitized method name * @return the sanitized method name
*/ */
@ -364,7 +364,7 @@ public class DefaultCodegen {
/** /**
* Return the variable name by removing invalid characters and proper escaping if * Return the variable name by removing invalid characters and proper escaping if
* it's a reserved word. * it's a reserved word.
* *
* @param name the variable name * @param name the variable name
* @return the sanitized 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 * Return the parameter name by removing invalid characters and proper escaping if
* it's a reserved word. * it's a reserved word.
* *
* @param name Codegen property object * @param name Codegen property object
* @return the sanitized parameter name * @return the sanitized parameter name
*/ */
@ -393,7 +393,7 @@ public class DefaultCodegen {
/** /**
* Return the Enum name (e.g. StatusEnum given 'status') * Return the Enum name (e.g. StatusEnum given 'status')
* *
* @param property Codegen property object * @param property Codegen property object
* @return the Enum name * @return the Enum name
*/ */
@ -401,10 +401,10 @@ public class DefaultCodegen {
public String toEnumName(CodegenProperty property) { public String toEnumName(CodegenProperty property) {
return StringUtils.capitalize(property.name) + "Enum"; return StringUtils.capitalize(property.name) + "Enum";
} }
/** /**
* Return the escaped name of the reserved word * Return the escaped name of the reserved word
* *
* @param name the name to be escaped * @param name the name to be escaped
* @return the escaped reserved word * @return the escaped reserved word
* *
@ -417,7 +417,7 @@ public class DefaultCodegen {
/** /**
* Return the fully-qualified "Model" name for import * Return the fully-qualified "Model" name for import
* *
* @param name the name of the "Model" * @param name the name of the "Model"
* @return the fully-qualified "Model" name for import * @return the fully-qualified "Model" name for import
*/ */
@ -431,7 +431,7 @@ public class DefaultCodegen {
/** /**
* Return the fully-qualified "Api" name for import * Return the fully-qualified "Api" name for import
* *
* @param name the name of the "Api" * @param name the name of the "Api"
* @return the fully-qualified "Api" name for import * @return the fully-qualified "Api" name for import
*/ */
@ -442,7 +442,7 @@ public class DefaultCodegen {
/** /**
* Default constructor. * Default constructor.
* This method will map between Swagger type and language-specified type, as well as mapping * 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. * also add some language specified CLI options, if any.
* *
* *
@ -603,7 +603,7 @@ public class DefaultCodegen {
* @param p Swagger property object * @param p Swagger property object
* @return string presentation of the example value of the property * @return string presentation of the example value of the property
*/ */
@SuppressWarnings("static-method") @SuppressWarnings("static-method")
public String toExampleValue(Property p) { public String toExampleValue(Property p) {
if(p.getExample() != null) { if(p.getExample() != null) {
return p.getExample().toString(); return p.getExample().toString();
@ -689,7 +689,7 @@ public class DefaultCodegen {
return "null"; return "null";
} }
} }
/** /**
* Return the property initialized from a data object * Return the property initialized from a data object
* Useful for initialization with a plain object in Javascript * Useful for initialization with a plain object in Javascript
@ -965,7 +965,7 @@ public class DefaultCodegen {
return camelize(toVarName(name)); return camelize(toVarName(name));
} }
/** /**
* Convert Swagger Property object to Codegen Property object * Convert Swagger Property object to Codegen Property object
* *
@ -1032,7 +1032,7 @@ public class DefaultCodegen {
property.allowableValues = allowableValues; property.allowableValues = allowableValues;
} }
} }
if (p instanceof IntegerProperty) { if (p instanceof IntegerProperty) {
IntegerProperty sp = (IntegerProperty) p; IntegerProperty sp = (IntegerProperty) p;
property.isInteger = true; property.isInteger = true;
@ -1050,7 +1050,7 @@ public class DefaultCodegen {
property.allowableValues = allowableValues; property.allowableValues = allowableValues;
} }
} }
if (p instanceof LongProperty) { if (p instanceof LongProperty) {
LongProperty sp = (LongProperty) p; LongProperty sp = (LongProperty) p;
property.isLong = true; property.isLong = true;
@ -1068,7 +1068,7 @@ public class DefaultCodegen {
property.allowableValues = allowableValues; property.allowableValues = allowableValues;
} }
} }
if (p instanceof BooleanProperty) { if (p instanceof BooleanProperty) {
property.isBoolean = true; property.isBoolean = true;
} }
@ -1098,7 +1098,7 @@ public class DefaultCodegen {
property.allowableValues = allowableValues; property.allowableValues = allowableValues;
} }
} }
if (p instanceof FloatProperty) { if (p instanceof FloatProperty) {
FloatProperty sp = (FloatProperty) p; FloatProperty sp = (FloatProperty) p;
property.isFloat = true; property.isFloat = true;
@ -1116,7 +1116,7 @@ public class DefaultCodegen {
property.allowableValues = allowableValues; property.allowableValues = allowableValues;
} }
} }
if (p instanceof DateProperty) { if (p instanceof DateProperty) {
DateProperty sp = (DateProperty) p; DateProperty sp = (DateProperty) p;
property.isDate = true; property.isDate = true;
@ -1134,7 +1134,7 @@ public class DefaultCodegen {
property.allowableValues = allowableValues; property.allowableValues = allowableValues;
} }
} }
if (p instanceof DateTimeProperty) { if (p instanceof DateTimeProperty) {
DateTimeProperty sp = (DateTimeProperty) p; DateTimeProperty sp = (DateTimeProperty) p;
property.isDateTime = true; property.isDateTime = true;
@ -1229,7 +1229,7 @@ public class DefaultCodegen {
} }
return responses.get(code); return responses.get(code);
} }
/** /**
* Convert Swagger Operation object to Codegen Operation object (without providing a Swagger object) * 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) { public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
return fromOperation(path, httpMethod, operation, definitions, null); return fromOperation(path, httpMethod, operation, definitions, null);
} }
/** /**
* Convert Swagger Operation object to Codegen Operation object * Convert Swagger Operation object to Codegen Operation object
* *
@ -1277,11 +1277,11 @@ public class DefaultCodegen {
// empty list, do nothing to override global setting // empty list, do nothing to override global setting
} }
} else if (swagger != null && swagger.getConsumes() != null && swagger.getConsumes().size() > 0) { } else if (swagger != null && swagger.getConsumes() != null && swagger.getConsumes().size() > 0) {
// use consumes defined globally // use consumes defined globally
consumes = swagger.getConsumes(); consumes = swagger.getConsumes();
LOGGER.debug("No consumes defined in operation. Using global consumes (" + swagger.getConsumes() + ") for " + op.operationId); 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" is defined (per operation or using global definition)
if (consumes != null && consumes.size() > 0) { if (consumes != null && consumes.size() > 0) {
List<Map<String, String>> c = new ArrayList<Map<String, String>>(); 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 // empty list, do nothing to override global setting
} }
} else if (swagger != null && swagger.getProduces() != null && swagger.getProduces().size() > 0) { } else if (swagger != null && swagger.getProduces() != null && swagger.getProduces().size() > 0) {
// use produces defined globally // use produces defined globally
produces = swagger.getProduces(); produces = swagger.getProduces();
LOGGER.debug("No produces defined in operation. Using global produces (" + swagger.getProduces() + ") for " + op.operationId); 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" is defined (per operation or using global definition)
if (produces != null && produces.size() > 0) { if (produces != null && produces.size() > 0) {
List<Map<String, String>> c = new ArrayList<Map<String, String>>(); List<Map<String, String>> c = new ArrayList<Map<String, String>>();
@ -1556,7 +1556,7 @@ public class DefaultCodegen {
} }
return r; return r;
} }
/** /**
* Convert Swagger Parameter object to Codegen Parameter object * Convert Swagger Parameter object to Codegen Parameter object
* *
@ -1658,7 +1658,7 @@ public class DefaultCodegen {
p.maxLength = qp.getMaxLength(); p.maxLength = qp.getMaxLength();
p.minLength = qp.getMinLength(); p.minLength = qp.getMinLength();
p.pattern = qp.getPattern(); p.pattern = qp.getPattern();
p.maximum = qp.getMaximum(); p.maximum = qp.getMaximum();
p.exclusiveMaximum = qp.isExclusiveMaximum(); p.exclusiveMaximum = qp.isExclusiveMaximum();
p.minimum = qp.getMinimum(); p.minimum = qp.getMinimum();
@ -1783,14 +1783,14 @@ public class DefaultCodegen {
Map<String, Object> scope = new HashMap<String, Object>(); Map<String, Object> scope = new HashMap<String, Object>();
scope.put("scope", scopeEntry.getKey()); scope.put("scope", scopeEntry.getKey());
scope.put("description", scopeEntry.getValue()); scope.put("description", scopeEntry.getValue());
count += 1; count += 1;
if (count < numScopes) { if (count < numScopes) {
scope.put("hasMore", "true"); scope.put("hasMore", "true");
} else { } else {
scope.put("hasMore", null); scope.put("hasMore", null);
} }
scopes.add(scope); scopes.add(scope);
} }
sec.scopes = scopes; sec.scopes = scopes;
@ -1803,6 +1803,17 @@ public class DefaultCodegen {
return secs; 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. * 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.vars.add(cp);
} }
} }
m.mandatory = mandatory; m.mandatory = mandatory;
} else { } else {
m.emptyVars = true; m.emptyVars = true;
m.hasVars = false; m.hasVars = false;
@ -2077,7 +2088,7 @@ public class DefaultCodegen {
} }
return name; return name;
} }
/** /**
* Camelize name (parameter, property, method, etc) with upper case for first letter * Camelize name (parameter, property, method, etc) with upper case for first letter
* copied from Twitter elephant bird * 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 // 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 // encountered so far and hopefully make it easier for others to add more special
// cases in the future. // cases in the future.
// better error handling when map/array type is invalid // better error handling when map/array type is invalid
if (name == null) { if (name == null) {
LOGGER.error("String to be sanitized is null. Default to ERROR_UNKNOWN"); LOGGER.error("String to be sanitized is null. Default to ERROR_UNKNOWN");

View File

@ -44,7 +44,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
Arrays.asList("IDictionary") Arrays.asList("IDictionary")
); );
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
// local variable names in API methods (endpoints) // local variable names in API methods (endpoints)
"path_", "pathParams", "queryParams", "headerParams", "formParams", "fileParams", "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 // 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))); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId)));
operationId = "call_" + operationId; operationId = "call_" + operationId;
} }
@ -305,7 +305,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
name = camelize(name); name = camelize(name);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
} }
@ -330,7 +330,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
name = camelize(name, true); name = camelize(name, true);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
} }
@ -471,7 +471,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
name = sanitizeName(name); name = sanitizeName(name);
// model name cannot use reserved keyword, e.g. return // model name cannot use reserved keyword, e.g. return
if (reservedWords.contains(name)) { if (isReservedWord(name)) {
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + 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) name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
} }

View File

@ -15,10 +15,10 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
public AbstractTypeScriptClientCodegen() { public AbstractTypeScriptClientCodegen() {
super(); super();
supportsInheritance = true; supportsInheritance = true;
reservedWords = new HashSet<String>(Arrays.asList( setReservedWordsLowerCase(Arrays.asList(
// local variable names used in API methods (endpoints) // local variable names used in API methods (endpoints)
"path", "queryParameters", "headerParams", "formParams", "useFormData", "deferred", "path", "queryParameters", "headerParams", "formParams", "useFormData", "deferred",
"requestOptions", "requestOptions",
// Typescript reserved words // 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")); "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", "Float",
"Object")); "Object"));
instantiationTypes.put("array", "Array"); instantiationTypes.put("array", "Array");
typeMapping = new HashMap<String, String>(); typeMapping = new HashMap<String, String>();
typeMapping.put("Array", "Array"); typeMapping.put("Array", "Array");
typeMapping.put("array", "Array"); typeMapping.put("array", "Array");
@ -67,7 +67,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
} }
} }
@Override @Override
public CodegenType getTag() { public CodegenType getTag() {
return CodegenType.CLIENT; return CodegenType.CLIENT;
@ -102,7 +102,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
name = camelize(name, true); name = camelize(name, true);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
return name; return name;
@ -117,7 +117,7 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
@Override @Override
public String toModelName(String name) { public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return // model name cannot use reserved keyword, e.g. return
if (reservedWords.contains(name)) if (isReservedWord(name))
throw new RuntimeException(name throw new RuntimeException(name
+ " (reserved word) cannot be used as a model 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 // method name cannot use reserved keyword, e.g. return
// append _ at the beginning, e.g. _return // append _ at the beginning, e.g. _return
if (reservedWords.contains(operationId)) { if (isReservedWord(operationId)) {
return escapeReservedWord(camelize(sanitizeName(operationId), true)); return escapeReservedWord(camelize(sanitizeName(operationId), true));
} }
@ -178,12 +178,12 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
} }
public void setModelPropertyNaming(String naming) { 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)) { "PascalCase".equals(naming) || "snake_case".equals(naming)) {
this.modelPropertyNaming = naming; this.modelPropertyNaming = naming;
} else { } else {
throw new IllegalArgumentException("Invalid model property naming '" + throw new IllegalArgumentException("Invalid model property naming '" +
naming + "'. Must be 'original', 'camelCase', " + naming + "'. Must be 'original', 'camelCase', " +
"'PascalCase' or 'snake_case'"); "'PascalCase' or 'snake_case'");
} }
} }
@ -198,9 +198,9 @@ public abstract class AbstractTypeScriptClientCodegen extends DefaultCodegen imp
case camelCase: return camelize(name, true); case camelCase: return camelize(name, true);
case PascalCase: return camelize(name); case PascalCase: return camelize(name);
case snake_case: return underscore(name); case snake_case: return underscore(name);
default: throw new IllegalArgumentException("Invalid model property naming '" + default: throw new IllegalArgumentException("Invalid model property naming '" +
name + "'. Must be 'original', 'camelCase', " + name + "'. Must be 'original', 'camelCase', " +
"'PascalCase' or 'snake_case'"); "'PascalCase' or 'snake_case'");
} }
} }

View File

@ -63,7 +63,7 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
* unmarshalling problems and any other RuntimeException will be considered as ApiErrors. * unmarshalling problems and any other RuntimeException will be considered as ApiErrors.
*/ */
protected boolean onlyOneSuccess = true; protected boolean onlyOneSuccess = true;
@SuppressWarnings("hiding") @SuppressWarnings("hiding")
protected Logger LOGGER = LoggerFactory.getLogger(AkkaScalaClientCodegen.class); protected Logger LOGGER = LoggerFactory.getLogger(AkkaScalaClientCodegen.class);
@ -76,7 +76,7 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
apiPackage = mainPackage + ".api"; apiPackage = mainPackage + ".api";
modelPackage = mainPackage + ".model"; modelPackage = mainPackage + ".model";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"abstract", "case", "catch", "class", "def", "do", "else", "extends", "abstract", "case", "catch", "class", "def", "do", "else", "extends",
"false", "final", "finally", "for", "forSome", "if", "implicit", "false", "final", "finally", "for", "forSome", "if", "implicit",
@ -276,7 +276,7 @@ public class AkkaScalaClientCodegen extends DefaultCodegen implements CodegenCon
if (capitalized) { if (capitalized) {
identifier = StringUtils.capitalize(identifier); 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 identifier;
} }
return escapeReservedWord(identifier); return escapeReservedWord(identifier);

View File

@ -15,8 +15,11 @@ import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfig { public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(AndroidClientCodegen.class);
public static final String USE_ANDROID_MAVEN_GRADLE_PLUGIN = "useAndroidMavenGradlePlugin"; public static final String USE_ANDROID_MAVEN_GRADLE_PLUGIN = "useAndroidMavenGradlePlugin";
protected String invokerPackage = "io.swagger.client"; protected String invokerPackage = "io.swagger.client";
protected String groupId = "io.swagger"; protected String groupId = "io.swagger";
@ -39,7 +42,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
apiPackage = "io.swagger.client.api"; apiPackage = "io.swagger.client.api";
modelPackage = "io.swagger.client.model"; modelPackage = "io.swagger.client.model";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
// local variable names used in API methods (endpoints) // local variable names used in API methods (endpoints)
"postBody", "path", "queryParams", "headerParams", "formParams", "postBody", "path", "queryParams", "headerParams", "formParams",
@ -162,7 +165,7 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
name = camelize(name, true); name = camelize(name, true);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
} }
@ -177,14 +180,18 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
@Override @Override
public String toModelName(String name) { public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return
if (reservedWords.contains(name)) {
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
}
// camelize the model name // camelize the model name
// phone_number => PhoneNumber // phone_number => PhoneNumber
return camelize(name); name = camelize(sanitizeName(name));
// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name)) {
String modelName = "Object" + name;
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
return modelName;
}
return name;
} }
@Override @Override
@ -200,12 +207,16 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi
throw new RuntimeException("Empty method name (operationId) not allowed"); throw new RuntimeException("Empty method name (operationId) not allowed");
} }
operationId = camelize(sanitizeName(operationId), true);
// method name cannot use reserved keyword, e.g. return // 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"); String newOperationId = camelize("call_" + operationId, true);
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
return newOperationId;
} }
return camelize(operationId, true); return operationId;
} }
@Override @Override

View File

@ -23,11 +23,9 @@ public class AspNet5ServerCodegen extends AbstractCSharpCodegen {
apiTemplateFiles.put("controller.mustache", ".cs"); apiTemplateFiles.put("controller.mustache", ".cs");
// contextually reserved words // contextually reserved words
reservedWords.add("var"); setReservedWordsLowerCase(
reservedWords.add("async"); Arrays.asList("var", "async", "await", "dynamic", "yield")
reservedWords.add("await"); );
reservedWords.add("dynamic");
reservedWords.add("yield");
cliOptions.clear(); cliOptions.clear();

View File

@ -43,7 +43,7 @@ public class AsyncScalaClientCodegen extends DefaultCodegen implements CodegenCo
apiPackage = "io.swagger.client.api"; apiPackage = "io.swagger.client.api";
modelPackage = "io.swagger.client.model"; modelPackage = "io.swagger.client.model";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
// local variable names used in API methods (endpoints) // local variable names used in API methods (endpoints)
"config", "path", "contentTypes", "contentType", "queryParams", "headerParams", "config", "path", "contentTypes", "contentType", "queryParams", "headerParams",

View File

@ -31,12 +31,12 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
apiPackage = "IO.Swagger.Api"; apiPackage = "IO.Swagger.Api";
modelPackage = "IO.Swagger.Model"; modelPackage = "IO.Swagger.Model";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
// local variable names in API methods (endpoints) // local variable names in API methods (endpoints)
"path", "queryParams", "headerParams", "formParams", "fileParams", "postBody", "path", "queryParams", "headerParams", "formParams", "fileParams", "postBody",
"authSettings", "response", "StatusCode", "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") "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 { } else {
additionalProperties.put(CLIENT_PACKAGE, clientPackage); additionalProperties.put(CLIENT_PACKAGE, clientPackage);
} }
supportingFiles.add(new SupportingFile("Configuration.mustache", supportingFiles.add(new SupportingFile("Configuration.mustache",
sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "Configuration.cs")); sourceFolder + File.separator + clientPackage.replace(".", java.io.File.separator), "Configuration.cs"));
supportingFiles.add(new SupportingFile("ApiClient.mustache", supportingFiles.add(new SupportingFile("ApiClient.mustache",
@ -184,7 +184,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
name = camelize(name); name = camelize(name);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
} }
@ -206,7 +206,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
name = camelize(name, true); name = camelize(name, true);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
} }
@ -218,7 +218,7 @@ public class CsharpDotNet2ClientCodegen extends DefaultCodegen implements Codege
name = sanitizeName(name); name = sanitizeName(name);
// model name cannot use reserved keyword, e.g. return // 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"); 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 @Override
public String toOperationId(String operationId) { public String toOperationId(String operationId) {
// method name cannot use reserved keyword, e.g. return // 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"); throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
} }

View File

@ -35,7 +35,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
apiPackage = "lib.api"; apiPackage = "lib.api";
modelPackage = "lib.model"; modelPackage = "lib.model";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"abstract", "as", "assert", "async", "async*", "await", "abstract", "as", "assert", "async", "async*", "await",
"break", "case", "catch", "class", "const", "continue", "break", "case", "catch", "class", "const", "continue",
@ -183,7 +183,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
name = camelize(name, true); name = camelize(name, true);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
} }
@ -199,7 +199,7 @@ public class DartClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override @Override
public String toModelName(String name) { public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return // 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"); 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 @Override
public String toOperationId(String operationId) { public String toOperationId(String operationId) {
// method name cannot use reserved keyword, e.g. return // 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"); throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
} }

View File

@ -70,8 +70,8 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
importMapping = new HashMap<String, String>(); importMapping = new HashMap<String, String>();
importMapping.put("File", "flash.filesystem.File"); importMapping.put("File", "flash.filesystem.File");
// from // from
reservedWords = new HashSet<String>(Arrays.asList("add", "for", "lt", "tellTarget", "and", setReservedWordsLowerCase(Arrays.asList("add", "for", "lt", "tellTarget", "and",
"function", "ne", "this", "break", "ge", "new", "typeof", "continue", "gt", "not", "function", "ne", "this", "break", "ge", "new", "typeof", "continue", "gt", "not",
"var", "delete", "if", "on", "void", "do", "ifFrameLoaded", "onClipEvent", "while", "var", "delete", "if", "on", "void", "do", "ifFrameLoaded", "onClipEvent", "while",
"else", "in", "or", "with", "eq", "le", "return")); "else", "in", "or", "with", "eq", "le", "return"));
@ -261,7 +261,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
public String toVarName(String name) { public String toVarName(String name) {
// replace - with _ e.g. created-at => created_at // 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'. 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 it's all uppper case, convert to lower case
if (name.matches("^[A-Z_]*$")) { if (name.matches("^[A-Z_]*$")) {
name = name.toLowerCase(); name = name.toLowerCase();
@ -272,7 +272,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
name = camelize(dropDots(name), true); name = camelize(dropDots(name), true);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
} }
@ -288,7 +288,7 @@ public class FlashClientCodegen extends DefaultCodegen implements CodegenConfig
@Override @Override
public String toModelName(String name) { public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return // 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"); 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 @Override
public String toModelFilename(String name) { public String toModelFilename(String name) {
// model name cannot use reserved keyword, e.g. return // 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"); 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 // 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"); throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
} }

View File

@ -20,7 +20,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConfig { public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(FlaskConnexionCodegen.class); private static final Logger LOGGER = LoggerFactory.getLogger(FlaskConnexionCodegen.class);
public static final String CONTROLLER_PACKAGE = "controllerPackage"; public static final String CONTROLLER_PACKAGE = "controllerPackage";
@ -73,7 +73,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
embeddedTemplateDir = templateDir = "flaskConnexion"; embeddedTemplateDir = templateDir = "flaskConnexion";
// from https://docs.python.org/release/2.5.4/ref/keywords.html // from https://docs.python.org/release/2.5.4/ref/keywords.html
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"and", "del", "from", "not", "while", "as", "elif", "global", "or", "with", "and", "del", "from", "not", "while", "as", "elif", "global", "or", "with",
"assert", "else", "if", "pass", "yield", "break", "except", "import", "assert", "else", "if", "pass", "yield", "break", "except", "import",

View File

@ -38,7 +38,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
apiTemplateFiles.put("api.mustache", ".go"); apiTemplateFiles.put("api.mustache", ".go");
templateDir = "go"; templateDir = "go";
reservedWords = new HashSet<String> ( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"break", "default", "func", "interface", "select", "break", "default", "func", "interface", "select",
"case", "defer", "go", "map", "struct", "case", "defer", "go", "map", "struct",
@ -100,7 +100,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
.defaultValue("swagger")); .defaultValue("swagger"));
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Go package version.") cliOptions.add(new CliOption(CodegenConstants.PACKAGE_VERSION, "Go package version.")
.defaultValue("1.0.0")); .defaultValue("1.0.0"));
} }
@Override @Override
@ -128,7 +128,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
apiPackage = packageName; apiPackage = packageName;
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
} }
@Override @Override
public String escapeReservedWord(String name) { public String escapeReservedWord(String name) {
@ -158,7 +158,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
name = camelize(name); name = camelize(name);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
return name; return name;
@ -173,7 +173,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override @Override
public String toModelName(String name) { public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return // 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"); throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
// camelize the model name // camelize the model name
@ -220,7 +220,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override @Override
public String toOperationId(String operationId) { public String toOperationId(String operationId) {
// method name cannot use reserved keyword, e.g. return // 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"); throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
return camelize(operationId); return camelize(operationId);

View File

@ -17,7 +17,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
/** /**
* Configures the type of generator. * Configures the type of generator.
* *
* @return the CodegenType for this generator * @return the CodegenType for this generator
* @see io.swagger.codegen.CodegenType * @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 * Configures a friendly name for the generator. This will be used by the generator
* to select the library with the -l flag. * to select the library with the -l flag.
* *
* @return the friendly name for the generator * @return the friendly name for the generator
*/ */
public String getName() { 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 * Returns human-friendly help for the generator. Provide the consumer with help
* tips, parameters here * tips, parameters here
* *
* @return A string value for the help message * @return A string value for the help message
*/ */
public String getHelp() { 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 * Reserved words. Override this with reserved words specific to your language
*/ */
// from https://wiki.haskell.org/Keywords // from https://wiki.haskell.org/Keywords
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"as", "case", "of", "as", "case", "of",
"class", "data", // "data family", "data instance", "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 * 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 * those terms here. This logic is only called if a variable matches the reseved words
* *
* @return the escaped term * @return the escaped term
*/ */
@Override @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. * 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 * @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) { private String capturePath(String path, List<CodegenParameter> pathParams) {
for (CodegenParameter p : pathParams) { for (CodegenParameter p : pathParams) {
String pName = "{"+p.baseName+"}"; String pName = "{"+p.baseName+"}";
if (path.indexOf(pName) >= 0) { if (path.indexOf(pName) >= 0) {
path = path.replace(pName, "Capture " + "\""+p.baseName+"\" " + p.dataType); path = path.replace(pName, "Capture " + "\""+p.baseName+"\" " + p.dataType);
} }
} }
@ -270,7 +270,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
for (CodegenParameter p : formParams) { for (CodegenParameter p : formParams) {
if(p.dataType.equals("FilePath")){ if(p.dataType.equals("FilePath")){
// file data processing // file data processing
} }
names += p.baseName; names += p.baseName;
} }
if(formParams.size() > 0){ if(formParams.size() > 0){
@ -315,7 +315,7 @@ public class HaskellServantCodegen extends DefaultCodegen implements CodegenConf
String[] ps = path.replaceFirst("/", "").split("/", 0); String[] ps = path.replaceFirst("/", "").split("/", 0);
List<String> rs = new ArrayList<String>(); List<String> rs = new ArrayList<String>();
for (String p : ps) { for (String p : ps) {
if (p.indexOf("{") < 0) { if (p.indexOf("{") < 0) {
rs.add("\"" + p + "\""); rs.add("\"" + p + "\"");
} else { } else {
rs.add(p); rs.add(p);

View File

@ -52,20 +52,20 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
apiPackage = "io.swagger.client.api"; apiPackage = "io.swagger.client.api";
modelPackage = "io.swagger.client.model"; modelPackage = "io.swagger.client.model";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
// used as internal variables, can collide with parameter names // used as internal variables, can collide with parameter names
"path", "queryParams", "headerParams", "formParams", "postBody", "accepts", "accept", "contentTypes", "path", "queryParams", "headerParams", "formParams", "postBody", "accepts", "accept", "contentTypes",
"contentType", "authNames", "contentType", "authNames",
// language reserved words // language reserved words
"abstract", "continue", "for", "new", "switch", "assert", "abstract", "continue", "for", "new", "switch", "assert",
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private", "default", "if", "package", "synchronized", "boolean", "do", "goto", "private",
"this", "break", "double", "implements", "protected", "throw", "byte", "else", "this", "break", "double", "implements", "protected", "throw", "byte", "else",
"import", "public", "throws", "case", "enum", "instanceof", "return", "transient", "import", "public", "throws", "case", "enum", "instanceof", "return", "transient",
"catch", "extends", "int", "short", "try", "char", "final", "interface", "static", "catch", "extends", "int", "short", "try", "char", "final", "interface", "static",
"void", "class", "finally", "long", "strictfp", "volatile", "const", "float", "void", "class", "finally", "long", "strictfp", "volatile", "const", "float",
"native", "super", "while") "native", "super", "while")
); );
languageSpecificPrimitives = new HashSet<String>( languageSpecificPrimitives = new HashSet<String>(
@ -362,7 +362,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
name = camelize(name, true); name = camelize(name, true);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
} }
@ -379,14 +379,18 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
public String toModelName(String name) { public String toModelName(String name) {
name = sanitizeName(name); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'. 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)) {
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
}
// camelize the model name // camelize the model name
// phone_number => PhoneNumber // phone_number => PhoneNumber
return camelize(name); name = camelize(name);
// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name)) {
String modelName = "Object" + name;
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
return modelName;
}
return name;
} }
@Override @Override
@ -501,12 +505,16 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
throw new RuntimeException("Empty method/operation name (operationId) not allowed"); throw new RuntimeException("Empty method/operation name (operationId) not allowed");
} }
operationId = camelize(sanitizeName(operationId), true);
// method name cannot use reserved keyword, e.g. return // 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"); String newOperationId = camelize("call_" + operationId, true);
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
return newOperationId;
} }
return camelize(sanitizeName(operationId), true); return operationId;
} }
@Override @Override

View File

@ -75,7 +75,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
modelPackage = "model"; modelPackage = "model";
// reference: http://www.w3schools.com/js/js_reserved.asp // reference: http://www.w3schools.com/js/js_reserved.asp
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"abstract", "arguments", "boolean", "break", "byte", "abstract", "arguments", "boolean", "break", "byte",
"case", "catch", "char", "class", "const", "case", "catch", "char", "class", "const",
@ -276,7 +276,7 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
name = camelize(name, true); name = camelize(name, true);
// for reserved word or word starting with number, append _ // 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); 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" name = sanitizeName(name); // FIXME parameter should not be assigned. Also declare it as "final"
// model name cannot use reserved keyword, e.g. return // 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"); 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 // method name cannot use reserved keyword, e.g. return
if (reservedWords.contains(operationId)) { if (isReservedWord(operationId)) {
operationId = escapeReservedWord(operationId); operationId = escapeReservedWord(operationId);
} }

View File

@ -13,7 +13,7 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
super(); super();
supportsInheritance = false; supportsInheritance = false;
reservedWords = new HashSet<String>(Arrays.asList("abstract", setReservedWordsLowerCase(Arrays.asList("abstract",
"continue", "for", "new", "switch", "assert", "default", "if", "continue", "for", "new", "switch", "assert", "default", "if",
"package", "synchronized", "do", "goto", "private", "package", "synchronized", "do", "goto", "private",
"this", "break", "double", "implements", "protected", "throw", "this", "break", "double", "implements", "protected", "throw",
@ -114,7 +114,7 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
name = camelize(name, true); name = camelize(name, true);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
return name; return name;
@ -129,7 +129,7 @@ public class JavascriptClosureAngularClientCodegen extends DefaultCodegen implem
@Override @Override
public String toModelName(String name) { public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return // model name cannot use reserved keyword, e.g. return
if (reservedWords.contains(name)) if (isReservedWord(name))
throw new RuntimeException(name throw new RuntimeException(name
+ " (reserved word) cannot be used as a model name"); + " (reserved word) cannot be used as a model name");

View File

@ -21,7 +21,7 @@ import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig { public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSServerCodegen.class); private static final Logger LOGGER = LoggerFactory.getLogger(NodeJSServerCodegen.class);
protected String apiVersion = "1.0.0"; 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 * Reserved words. Override this with reserved words specific to your language
*/ */
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"break", "case", "class", "catch", "const", "continue", "debugger", "break", "case", "class", "catch", "const", "continue", "debugger",
"default", "delete", "do", "else", "export", "extends", "finally", "default", "delete", "do", "else", "export", "extends", "finally",
@ -251,7 +251,7 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
} }
} }
this.additionalProperties.put("serverPort", port); this.additionalProperties.put("serverPort", port);
if (swagger.getInfo() != null) { if (swagger.getInfo() != null) {
Info info = swagger.getInfo(); Info info = swagger.getInfo();
if (info.getTitle() != null) { if (info.getTitle() != null) {

View File

@ -39,7 +39,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
public ObjcClientCodegen() { public ObjcClientCodegen() {
super(); super();
outputFolder = "generated-code" + File.separator + "objc"; outputFolder = "generated-code" + File.separator + "objc";
modelTemplateFiles.put("model-header.mustache", ".h"); modelTemplateFiles.put("model-header.mustache", ".h");
modelTemplateFiles.put("model-body.mustache", ".m"); modelTemplateFiles.put("model-body.mustache", ".m");
@ -60,7 +60,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
defaultIncludes.add("NSDictionary"); defaultIncludes.add("NSDictionary");
defaultIncludes.add("NSMutableArray"); defaultIncludes.add("NSMutableArray");
defaultIncludes.add("NSMutableDictionary"); defaultIncludes.add("NSMutableDictionary");
languageSpecificPrimitives.clear(); languageSpecificPrimitives.clear();
languageSpecificPrimitives.add("NSNumber"); languageSpecificPrimitives.add("NSNumber");
languageSpecificPrimitives.add("NSString"); 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 // ref: http://www.tutorialspoint.com/objective_c/objective_c_basic_syntax.htm
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
// local variable names in API methods (endpoints) // local variable names in API methods (endpoints)
"resourcePath", "pathParams", "queryParams", "headerParams", "resourcePath", "pathParams", "queryParams", "headerParams",
"responseContentType", "requestContentType", "authSettings", "responseContentType", "requestContentType", "authSettings",
@ -174,19 +174,19 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
if (additionalProperties.containsKey(CLASS_PREFIX)) { if (additionalProperties.containsKey(CLASS_PREFIX)) {
setClassPrefix((String) additionalProperties.get(CLASS_PREFIX)); setClassPrefix((String) additionalProperties.get(CLASS_PREFIX));
} }
if (additionalProperties.containsKey(AUTHOR_NAME)) { if (additionalProperties.containsKey(AUTHOR_NAME)) {
setAuthorName((String) additionalProperties.get(AUTHOR_NAME)); setAuthorName((String) additionalProperties.get(AUTHOR_NAME));
} }
if (additionalProperties.containsKey(AUTHOR_EMAIL)) { if (additionalProperties.containsKey(AUTHOR_EMAIL)) {
setAuthorEmail((String) additionalProperties.get(AUTHOR_EMAIL)); setAuthorEmail((String) additionalProperties.get(AUTHOR_EMAIL));
} }
if (additionalProperties.containsKey(GIT_REPO_URL)) { if (additionalProperties.containsKey(GIT_REPO_URL)) {
setGitRepoURL((String) additionalProperties.get(GIT_REPO_URL)); setGitRepoURL((String) additionalProperties.get(GIT_REPO_URL));
} }
if (additionalProperties.containsKey(LICENSE)) { if (additionalProperties.containsKey(LICENSE)) {
setLicense((String) additionalProperties.get(LICENSE)); setLicense((String) additionalProperties.get(LICENSE));
} }
@ -409,7 +409,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
name = camelize(name, true); name = camelize(name, true);
// for reserved word or word starting with number, prepend `_` // 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); name = escapeReservedWord(name);
} }
@ -441,7 +441,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
} }
// method name cannot use reserved keyword, e.g. return // 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)); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true));
operationId = "call_" + operationId; operationId = "call_" + operationId;
} }
@ -460,19 +460,19 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
public void setPodVersion(String podVersion) { public void setPodVersion(String podVersion) {
this.podVersion = podVersion; this.podVersion = podVersion;
} }
public void setAuthorEmail(String authorEmail) { public void setAuthorEmail(String authorEmail) {
this.authorEmail = authorEmail; this.authorEmail = authorEmail;
} }
public void setAuthorName(String authorName) { public void setAuthorName(String authorName) {
this.authorName = authorName; this.authorName = authorName;
} }
public void setGitRepoURL(String gitRepoURL) { public void setGitRepoURL(String gitRepoURL) {
this.gitRepoURL = gitRepoURL; this.gitRepoURL = gitRepoURL;
} }
public void setLicense(String license) { public void setLicense(String license) {
this.license = license; this.license = license;
} }

View File

@ -37,7 +37,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
embeddedTemplateDir = templateDir = "perl"; embeddedTemplateDir = templateDir = "perl";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"else", "lock", "qw", "else", "lock", "qw",
"__END__", "elsif", "lt", "qx", "__END__", "elsif", "lt", "qx",
@ -219,7 +219,7 @@ public class PerlClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override @Override
public String toModelName(String name) { public String toModelName(String name) {
// model name cannot use reserved keyword // model name cannot use reserved keyword
if (reservedWords.contains(name)) { if (isReservedWord(name)) {
escapeReservedWord(name); // e.g. return => _return 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 // 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)); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore("call_" + operationId));
return underscore("call_" + operationId); return underscore("call_" + operationId);
} }

View File

@ -49,7 +49,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
modelPackage = invokerPackage + "\\Model"; modelPackage = invokerPackage + "\\Model";
testPackage = invokerPackage + "\\Tests"; testPackage = invokerPackage + "\\Tests";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
// local variables used in api methods (endpoints) // local variables used in api methods (endpoints)
"resourcePath", "method", "httpBody", "queryParams", "headerParams", "resourcePath", "method", "httpBody", "queryParams", "headerParams",
@ -178,13 +178,13 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
} else { } else {
additionalProperties.put(SRC_BASE_PATH, srcBasePath); additionalProperties.put(SRC_BASE_PATH, srcBasePath);
} }
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) { if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE)); this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
} else { } else {
additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage); additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
} }
if (!additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) { if (!additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE)) {
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage); additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
} }
@ -192,19 +192,19 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
if (!additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) { if (!additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage); additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
} }
if (additionalProperties.containsKey(COMPOSER_PROJECT_NAME)) { if (additionalProperties.containsKey(COMPOSER_PROJECT_NAME)) {
this.setComposerProjectName((String) additionalProperties.get(COMPOSER_PROJECT_NAME)); this.setComposerProjectName((String) additionalProperties.get(COMPOSER_PROJECT_NAME));
} else { } else {
additionalProperties.put(COMPOSER_PROJECT_NAME, composerProjectName); additionalProperties.put(COMPOSER_PROJECT_NAME, composerProjectName);
} }
if (additionalProperties.containsKey(COMPOSER_VENDOR_NAME)) { if (additionalProperties.containsKey(COMPOSER_VENDOR_NAME)) {
this.setComposerVendorName((String) additionalProperties.get(COMPOSER_VENDOR_NAME)); this.setComposerVendorName((String) additionalProperties.get(COMPOSER_VENDOR_NAME));
} else { } else {
additionalProperties.put(COMPOSER_VENDOR_NAME, composerVendorName); additionalProperties.put(COMPOSER_VENDOR_NAME, composerVendorName);
} }
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) { if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) {
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION)); this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
} else { } else {
@ -214,7 +214,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
if (additionalProperties.containsKey(VARIABLE_NAMING_CONVENTION)) { if (additionalProperties.containsKey(VARIABLE_NAMING_CONVENTION)) {
this.setParameterNamingConvention((String) additionalProperties.get(VARIABLE_NAMING_CONVENTION)); this.setParameterNamingConvention((String) additionalProperties.get(VARIABLE_NAMING_CONVENTION));
} }
additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\")); additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
supportingFiles.add(new SupportingFile("configuration.mustache", toPackagePath(invokerPackage, srcBasePath), "Configuration.php")); 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) { public void setInvokerPackage(String invokerPackage) {
this.invokerPackage = invokerPackage; this.invokerPackage = invokerPackage;
} }
public void setArtifactVersion(String artifactVersion) { public void setArtifactVersion(String artifactVersion) {
this.artifactVersion = artifactVersion; this.artifactVersion = artifactVersion;
} }
@ -313,7 +313,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
public void setSrcBasePath(String srcBasePath) { public void setSrcBasePath(String srcBasePath) {
this.srcBasePath = srcBasePath; this.srcBasePath = srcBasePath;
} }
public void setParameterNamingConvention(String variableNamingConvention) { public void setParameterNamingConvention(String variableNamingConvention) {
this.variableNamingConvention = variableNamingConvention; this.variableNamingConvention = variableNamingConvention;
} }
@ -321,7 +321,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
public void setComposerVendorName(String composerVendorName) { public void setComposerVendorName(String composerVendorName) {
this.composerVendorName = composerVendorName; this.composerVendorName = composerVendorName;
} }
public void setComposerProjectName(String composerProjectName) { public void setComposerProjectName(String composerProjectName) {
this.composerProjectName = composerProjectName; this.composerProjectName = composerProjectName;
} }
@ -365,7 +365,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
name = name.replaceAll("$", ""); name = name.replaceAll("$", "");
// model name cannot use reserved keyword // 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)); 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) 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 // 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)); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true));
operationId = "call_" + operationId; operationId = "call_" + operationId;
} }

View File

@ -56,7 +56,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
typeMapping.put("binary", "str"); typeMapping.put("binary", "str");
// from https://docs.python.org/release/2.5.4/ref/keywords.html // from https://docs.python.org/release/2.5.4/ref/keywords.html
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
// local variable name used in API methods (endpoints) // local variable name used in API methods (endpoints)
"all_params", "resource_path", "method", "path_params", "query_params", "all_params", "resource_path", "method", "path_params", "query_params",
@ -197,7 +197,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
name = name.replaceAll("^_*", ""); name = name.replaceAll("^_*", "");
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
} }
@ -218,7 +218,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
name = name.replaceAll("$", ""); name = name.replaceAll("$", "");
// model name cannot use reserved keyword, e.g. return // model name cannot use reserved keyword, e.g. return
if (reservedWords.contains(name)) { if (isReservedWord(name)) {
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + 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) name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
} }
@ -231,7 +231,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
@Override @Override
public String toModelFilename(String name) { public String toModelFilename(String name) {
// model name cannot use reserved keyword, e.g. return // model name cannot use reserved keyword, e.g. return
if (reservedWords.contains(name)) { if (isReservedWord(name)) {
LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + underscore(dropDots("object_" + name))); LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + underscore(dropDots("object_" + name)));
name = "object_" + name; // e.g. return => ObjectReturn (after camelize) name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
} }
@ -275,7 +275,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
} }
// method name cannot use reserved keyword, e.g. return // 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(sanitizeName("call_" + operationId))); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
operationId = "call_" + operationId; operationId = "call_" + operationId;
} }

View File

@ -76,7 +76,7 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
/** /**
* Reserved words. Override this with reserved words specific to your language * Reserved words. Override this with reserved words specific to your language
*/ */
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"sample1", // replace with static values "sample1", // replace with static values
"sample2") "sample2")

View File

@ -14,8 +14,11 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(RubyClientCodegen.class);
public static final String GEM_NAME = "gemName"; public static final String GEM_NAME = "gemName";
public static final String MODULE_NAME = "moduleName"; public static final String MODULE_NAME = "moduleName";
public static final String GEM_VERSION = "gemVersion"; public static final String GEM_VERSION = "gemVersion";
@ -55,7 +58,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.clear(); typeMapping.clear();
languageSpecificPrimitives.clear(); languageSpecificPrimitives.clear();
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
// local variable names used in API methods (endpoints) // local variable names used in API methods (endpoints)
"path", "query_params", "header_params", "_header_accept", "_header_accept_result", "path", "query_params", "header_params", "_header_accept", "_header_accept_result",
@ -341,7 +344,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
name = underscore(name); name = underscore(name);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
} }
@ -359,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'. 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 // model name cannot use reserved keyword, e.g. return
if (reservedWords.contains(name)) { if (isReservedWord(name)) {
String modelName = camelize("object_" + name); String modelName = camelize("object_" + name);
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName); LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + modelName);
return modelName; return modelName;
@ -373,7 +376,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override @Override
public String toModelFilename(String name) { public String toModelFilename(String name) {
// model name cannot use reserved keyword, e.g. return // model name cannot use reserved keyword, e.g. return
if (reservedWords.contains(name)) { if (isReservedWord(name)) {
String filename = underscore("object_" + name); String filename = underscore("object_" + name);
LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + filename); LOGGER.warn(name + " (reserved word) cannot be used as model filename. Renamed to " + filename);
return filename; return filename;
@ -422,7 +425,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
} }
// method name cannot use reserved keyword, e.g. return // method name cannot use reserved keyword, e.g. return
if (reservedWords.contains(operationId)) { if (isReservedWord(operationId)) {
String newOperationId = underscore("call_" + operationId); String newOperationId = underscore("call_" + operationId);
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId); LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
return newOperationId; return newOperationId;

View File

@ -47,7 +47,7 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig
apiPackage = "io.swagger.client.api"; apiPackage = "io.swagger.client.api";
modelPackage = "io.swagger.client.model"; modelPackage = "io.swagger.client.model";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
// local variable names used in API methods (endpoints) // local variable names used in API methods (endpoints)
"path", "contentTypes", "contentType", "queryParams", "headerParams", "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 // 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"); throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
} }

View File

@ -34,7 +34,7 @@ public class ScalatraServerCodegen extends DefaultCodegen implements CodegenConf
apiPackage = "com.wordnik.client.api"; apiPackage = "com.wordnik.client.api";
modelPackage = "com.wordnik.client.model"; modelPackage = "com.wordnik.client.model";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"abstract", "continue", "for", "new", "switch", "assert", "abstract", "continue", "for", "new", "switch", "assert",
"default", "if", "package", "synchronized", "boolean", "do", "goto", "private", "default", "if", "package", "synchronized", "boolean", "do", "goto", "private",

View File

@ -37,7 +37,7 @@ public class SilexServerCodegen extends DefaultCodegen implements CodegenConfig
embeddedTemplateDir = templateDir = "silex"; embeddedTemplateDir = templateDir = "silex";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( 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") "__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 @Override
public String toModelName(String name) { public String toModelName(String name) {
// model name cannot use reserved keyword // model name cannot use reserved keyword
if (reservedWords.contains(name)) { if (isReservedWord(name)) {
escapeReservedWord(name); // e.g. return => _return escapeReservedWord(name); // e.g. return => _return
} }

View File

@ -22,7 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfig { public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(SinatraServerCodegen.class); private static final Logger LOGGER = LoggerFactory.getLogger(SinatraServerCodegen.class);
protected String gemName; protected String gemName;
@ -43,7 +43,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
typeMapping.clear(); typeMapping.clear();
languageSpecificPrimitives.clear(); languageSpecificPrimitives.clear();
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__", "__FILE__", "and", "def", "end", "in", "or", "self", "unless", "__LINE__",
"begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN", "begin", "defined?", "ensure", "module", "redo", "super", "until", "BEGIN",
@ -165,7 +165,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
name = underscore(name); name = underscore(name);
// for reserved word or word starting with number, append _ // 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); name = escapeReservedWord(name);
} }
@ -181,7 +181,7 @@ public class SinatraServerCodegen extends DefaultCodegen implements CodegenConfi
@Override @Override
public String toModelName(String name) { public String toModelName(String name) {
// model name cannot use reserved keyword, e.g. return // 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"); 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 @Override
public String toModelFilename(String name) { public String toModelFilename(String name) {
// model name cannot use reserved keyword, e.g. return // 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"); 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 @Override
public String toOperationId(String operationId) { public String toOperationId(String operationId) {
// method name cannot use reserved keyword, e.g. return // 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"); throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
} }

View File

@ -39,7 +39,7 @@ public class SlimFrameworkServerCodegen extends DefaultCodegen implements Codege
embeddedTemplateDir = templateDir = "slim"; embeddedTemplateDir = templateDir = "slim";
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( 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") "__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 @Override
public String toModelName(String name) { public String toModelName(String name) {
// model name cannot use reserved keyword // model name cannot use reserved keyword
if (reservedWords.contains(name)) { if (isReservedWord(name)) {
escapeReservedWord(name); // e.g. return => _return escapeReservedWord(name); // e.g. return => _return
} }

View File

@ -90,7 +90,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
"Empty", "Empty",
"AnyObject") "AnyObject")
); );
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
Arrays.asList( Arrays.asList(
"class", "break", "as", "associativity", "deinit", "case", "dynamicType", "convenience", "enum", "continue", "class", "break", "as", "associativity", "deinit", "case", "dynamicType", "convenience", "enum", "continue",
"false", "dynamic", "extension", "default", "is", "didSet", "func", "do", "nil", "final", "import", "else", "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 // Ensure that the enum type doesn't match a reserved word or
// the variable name doesn't match the generated enum type or the // the variable name doesn't match the generated enum type or the
// Swift compiler will generate an error // Swift compiler will generate an error
if (reservedWords.contains(codegenProperty.datatypeWithEnum) || if (isReservedWord(codegenProperty.datatypeWithEnum) ||
name.equals(codegenProperty.datatypeWithEnum)) { name.equals(codegenProperty.datatypeWithEnum)) {
codegenProperty.datatypeWithEnum = escapeReservedWord(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 // 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"); throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
} }

View File

@ -53,7 +53,7 @@ public class TizenClientCodegen extends DefaultCodegen implements CodegenConfig
additionalProperties().put("prefix", PREFIX); additionalProperties().put("prefix", PREFIX);
reservedWords = new HashSet<String>( setReservedWordsLowerCase(
// VERIFY // VERIFY
Arrays.asList( Arrays.asList(
"void", "char", "short", "int", "void", "char", "short", "int", "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$ // 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"); throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
} }

View File

@ -15,7 +15,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-23T20:01:57.005+08:00") @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-25T16:09:10.101+08:00")
public class PetApi { public class PetApi {
private ApiClient apiClient; private ApiClient apiClient;
@ -412,12 +412,12 @@ public class PetApi {
* @return byte[] * @return byte[]
* @throws ApiException if fails to make API call * @throws ApiException if fails to make API call
*/ */
public byte[] getPetByIdWithByteArray(Long petId) throws ApiException { public byte[] petPetIdtestingByteArraytrueGet(Long petId) throws ApiException {
Object postBody = null; Object postBody = null;
// verify the required parameter 'petId' is set // verify the required parameter 'petId' is set
if (petId == null) { if (petId == null) {
throw new ApiException(400, "Missing the required parameter 'petId' when calling getPetByIdWithByteArray"); throw new ApiException(400, "Missing the required parameter 'petId' when calling petPetIdtestingByteArraytrueGet");
} }
// create path and map variables // create path and map variables

View File

@ -78,7 +78,7 @@ public class PetApiTest {
byte[] bytes = serializeJson(pet).getBytes(); byte[] bytes = serializeJson(pet).getBytes();
api.addPetUsingByteArray(bytes); api.addPetUsingByteArray(bytes);
byte[] fetchedBytes = api.getPetByIdWithByteArray(pet.getId()); byte[] fetchedBytes = api.petPetIdtestingByteArraytrueGet(pet.getId());
Pet fetched = deserializeJson(new String(fetchedBytes), Pet.class); Pet fetched = deserializeJson(new String(fetchedBytes), Pet.class);
assertNotNull(fetched); assertNotNull(fetched);
assertEquals(pet.getId(), fetched.getId()); assertEquals(pet.getId(), fetched.getId());

View File

@ -11,7 +11,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import feign.*; import feign.*;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-17T17:16:23.375+08:00") @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-25T16:20:49.744+08:00")
public interface PetApi extends ApiClient.Api { public interface PetApi extends ApiClient.Api {
@ -136,7 +136,7 @@ public interface PetApi extends ApiClient.Api {
"Content-type: application/json", "Content-type: application/json",
"Accepts: application/json", "Accepts: application/json",
}) })
byte[] getPetByIdWithByteArray(@Param("petId") Long petId); byte[] petPetIdtestingByteArraytrueGet(@Param("petId") Long petId);
/** /**
* Fake endpoint to test byte array in body parameter for adding a new pet to the store * Fake endpoint to test byte array in body parameter for adding a new pet to the store

View File

@ -15,7 +15,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-23T20:02:09.740+08:00") @javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-25T16:20:48.283+08:00")
public class PetApi { public class PetApi {
private ApiClient apiClient; private ApiClient apiClient;
@ -412,12 +412,12 @@ public class PetApi {
* @return byte[] * @return byte[]
* @throws ApiException if fails to make API call * @throws ApiException if fails to make API call
*/ */
public byte[] getPetByIdWithByteArray(Long petId) throws ApiException { public byte[] petPetIdtestingByteArraytrueGet(Long petId) throws ApiException {
Object postBody = null; Object postBody = null;
// verify the required parameter 'petId' is set // verify the required parameter 'petId' is set
if (petId == null) { if (petId == null) {
throw new ApiException(400, "Missing the required parameter 'petId' when calling getPetByIdWithByteArray"); throw new ApiException(400, "Missing the required parameter 'petId' when calling petPetIdtestingByteArraytrueGet");
} }
// create path and map variables // create path and map variables

View File

@ -75,7 +75,7 @@ public class PetApiTest {
byte[] bytes = serializeJson(pet, api.getApiClient()).getBytes(); byte[] bytes = serializeJson(pet, api.getApiClient()).getBytes();
api.addPetUsingByteArray(bytes); api.addPetUsingByteArray(bytes);
byte[] fetchedBytes = api.getPetByIdWithByteArray(pet.getId()); byte[] fetchedBytes = api.petPetIdtestingByteArraytrueGet(pet.getId());
Pet fetched = deserializeJson(new String(fetchedBytes), Pet.class, api.getApiClient()); Pet fetched = deserializeJson(new String(fetchedBytes), Pet.class, api.getApiClient());
assertNotNull(fetched); assertNotNull(fetched);
assertEquals(pet.getId(), fetched.getId()); assertEquals(pet.getId(), fetched.getId());

View File

@ -895,13 +895,13 @@ public class PetApi {
return call; return call;
} }
/* Build call for getPetByIdWithByteArray */ /* Build call for petPetIdtestingByteArraytrueGet */
private Call getPetByIdWithByteArrayCall(Long petId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { private Call petPetIdtestingByteArraytrueGetCall(Long petId, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
Object postBody = null; Object postBody = null;
// verify the required parameter 'petId' is set // verify the required parameter 'petId' is set
if (petId == null) { if (petId == null) {
throw new ApiException("Missing the required parameter 'petId' when calling getPetByIdWithByteArray(Async)"); throw new ApiException("Missing the required parameter 'petId' when calling petPetIdtestingByteArraytrueGet(Async)");
} }
@ -950,8 +950,8 @@ public class PetApi {
* @return byte[] * @return byte[]
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/ */
public byte[] getPetByIdWithByteArray(Long petId) throws ApiException { public byte[] petPetIdtestingByteArraytrueGet(Long petId) throws ApiException {
ApiResponse<byte[]> resp = getPetByIdWithByteArrayWithHttpInfo(petId); ApiResponse<byte[]> resp = petPetIdtestingByteArraytrueGetWithHttpInfo(petId);
return resp.getData(); return resp.getData();
} }
@ -962,8 +962,8 @@ public class PetApi {
* @return ApiResponse<byte[]> * @return ApiResponse<byte[]>
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/ */
public ApiResponse<byte[]> getPetByIdWithByteArrayWithHttpInfo(Long petId) throws ApiException { public ApiResponse<byte[]> petPetIdtestingByteArraytrueGetWithHttpInfo(Long petId) throws ApiException {
Call call = getPetByIdWithByteArrayCall(petId, null, null); Call call = petPetIdtestingByteArraytrueGetCall(petId, null, null);
Type returnType = new TypeToken<byte[]>(){}.getType(); Type returnType = new TypeToken<byte[]>(){}.getType();
return apiClient.execute(call, returnType); return apiClient.execute(call, returnType);
} }
@ -976,7 +976,7 @@ public class PetApi {
* @return The request call * @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object * @throws ApiException If fail to process the API call, e.g. serializing the request body object
*/ */
public Call getPetByIdWithByteArrayAsync(Long petId, final ApiCallback<byte[]> callback) throws ApiException { public Call petPetIdtestingByteArraytrueGetAsync(Long petId, final ApiCallback<byte[]> callback) throws ApiException {
ProgressResponseBody.ProgressListener progressListener = null; ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
@ -997,7 +997,7 @@ public class PetApi {
}; };
} }
Call call = getPetByIdWithByteArrayCall(petId, progressListener, progressRequestListener); Call call = petPetIdtestingByteArraytrueGetCall(petId, progressListener, progressRequestListener);
Type returnType = new TypeToken<byte[]>(){}.getType(); Type returnType = new TypeToken<byte[]>(){}.getType();
apiClient.executeAsync(call, returnType, callback); apiClient.executeAsync(call, returnType, callback);
return call; return call;

View File

@ -79,7 +79,7 @@ public class PetApiTest {
byte[] bytes = serializeJson(pet, api.getApiClient()).getBytes(); byte[] bytes = serializeJson(pet, api.getApiClient()).getBytes();
api.addPetUsingByteArray(bytes); api.addPetUsingByteArray(bytes);
byte[] fetchedBytes = api.getPetByIdWithByteArray(pet.getId()); byte[] fetchedBytes = api.petPetIdtestingByteArraytrueGet(pet.getId());
System.out.println(new String(fetchedBytes)); System.out.println(new String(fetchedBytes));
Type type = new TypeToken<Pet>(){}.getType(); Type type = new TypeToken<Pet>(){}.getType();
Pet fetched = deserializeJson(new String(fetchedBytes), type, api.getApiClient()); Pet fetched = deserializeJson(new String(fetchedBytes), type, api.getApiClient());

View File

@ -247,7 +247,7 @@ public interface PetApi {
*/ */
@GET("/pet/{petId}?testing_byte_array=true") @GET("/pet/{petId}?testing_byte_array=true")
byte[] getPetByIdWithByteArray( byte[] petPetIdtestingByteArraytrueGet(
@Path("petId") Long petId @Path("petId") Long petId
); );
@ -260,7 +260,7 @@ public interface PetApi {
*/ */
@GET("/pet/{petId}?testing_byte_array=true") @GET("/pet/{petId}?testing_byte_array=true")
void getPetByIdWithByteArray( void petPetIdtestingByteArraytrueGet(
@Path("petId") Long petId, Callback<byte[]> cb @Path("petId") Long petId, Callback<byte[]> cb
); );

View File

@ -137,7 +137,7 @@ public interface PetApi {
*/ */
@GET("pet/{petId}?testing_byte_array=true") @GET("pet/{petId}?testing_byte_array=true")
Call<byte[]> getPetByIdWithByteArray( Call<byte[]> petPetIdtestingByteArraytrueGet(
@Path("petId") Long petId @Path("petId") Long petId
); );