forked from loafle/openapi-generator-original
add file response for php
This commit is contained in:
@@ -79,7 +79,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
typeMapping.put("boolean", "bool");
|
typeMapping.put("boolean", "bool");
|
||||||
typeMapping.put("date", "\\DateTime");
|
typeMapping.put("date", "\\DateTime");
|
||||||
typeMapping.put("datetime", "\\DateTime");
|
typeMapping.put("datetime", "\\DateTime");
|
||||||
typeMapping.put("file", "string");
|
typeMapping.put("file", "\\SplFileObject");
|
||||||
typeMapping.put("map", "map");
|
typeMapping.put("map", "map");
|
||||||
typeMapping.put("array", "array");
|
typeMapping.put("array", "array");
|
||||||
typeMapping.put("list", "array");
|
typeMapping.put("list", "array");
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class ApiClient {
|
|||||||
* @throws \{{invokerPackage}}\ApiException on a non 2xx response
|
* @throws \{{invokerPackage}}\ApiException on a non 2xx response
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams) {
|
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) {
|
||||||
|
|
||||||
$headers = array();
|
$headers = array();
|
||||||
|
|
||||||
@@ -174,6 +174,11 @@ class ApiClient {
|
|||||||
if ($response_info['http_code'] == 0) {
|
if ($response_info['http_code'] == 0) {
|
||||||
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
|
||||||
|
if ($responseType == 'SplFileObject') {
|
||||||
|
return array($http_body, $http_header);
|
||||||
|
}
|
||||||
|
|
||||||
$data = json_decode($http_body);
|
$data = json_decode($http_body);
|
||||||
if (json_last_error() > 0) { // if response is a string
|
if (json_last_error() > 0) { // if response is a string
|
||||||
$data = $http_body;
|
$data = $http_body;
|
||||||
|
|||||||
@@ -79,7 +79,11 @@ class ObjectSerializer {
|
|||||||
* @return string the form string
|
* @return string the form string
|
||||||
*/
|
*/
|
||||||
public function toFormValue($value) {
|
public function toFormValue($value) {
|
||||||
return $this->toString($value);
|
if ($value instanceof SplFileObject) {
|
||||||
|
return $value->getRealPath();
|
||||||
|
} else {
|
||||||
|
return $this->toString($value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,7 +108,7 @@ class ObjectSerializer {
|
|||||||
* @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 function deserialize($data, $class) {
|
public function deserialize($data, $class, $httpHeader=null) {
|
||||||
if (null === $data) {
|
if (null === $data) {
|
||||||
$deserialized = null;
|
$deserialized = null;
|
||||||
} elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int]
|
} elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int]
|
||||||
@@ -129,6 +133,24 @@ 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') {
|
||||||
|
# determine temp folder path
|
||||||
|
if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) {
|
||||||
|
$tmpFolderPath = sys_get_temp_dir();
|
||||||
|
} else {
|
||||||
|
$tmpFolderPath = Configuration::tempFolderPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
# determine file name
|
||||||
|
if (preg_match('/Content-Disposition: inline; filename=(.*)/i', $httpHeader, $match)) {
|
||||||
|
$filename = $tmpFolderPath.$match[1];
|
||||||
|
} else {
|
||||||
|
$filename = tempnam($tmpFolderPath, '');
|
||||||
|
}
|
||||||
|
$deserialized = new \SplFileObject($filename, "w");
|
||||||
|
$byte_written = $deserialized->fwrite($data);
|
||||||
|
error_log("[INFO] Written $byte_written to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$instance = new $class();
|
$instance = new $class();
|
||||||
foreach ($instance::$swaggerTypes as $property => $type) {
|
foreach ($instance::$swaggerTypes as $property => $type) {
|
||||||
@@ -148,4 +170,4 @@ class ObjectSerializer {
|
|||||||
|
|
||||||
return $deserialized;
|
return $deserialized;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,13 +134,13 @@ class {{classname}} {
|
|||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams{{#returnType}}, '{{returnType}}'{{/returnType}});
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
switch ($e->getCode()) { {{#responses}}{{#dataType}}
|
switch ($e->getCode()) { {{#responses}}{{#dataType}}
|
||||||
case {{code}}:
|
case {{code}}:
|
||||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}');
|
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}', $httpHeader);
|
||||||
$e->setResponseObject($data);
|
$e->setResponseObject($data);
|
||||||
break;{{/dataType}}{{/responses}}
|
break;{{/dataType}}{{/responses}}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,4 +263,18 @@ class Configuration {
|
|||||||
public static function setDefaultConfiguration(Configuration $config) {
|
public static function setDefaultConfiguration(Configuration $config) {
|
||||||
self::$defaultConfiguration = $config;
|
self::$defaultConfiguration = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the report for debuggin
|
||||||
|
*/
|
||||||
|
public static function toDebugReport() {
|
||||||
|
$report = "PHP SDK ({{invokerPackage}}) Debug Report:\n";
|
||||||
|
$report .= " OS: ".php_uname()."\n";
|
||||||
|
$report .= " PHP Version: ".phpversion()."\n";
|
||||||
|
$report .= " Swagger Spec Version: {{version}}\n";
|
||||||
|
$report .= " SDK Package Version: {{version}}\n";
|
||||||
|
|
||||||
|
return $report;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,9 +100,9 @@ class {{classname}} implements ArrayAccess {
|
|||||||
|
|
||||||
public function __toString() {
|
public function __toString() {
|
||||||
if (defined('JSON_PRETTY_PRINT')) {
|
if (defined('JSON_PRETTY_PRINT')) {
|
||||||
return json_encode($this, JSON_PRETTY_PRINT);
|
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
|
||||||
} else {
|
} else {
|
||||||
return json_encode($this);
|
return json_encode(get_object_vars($this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $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,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -231,13 +231,13 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams, '\Swagger\Client\Model\Pet[]');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
switch ($e->getCode()) {
|
switch ($e->getCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]');
|
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader);
|
||||||
$e->setResponseObject($data);
|
$e->setResponseObject($data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -302,13 +302,13 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams, '\Swagger\Client\Model\Pet[]');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
switch ($e->getCode()) {
|
switch ($e->getCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]');
|
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader);
|
||||||
$e->setResponseObject($data);
|
$e->setResponseObject($data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -375,9 +375,6 @@ class PetApi {
|
|||||||
$httpBody = $formParams;
|
$httpBody = $formParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO support oauth
|
|
||||||
|
|
||||||
|
|
||||||
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
|
$apiKey = $this->apiClient->getApiKeyWithPrefix('api_key');
|
||||||
if (isset($apiKey)) {
|
if (isset($apiKey)) {
|
||||||
$headerParams['api_key'] = $apiKey;
|
$headerParams['api_key'] = $apiKey;
|
||||||
@@ -385,15 +382,18 @@ class PetApi {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//TODO support oauth
|
||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams, '\Swagger\Client\Model\Pet');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
switch ($e->getCode()) {
|
switch ($e->getCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet');
|
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet', $httpHeader);
|
||||||
$e->setResponseObject($data);
|
$e->setResponseObject($data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -473,7 +473,7 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $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,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -563,7 +563,7 @@ class PetApi {
|
|||||||
*
|
*
|
||||||
* @param int $pet_id ID of pet to update (required)
|
* @param int $pet_id ID of pet to update (required)
|
||||||
* @param string $additional_metadata Additional data to pass to server (required)
|
* @param string $additional_metadata Additional data to pass to server (required)
|
||||||
* @param string $file file to upload (required)
|
* @param \SplFileObject $file file to upload (required)
|
||||||
* @return void
|
* @return void
|
||||||
* @throws \Swagger\Client\ApiException on non-2xx response
|
* @throws \Swagger\Client\ApiException on non-2xx response
|
||||||
*/
|
*/
|
||||||
@@ -619,7 +619,7 @@ class PetApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
|
|||||||
@@ -109,13 +109,13 @@ class StoreApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams, 'map[string,int]');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
switch ($e->getCode()) {
|
switch ($e->getCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]');
|
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]', $httpHeader);
|
||||||
$e->setResponseObject($data);
|
$e->setResponseObject($data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -178,13 +178,13 @@ class StoreApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams, '\Swagger\Client\Model\Order');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
switch ($e->getCode()) {
|
switch ($e->getCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order');
|
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader);
|
||||||
$e->setResponseObject($data);
|
$e->setResponseObject($data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -253,13 +253,13 @@ class StoreApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams, '\Swagger\Client\Model\Order');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
switch ($e->getCode()) {
|
switch ($e->getCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order');
|
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader);
|
||||||
$e->setResponseObject($data);
|
$e->setResponseObject($data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -328,7 +328,7 @@ class StoreApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $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,
|
$response = $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,
|
$response = $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,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -284,13 +284,13 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams, 'string');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
switch ($e->getCode()) {
|
switch ($e->getCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'string');
|
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'string', $httpHeader);
|
||||||
$e->setResponseObject($data);
|
$e->setResponseObject($data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -348,7 +348,7 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
@@ -412,13 +412,13 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams, '\Swagger\Client\Model\User');
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
switch ($e->getCode()) {
|
switch ($e->getCode()) {
|
||||||
case 200:
|
case 200:
|
||||||
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\User');
|
$data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\User', $httpHeader);
|
||||||
$e->setResponseObject($data);
|
$e->setResponseObject($data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -492,7 +492,7 @@ class UserApi {
|
|||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
try {
|
try {
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $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,
|
$response = $this->apiClient->callApi($resourcePath, $method,
|
||||||
$queryParams, $httpBody,
|
$queryParams, $httpBody,
|
||||||
$headerParams);
|
$headerParams);
|
||||||
} catch (ApiException $e) {
|
} catch (ApiException $e) {
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class ApiClient {
|
|||||||
* @throws \Swagger\Client\ApiException on a non 2xx response
|
* @throws \Swagger\Client\ApiException on a non 2xx response
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams) {
|
public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) {
|
||||||
|
|
||||||
$headers = array();
|
$headers = array();
|
||||||
|
|
||||||
@@ -174,6 +174,11 @@ class ApiClient {
|
|||||||
if ($response_info['http_code'] == 0) {
|
if ($response_info['http_code'] == 0) {
|
||||||
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
|
||||||
|
if ($responseType == 'SplFileObject') {
|
||||||
|
return array($http_body, $http_header);
|
||||||
|
}
|
||||||
|
|
||||||
$data = json_decode($http_body);
|
$data = json_decode($http_body);
|
||||||
if (json_last_error() > 0) { // if response is a string
|
if (json_last_error() > 0) { // if response is a string
|
||||||
$data = $http_body;
|
$data = $http_body;
|
||||||
|
|||||||
@@ -263,4 +263,18 @@ class Configuration {
|
|||||||
public static function setDefaultConfiguration(Configuration $config) {
|
public static function setDefaultConfiguration(Configuration $config) {
|
||||||
self::$defaultConfiguration = $config;
|
self::$defaultConfiguration = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return the report for debuggin
|
||||||
|
*/
|
||||||
|
public static function toDebugReport() {
|
||||||
|
$report = "PHP SDK (Swagger\Client) Debug Report:\n";
|
||||||
|
$report .= " OS: ".php_uname()."\n";
|
||||||
|
$report .= " PHP Version: ".phpversion()."\n";
|
||||||
|
$report .= " Swagger Spec Version: 1.0.0\n";
|
||||||
|
$report .= " SDK Package Version: 1.0.0\n";
|
||||||
|
|
||||||
|
return $report;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ class Category implements ArrayAccess {
|
|||||||
|
|
||||||
public function __toString() {
|
public function __toString() {
|
||||||
if (defined('JSON_PRETTY_PRINT')) {
|
if (defined('JSON_PRETTY_PRINT')) {
|
||||||
return json_encode($this, JSON_PRETTY_PRINT);
|
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
|
||||||
} else {
|
} else {
|
||||||
return json_encode($this);
|
return json_encode(get_object_vars($this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,9 +223,9 @@ class Order implements ArrayAccess {
|
|||||||
|
|
||||||
public function __toString() {
|
public function __toString() {
|
||||||
if (defined('JSON_PRETTY_PRINT')) {
|
if (defined('JSON_PRETTY_PRINT')) {
|
||||||
return json_encode($this, JSON_PRETTY_PRINT);
|
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
|
||||||
} else {
|
} else {
|
||||||
return json_encode($this);
|
return json_encode(get_object_vars($this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,9 +223,9 @@ class Pet implements ArrayAccess {
|
|||||||
|
|
||||||
public function __toString() {
|
public function __toString() {
|
||||||
if (defined('JSON_PRETTY_PRINT')) {
|
if (defined('JSON_PRETTY_PRINT')) {
|
||||||
return json_encode($this, JSON_PRETTY_PRINT);
|
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
|
||||||
} else {
|
} else {
|
||||||
return json_encode($this);
|
return json_encode(get_object_vars($this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ class Tag implements ArrayAccess {
|
|||||||
|
|
||||||
public function __toString() {
|
public function __toString() {
|
||||||
if (defined('JSON_PRETTY_PRINT')) {
|
if (defined('JSON_PRETTY_PRINT')) {
|
||||||
return json_encode($this, JSON_PRETTY_PRINT);
|
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
|
||||||
} else {
|
} else {
|
||||||
return json_encode($this);
|
return json_encode(get_object_vars($this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -275,9 +275,9 @@ class User implements ArrayAccess {
|
|||||||
|
|
||||||
public function __toString() {
|
public function __toString() {
|
||||||
if (defined('JSON_PRETTY_PRINT')) {
|
if (defined('JSON_PRETTY_PRINT')) {
|
||||||
return json_encode($this, JSON_PRETTY_PRINT);
|
return json_encode(get_object_vars($this), JSON_PRETTY_PRINT);
|
||||||
} else {
|
} else {
|
||||||
return json_encode($this);
|
return json_encode(get_object_vars($this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,7 +79,11 @@ class ObjectSerializer {
|
|||||||
* @return string the form string
|
* @return string the form string
|
||||||
*/
|
*/
|
||||||
public function toFormValue($value) {
|
public function toFormValue($value) {
|
||||||
return $this->toString($value);
|
if ($value instanceof SplFileObject) {
|
||||||
|
return $value->getRealPath();
|
||||||
|
} else {
|
||||||
|
return $this->toString($value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,7 +108,7 @@ class ObjectSerializer {
|
|||||||
* @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 function deserialize($data, $class) {
|
public function deserialize($data, $class, $httpHeader=null) {
|
||||||
if (null === $data) {
|
if (null === $data) {
|
||||||
$deserialized = null;
|
$deserialized = null;
|
||||||
} elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int]
|
} elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int]
|
||||||
@@ -129,6 +133,24 @@ 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') {
|
||||||
|
# determine temp folder path
|
||||||
|
if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) {
|
||||||
|
$tmpFolderPath = sys_get_temp_dir();
|
||||||
|
} else {
|
||||||
|
$tmpFolderPath = Configuration::tempFolderPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
# determine file name
|
||||||
|
if (preg_match('/Content-Disposition: inline; filename=(.*)/i', $httpHeader, $match)) {
|
||||||
|
$filename = $tmpFolderPath.$match[1];
|
||||||
|
} else {
|
||||||
|
$filename = tempnam($tmpFolderPath, '');
|
||||||
|
}
|
||||||
|
$deserialized = new \SplFileObject($filename, "w");
|
||||||
|
$byte_written = $deserialized->fwrite($data);
|
||||||
|
error_log("[INFO] Written $byte_written to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$instance = new $class();
|
$instance = new $class();
|
||||||
foreach ($instance::$swaggerTypes as $property => $type) {
|
foreach ($instance::$swaggerTypes as $property => $type) {
|
||||||
@@ -148,4 +170,4 @@ class ObjectSerializer {
|
|||||||
|
|
||||||
return $deserialized;
|
return $deserialized;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
main: Contrib
|
|
||||||
title: php-coveralls
|
|
||||||
internal: yes
|
|
||||||
todo: yes
|
|
||||||
wipeout: yes
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<ruleset name="PHP">
|
|
||||||
<description>The coding standard for standard PHP application</description>
|
|
||||||
<exclude-pattern>*/img/*</exclude-pattern>
|
|
||||||
<exclude-pattern>*/images/*</exclude-pattern>
|
|
||||||
<exclude-pattern>*/less/*</exclude-pattern>
|
|
||||||
<exclude-pattern>*/css/*</exclude-pattern>
|
|
||||||
<exclude-pattern>*/js/*</exclude-pattern>
|
|
||||||
<exclude-pattern>*.html</exclude-pattern>
|
|
||||||
<exclude-pattern>*.twig</exclude-pattern>
|
|
||||||
<exclude-pattern>*.yml</exclude-pattern>
|
|
||||||
<exclude-pattern>*.xml</exclude-pattern>
|
|
||||||
<exclude-pattern>*.txt</exclude-pattern>
|
|
||||||
<exclude-pattern>*.less</exclude-pattern>
|
|
||||||
<exclude-pattern>*.css</exclude-pattern>
|
|
||||||
<exclude-pattern>*.js</exclude-pattern>
|
|
||||||
<exclude-pattern>*.jpg</exclude-pattern>
|
|
||||||
<exclude-pattern>*.jpeg</exclude-pattern>
|
|
||||||
<exclude-pattern>*.png</exclude-pattern>
|
|
||||||
<exclude-pattern>*.gif</exclude-pattern>
|
|
||||||
|
|
||||||
<!-- Include the whole PSR-2 standard -->
|
|
||||||
<rule ref="PSR2"/>
|
|
||||||
<rule ref="Generic.Files.LineLength">
|
|
||||||
<properties>
|
|
||||||
<property name="lineLimit" value="140"/>
|
|
||||||
<property name="absoluteLineLimit" value="0"/>
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
</ruleset>
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<ruleset name="My first PHPMD rule set"
|
|
||||||
xmlns="http://pmd.sf.net/ruleset/1.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
|
|
||||||
http://pmd.sf.net/ruleset_xml_schema.xsd"
|
|
||||||
xsi:noNamespaceSchemaLocation="
|
|
||||||
http://pmd.sf.net/ruleset_xml_schema.xsd">
|
|
||||||
|
|
||||||
<description>My custom rule set that checks my code...</description>
|
|
||||||
|
|
||||||
<!-- Import the entire unused code rule set -->
|
|
||||||
<rule ref="rulesets/unusedcode.xml" />
|
|
||||||
<rule ref="rulesets/design.xml" />
|
|
||||||
|
|
||||||
<rule ref="rulesets/naming.xml">
|
|
||||||
<exclude name="ShortVariable"/>
|
|
||||||
<exclude name="LongVariable"/>
|
|
||||||
</rule>
|
|
||||||
<rule ref="rulesets/naming.xml/ShortVariable">
|
|
||||||
<properties>
|
|
||||||
<property name="minimum" value="2" />
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
<rule ref="rulesets/naming.xml/LongVariable">
|
|
||||||
<properties>
|
|
||||||
<property name="maximum" value="30" />
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
|
|
||||||
<rule ref="rulesets/codesize.xml">
|
|
||||||
<exclude name="TooManyMethods"/>
|
|
||||||
<exclude name="ExcessiveClassComplexity"/>
|
|
||||||
</rule>
|
|
||||||
<rule ref="rulesets/codesize.xml/TooManyMethods">
|
|
||||||
<properties>
|
|
||||||
<property name="maxmethods" value="20" />
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
|
|
||||||
<properties>
|
|
||||||
<property name="maximum" value="70" />
|
|
||||||
</properties>
|
|
||||||
</rule>
|
|
||||||
</ruleset>
|
|
||||||
@@ -19,7 +19,7 @@ try {
|
|||||||
//$pet_api = new SwaggerClient\PetAPI($api_client);
|
//$pet_api = new SwaggerClient\PetAPI($api_client);
|
||||||
$pet_api = new Swagger\Client\Api\PetAPI();
|
$pet_api = new Swagger\Client\Api\PetAPI();
|
||||||
// test default header
|
// test default header
|
||||||
$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
|
//$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
|
||||||
// return Pet (model)
|
// return Pet (model)
|
||||||
$response = $pet_api->getPetById($petId);
|
$response = $pet_api->getPetById($petId);
|
||||||
// to test __toString()
|
// to test __toString()
|
||||||
@@ -28,26 +28,26 @@ try {
|
|||||||
// add pet (post json)
|
// add pet (post json)
|
||||||
$new_pet_id = 10005;
|
$new_pet_id = 10005;
|
||||||
$new_pet = new Swagger\Client\Model\Pet;
|
$new_pet = new Swagger\Client\Model\Pet;
|
||||||
$new_pet->id = $new_pet_id;
|
$new_pet->setId($new_pet_id);
|
||||||
$new_pet->name = "PHP Unit Test";
|
$new_pet->setName("PHP Unit Test");
|
||||||
// new tag
|
// new tag
|
||||||
$tag= new Swagger\Client\Model\Tag;
|
$tag= new Swagger\Client\Model\Tag;
|
||||||
$tag->id = $new_pet_id; // use the same id as pet
|
$tag->setId($new_pet_id); // use the same id as pet
|
||||||
//$tag->name = "test php tag";
|
//$tag->name = "test php tag";
|
||||||
// new category
|
// new category
|
||||||
$category = new Swagger\Client\Model\Category;
|
$category = new Swagger\Client\Model\Category;
|
||||||
$category->id = 0; // use the same id as pet
|
$category->setId(10005); // use the same id as pet
|
||||||
//$category->name = "test php category";
|
//$category->name = "test php category";
|
||||||
|
|
||||||
$new_pet->tags = array($tag);
|
$new_pet->setTags(array($tag));
|
||||||
$new_pet->category = $category;
|
$new_pet->setCategory($category);
|
||||||
|
|
||||||
$pet_api = new Swagger\Client\Api\PetAPI();
|
$pet_api = new Swagger\Client\Api\PetAPI();
|
||||||
// add a new pet (model)
|
// add a new pet (model)
|
||||||
$add_response = $pet_api->addPet($new_pet);
|
$add_response = $pet_api->addPet($new_pet);
|
||||||
|
|
||||||
// test upload file (exception)
|
// test upload file (exception)
|
||||||
$upload_response = $pet_api->uploadFile($petId, "test meta", NULL);
|
//$upload_response = $pet_api->uploadFile($petId, "test meta", NULL);
|
||||||
|
|
||||||
} catch (Swagger\Client\Exception $e) {
|
} catch (Swagger\Client\Exception $e) {
|
||||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user