From 6e13403a371d140d28cd89e1e39d5883a2b9f001 Mon Sep 17 00:00:00 2001 From: wing328 Date: Wed, 20 May 2015 21:55:16 +0800 Subject: [PATCH] fix http basic auth, add test cases for new api client without host --- .../src/main/resources/php/APIClient.mustache | 2 +- .../swagger-codegen/src/test/resources/2_0/petstore.json | 8 -------- .../petstore/php/SwaggerClient-php/lib/APIClient.php | 5 ----- .../petstore/php/SwaggerClient-php/lib/StoreApi.php | 2 +- .../petstore/php/SwaggerClient-php/tests/PetApiTest.php | 5 +++-- 5 files changed, 5 insertions(+), 17 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/APIClient.mustache b/modules/swagger-codegen/src/main/resources/php/APIClient.mustache index 9f07b721d1ee..03918b79d762 100644 --- a/modules/swagger-codegen/src/main/resources/php/APIClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/APIClient.mustache @@ -99,7 +99,7 @@ class APIClient { switch($auth) { {{#authMethods}} case '{{name}}': - {{#isApiKey}}{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $this->getApiKeyWithPrefix('{{keyParamName}}');{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $this->getApiKeyWithPrefix('{{keyParamName}}');{{/isKeyInQuery}}{{#isBasic}}$headerParams['Authorization'] = base64_encode(Configuraiton::$username.":"Configuration::$password){{/isBasic}}{{/isApiKey}} + {{#isApiKey}}{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $this->getApiKeyWithPrefix('{{keyParamName}}');{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $this->getApiKeyWithPrefix('{{keyParamName}}');{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}$headerParams['Authorization'] = 'Basic '.base64_encode(Configuration::$username.":".Configuration::$password);{{/isBasic}} {{#isOAuth}}//TODO support oauth{{/isOAuth}} break; {{/authMethods}} diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore.json b/modules/swagger-codegen/src/test/resources/2_0/petstore.json index 5bc9b83ca0cc..b4678fc3ab95 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore.json +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore.json @@ -429,9 +429,6 @@ "security": [ { "api_key": [] - }, - { - "api_secret": [] } ] } @@ -805,11 +802,6 @@ "name": "api_key", "in": "header" }, - "api_secret": { - "type": "apiKey", - "name": "api_secret", - "in": "query" - }, "petstore_auth": { "type": "oauth2", "authorizationUrl": "http://petstore.swagger.io/api/oauth/dialog", diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php index 9f7ee55e6932..84e261b49596 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php @@ -103,11 +103,6 @@ class APIClient { break; - case 'api_secret': - $queryParams['api_secret'] = $this->getApiKeyWithPrefix('api_secret'); - - break; - case 'petstore_auth': //TODO support oauth diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php index 2b719114ff64..4012a88fc541 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php @@ -69,7 +69,7 @@ class StoreApi { } // authentication setting, if any - $authSettings = array('api_key', 'api_secret'); + $authSettings = array('api_key'); // make the API Call $response = $this->apiClient->callAPI($resourcePath, $method, diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index 9dd4042f3e0f..f920381f646d 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -35,6 +35,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase { $api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2'); SwaggerClient\Configuration::$apiKey['api_key'] = '123456'; + $headerParams = array('test1' => 'value1'); $queryParams = array('test2' => 'value2'); $authSettings = array('api_key', 'unknown'); @@ -62,8 +63,8 @@ class PetApiTest extends \PHPUnit_Framework_TestCase // test getPetById with a Pet object (id 10005) public function testGetPetById() { - // initialize the API client - $api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2'); + // initialize the API client without host + $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);