fix http basic auth, add test cases for new api client without host

This commit is contained in:
wing328
2015-05-20 21:55:16 +08:00
parent 9a1dedbe76
commit 6e13403a37
5 changed files with 5 additions and 17 deletions

View File

@@ -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}}

View File

@@ -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",

View File

@@ -103,11 +103,6 @@ class APIClient {
break;
case 'api_secret':
$queryParams['api_secret'] = $this->getApiKeyWithPrefix('api_secret');
break;
case 'petstore_auth':
//TODO support oauth

View File

@@ -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,

View File

@@ -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);