Merge pull request #2239 from wing328/php_reserved_words

[PHP] better reserved words handling for method and model names
This commit is contained in:
wing328
2016-02-25 15:06:14 +08:00
5 changed files with 15 additions and 11 deletions

View File

@@ -2279,6 +2279,8 @@ public class DefaultCodegen {
}
if(!new File(folder).exists()) {
supportingFiles.add(supportingFile);
} else {
LOGGER.info("Skipped overwriting " + supportingFile.destinationFilename + " as the file already exists in " + folder);
}
}

View File

@@ -366,7 +366,8 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
// model name cannot use reserved keyword
if (reservedWords.contains(name)) {
escapeReservedWord(name); // e.g. return => _return
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
@@ -395,7 +396,8 @@ public class PhpClientCodegen 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);