mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
add file response for php, update test case
This commit is contained in:
parent
fcd0b31d7d
commit
7f31da734d
@ -175,7 +175,7 @@ class ApiClient {
|
||||
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
|
||||
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
|
||||
// return raw body if response is a file
|
||||
if ($responseType == 'SplFileObject') {
|
||||
if ($responseType == '\SplFileObject') {
|
||||
return array($http_body, $http_header);
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ class ApiClient {
|
||||
throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)",
|
||||
$response_info['http_code'], $http_header, $http_body);
|
||||
}
|
||||
return $data;
|
||||
return array($data, $http_header);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -133,7 +133,7 @@ class ObjectSerializer {
|
||||
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
|
||||
settype($data, $class);
|
||||
$deserialized = $data;
|
||||
} elseif ($class === 'SplFileObject') {
|
||||
} elseif ($class === '\SplFileObject') {
|
||||
# determine temp folder path
|
||||
if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) {
|
||||
$tmpFolderPath = sys_get_temp_dir();
|
||||
@ -149,7 +149,7 @@ class ObjectSerializer {
|
||||
}
|
||||
$deserialized = new \SplFileObject($filename, "w");
|
||||
$byte_written = $deserialized->fwrite($data);
|
||||
error_log("[INFO] Written $byte_written to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file);
|
||||
error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile());
|
||||
|
||||
} else {
|
||||
$instance = new $class();
|
||||
|
@ -134,7 +134,7 @@ class {{classname}} {
|
||||
{{/authMethods}}
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams{{#returnType}}, '{{returnType}}'{{/returnType}});
|
||||
} catch (ApiException $e) {
|
||||
|
@ -110,7 +110,7 @@ class PetApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
@ -171,7 +171,7 @@ class PetApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
@ -231,7 +231,7 @@ class PetApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, '\Swagger\Client\Model\Pet[]');
|
||||
} catch (ApiException $e) {
|
||||
@ -302,7 +302,7 @@ class PetApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, '\Swagger\Client\Model\Pet[]');
|
||||
} catch (ApiException $e) {
|
||||
@ -387,7 +387,7 @@ class PetApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, '\Swagger\Client\Model\Pet');
|
||||
} catch (ApiException $e) {
|
||||
@ -473,7 +473,7 @@ class PetApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
@ -544,7 +544,7 @@ class PetApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
@ -619,7 +619,7 @@ class PetApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
|
@ -109,7 +109,7 @@ class StoreApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, 'map[string,int]');
|
||||
} catch (ApiException $e) {
|
||||
@ -178,7 +178,7 @@ class StoreApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, '\Swagger\Client\Model\Order');
|
||||
} catch (ApiException $e) {
|
||||
@ -253,7 +253,7 @@ class StoreApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, '\Swagger\Client\Model\Order');
|
||||
} catch (ApiException $e) {
|
||||
@ -328,7 +328,7 @@ class StoreApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
|
@ -107,7 +107,7 @@ class UserApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
@ -165,7 +165,7 @@ class UserApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
@ -223,7 +223,7 @@ class UserApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
@ -284,7 +284,7 @@ class UserApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, 'string');
|
||||
} catch (ApiException $e) {
|
||||
@ -348,7 +348,7 @@ class UserApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
@ -412,7 +412,7 @@ class UserApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams, '\Swagger\Client\Model\User');
|
||||
} catch (ApiException $e) {
|
||||
@ -492,7 +492,7 @@ class UserApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
@ -556,7 +556,7 @@ class UserApi {
|
||||
|
||||
// make the API Call
|
||||
try {
|
||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||
$queryParams, $httpBody,
|
||||
$headerParams);
|
||||
} catch (ApiException $e) {
|
||||
|
@ -175,7 +175,7 @@ class ApiClient {
|
||||
throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null);
|
||||
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
|
||||
// return raw body if response is a file
|
||||
if ($responseType == 'SplFileObject') {
|
||||
if ($responseType == '\SplFileObject') {
|
||||
return array($http_body, $http_header);
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ class ApiClient {
|
||||
throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)",
|
||||
$response_info['http_code'], $http_header, $http_body);
|
||||
}
|
||||
return $data;
|
||||
return array($data, $http_header);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -133,7 +133,7 @@ class ObjectSerializer {
|
||||
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
|
||||
settype($data, $class);
|
||||
$deserialized = $data;
|
||||
} elseif ($class === 'SplFileObject') {
|
||||
} elseif ($class === '\SplFileObject') {
|
||||
# determine temp folder path
|
||||
if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) {
|
||||
$tmpFolderPath = sys_get_temp_dir();
|
||||
@ -149,7 +149,7 @@ class ObjectSerializer {
|
||||
}
|
||||
$deserialized = new \SplFileObject($filename, "w");
|
||||
$byte_written = $deserialized->fwrite($data);
|
||||
error_log("[INFO] Written $byte_written to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file);
|
||||
error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile());
|
||||
|
||||
} else {
|
||||
$instance = new $class();
|
||||
|
@ -10,9 +10,11 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
||||
// for error reporting (need to run with php5.3 to get no warning)
|
||||
//ini_set('display_errors', 1);
|
||||
//error_reporting(~0);
|
||||
ini_set('display_startup_errors',1);
|
||||
ini_set('display_errors',1);
|
||||
error_reporting(-1);
|
||||
// when running with php5.5, comment out below to skip the warning about
|
||||
// using @ to handle file upload
|
||||
//ini_set('display_startup_errors',1);
|
||||
//ini_set('display_errors',1);
|
||||
//error_reporting(-1);
|
||||
|
||||
// enable debugging
|
||||
//Swagger\Client\Configuration::$debug = true;
|
||||
|
@ -10,6 +10,27 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase
|
||||
// for error reporting (need to run with php5.3 to get no warning)
|
||||
//ini_set('display_errors', 1);
|
||||
//error_reporting(~0);
|
||||
// new pet
|
||||
$new_pet_id = 10005;
|
||||
$new_pet = new Swagger\Client\Model\Pet;
|
||||
$new_pet->setId($new_pet_id);
|
||||
$new_pet->setName("PHP Unit Test");
|
||||
$new_pet->setStatus("available");
|
||||
// new tag
|
||||
$tag= new Swagger\Client\Model\Tag;
|
||||
$tag->setId($new_pet_id); // use the same id as pet
|
||||
$tag->setName("test php tag");
|
||||
// new category
|
||||
$category = new Swagger\Client\Model\Category;
|
||||
$category->setId($new_pet_id); // use the same id as pet
|
||||
$category->setName("test php category");
|
||||
|
||||
$new_pet->setTags(array($tag));
|
||||
$new_pet->setCategory($category);
|
||||
|
||||
$pet_api = new Swagger\Client\Api\PetAPI();
|
||||
// add a new pet (model)
|
||||
$add_response = $pet_api->addPet($new_pet);
|
||||
}
|
||||
|
||||
// test get inventory
|
||||
@ -22,8 +43,7 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase
|
||||
// get inventory
|
||||
$get_response = $store_api->getInventory();
|
||||
|
||||
$this->assertInternalType("int", $get_response['sold']);
|
||||
$this->assertInternalType("int", $get_response['pending']);
|
||||
$this->assertInternalType("int", $get_response['available']);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user