Merge pull request #1990 from expectedbehavior/php-raw-string

[PHP] Use String instead of Byte Array
This commit is contained in:
wing328
2016-03-04 10:57:59 +08:00
8 changed files with 15 additions and 19 deletions

View File

@@ -101,7 +101,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("array", "array"); typeMapping.put("array", "array");
typeMapping.put("list", "array"); typeMapping.put("list", "array");
typeMapping.put("object", "object"); typeMapping.put("object", "object");
typeMapping.put("binary", "ByteArray"); typeMapping.put("binary", "string");
cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC)); cliOptions.add(new CliOption(CodegenConstants.MODEL_PACKAGE, CodegenConstants.MODEL_PACKAGE_DESC));
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC)); cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));

View File

@@ -230,7 +230,7 @@ class ApiClient
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null); throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
} elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { } elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
// return raw body if response is a file // return raw body if response is a file
if ($responseType == '\SplFileObject' || $responseType == 'ByteArray') { if ($responseType == '\SplFileObject' || $responseType == 'string') {
return array($http_body, $response_info['http_code'], $http_header); return array($http_body, $response_info['http_code'], $http_header);
} }

View File

@@ -241,8 +241,6 @@ class ObjectSerializer
$values[] = self::deserialize($value, $subClass); $values[] = self::deserialize($value, $subClass);
} }
$deserialized = $values; $deserialized = $values;
} elseif ($class === 'ByteArray') { // byte array
$deserialized = unpack('C*', (string)$data);
} elseif ($class === '\DateTime') { } elseif ($class === '\DateTime') {
$deserialized = new \DateTime($data); $deserialized = new \DateTime($data);
} elseif (in_array($class, array({{&primitives}}))) { } elseif (in_array($class, array({{&primitives}}))) {

View File

@@ -188,7 +188,7 @@ use \{{invokerPackage}}\ObjectSerializer;
{{#bodyParams}}// body params {{#bodyParams}}// body params
$_tempBody = null; $_tempBody = null;
if (isset(${{paramName}})) { if (isset(${{paramName}})) {
{{^isBinary}}$_tempBody = ${{paramName}};{{/isBinary}}{{#isBinary}}$_tempBody = call_user_func_array('pack', array_merge(array('C*'), ${{paramName}}));{{/isBinary}} $_tempBody = ${{paramName}};
}{{/bodyParams}} }{{/bodyParams}}
// for model (json/xml) // for model (json/xml)

View File

@@ -991,7 +991,7 @@ class PetApi
* Fake endpoint to test byte array return by 'Find pet by ID' * Fake endpoint to test byte array return by 'Find pet by ID'
* *
* @param int $pet_id ID of pet that needs to be fetched (required) * @param int $pet_id ID of pet that needs to be fetched (required)
* @return ByteArray * @return string
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function petPetIdtestingByteArraytrueGet($pet_id) public function petPetIdtestingByteArraytrueGet($pet_id)
@@ -1007,7 +1007,7 @@ class PetApi
* Fake endpoint to test byte array return by 'Find pet by ID' * Fake endpoint to test byte array return by 'Find pet by ID'
* *
* @param int $pet_id ID of pet that needs to be fetched (required) * @param int $pet_id ID of pet that needs to be fetched (required)
* @return Array of ByteArray, HTTP status code, HTTP response headers (array of strings) * @return Array of string, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function petPetIdtestingByteArraytrueGetWithHttpInfo($pet_id) public function petPetIdtestingByteArraytrueGetWithHttpInfo($pet_id)
@@ -1071,19 +1071,19 @@ class PetApi
list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
$resourcePath, 'GET', $resourcePath, 'GET',
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams, 'ByteArray' $headerParams, 'string'
); );
if (!$response) { if (!$response) {
return array(null, $statusCode, $httpHeader); return array(null, $statusCode, $httpHeader);
} }
return array(\Swagger\Client\ObjectSerializer::deserialize($response, 'ByteArray', $httpHeader), $statusCode, $httpHeader); return array(\Swagger\Client\ObjectSerializer::deserialize($response, 'string', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
case 200: case 200:
$data = \Swagger\Client\ObjectSerializer::deserialize($e->getResponseBody(), 'ByteArray', $e->getResponseHeaders()); $data = \Swagger\Client\ObjectSerializer::deserialize($e->getResponseBody(), 'string', $e->getResponseHeaders());
$e->setResponseObject($data); $e->setResponseObject($data);
break; break;
} }
@@ -1097,7 +1097,7 @@ class PetApi
* *
* 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
* *
* @param ByteArray $body Pet object in the form of byte array (optional) * @param string $body Pet object in the form of byte array (optional)
* @return void * @return void
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
@@ -1113,7 +1113,7 @@ class PetApi
* *
* 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
* *
* @param ByteArray $body Pet object in the form of byte array (optional) * @param string $body Pet object in the form of byte array (optional)
* @return Array of null, HTTP status code, HTTP response headers (array of strings) * @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
@@ -1143,7 +1143,7 @@ class PetApi
// body params // body params
$_tempBody = null; $_tempBody = null;
if (isset($body)) { if (isset($body)) {
$_tempBody = call_user_func_array('pack', array_merge(array('C*'), $body)); $_tempBody = $body;
} }
// for model (json/xml) // for model (json/xml)

View File

@@ -230,7 +230,7 @@ class ApiClient
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null); throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
} elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { } elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
// return raw body if response is a file // return raw body if response is a file
if ($responseType == '\SplFileObject' || $responseType == 'ByteArray') { if ($responseType == '\SplFileObject' || $responseType == 'string') {
return array($http_body, $response_info['http_code'], $http_header); return array($http_body, $response_info['http_code'], $http_header);
} }

View File

@@ -241,8 +241,6 @@ class ObjectSerializer
$values[] = self::deserialize($value, $subClass); $values[] = self::deserialize($value, $subClass);
} }
$deserialized = $values; $deserialized = $values;
} elseif ($class === 'ByteArray') { // byte array
$deserialized = unpack('C*', (string)$data);
} elseif ($class === '\DateTime') { } elseif ($class === '\DateTime') {
$deserialized = new \DateTime($data); $deserialized = new \DateTime($data);
} elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) { } elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) {

View File

@@ -279,7 +279,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
// add a new pet (model) // add a new pet (model)
$object_serializer = new Swagger\Client\ObjectSerializer(); $object_serializer = new Swagger\Client\ObjectSerializer();
$pet_json_string = json_encode($object_serializer->sanitizeForSerialization($new_pet)); $pet_json_string = json_encode($object_serializer->sanitizeForSerialization($new_pet));
$add_response = $pet_api->addPetUsingByteArray(unpack('C*', $pet_json_string)); $add_response = $pet_api->addPetUsingByteArray($pet_json_string);
// return nothing (void) // return nothing (void)
$this->assertSame($add_response, NULL); $this->assertSame($add_response, NULL);
// verify added Pet // verify added Pet
@@ -330,9 +330,9 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
// test getPetByIdWithByteArray // test getPetByIdWithByteArray
$pet_id = 10005; $pet_id = 10005;
$bytes = $pet_api->petPetIdtestingByteArraytrueGet($pet_id); $bytes = $pet_api->petPetIdtestingByteArraytrueGet($pet_id);
$json = json_decode(call_user_func_array('pack', array_merge(array('C*'), $bytes )), true); $json = json_decode($bytes, true);
$this->assertInternalType("array", $bytes); $this->assertInternalType("string", $bytes);
$this->assertSame($json['id'], $pet_id); $this->assertSame($json['id'], $pet_id);
// not testing name as it's tested by addPetUsingByteArray // not testing name as it's tested by addPetUsingByteArray