forked from loafle/openapi-generator-original
fix http basic auth, add test cases for new api client without host
This commit is contained in:
@@ -99,7 +99,7 @@ class APIClient {
|
|||||||
switch($auth) {
|
switch($auth) {
|
||||||
{{#authMethods}}
|
{{#authMethods}}
|
||||||
case '{{name}}':
|
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}}
|
{{#isOAuth}}//TODO support oauth{{/isOAuth}}
|
||||||
break;
|
break;
|
||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
|
|||||||
@@ -429,9 +429,6 @@
|
|||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"api_key": []
|
"api_key": []
|
||||||
},
|
|
||||||
{
|
|
||||||
"api_secret": []
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -805,11 +802,6 @@
|
|||||||
"name": "api_key",
|
"name": "api_key",
|
||||||
"in": "header"
|
"in": "header"
|
||||||
},
|
},
|
||||||
"api_secret": {
|
|
||||||
"type": "apiKey",
|
|
||||||
"name": "api_secret",
|
|
||||||
"in": "query"
|
|
||||||
},
|
|
||||||
"petstore_auth": {
|
"petstore_auth": {
|
||||||
"type": "oauth2",
|
"type": "oauth2",
|
||||||
"authorizationUrl": "http://petstore.swagger.io/api/oauth/dialog",
|
"authorizationUrl": "http://petstore.swagger.io/api/oauth/dialog",
|
||||||
|
|||||||
@@ -103,11 +103,6 @@ class APIClient {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'api_secret':
|
|
||||||
$queryParams['api_secret'] = $this->getApiKeyWithPrefix('api_secret');
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'petstore_auth':
|
case 'petstore_auth':
|
||||||
|
|
||||||
//TODO support oauth
|
//TODO support oauth
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class StoreApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// authentication setting, if any
|
// authentication setting, if any
|
||||||
$authSettings = array('api_key', 'api_secret');
|
$authSettings = array('api_key');
|
||||||
|
|
||||||
// make the API Call
|
// make the API Call
|
||||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
|
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
|
||||||
SwaggerClient\Configuration::$apiKey['api_key'] = '123456';
|
SwaggerClient\Configuration::$apiKey['api_key'] = '123456';
|
||||||
|
|
||||||
$headerParams = array('test1' => 'value1');
|
$headerParams = array('test1' => 'value1');
|
||||||
$queryParams = array('test2' => 'value2');
|
$queryParams = array('test2' => 'value2');
|
||||||
$authSettings = array('api_key', 'unknown');
|
$authSettings = array('api_key', 'unknown');
|
||||||
@@ -62,8 +63,8 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
// test getPetById with a Pet object (id 10005)
|
// test getPetById with a Pet object (id 10005)
|
||||||
public function testGetPetById()
|
public function testGetPetById()
|
||||||
{
|
{
|
||||||
// initialize the API client
|
// initialize the API client without host
|
||||||
$api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2');
|
$api_client = new SwaggerClient\APIClient();
|
||||||
SwaggerClient\Configuration::$apiKey['api_key'] = '111222333444555';
|
SwaggerClient\Configuration::$apiKey['api_key'] = '111222333444555';
|
||||||
$pet_id = 10005; // ID of pet that needs to be fetched
|
$pet_id = 10005; // ID of pet that needs to be fetched
|
||||||
$pet_api = new SwaggerClient\PetAPI($api_client);
|
$pet_api = new SwaggerClient\PetAPI($api_client);
|
||||||
|
|||||||
Reference in New Issue
Block a user