forked from loafle/openapi-generator-original
add todo for oauth, support multiple api key
This commit is contained in:
parent
278a653154
commit
06c7a6a109
@ -84,6 +84,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
typeMapping.put("list", "array");
|
||||
|
||||
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("require.mustache", packagePath, invokerPackage + ".php"));
|
||||
|
@ -68,6 +68,8 @@ class APIClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* update hearder and query param based on authentication setting
|
||||
*
|
||||
* @param array $headerParams
|
||||
* @param array $queryParams
|
||||
* @param array $authSettings
|
||||
@ -83,7 +85,8 @@ class APIClient {
|
||||
switch($auth) {
|
||||
{{#authMethods}}
|
||||
case '{{name}}':
|
||||
{{#isApiKey}}{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = Configuration::$api_key;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = Configuration::$api_key;{{/isKeyInQuery}}{{#isBasic}}$headerParams['Authorization'] = base64_encode(Configuraiton::$username.":"Configuration::$password){{/isBasic}}{{/isApiKey}}
|
||||
{{#isApiKey}}{{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = Configuration::$apiKey['{{keyParamName}}'];{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = Configuration::$apiKey['{{keyParamName}}'];{{/isKeyInQuery}}{{#isBasic}}$headerParams['Authorization'] = base64_encode(Configuraiton::$username.":"Configuration::$password){{/isBasic}}{{/isApiKey}}
|
||||
{{#isOAuth}}#TODO support oauth{{/isOAuth}}
|
||||
break;
|
||||
{{/authMethods}}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2015 Reverb Technologies, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace {{invokerPackage}};
|
||||
|
||||
class Configuration {
|
||||
|
||||
public static $PATCH = "PATCH";
|
||||
public static $POST = "POST";
|
||||
public static $GET = "GET";
|
||||
public static $PUT = "PUT";
|
||||
public static $DELETE = "DELETE";
|
||||
|
||||
// authentication setting
|
||||
public static $apiKey = array();
|
||||
public static $apiKeyPrefix = array();
|
||||
public static $username = '';
|
||||
public static $password = '';
|
||||
|
||||
|
||||
}
|
||||
|
@ -429,6 +429,9 @@
|
||||
"security": [
|
||||
{
|
||||
"api_key": []
|
||||
},
|
||||
{
|
||||
"api_secret": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -802,6 +805,11 @@
|
||||
"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",
|
||||
|
@ -68,6 +68,8 @@ class APIClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* update hearder and query param based on authentication setting
|
||||
*
|
||||
* @param array $headerParams
|
||||
* @param array $queryParams
|
||||
* @param array $authSettings
|
||||
@ -79,16 +81,22 @@ class APIClient {
|
||||
|
||||
// one endpoint can have more than 1 auth settings
|
||||
foreach($authSettings as $auth) {
|
||||
// determine which auth scheme to use
|
||||
// determine which one to use
|
||||
switch($auth) {
|
||||
|
||||
case 'api_key':
|
||||
$headerParams['api_key'] = Configuration::$api_key;
|
||||
$headerParams['api_key'] = Configuration::$apiKey['api_key'];
|
||||
|
||||
break;
|
||||
|
||||
case 'api_secret':
|
||||
$queryParams['api_secret'] = Configuration::$apiKey['api_secret'];
|
||||
|
||||
break;
|
||||
|
||||
case 'petstore_auth':
|
||||
|
||||
#TODO support oauth
|
||||
break;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2015 Reverb Technologies, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace SwaggerClient;
|
||||
|
||||
class Configuration {
|
||||
|
||||
public static $PATCH = "PATCH";
|
||||
public static $POST = "POST";
|
||||
public static $GET = "GET";
|
||||
public static $PUT = "PUT";
|
||||
public static $DELETE = "DELETE";
|
||||
|
||||
// authentication setting
|
||||
public static $apiKey = array();
|
||||
public static $apiKeyPrefix = array();
|
||||
public static $username = '';
|
||||
public static $password = '';
|
||||
|
||||
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class StoreApi {
|
||||
}
|
||||
|
||||
// authentication setting, if any
|
||||
$authSettings = array('api_key');
|
||||
$authSettings = array('api_key', 'api_secret');
|
||||
|
||||
// make the API Call
|
||||
$response = $this->apiClient->callAPI($resourcePath, $method,
|
||||
|
Loading…
x
Reference in New Issue
Block a user