我在Lumen有Basic Auth Api。对于那个Api,我使用以下网址集成了Swagger-ui:https://github.com/DarkaOnLine/SwaggerLume
在swagger ui中启用自定义标头。我们在以下2个文件中完成了更改
1。招摇-lume.php
'headers' => [
/*
|--------------------------------------------------------------------------
| Uncomment to add response headers when swagger is generated
|--------------------------------------------------------------------------
*/
/*"view" => [
'Content-Type' => 'text/plain'
],*/
/*
|--------------------------------------------------------------------------
| Uncomment to add request headers when swagger performs requests
|--------------------------------------------------------------------------
*/
"request" => [
'Authorization ' => 'Basic YWRtaW46YWRtaW4='
],
],
2。生成的index.blade.php代码如下
basicAuth= "Basic " + btoa("admin:admin");
swaggerUi.api.clientAuthorizations.add("key", new SwaggerClient.ApiKeyAuthorization("Authorization", basicAuth, "header"));
但是标头不是在请求中发送的。请查看下面的图片以供参考
请建议如何解决此问题。
答案 0 :(得分:0)
我在api文件中的注释语法中定义了许多securityDefinitions。我发现问题来自json文件。删除了注释语法,然后标题在ajax调用中接受。
...,
"securityDefinitions":{
"administrator":{
"type":"basic",
"description":"The administrator."
},
"supervisor":{
"type":"basic",
"description":"A supervisor."
},
"customer":{
"type":"basic",
"description":"A customer."
}
},
...