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
commit a351724365
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);

View File

@ -879,7 +879,7 @@ class PetApi
}
/**
* getPetByIdWithByteArray
* petPetIdtestingByteArraytrueGet
*
* Fake endpoint to test byte array return by 'Find pet by ID'
*
@ -887,15 +887,15 @@ class PetApi
* @return ByteArray
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function getPetByIdWithByteArray($pet_id)
public function petPetIdtestingByteArraytrueGet($pet_id)
{
list($response, $statusCode, $httpHeader) = $this->getPetByIdWithByteArrayWithHttpInfo ($pet_id);
list($response, $statusCode, $httpHeader) = $this->petPetIdtestingByteArraytrueGetWithHttpInfo ($pet_id);
return $response;
}
/**
* getPetByIdWithByteArrayWithHttpInfo
* petPetIdtestingByteArraytrueGetWithHttpInfo
*
* Fake endpoint to test byte array return by 'Find pet by ID'
*
@ -903,12 +903,12 @@ class PetApi
* @return Array of ByteArray, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function getPetByIdWithByteArrayWithHttpInfo($pet_id)
public function petPetIdtestingByteArraytrueGetWithHttpInfo($pet_id)
{
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetByIdWithByteArray');
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling petPetIdtestingByteArraytrueGet');
}
// parse inputs

View File

@ -146,12 +146,12 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
}
/**
* Test case for getPetByIdWithByteArray
* Test case for petPetIdtestingByteArraytrueGet
*
* Fake endpoint to test byte array return by 'Find pet by ID'
*
*/
public function test_getPetByIdWithByteArray() {
public function test_petPetIdtestingByteArraytrueGet() {
}

View File

@ -329,7 +329,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
$pet_api = new Swagger\Client\Api\PetAPI($api_client);
// test getPetByIdWithByteArray
$pet_id = 10005;
$bytes = $pet_api->getPetByIdWithByteArray($pet_id);
$bytes = $pet_api->petPetIdtestingByteArraytrueGet($pet_id);
$json = json_decode(call_user_func_array('pack', array_merge(array('C*'), $bytes )), true);
$this->assertInternalType("array", $bytes);