forked from loafle/openapi-generator-original
Merge branch 'wing328-php-improve-header' into develop_2.0
This commit is contained in:
commit
35f63b3f6a
@ -25,6 +25,8 @@ class APIClient {
|
|||||||
public static $PUT = "PUT";
|
public static $PUT = "PUT";
|
||||||
public static $DELETE = "DELETE";
|
public static $DELETE = "DELETE";
|
||||||
|
|
||||||
|
private static $default_header = array();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @var string timeout (second) of the HTTP request, by default set to 0, no timeout
|
* @var string timeout (second) of the HTTP request, by default set to 0, no timeout
|
||||||
*/
|
*/
|
||||||
@ -46,14 +48,45 @@ class APIClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the user agent of the API client
|
* add default header
|
||||||
*
|
*
|
||||||
* @param string $user_agent The user agent of the API client
|
* @param string $header_name header name (e.g. Token)
|
||||||
|
* @param string $header_value header value (e.g. 1z8wp3)
|
||||||
|
*/
|
||||||
|
public function addDefaultHeader($header_name, $header_value) {
|
||||||
|
if (!is_string($header_name))
|
||||||
|
throw new \InvalidArgumentException('Header name must be a string.');
|
||||||
|
|
||||||
|
self::$default_header[$header_name] = $header_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the default header
|
||||||
|
*
|
||||||
|
* @return array default header
|
||||||
|
*/
|
||||||
|
public function getDefaultHeader() {
|
||||||
|
return self::$default_header;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete the default header based on header name
|
||||||
|
*
|
||||||
|
* @param string $header_name header name (e.g. Token)
|
||||||
|
*/
|
||||||
|
public function deleteDefaultHeader($header_name) {
|
||||||
|
unset(self::$default_header[$header_name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the user agent of the api client
|
||||||
|
*
|
||||||
|
* @param string $user_agent the user agent of the api client
|
||||||
*/
|
*/
|
||||||
public function setUserAgent($user_agent) {
|
public function setUserAgent($user_agent) {
|
||||||
if (!is_string($user_agent)) {
|
if (!is_string($user_agent))
|
||||||
throw new Exception('User-agent must be a string.');
|
throw new \InvalidArgumentException('User-agent must be a string.');
|
||||||
}
|
|
||||||
$this->user_agent= $user_agent;
|
$this->user_agent= $user_agent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,9 +94,9 @@ class APIClient {
|
|||||||
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
|
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
|
||||||
*/
|
*/
|
||||||
public function setTimeout($seconds) {
|
public function setTimeout($seconds) {
|
||||||
if (!is_numeric($seconds)) {
|
if (!is_numeric($seconds))
|
||||||
throw new Exception('Timeout variable must be numeric.');
|
throw new \InvalidArgumentException('Timeout variable must be numeric.');
|
||||||
}
|
|
||||||
$this->curl_timeout = $seconds;
|
$this->curl_timeout = $seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +116,9 @@ class APIClient {
|
|||||||
# Allow API key from $headerParams to override default
|
# Allow API key from $headerParams to override default
|
||||||
$added_api_key = False;
|
$added_api_key = False;
|
||||||
if ($headerParams != null) {
|
if ($headerParams != null) {
|
||||||
|
# add default header
|
||||||
|
$headerParams = array_merge((array)self::$default_header, $headerParams);
|
||||||
|
|
||||||
foreach ($headerParams as $key => $val) {
|
foreach ($headerParams as $key => $val) {
|
||||||
$headers[] = "$key: $val";
|
$headers[] = "$key: $val";
|
||||||
if ($key == $this->headerName) {
|
if ($key == $this->headerName) {
|
||||||
@ -111,6 +147,7 @@ class APIClient {
|
|||||||
}
|
}
|
||||||
// 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);
|
||||||
|
|
||||||
if (! empty($queryParams)) {
|
if (! empty($queryParams)) {
|
||||||
@ -130,7 +167,7 @@ class APIClient {
|
|||||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||||
} else if ($method != self::$GET) {
|
} else if ($method != self::$GET) {
|
||||||
throw new Exception('Method ' . $method . ' is not recognized.');
|
throw new APIClientException('Method ' . $method . ' is not recognized.');
|
||||||
}
|
}
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
|
||||||
@ -261,7 +298,6 @@ class APIClient {
|
|||||||
* @param string $class class name is passed as a string
|
* @param string $class class name is passed as a string
|
||||||
* @return object an instance of $class
|
* @return object an instance of $class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static function deserialize($data, $class)
|
public static function deserialize($data, $class)
|
||||||
{
|
{
|
||||||
if (null === $data) {
|
if (null === $data) {
|
||||||
@ -304,5 +340,37 @@ class APIClient {
|
|||||||
return $deserialized;
|
return $deserialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the header 'Accept' based on an array of Accept provided
|
||||||
|
*
|
||||||
|
* @param array[string] $accept Array of header
|
||||||
|
* @return string Accept (e.g. application/json)
|
||||||
|
*/
|
||||||
|
public static function selectHeaderAccept($accept) {
|
||||||
|
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
|
||||||
|
return NULL;
|
||||||
|
} elseif (preg_grep("/application\/json/i", $accept)) {
|
||||||
|
return 'application/json';
|
||||||
|
} else {
|
||||||
|
return implode(',', $accept);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the content type based on an array of content-type provided
|
||||||
|
*
|
||||||
|
* @param array[string] content_type_array Array fo content-type
|
||||||
|
* @return string Content-Type (e.g. application/json)
|
||||||
|
*/
|
||||||
|
public static function selectHeaderContentType($content_type) {
|
||||||
|
if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) {
|
||||||
|
return 'application/json';
|
||||||
|
} elseif (preg_grep("/application\/json/i", $content_type)) {
|
||||||
|
return 'application/json';
|
||||||
|
} else {
|
||||||
|
return implode(',', $content_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class {{classname}} {
|
|||||||
{{#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 \Exception("Missing the required parameter ${{paramName}} when calling {{nickname}}");
|
throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}');
|
||||||
}
|
}
|
||||||
{{/required}}{{/allParams}}
|
{{/required}}{{/allParams}}
|
||||||
|
|
||||||
@ -54,12 +54,11 @@ class {{classname}} {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = '{{#produces}}{{mediaType}}{{#hasMore}}, {{/hasMore}}{{/produces}}';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array({{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}});
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}}));
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
{{#queryParams}}// query params
|
{{#queryParams}}// query params
|
||||||
if(${{paramName}} !== null) {
|
if(${{paramName}} !== null) {
|
||||||
|
@ -25,6 +25,8 @@ class APIClient {
|
|||||||
public static $PUT = "PUT";
|
public static $PUT = "PUT";
|
||||||
public static $DELETE = "DELETE";
|
public static $DELETE = "DELETE";
|
||||||
|
|
||||||
|
private static $default_header = array();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @var string timeout (second) of the HTTP request, by default set to 0, no timeout
|
* @var string timeout (second) of the HTTP request, by default set to 0, no timeout
|
||||||
*/
|
*/
|
||||||
@ -46,14 +48,45 @@ class APIClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the user agent of the API client
|
* add default header
|
||||||
*
|
*
|
||||||
* @param string $user_agent The user agent of the API client
|
* @param string $header_name header name (e.g. Token)
|
||||||
|
* @param string $header_value header value (e.g. 1z8wp3)
|
||||||
|
*/
|
||||||
|
public function addDefaultHeader($header_name, $header_value) {
|
||||||
|
if (!is_string($header_name))
|
||||||
|
throw new \InvalidArgumentException('Header name must be a string.');
|
||||||
|
|
||||||
|
self::$default_header[$header_name] = $header_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the default header
|
||||||
|
*
|
||||||
|
* @return array default header
|
||||||
|
*/
|
||||||
|
public function getDefaultHeader() {
|
||||||
|
return self::$default_header;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete the default header based on header name
|
||||||
|
*
|
||||||
|
* @param string $header_name header name (e.g. Token)
|
||||||
|
*/
|
||||||
|
public function deleteDefaultHeader($header_name) {
|
||||||
|
unset(self::$default_header[$header_name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set the user agent of the api client
|
||||||
|
*
|
||||||
|
* @param string $user_agent the user agent of the api client
|
||||||
*/
|
*/
|
||||||
public function setUserAgent($user_agent) {
|
public function setUserAgent($user_agent) {
|
||||||
if (!is_string($user_agent)) {
|
if (!is_string($user_agent))
|
||||||
throw new Exception('User-agent must be a string.');
|
throw new \InvalidArgumentException('User-agent must be a string.');
|
||||||
}
|
|
||||||
$this->user_agent= $user_agent;
|
$this->user_agent= $user_agent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,9 +94,9 @@ class APIClient {
|
|||||||
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
|
* @param integer $seconds Number of seconds before timing out [set to 0 for no timeout]
|
||||||
*/
|
*/
|
||||||
public function setTimeout($seconds) {
|
public function setTimeout($seconds) {
|
||||||
if (!is_numeric($seconds)) {
|
if (!is_numeric($seconds))
|
||||||
throw new Exception('Timeout variable must be numeric.');
|
throw new \InvalidArgumentException('Timeout variable must be numeric.');
|
||||||
}
|
|
||||||
$this->curl_timeout = $seconds;
|
$this->curl_timeout = $seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +116,9 @@ class APIClient {
|
|||||||
# Allow API key from $headerParams to override default
|
# Allow API key from $headerParams to override default
|
||||||
$added_api_key = False;
|
$added_api_key = False;
|
||||||
if ($headerParams != null) {
|
if ($headerParams != null) {
|
||||||
|
# add default header
|
||||||
|
$headerParams = array_merge((array)self::$default_header, $headerParams);
|
||||||
|
|
||||||
foreach ($headerParams as $key => $val) {
|
foreach ($headerParams as $key => $val) {
|
||||||
$headers[] = "$key: $val";
|
$headers[] = "$key: $val";
|
||||||
if ($key == $this->headerName) {
|
if ($key == $this->headerName) {
|
||||||
@ -111,6 +147,7 @@ class APIClient {
|
|||||||
}
|
}
|
||||||
// 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);
|
||||||
|
|
||||||
if (! empty($queryParams)) {
|
if (! empty($queryParams)) {
|
||||||
@ -130,7 +167,7 @@ class APIClient {
|
|||||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
|
||||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
|
||||||
} else if ($method != self::$GET) {
|
} else if ($method != self::$GET) {
|
||||||
throw new Exception('Method ' . $method . ' is not recognized.');
|
throw new APIClientException('Method ' . $method . ' is not recognized.');
|
||||||
}
|
}
|
||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
|
|
||||||
@ -261,7 +298,6 @@ class APIClient {
|
|||||||
* @param string $class class name is passed as a string
|
* @param string $class class name is passed as a string
|
||||||
* @return object an instance of $class
|
* @return object an instance of $class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static function deserialize($data, $class)
|
public static function deserialize($data, $class)
|
||||||
{
|
{
|
||||||
if (null === $data) {
|
if (null === $data) {
|
||||||
@ -304,5 +340,37 @@ class APIClient {
|
|||||||
return $deserialized;
|
return $deserialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the header 'Accept' based on an array of Accept provided
|
||||||
|
*
|
||||||
|
* @param array[string] $accept Array of header
|
||||||
|
* @return string Accept (e.g. application/json)
|
||||||
|
*/
|
||||||
|
public static function selectHeaderAccept($accept) {
|
||||||
|
if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) {
|
||||||
|
return NULL;
|
||||||
|
} elseif (preg_grep("/application\/json/i", $accept)) {
|
||||||
|
return 'application/json';
|
||||||
|
} else {
|
||||||
|
return implode(',', $accept);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the content type based on an array of content-type provided
|
||||||
|
*
|
||||||
|
* @param array[string] content_type_array Array fo content-type
|
||||||
|
* @return string Content-Type (e.g. application/json)
|
||||||
|
*/
|
||||||
|
public static function selectHeaderContentType($content_type) {
|
||||||
|
if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) {
|
||||||
|
return 'application/json';
|
||||||
|
} elseif (preg_grep("/application\/json/i", $content_type)) {
|
||||||
|
return 'application/json';
|
||||||
|
} else {
|
||||||
|
return implode(',', $content_type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,12 +48,11 @@ class PetApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array('application/json','application/xml');
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','application/xml'));
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -100,12 +99,11 @@ class PetApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array('application/json','application/xml');
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','application/xml'));
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -152,12 +150,11 @@ class PetApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
// query params
|
// query params
|
||||||
if($status !== null) {
|
if($status !== null) {
|
||||||
@ -209,12 +206,11 @@ class PetApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
// query params
|
// query params
|
||||||
if($tags !== null) {
|
if($tags !== null) {
|
||||||
@ -259,7 +255,7 @@ class PetApi {
|
|||||||
|
|
||||||
// verify the required parameter 'pet_id' is set
|
// verify the required parameter 'pet_id' is set
|
||||||
if ($pet_id === null) {
|
if ($pet_id === null) {
|
||||||
throw new \Exception("Missing the required parameter $pet_id when calling getPetById");
|
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -271,12 +267,11 @@ class PetApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -324,7 +319,7 @@ class PetApi {
|
|||||||
|
|
||||||
// verify the required parameter 'pet_id' is set
|
// verify the required parameter 'pet_id' is set
|
||||||
if ($pet_id === null) {
|
if ($pet_id === null) {
|
||||||
throw new \Exception("Missing the required parameter $pet_id when calling updatePetWithForm");
|
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -336,12 +331,11 @@ class PetApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array('application/x-www-form-urlencoded');
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/x-www-form-urlencoded'));
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -388,7 +382,7 @@ class PetApi {
|
|||||||
|
|
||||||
// verify the required parameter 'pet_id' is set
|
// verify the required parameter 'pet_id' is set
|
||||||
if ($pet_id === null) {
|
if ($pet_id === null) {
|
||||||
throw new \Exception("Missing the required parameter $pet_id when calling deletePet");
|
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -400,12 +394,11 @@ class PetApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
// header params
|
// header params
|
||||||
@ -450,7 +443,7 @@ class PetApi {
|
|||||||
|
|
||||||
// verify the required parameter 'pet_id' is set
|
// verify the required parameter 'pet_id' is set
|
||||||
if ($pet_id === null) {
|
if ($pet_id === null) {
|
||||||
throw new \Exception("Missing the required parameter $pet_id when calling uploadFile");
|
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -462,12 +455,11 @@ class PetApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array('multipart/form-data');
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('multipart/form-data'));
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,12 +47,11 @@ class StoreApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -101,12 +100,11 @@ class StoreApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -152,7 +150,7 @@ class StoreApi {
|
|||||||
|
|
||||||
// verify the required parameter 'order_id' is set
|
// verify the required parameter 'order_id' is set
|
||||||
if ($order_id === null) {
|
if ($order_id === null) {
|
||||||
throw new \Exception("Missing the required parameter $order_id when calling getOrderById");
|
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -164,12 +162,11 @@ class StoreApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -215,7 +212,7 @@ class StoreApi {
|
|||||||
|
|
||||||
// verify the required parameter 'order_id' is set
|
// verify the required parameter 'order_id' is set
|
||||||
if ($order_id === null) {
|
if ($order_id === null) {
|
||||||
throw new \Exception("Missing the required parameter $order_id when calling deleteOrder");
|
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -227,12 +224,11 @@ class StoreApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,12 +48,11 @@ class UserApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -100,12 +99,11 @@ class UserApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -152,12 +150,11 @@ class UserApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -205,12 +202,11 @@ class UserApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
// query params
|
// query params
|
||||||
if($username !== null) {
|
if($username !== null) {
|
||||||
@ -264,12 +260,11 @@ class UserApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -305,7 +300,7 @@ class UserApi {
|
|||||||
|
|
||||||
// verify the required parameter 'username' is set
|
// verify the required parameter 'username' is set
|
||||||
if ($username === null) {
|
if ($username === null) {
|
||||||
throw new \Exception("Missing the required parameter $username when calling getUserByName");
|
throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -317,12 +312,11 @@ class UserApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -369,7 +363,7 @@ class UserApi {
|
|||||||
|
|
||||||
// verify the required parameter 'username' is set
|
// verify the required parameter 'username' is set
|
||||||
if ($username === null) {
|
if ($username === null) {
|
||||||
throw new \Exception("Missing the required parameter $username when calling updateUser");
|
throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -381,12 +375,11 @@ class UserApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -430,7 +423,7 @@ class UserApi {
|
|||||||
|
|
||||||
// verify the required parameter 'username' is set
|
// verify the required parameter 'username' is set
|
||||||
if ($username === null) {
|
if ($username === null) {
|
||||||
throw new \Exception("Missing the required parameter $username when calling deleteUser");
|
throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -442,12 +435,11 @@ class UserApi {
|
|||||||
$queryParams = array();
|
$queryParams = array();
|
||||||
$headerParams = array();
|
$headerParams = array();
|
||||||
$formParams = array();
|
$formParams = array();
|
||||||
$_header_accept = 'application/json, application/xml';
|
$_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml'));
|
||||||
if ($_header_accept !== '') {
|
if (!is_null($_header_accept)) {
|
||||||
$headerParams['Accept'] = $_header_accept;
|
$headerParams['Accept'] = $_header_accept;
|
||||||
}
|
}
|
||||||
$_header_content_type = array();
|
$headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array());
|
||||||
$headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,6 +31,30 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
$add_response = $pet_api->addPet($new_pet);
|
$add_response = $pet_api->addPet($new_pet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// test static functions defined in APIClient
|
||||||
|
public function testAPIClient()
|
||||||
|
{
|
||||||
|
# test selectHeaderAccept
|
||||||
|
$this->assertSame('application/json', SwaggerClient\APIClient::selectHeaderAccept(array('application/xml','application/json')));
|
||||||
|
$this->assertSame(NULL, SwaggerClient\APIClient::selectHeaderAccept(array()));
|
||||||
|
$this->assertSame('application/yaml,application/xml', SwaggerClient\APIClient::selectHeaderAccept(array('application/yaml','application/xml')));
|
||||||
|
|
||||||
|
# test selectHeaderContentType
|
||||||
|
$this->assertSame('application/json', SwaggerClient\APIClient::selectHeaderContentType(array('application/xml','application/json')));
|
||||||
|
$this->assertSame('application/json', SwaggerClient\APIClient::selectHeaderContentType(array()));
|
||||||
|
$this->assertSame('application/yaml,application/xml', SwaggerClient\APIClient::selectHeaderContentType(array('application/yaml','application/xml')));
|
||||||
|
|
||||||
|
# test addDefaultHeader and getDefaultHeader
|
||||||
|
SwaggerClient\APIClient::addDefaultHeader('test1', 'value1');
|
||||||
|
SwaggerClient\APIClient::addDefaultHeader('test2', 200);
|
||||||
|
$this->assertSame('value1', SwaggerClient\APIClient::getDefaultHeader()['test1']);
|
||||||
|
$this->assertSame(200, SwaggerClient\APIClient::getDefaultHeader()['test2']);
|
||||||
|
|
||||||
|
# test deleteDefaultHeader
|
||||||
|
SwaggerClient\APIClient::deleteDefaultHeader('test2');
|
||||||
|
$this->assertFalse(isset(SwaggerClient\APIClient::getDefaultHeader()['test2']));
|
||||||
|
}
|
||||||
|
|
||||||
// test getPetById with a Pet object (id 10005)
|
// test getPetById with a Pet object (id 10005)
|
||||||
public function testGetPetById()
|
public function testGetPetById()
|
||||||
{
|
{
|
||||||
@ -77,7 +101,8 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
// create updated pet object
|
// create updated pet object
|
||||||
$updated_pet = new SwaggerClient\models\Pet;
|
$updated_pet = new SwaggerClient\models\Pet;
|
||||||
$updated_pet->id = $pet_id;
|
$updated_pet->id = $pet_id;
|
||||||
$updated_pet->status = "pending"; // new status
|
$updated_pet->name = 'updatePet'; // new name
|
||||||
|
$updated_pet->status = 'pending'; // new status
|
||||||
// update Pet (model/json)
|
// update Pet (model/json)
|
||||||
$update_response = $pet_api->updatePet($updated_pet);
|
$update_response = $pet_api->updatePet($updated_pet);
|
||||||
// return nothing (void)
|
// return nothing (void)
|
||||||
@ -86,6 +111,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
$response = $pet_api->getPetById($pet_id);
|
$response = $pet_api->getPetById($pet_id);
|
||||||
$this->assertSame($response->id, $pet_id);
|
$this->assertSame($response->id, $pet_id);
|
||||||
$this->assertSame($response->status, 'pending');
|
$this->assertSame($response->status, 'pending');
|
||||||
|
$this->assertSame($response->name, 'updatePet');
|
||||||
}
|
}
|
||||||
|
|
||||||
// test updatePet and verify by the "id" of the response
|
// test updatePet and verify by the "id" of the response
|
||||||
@ -96,15 +122,13 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
$pet_id = 10001; // ID of pet that needs to be fetched
|
$pet_id = 10001; // ID of pet that needs to be fetched
|
||||||
$pet_api = new SwaggerClient\PetAPI($api_client);
|
$pet_api = new SwaggerClient\PetAPI($api_client);
|
||||||
// update Pet (form)
|
// update Pet (form)
|
||||||
$update_response = $pet_api->updatePetWithForm($pet_id, null, 'sold');
|
$update_response = $pet_api->updatePetWithForm($pet_id, 'update pet with form', 'sold');
|
||||||
// return nothing (void)
|
// return nothing (void)
|
||||||
$this->assertSame($update_response, NULL);
|
$this->assertSame($update_response, NULL);
|
||||||
// TODO commented out for the time being since it's broken
|
$response = $pet_api->getPetById($pet_id);
|
||||||
// https://github.com/swagger-api/swagger-codegen/issues/656
|
$this->assertSame($response->id, $pet_id);
|
||||||
// verify updated Pet
|
$this->assertSame($response->name, 'update pet with form');
|
||||||
//$response = $pet_api->getPetById($pet_id);
|
$this->assertSame($response->status, 'sold');
|
||||||
//$this->assertSame($response->id, $pet_id);
|
|
||||||
//$this->assertSame($response->status, 'sold');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// test addPet and verify by the "id" and "name" of the response
|
// test addPet and verify by the "id" and "name" of the response
|
||||||
|
@ -4,6 +4,8 @@ require_once('SwaggerClient-php/SwaggerClient.php');
|
|||||||
|
|
||||||
// initialize the API client
|
// initialize the API client
|
||||||
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
|
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
|
||||||
|
$api_client->addDefaultHeader("test1", "value1");
|
||||||
|
|
||||||
$petId = 10005; // ID of pet that needs to be fetched
|
$petId = 10005; // ID of pet that needs to be fetched
|
||||||
try {
|
try {
|
||||||
$pet_api = new SwaggerClient\PetAPI($api_client);
|
$pet_api = new SwaggerClient\PetAPI($api_client);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user