使用昂首阔步版本2.1.0,我试图向请求的URL传递多个授权参数。看看我尝试过的关于github的实例:
var api_key = 'api_key',
username = 'username';
swaggerUi.api.clientAuthorizations.add('api_key', new SwaggerClient.ApiKeyAuthorization('api_key', api_key, 'query'));
swaggerUi.api.clientAuthorizations.add('username', new SwaggerClient.ApiKeyAuthorization('username', username, 'query'));但这只会导致第一次传递给XHR,例如:
钥匙
如果我换了订单:
swaggerUi.api.clientAuthorizations.add('username', new SwaggerClient.ApiKeyAuthorization('username', username, 'query'));
swaggerUi.api.clientAuthorizations.add('api_key', new SwaggerClient.ApiKeyAuthorization('api_key', api_key, 'query'));然后:
http://127.0.0.1:8000/api/v1/channel?username=username
我还尝试在add中使用对象表示法:
swaggerUi.api.clientAuthorizations.add({
'api_key': new SwaggerClient.ApiKeyAuthorization("api_key", api_key, "query"),
'username': new SwaggerClient.ApiKeyAuthorization("username", username, "query")
});但是,仍然只传递了一个参数:
钥匙
函数的名称表明,应该可以在不发生任何冲突的情况下传递多个授权参数,但实践表明并非如此。
发布于 2015-07-07 16:09:33
唯一适合我的方法是将自定义函数绑定到swaggerUi.api.clientAuthorizations.apply,例如:
swaggerUi.api.clientAuthorizations.apply = function (obj) {
obj.url += '?api_key=' + api_key + '&username=' + username;
}(该示例假定api_key和用户名存在于当前范围中)
swaggerUi.api.clientAuthorizations.apply采用两个参数-- obj, securities --这是第一个要将凭据附加到您的HTTP请求的参数。
https://stackoverflow.com/questions/30807936
复制相似问题