Merge pull request #1672 from wing328/php_add_http_info

[PHP] add `WithHttpInfo` method to return HTTP status code and response headers
This commit is contained in:
wing328 2015-12-08 18:31:43 +08:00
commit 258bb27f30
9 changed files with 633 additions and 192 deletions

View File

@ -160,7 +160,7 @@ class ApiClient
if ($this->config->getCurlTimeout() != 0) { if ($this->config->getCurlTimeout() != 0) {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
} }
// return the result on success, rather than just TRUE // return the result on success, rather than just true
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
@ -216,7 +216,7 @@ class ApiClient
// Make the request // Make the request
$response = curl_exec($curl); $response = curl_exec($curl);
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$http_header = substr($response, 0, $http_header_size); $http_header = $this->http_parse_headers(substr($response, 0, $http_header_size));
$http_body = substr($response, $http_header_size); $http_body = substr($response, $http_header_size);
$response_info = curl_getinfo($curl); $response_info = curl_getinfo($curl);
@ -231,7 +231,7 @@ class ApiClient
} 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') { if ($responseType == '\SplFileObject') {
return array($http_body, $http_header); return array($http_body, $response_info['http_code'], $http_header);
} }
$data = json_decode($http_body); $data = json_decode($http_body);
@ -249,7 +249,7 @@ class ApiClient
$response_info['http_code'], $http_header, $data $response_info['http_code'], $http_header, $data
); );
} }
return array($data, $http_header); return array($data, $response_info['http_code'], $http_header);
} }
/** /**
@ -287,4 +287,52 @@ class ApiClient
return implode(',', $content_type); return implode(',', $content_type);
} }
} }
/**
* Return an array of HTTP response headers
*
* @param string $raw_headers A string of raw HTTP response headers
*
* @return string[] Array of HTTP response heaers
*/
protected function http_parse_headers($raw_headers)
{
// ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986
$headers = array();
$key = ''; // [+]
foreach(explode("\n", $raw_headers) as $i => $h)
{
$h = explode(':', $h, 2);
if (isset($h[1]))
{
if (!isset($headers[$h[0]]))
$headers[$h[0]] = trim($h[1]);
elseif (is_array($headers[$h[0]]))
{
// $tmp = array_merge($headers[$h[0]], array(trim($h[1]))); // [-]
// $headers[$h[0]] = $tmp; // [-]
$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1]))); // [+]
}
else
{
// $tmp = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [-]
// $headers[$h[0]] = $tmp; // [-]
$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [+]
}
$key = $h[0]; // [+]
}
else // [+]
{ // [+]
if (substr($h[0], 0, 1) == "\t") // [+]
$headers[$key] .= "\r\n\t".trim($h[0]); // [+]
elseif (!$key) // [+]
$headers[0] = trim($h[0]);trim($h[0]); // [+]
} // [+]
}
return $headers;
}
} }

View File

@ -198,7 +198,7 @@ class ObjectSerializer
$deserialized = $data; $deserialized = $data;
} elseif ($class === '\SplFileObject') { } elseif ($class === '\SplFileObject') {
// determine file name // determine file name
if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) { if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader['Content-Disposition'], $match)) {
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1]; $filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1];
} else { } else {
$filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), '');

View File

@ -92,7 +92,7 @@ use \{{invokerPackage}}\ObjectSerializer;
{{#operation}} {{#operation}}
/** /**
* {{{nickname}}} * {{{operationId}}}
* *
* {{{summary}}} * {{{summary}}}
* *
@ -100,12 +100,28 @@ use \{{invokerPackage}}\ObjectSerializer;
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
* @throws \{{invokerPackage}}\ApiException on non-2xx response * @throws \{{invokerPackage}}\ApiException on non-2xx response
*/ */
public function {{nickname}}({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) public function {{operationId}}({{#allParams}}${{paramName}}{{^required}} = null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
{
list($response, $statusCode, $httpHeader) = $this->{{operationId}}WithHttpInfo ({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
return $response;
}
/**
* {{{operationId}}}WithHttpInfo
*
* {{{summary}}}
*
{{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}}
{{/allParams}} * @return Array of {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings)
* @throws \{{invokerPackage}}\ApiException on non-2xx response
*/
public function {{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{^required}} = null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
{ {
{{#allParams}}{{#required}} {{#allParams}}{{#required}}
// verify the required parameter '{{paramName}}' is set // verify the required parameter '{{paramName}}' is set
if (${{paramName}} === null) { if (${{paramName}} === null) {
throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}'); throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{operationId}}');
}{{/required}}{{/allParams}} }{{/required}}{{/allParams}}
// parse inputs // parse inputs
@ -180,19 +196,20 @@ use \{{invokerPackage}}\ObjectSerializer;
}{{/isOAuth}} }{{/isOAuth}}
{{/authMethods}} {{/authMethods}}
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams{{#returnType}}, '{{returnType}}'{{/returnType}} $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}}
); );
{{#returnType}} {{#returnType}}
if (!$response) { if (!$response) {
return null; return array(null, $statusCode, $httpHeader);
} }
return $this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader); return array($this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader), $statusCode, $httpHeader);
{{/returnType}}{{^returnType}}
return array(null, $statusCode, $httpHeader);
{{/returnType}} {{/returnType}}
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { {{#responses}}{{#dataType}} switch ($e->getCode()) { {{#responses}}{{#dataType}}
@ -204,9 +221,6 @@ use \{{invokerPackage}}\ObjectSerializer;
throw $e; throw $e;
} }
{{#returnType}}
return null;
{{/returnType}}
} }
{{/operation}} {{/operation}}
} }

View File

@ -101,6 +101,22 @@ class PetApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function updatePet($body = null) public function updatePet($body = null)
{
list($response, $statusCode, $httpHeader) = $this->updatePetWithHttpInfo ($body);
return $response;
}
/**
* updatePetWithHttpInfo
*
* Update an existing pet
*
* @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (optional)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function updatePetWithHttpInfo($body = null)
{ {
@ -141,21 +157,21 @@ class PetApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
/** /**
@ -168,6 +184,22 @@ class PetApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function addPet($body = null) public function addPet($body = null)
{
list($response, $statusCode, $httpHeader) = $this->addPetWithHttpInfo ($body);
return $response;
}
/**
* addPetWithHttpInfo
*
* Add a new pet to the store
*
* @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (optional)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function addPetWithHttpInfo($body = null)
{ {
@ -208,21 +240,21 @@ class PetApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
/** /**
@ -235,6 +267,22 @@ class PetApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function findPetsByStatus($status = null) public function findPetsByStatus($status = null)
{
list($response, $statusCode, $httpHeader) = $this->findPetsByStatusWithHttpInfo ($status);
return $response;
}
/**
* findPetsByStatusWithHttpInfo
*
* Finds Pets by status
*
* @param string[] $status Status values that need to be considered for filter (optional)
* @return Array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function findPetsByStatusWithHttpInfo($status = null)
{ {
@ -274,19 +322,18 @@ class PetApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams, '\Swagger\Client\Model\Pet[]' $headerParams, '\Swagger\Client\Model\Pet[]'
); );
if (!$response) { if (!$response) {
return null; return array(null, $statusCode, $httpHeader);
} }
return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader); return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
@ -298,9 +345,6 @@ class PetApi
throw $e; throw $e;
} }
return null;
} }
/** /**
@ -313,6 +357,22 @@ class PetApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function findPetsByTags($tags = null) public function findPetsByTags($tags = null)
{
list($response, $statusCode, $httpHeader) = $this->findPetsByTagsWithHttpInfo ($tags);
return $response;
}
/**
* findPetsByTagsWithHttpInfo
*
* Finds Pets by tags
*
* @param string[] $tags Tags to filter by (optional)
* @return Array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function findPetsByTagsWithHttpInfo($tags = null)
{ {
@ -352,19 +412,18 @@ class PetApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams, '\Swagger\Client\Model\Pet[]' $headerParams, '\Swagger\Client\Model\Pet[]'
); );
if (!$response) { if (!$response) {
return null; return array(null, $statusCode, $httpHeader);
} }
return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader); return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
@ -376,9 +435,6 @@ class PetApi
throw $e; throw $e;
} }
return null;
} }
/** /**
@ -391,6 +447,22 @@ class PetApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function getPetById($pet_id) public function getPetById($pet_id)
{
list($response, $statusCode, $httpHeader) = $this->getPetByIdWithHttpInfo ($pet_id);
return $response;
}
/**
* getPetByIdWithHttpInfo
*
* Find pet by ID
*
* @param int $pet_id ID of pet that needs to be fetched (required)
* @return Array of \Swagger\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function getPetByIdWithHttpInfo($pet_id)
{ {
// verify the required parameter 'pet_id' is set // verify the required parameter 'pet_id' is set
@ -440,19 +512,18 @@ class PetApi
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams, '\Swagger\Client\Model\Pet' $headerParams, '\Swagger\Client\Model\Pet'
); );
if (!$response) { if (!$response) {
return null; return array(null, $statusCode, $httpHeader);
} }
return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet', $httpHeader); return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
@ -464,9 +535,6 @@ class PetApi
throw $e; throw $e;
} }
return null;
} }
/** /**
@ -481,6 +549,24 @@ class PetApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function updatePetWithForm($pet_id, $name = null, $status = null) public function updatePetWithForm($pet_id, $name = null, $status = null)
{
list($response, $statusCode, $httpHeader) = $this->updatePetWithFormWithHttpInfo ($pet_id, $name, $status);
return $response;
}
/**
* updatePetWithFormWithHttpInfo
*
* Updates a pet in the store with form data
*
* @param string $pet_id ID of pet that needs to be updated (required)
* @param string $name Updated name of the pet (optional)
* @param string $status Updated status of the pet (optional)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function updatePetWithFormWithHttpInfo($pet_id, $name = null, $status = null)
{ {
// verify the required parameter 'pet_id' is set // verify the required parameter 'pet_id' is set
@ -540,21 +626,21 @@ class PetApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
/** /**
@ -568,6 +654,23 @@ class PetApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function deletePet($pet_id, $api_key = null) public function deletePet($pet_id, $api_key = null)
{
list($response, $statusCode, $httpHeader) = $this->deletePetWithHttpInfo ($pet_id, $api_key);
return $response;
}
/**
* deletePetWithHttpInfo
*
* Deletes a pet
*
* @param int $pet_id Pet id to delete (required)
* @param string $api_key (optional)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function deletePetWithHttpInfo($pet_id, $api_key = null)
{ {
// verify the required parameter 'pet_id' is set // verify the required parameter 'pet_id' is set
@ -618,21 +721,21 @@ class PetApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
/** /**
@ -647,6 +750,24 @@ class PetApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function uploadFile($pet_id, $additional_metadata = null, $file = null) public function uploadFile($pet_id, $additional_metadata = null, $file = null)
{
list($response, $statusCode, $httpHeader) = $this->uploadFileWithHttpInfo ($pet_id, $additional_metadata, $file);
return $response;
}
/**
* uploadFileWithHttpInfo
*
* uploads an image
*
* @param int $pet_id ID of pet to update (required)
* @param string $additional_metadata Additional data to pass to server (optional)
* @param \SplFileObject $file file to upload (optional)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $file = null)
{ {
// verify the required parameter 'pet_id' is set // verify the required parameter 'pet_id' is set
@ -712,21 +833,21 @@ class PetApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
} }

View File

@ -100,6 +100,21 @@ class StoreApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function getInventory() public function getInventory()
{
list($response, $statusCode, $httpHeader) = $this->getInventoryWithHttpInfo ();
return $response;
}
/**
* getInventoryWithHttpInfo
*
* Returns pet inventories by status
*
* @return Array of map[string,int], HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function getInventoryWithHttpInfo()
{ {
@ -138,19 +153,18 @@ class StoreApi
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams, 'map[string,int]' $headerParams, 'map[string,int]'
); );
if (!$response) { if (!$response) {
return null; return array(null, $statusCode, $httpHeader);
} }
return $this->apiClient->getSerializer()->deserialize($response, 'map[string,int]', $httpHeader); return array($this->apiClient->getSerializer()->deserialize($response, 'map[string,int]', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
@ -162,9 +176,6 @@ class StoreApi
throw $e; throw $e;
} }
return null;
} }
/** /**
@ -177,6 +188,22 @@ class StoreApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function placeOrder($body = null) public function placeOrder($body = null)
{
list($response, $statusCode, $httpHeader) = $this->placeOrderWithHttpInfo ($body);
return $response;
}
/**
* placeOrderWithHttpInfo
*
* Place an order for a pet
*
* @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (optional)
* @return Array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function placeOrderWithHttpInfo($body = null)
{ {
@ -212,19 +239,18 @@ class StoreApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams, '\Swagger\Client\Model\Order' $headerParams, '\Swagger\Client\Model\Order'
); );
if (!$response) { if (!$response) {
return null; return array(null, $statusCode, $httpHeader);
} }
return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader); return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
@ -236,9 +262,6 @@ class StoreApi
throw $e; throw $e;
} }
return null;
} }
/** /**
@ -251,6 +274,22 @@ class StoreApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function getOrderById($order_id) public function getOrderById($order_id)
{
list($response, $statusCode, $httpHeader) = $this->getOrderByIdWithHttpInfo ($order_id);
return $response;
}
/**
* getOrderByIdWithHttpInfo
*
* Find purchase order by ID
*
* @param string $order_id ID of pet that needs to be fetched (required)
* @return Array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function getOrderByIdWithHttpInfo($order_id)
{ {
// verify the required parameter 'order_id' is set // verify the required parameter 'order_id' is set
@ -293,19 +332,18 @@ class StoreApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams, '\Swagger\Client\Model\Order' $headerParams, '\Swagger\Client\Model\Order'
); );
if (!$response) { if (!$response) {
return null; return array(null, $statusCode, $httpHeader);
} }
return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader); return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
@ -317,9 +355,6 @@ class StoreApi
throw $e; throw $e;
} }
return null;
} }
/** /**
@ -332,6 +367,22 @@ class StoreApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function deleteOrder($order_id) public function deleteOrder($order_id)
{
list($response, $statusCode, $httpHeader) = $this->deleteOrderWithHttpInfo ($order_id);
return $response;
}
/**
* deleteOrderWithHttpInfo
*
* Delete purchase order by ID
*
* @param string $order_id ID of the order that needs to be deleted (required)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function deleteOrderWithHttpInfo($order_id)
{ {
// verify the required parameter 'order_id' is set // verify the required parameter 'order_id' is set
@ -374,21 +425,21 @@ class StoreApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
} }

View File

@ -101,6 +101,22 @@ class UserApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function createUser($body = null) public function createUser($body = null)
{
list($response, $statusCode, $httpHeader) = $this->createUserWithHttpInfo ($body);
return $response;
}
/**
* createUserWithHttpInfo
*
* Create user
*
* @param \Swagger\Client\Model\User $body Created user object (optional)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function createUserWithHttpInfo($body = null)
{ {
@ -136,21 +152,21 @@ class UserApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
/** /**
@ -163,6 +179,22 @@ class UserApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function createUsersWithArrayInput($body = null) public function createUsersWithArrayInput($body = null)
{
list($response, $statusCode, $httpHeader) = $this->createUsersWithArrayInputWithHttpInfo ($body);
return $response;
}
/**
* createUsersWithArrayInputWithHttpInfo
*
* Creates list of users with given input array
*
* @param \Swagger\Client\Model\User[] $body List of user object (optional)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function createUsersWithArrayInputWithHttpInfo($body = null)
{ {
@ -198,21 +230,21 @@ class UserApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
/** /**
@ -225,6 +257,22 @@ class UserApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function createUsersWithListInput($body = null) public function createUsersWithListInput($body = null)
{
list($response, $statusCode, $httpHeader) = $this->createUsersWithListInputWithHttpInfo ($body);
return $response;
}
/**
* createUsersWithListInputWithHttpInfo
*
* Creates list of users with given input array
*
* @param \Swagger\Client\Model\User[] $body List of user object (optional)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function createUsersWithListInputWithHttpInfo($body = null)
{ {
@ -260,21 +308,21 @@ class UserApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
/** /**
@ -288,6 +336,23 @@ class UserApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function loginUser($username = null, $password = null) public function loginUser($username = null, $password = null)
{
list($response, $statusCode, $httpHeader) = $this->loginUserWithHttpInfo ($username, $password);
return $response;
}
/**
* loginUserWithHttpInfo
*
* Logs user into the system
*
* @param string $username The user name for login (optional)
* @param string $password The password for login in clear text (optional)
* @return Array of string, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function loginUserWithHttpInfo($username = null, $password = null)
{ {
@ -325,19 +390,18 @@ class UserApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams, 'string' $headerParams, 'string'
); );
if (!$response) { if (!$response) {
return null; return array(null, $statusCode, $httpHeader);
} }
return $this->apiClient->getSerializer()->deserialize($response, 'string', $httpHeader); return array($this->apiClient->getSerializer()->deserialize($response, 'string', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
@ -349,9 +413,6 @@ class UserApi
throw $e; throw $e;
} }
return null;
} }
/** /**
@ -363,6 +424,21 @@ class UserApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function logoutUser() public function logoutUser()
{
list($response, $statusCode, $httpHeader) = $this->logoutUserWithHttpInfo ();
return $response;
}
/**
* logoutUserWithHttpInfo
*
* Logs out current logged in user session
*
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function logoutUserWithHttpInfo()
{ {
@ -394,21 +470,21 @@ class UserApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
/** /**
@ -421,6 +497,22 @@ class UserApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function getUserByName($username) public function getUserByName($username)
{
list($response, $statusCode, $httpHeader) = $this->getUserByNameWithHttpInfo ($username);
return $response;
}
/**
* getUserByNameWithHttpInfo
*
* Get user by user name
*
* @param string $username The name that needs to be fetched. Use user1 for testing. (required)
* @return Array of \Swagger\Client\Model\User, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function getUserByNameWithHttpInfo($username)
{ {
// verify the required parameter 'username' is set // verify the required parameter 'username' is set
@ -463,19 +555,18 @@ class UserApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams, '\Swagger\Client\Model\User' $headerParams, '\Swagger\Client\Model\User'
); );
if (!$response) { if (!$response) {
return null; return array(null, $statusCode, $httpHeader);
} }
return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User', $httpHeader); return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User', $httpHeader), $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
@ -487,9 +578,6 @@ class UserApi
throw $e; throw $e;
} }
return null;
} }
/** /**
@ -503,6 +591,23 @@ class UserApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function updateUser($username, $body = null) public function updateUser($username, $body = null)
{
list($response, $statusCode, $httpHeader) = $this->updateUserWithHttpInfo ($username, $body);
return $response;
}
/**
* updateUserWithHttpInfo
*
* Updated user
*
* @param string $username name that need to be deleted (required)
* @param \Swagger\Client\Model\User $body Updated user object (optional)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function updateUserWithHttpInfo($username, $body = null)
{ {
// verify the required parameter 'username' is set // verify the required parameter 'username' is set
@ -549,21 +654,21 @@ class UserApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
/** /**
@ -576,6 +681,22 @@ class UserApi
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function deleteUser($username) public function deleteUser($username)
{
list($response, $statusCode, $httpHeader) = $this->deleteUserWithHttpInfo ($username);
return $response;
}
/**
* deleteUserWithHttpInfo
*
* Delete user
*
* @param string $username The name that needs to be deleted (required)
* @return Array of null, HTTP status code, HTTP response headers (array of strings)
* @throws \Swagger\Client\ApiException on non-2xx response
*/
public function deleteUserWithHttpInfo($username)
{ {
// verify the required parameter 'username' is set // verify the required parameter 'username' is set
@ -618,21 +739,21 @@ class UserApi
} }
// make the API Call // make the API Call
try try {
{ list($response, $statusCode, $httpHeader) = $this->apiClient->callApi(
list($response, $httpHeader) = $this->apiClient->callApi(
$resourcePath, $method, $resourcePath, $method,
$queryParams, $httpBody, $queryParams, $httpBody,
$headerParams $headerParams
); );
return array(null, $statusCode, $httpHeader);
} catch (ApiException $e) { } catch (ApiException $e) {
switch ($e->getCode()) { switch ($e->getCode()) {
} }
throw $e; throw $e;
} }
} }
} }

View File

@ -160,7 +160,7 @@ class ApiClient
if ($this->config->getCurlTimeout() != 0) { if ($this->config->getCurlTimeout() != 0) {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
} }
// return the result on success, rather than just TRUE // return the result on success, rather than just true
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
@ -216,7 +216,7 @@ class ApiClient
// Make the request // Make the request
$response = curl_exec($curl); $response = curl_exec($curl);
$http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$http_header = substr($response, 0, $http_header_size); $http_header = $this->http_parse_headers(substr($response, 0, $http_header_size));
$http_body = substr($response, $http_header_size); $http_body = substr($response, $http_header_size);
$response_info = curl_getinfo($curl); $response_info = curl_getinfo($curl);
@ -231,7 +231,7 @@ class ApiClient
} 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') { if ($responseType == '\SplFileObject') {
return array($http_body, $http_header); return array($http_body, $response_info['http_code'], $http_header);
} }
$data = json_decode($http_body); $data = json_decode($http_body);
@ -249,7 +249,7 @@ class ApiClient
$response_info['http_code'], $http_header, $data $response_info['http_code'], $http_header, $data
); );
} }
return array($data, $http_header); return array($data, $response_info['http_code'], $http_header);
} }
/** /**
@ -287,4 +287,52 @@ class ApiClient
return implode(',', $content_type); return implode(',', $content_type);
} }
} }
/**
* Return an array of HTTP response headers
*
* @param string $raw_headers A string of raw HTTP response headers
*
* @return string[] Array of HTTP response heaers
*/
protected function http_parse_headers($raw_headers)
{
// ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986
$headers = array();
$key = ''; // [+]
foreach(explode("\n", $raw_headers) as $i => $h)
{
$h = explode(':', $h, 2);
if (isset($h[1]))
{
if (!isset($headers[$h[0]]))
$headers[$h[0]] = trim($h[1]);
elseif (is_array($headers[$h[0]]))
{
// $tmp = array_merge($headers[$h[0]], array(trim($h[1]))); // [-]
// $headers[$h[0]] = $tmp; // [-]
$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1]))); // [+]
}
else
{
// $tmp = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [-]
// $headers[$h[0]] = $tmp; // [-]
$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [+]
}
$key = $h[0]; // [+]
}
else // [+]
{ // [+]
if (substr($h[0], 0, 1) == "\t") // [+]
$headers[$key] .= "\r\n\t".trim($h[0]); // [+]
elseif (!$key) // [+]
$headers[0] = trim($h[0]);trim($h[0]); // [+]
} // [+]
}
return $headers;
}
} }

View File

@ -198,7 +198,7 @@ class ObjectSerializer
$deserialized = $data; $deserialized = $data;
} elseif ($class === '\SplFileObject') { } elseif ($class === '\SplFileObject') {
// determine file name // determine file name
if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) { if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader['Content-Disposition'], $match)) {
$filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1]; $filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1];
} else { } else {
$filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), '');

View File

@ -105,6 +105,25 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
$this->assertSame($response->getTags()[0]->getName(), 'test php tag'); $this->assertSame($response->getTags()[0]->getName(), 'test php tag');
} }
// test getPetById with a Pet object (id 10005)
public function testGetPetByIdWithHttpInfo()
{
// initialize the API client without host
$pet_id = 10005; // ID of pet that needs to be fetched
$pet_api = new Swagger\Client\Api\PetAPI();
$pet_api->getApiClient()->getConfig()->setApiKey('api_key', '111222333444555');
// return Pet (model)
list($response, $status_code, $response_headers) = $pet_api->getPetByIdWithHttpInfo($pet_id);
$this->assertSame($response->getId(), $pet_id);
$this->assertSame($response->getName(), 'PHP Unit Test');
$this->assertSame($response->getCategory()->getId(), $pet_id);
$this->assertSame($response->getCategory()->getName(), 'test php category');
$this->assertSame($response->getTags()[0]->getId(), $pet_id);
$this->assertSame($response->getTags()[0]->getName(), 'test php tag');
$this->assertSame($status_code, 200);
$this->assertSame($response_headers['Content-Type'], 'application/json');
}
// test getPetByStatus and verify by the "id" of the response // test getPetByStatus and verify by the "id" of the response
public function testFindPetByStatus() public function testFindPetByStatus()
{ {
@ -149,7 +168,26 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
$this->assertSame($response->getName(), 'updatePet'); $this->assertSame($response->getName(), 'updatePet');
} }
// test updatePet and verify by the "id" of the response // test updatePetWithFormWithHttpInfo and verify by the "name" of the response
public function testUpdatePetWithFormWithHttpInfo()
{
// initialize the API client
$config = (new Swagger\Client\Configuration())->setHost('http://petstore.swagger.io/v2');
$api_client = new Swagger\Client\ApiClient($config);
$pet_id = 10001; // ID of pet that needs to be fetched
$pet_api = new Swagger\Client\Api\PetAPI($api_client);
// update Pet (form)
list($update_response, $status_code, $http_headers) = $pet_api->updatePetWithFormWithHttpInfo($pet_id, 'update pet with form with http info');
// return nothing (void)
$this->assertNull($update_response);
$this->assertSame($status_code, 200);
$this->assertSame($http_headers['Content-Type'], 'application/json');
$response = $pet_api->getPetById($pet_id);
$this->assertSame($response->getId(), $pet_id);
$this->assertSame($response->getName(), 'update pet with form with http info');
}
// test updatePetWithForm and verify by the "name" and "status" of the response
public function testUpdatePetWithForm() public function testUpdatePetWithForm()
{ {
// initialize the API client // initialize the API client