add test case to python, better resered word handling for objc

This commit is contained in:
wing328
2016-02-25 20:09:58 +08:00
parent a351724365
commit 2d4ccbfd79
18 changed files with 377 additions and 198 deletions

View File

@@ -249,12 +249,12 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
if (typeMapping.containsKey(swaggerType)) {
type = typeMapping.get(swaggerType);
if (languageSpecificPrimitives.contains(type) && !foundationClasses.contains(type)) {
return toModelName(type);
return toModelNameWithoutReservedWordCheck(type);
}
} else {
type = swaggerType;
}
return toModelName(type);
return toModelNameWithoutReservedWordCheck(type);
}
@Override
@@ -314,6 +314,23 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public String toModelName(String type) {
// model name cannot use reserved keyword
if (reservedWords.contains(type)) {
LOGGER.warn(type+ " (reserved word) cannot be used as model name. Renamed to " + ("object_" + type) + " before further processing");
type = "object_" + type; // e.g. return => ObjectReturn (after camelize)
}
return toModelNameWithoutReservedWordCheck(type);
}
/*
* Convert input to proper model name according to ObjC style guide
* without checking for reserved words
*
* @param type Model anme
* @return model Name in ObjC style guide
*/
public String toModelNameWithoutReservedWordCheck(String type) {
type = type.replaceAll("[^0-9a-zA-Z_]", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
// language build-in classes
@@ -425,7 +442,8 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
// method name cannot use reserved keyword, e.g. return
if (reservedWords.contains(operationId)) {
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId), true));
operationId = "call_" + operationId;
}
return camelize(sanitizeName(operationId), true);

View File

@@ -219,7 +219,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
// 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");
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)
}
// camelize the model name
@@ -231,7 +232,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
public String toModelFilename(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");
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)
}
// underscore the model file name
@@ -267,14 +269,15 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
@Override
public String toOperationId(String operationId) {
// throw exception if method name is empty
// throw exception if method name is empty (should not occur as an auto-generated method name will be used)
if (StringUtils.isEmpty(operationId)) {
throw new RuntimeException("Empty method name (operationId) not allowed");
}
// method name cannot use reserved keyword, e.g. return
if (reservedWords.contains(operationId)) {
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + underscore(sanitizeName("call_" + operationId)));
operationId = "call_" + operationId;
}
return underscore(sanitizeName(operationId));