我正在使用servicestack的Swagger,但我的/resources URL出现了401未授权错误,因为它需要一个API密钥。
除非我错了,根据文档,我应该在从html页面初始化Swagger时将supportHeaderParams设置为true,以及在JSON参数中设置apiKeyName和apiKey值。
然后我期望在http请求头中看到我的API密钥,但它仍然被附加到URL中而不是在头集合中。
这是在我的HTML页面中初始化Swagger的代码:
window.swaggerUi = new SwaggerUi({
discoveryUrl: "http://pathtomyservice.com/resources",
headers: { "testheader" : "123" },
apiKey: "123",
apiKeyName: "Api-Key",
dom_id:"swagger-ui-container",
supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
if(console) {
console.log("Loaded SwaggerUI");
console.log(swaggerApi);
console.log(swaggerUi);
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: "none"
});
不幸的是,我得不到任何标题,没有“Api-Key”或“testheader”。