diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PhpClientCodegen.java index 55d358154f8..dd50d623e5f 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PhpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PhpClientCodegen.java @@ -85,8 +85,8 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { supportingFiles.add(new SupportingFile("composer.mustache", packagePath, "composer.json")); supportingFiles.add(new SupportingFile("configuration.mustache", packagePath + "/lib", "Configuration.php")); - supportingFiles.add(new SupportingFile("APIClient.mustache", packagePath + "/lib", "APIClient.php")); - supportingFiles.add(new SupportingFile("APIClientException.mustache", packagePath + "/lib", "APIClientException.php")); + supportingFiles.add(new SupportingFile("ApiClient.mustache", packagePath + "/lib", "ApiClient.php")); + supportingFiles.add(new SupportingFile("ApiException.mustache", packagePath + "/lib", "ApiException.php")); supportingFiles.add(new SupportingFile("require.mustache", packagePath, invokerPackage + ".php")); } diff --git a/modules/swagger-codegen/src/main/resources/php/APIClient.mustache b/modules/swagger-codegen/src/main/resources/php/APIClient.mustache index 88954ffad3b..cadce36f64d 100644 --- a/modules/swagger-codegen/src/main/resources/php/APIClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/APIClient.mustache @@ -17,7 +17,7 @@ namespace {{invokerPackage}}; -class APIClient { +class ApiClient { public static $PATCH = "PATCH"; public static $POST = "POST"; @@ -173,7 +173,7 @@ class APIClient { * @param array $headerParams parameters to be place in request header * @return mixed */ - public function callAPI($resourcePath, $method, $queryParams, $postData, + public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $authSettings) { $headers = array(); @@ -228,7 +228,7 @@ class APIClient { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); } else if ($method != self::$GET) { - throw new APIClientException('Method ' . $method . ' is not recognized.'); + throw new ApiException('Method ' . $method . ' is not recognized.'); } curl_setopt($curl, CURLOPT_URL, $url); @@ -256,7 +256,7 @@ class APIClient { // Handle the response if ($response_info['http_code'] == 0) { - throw new APIClientException("TIMEOUT: api call to " . $url . + throw new ApiException("TIMEOUT: api call to " . $url . " took more than 5s to return", 0, $response_info, $response); } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { $data = json_decode($response); @@ -264,12 +264,12 @@ class APIClient { $data = $response; } } else if ($response_info['http_code'] == 401) { - throw new APIClientException("Unauthorized API request to " . $url . + throw new ApiException("Unauthorized API request to " . $url . ": " . serialize($response), 0, $response_info, $response); } else if ($response_info['http_code'] == 404) { $data = null; } else { - throw new APIClientException("Can't connect to the api: " . $url . + throw new ApiException("Can't connect to the api: " . $url . " response code: " . $response_info['http_code'], 0, $response_info, $response); } diff --git a/modules/swagger-codegen/src/main/resources/php/APIClientException.mustache b/modules/swagger-codegen/src/main/resources/php/ApiException.mustache similarity index 95% rename from modules/swagger-codegen/src/main/resources/php/APIClientException.mustache rename to modules/swagger-codegen/src/main/resources/php/ApiException.mustache index 3cf74d69288..58a75eabeb1 100644 --- a/modules/swagger-codegen/src/main/resources/php/APIClientException.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiException.mustache @@ -19,7 +19,7 @@ namespace {{invokerPackage}}; use \Exception; -class APIClientException extends Exception { +class ApiException extends Exception { protected $response, $response_info; public function __construct($message="", $code=0, $response_info=null, $response=null) { diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 1c32eeb01c5..6b4e6e3db16 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -28,7 +28,7 @@ class {{classname}} { function __construct($apiClient = null) { if (null === $apiClient) { if (Configuration::$apiClient === null) { - Configuration::$apiClient = new APIClient(); // create a new API client if not present + Configuration::$apiClient = new ApiClient(); // create a new API client if not present $this->apiClient = Configuration::$apiClient; } else @@ -38,7 +38,7 @@ class {{classname}} { } } - private $apiClient; // instance of the APIClient + private $apiClient; // instance of the ApiClient /** * get the API client diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache index 5528e8076f3..ea5f813b5e0 100644 --- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache @@ -31,7 +31,7 @@ class Configuration { public static $username = ''; public static $password = ''; - // an instance of APIClient + // an instance of ApiClient public static $apiClient; // debugging @@ -39,11 +39,11 @@ class Configuration { public static $debug_file = 'php://output'; //output debug log to STDOUT by default /* - * manually initalize API client + * manually initalize Api client */ public static function init() { if (self::$apiClient === null) - self::$apiClient = new APIClient(); + self::$apiClient = new ApiClient(); } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php index 3e9119003d7..5b3289b5a29 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php @@ -17,7 +17,7 @@ namespace SwaggerClient; -class APIClient { +class ApiClient { public static $PATCH = "PATCH"; public static $POST = "POST"; @@ -178,7 +178,7 @@ class APIClient { * @param array $headerParams parameters to be place in request header * @return mixed */ - public function callAPI($resourcePath, $method, $queryParams, $postData, + public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $authSettings) { $headers = array(); @@ -233,7 +233,7 @@ class APIClient { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); } else if ($method != self::$GET) { - throw new APIClientException('Method ' . $method . ' is not recognized.'); + throw new ApiException('Method ' . $method . ' is not recognized.'); } curl_setopt($curl, CURLOPT_URL, $url); @@ -261,7 +261,7 @@ class APIClient { // Handle the response if ($response_info['http_code'] == 0) { - throw new APIClientException("TIMEOUT: api call to " . $url . + throw new ApiException("TIMEOUT: api call to " . $url . " took more than 5s to return", 0, $response_info, $response); } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { $data = json_decode($response); @@ -269,12 +269,12 @@ class APIClient { $data = $response; } } else if ($response_info['http_code'] == 401) { - throw new APIClientException("Unauthorized API request to " . $url . + throw new ApiException("Unauthorized API request to " . $url . ": " . serialize($response), 0, $response_info, $response); } else if ($response_info['http_code'] == 404) { $data = null; } else { - throw new APIClientException("Can't connect to the api: " . $url . + throw new ApiException("Can't connect to the api: " . $url . " response code: " . $response_info['http_code'], 0, $response_info, $response); } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/APIClientException.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php similarity index 95% rename from samples/client/petstore/php/SwaggerClient-php/lib/APIClientException.php rename to samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php index 8d83da0186e..8b8244718ee 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/APIClientException.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php @@ -19,7 +19,7 @@ namespace SwaggerClient; use \Exception; -class APIClientException extends Exception { +class ApiException extends Exception { protected $response, $response_info; public function __construct($message="", $code=0, $response_info=null, $response=null) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php index fe4cbc59998..a3412c93eb6 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php @@ -31,7 +31,7 @@ class Configuration { public static $username = ''; public static $password = ''; - // an instance of APIClient + // an instance of ApiClient public static $apiClient; // debugging @@ -39,11 +39,11 @@ class Configuration { public static $debug_file = 'php://output'; //output debug log to STDOUT by default /* - * manually initalize API client + * manually initalize Api client */ public static function init() { if (self::$apiClient === null) - self::$apiClient = new APIClient(); + self::$apiClient = new ApiClient(); } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php index 9456f42bc15..338646bfefe 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php @@ -27,7 +27,7 @@ class PetApi { function __construct($apiClient = null) { if (null === $apiClient) { if (Configuration::$apiClient === null) { - Configuration::$apiClient = new APIClient(); // create a new API client if not present + Configuration::$apiClient = new ApiClient(); // create a new API client if not present $this->apiClient = Configuration::$apiClient; } else @@ -37,7 +37,7 @@ class PetApi { } } - private $apiClient; // instance of the APIClient + private $apiClient; // instance of the ApiClient /** * get the API client diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php index 629201965dc..73a060f421d 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php @@ -27,7 +27,7 @@ class StoreApi { function __construct($apiClient = null) { if (null === $apiClient) { if (Configuration::$apiClient === null) { - Configuration::$apiClient = new APIClient(); // create a new API client if not present + Configuration::$apiClient = new ApiClient(); // create a new API client if not present $this->apiClient = Configuration::$apiClient; } else @@ -37,7 +37,7 @@ class StoreApi { } } - private $apiClient; // instance of the APIClient + private $apiClient; // instance of the ApiClient /** * get the API client diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php index 0f4a1bf2dac..1e4f7dbc293 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php @@ -27,7 +27,7 @@ class UserApi { function __construct($apiClient = null) { if (null === $apiClient) { if (Configuration::$apiClient === null) { - Configuration::$apiClient = new APIClient(); // create a new API client if not present + Configuration::$apiClient = new ApiClient(); // create a new API client if not present $this->apiClient = Configuration::$apiClient; } else @@ -37,7 +37,7 @@ class UserApi { } } - private $apiClient; // instance of the APIClient + private $apiClient; // instance of the ApiClient /** * get the API client diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index 85f0c900a6c..d02b8e74558 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -11,7 +11,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase //SwaggerClient\Configuration::$debug = true; // skip initializing the API client as it should be automatic - //$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2'); + //$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); // new pet $new_pet_id = 10005; $new_pet = new SwaggerClient\models\Pet; @@ -34,36 +34,36 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $add_response = $pet_api->addPet($new_pet); } - // test static functions defined in APIClient - public function testAPIClient() + // 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'))); + $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'))); + $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); - $defaultHeader = SwaggerClient\APIClient::getDefaultHeader(); + SwaggerClient\ApiClient::addDefaultHeader('test1', 'value1'); + SwaggerClient\ApiClient::addDefaultHeader('test2', 200); + $defaultHeader = SwaggerClient\ApiClient::getDefaultHeader(); $this->assertSame('value1', $defaultHeader['test1']); $this->assertSame(200, $defaultHeader['test2']); // test deleteDefaultHeader - SwaggerClient\APIClient::deleteDefaultHeader('test2'); - $defaultHeader = SwaggerClient\APIClient::getDefaultHeader(); + SwaggerClient\ApiClient::deleteDefaultHeader('test2'); + $defaultHeader = SwaggerClient\ApiClient::getDefaultHeader(); $this->assertFalse(isset($defaultHeader['test2'])); $pet_api = new SwaggerClient\PetAPI(); $pet_api2 = new SwaggerClient\PetAPI(); - $apiClient3 = new SwaggerClient\APIClient(); + $apiClient3 = new SwaggerClient\ApiClient(); $apiClient3->setUserAgent = 'api client 3'; - $apiClient4 = new SwaggerClient\APIClient(); + $apiClient4 = new SwaggerClient\ApiClient(); $apiClient4->setUserAgent = 'api client 4'; $pet_api3 = new SwaggerClient\PetAPI($apiClient3); @@ -88,7 +88,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testGetPetById() { // initialize the API client without host - $api_client = new SwaggerClient\APIClient(); + $api_client = new SwaggerClient\ApiClient(); SwaggerClient\Configuration::$apiKey['api_key'] = '111222333444555'; $pet_id = 10005; // ID of pet that needs to be fetched $pet_api = new SwaggerClient\PetAPI($api_client); @@ -106,7 +106,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testFindPetByStatus() { // initialize the API client - $api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2'); + $api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); $pet_api = new SwaggerClient\PetAPI($api_client); // return Pet (model) $response = $pet_api->findPetsByStatus("available"); @@ -125,7 +125,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testUpdatePet() { // initialize the API client - $api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2'); + $api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); $pet_id = 10001; // ID of pet that needs to be fetched $pet_api = new SwaggerClient\PetAPI($api_client); // create updated pet object @@ -148,7 +148,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testUpdatePetWithForm() { // initialize the API client - $api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2'); + $api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); $pet_id = 10001; // ID of pet that needs to be fetched $pet_api = new SwaggerClient\PetAPI($api_client); // update Pet (form) @@ -165,7 +165,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testAddPet() { // initialize the API client - $api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2'); + $api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); $new_pet_id = 10001; $new_pet = new SwaggerClient\models\Pet; $new_pet->id = $new_pet_id; @@ -185,7 +185,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testUploadFile() { // initialize the API client - $api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2'); + $api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); $pet_api = new SwaggerClient\PetAPI($api_client); // upload file $pet_id = 10001; diff --git a/samples/client/petstore/php/test.php b/samples/client/petstore/php/test.php index 4b63c75f472..0721d7614f2 100644 --- a/samples/client/petstore/php/test.php +++ b/samples/client/petstore/php/test.php @@ -3,7 +3,7 @@ require_once('SwaggerClient-php/SwaggerClient.php'); // 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"); // to enable logging