forked from loafle/openapi-generator-original
add file response for php, update test case
This commit is contained in:
@@ -175,7 +175,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);
|
||||||
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
|
} else if ($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') {
|
if ($responseType == '\SplFileObject') {
|
||||||
return array($http_body, $http_header);
|
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)",
|
throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)",
|
||||||
$response_info['http_code'], $http_header, $http_body);
|
$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'))) {
|
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
|
||||||
settype($data, $class);
|
settype($data, $class);
|
||||||
$deserialized = $data;
|
$deserialized = $data;
|
||||||
} elseif ($class === 'SplFileObject') {
|
} elseif ($class === '\SplFileObject') {
|
||||||
# determine temp folder path
|
# determine temp folder path
|
||||||
if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) {
|
if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) {
|
||||||
$tmpFolderPath = sys_get_temp_dir();
|
$tmpFolderPath = sys_get_temp_dir();
|
||||||
@@ -149,7 +149,7 @@ class ObjectSerializer {
|
|||||||
}
|
}
|
||||||
$deserialized = new \SplFileObject($filename, "w");
|
$deserialized = new \SplFileObject($filename, "w");
|
||||||
$byte_written = $deserialized->fwrite($data);
|
$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 {
|
} else {
|
||||||
$instance = new $class();
|
$instance = new $class();
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ class {{classname}} {
|
|||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams{{#returnType}}, '{{returnType}}'{{/returnType}});
|
$headerParams{{#returnType}}, '{{returnType}}'{{/returnType}});
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -171,7 +171,7 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -231,7 +231,7 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams, '\Swagger\Client\Model\Pet[]');
|
$headerParams, '\Swagger\Client\Model\Pet[]');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -302,7 +302,7 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams, '\Swagger\Client\Model\Pet[]');
|
$headerParams, '\Swagger\Client\Model\Pet[]');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -387,7 +387,7 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams, '\Swagger\Client\Model\Pet');
|
$headerParams, '\Swagger\Client\Model\Pet');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -473,7 +473,7 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -544,7 +544,7 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -619,7 +619,7 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class StoreApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams, 'map[string,int]');
|
$headerParams, 'map[string,int]');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -178,7 +178,7 @@ class StoreApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams, '\Swagger\Client\Model\Order');
|
$headerParams, '\Swagger\Client\Model\Order');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -253,7 +253,7 @@ class StoreApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams, '\Swagger\Client\Model\Order');
|
$headerParams, '\Swagger\Client\Model\Order');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -328,7 +328,7 @@ class StoreApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -165,7 +165,7 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -223,7 +223,7 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -284,7 +284,7 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams, 'string');
|
$headerParams, 'string');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -348,7 +348,7 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -412,7 +412,7 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams, '\Swagger\Client\Model\User');
|
$headerParams, '\Swagger\Client\Model\User');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -492,7 +492,7 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -556,7 +556,7 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callApi($resourcePath, $method,
|
list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
|
|||||||
@@ -175,7 +175,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);
|
||||||
} else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) {
|
} else if ($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') {
|
if ($responseType == '\SplFileObject') {
|
||||||
return array($http_body, $http_header);
|
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)",
|
throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)",
|
||||||
$response_info['http_code'], $http_header, $http_body);
|
$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'))) {
|
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
|
||||||
settype($data, $class);
|
settype($data, $class);
|
||||||
$deserialized = $data;
|
$deserialized = $data;
|
||||||
} elseif ($class === 'SplFileObject') {
|
} elseif ($class === '\SplFileObject') {
|
||||||
# determine temp folder path
|
# determine temp folder path
|
||||||
if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) {
|
if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) {
|
||||||
$tmpFolderPath = sys_get_temp_dir();
|
$tmpFolderPath = sys_get_temp_dir();
|
||||||
@@ -149,7 +149,7 @@ class ObjectSerializer {
|
|||||||
}
|
}
|
||||||
$deserialized = new \SplFileObject($filename, "w");
|
$deserialized = new \SplFileObject($filename, "w");
|
||||||
$byte_written = $deserialized->fwrite($data);
|
$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 {
|
} else {
|
||||||
$instance = new $class();
|
$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)
|
// for error reporting (need to run with php5.3 to get no warning)
|
||||||
//ini_set('display_errors', 1);
|
//ini_set('display_errors', 1);
|
||||||
//error_reporting(~0);
|
//error_reporting(~0);
|
||||||
ini_set('display_startup_errors',1);
|
// when running with php5.5, comment out below to skip the warning about
|
||||||
ini_set('display_errors',1);
|
// using @ to handle file upload
|
||||||
error_reporting(-1);
|
//ini_set('display_startup_errors',1);
|
||||||
|
//ini_set('display_errors',1);
|
||||||
|
//error_reporting(-1);
|
||||||
|
|
||||||
// enable debugging
|
// enable debugging
|
||||||
//Swagger\Client\Configuration::$debug = true;
|
//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)
|
// for error reporting (need to run with php5.3 to get no warning)
|
||||||
//ini_set('display_errors', 1);
|
//ini_set('display_errors', 1);
|
||||||
//error_reporting(~0);
|
//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
|
// test get inventory
|
||||||
@@ -22,8 +43,7 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
// get inventory
|
// get inventory
|
||||||
$get_response = $store_api->getInventory();
|
$get_response = $store_api->getInventory();
|
||||||
|
|
||||||
$this->assertInternalType("int", $get_response['sold']);
|
$this->assertInternalType("int", $get_response['available']);
|
||||||
$this->assertInternalType("int", $get_response['pending']);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user