为什么从 Swagger UI 发送的请求中缺少授权标头?

8 node.js swagger swagger-ui swagger-2.0 openapi

我想向我的 Node.js API 添加文档,为此我有一个 YAML 文件,我在其中放置我的定义,swagger 文档位于 localhost:5000/api-doc 并且工作正常。

现在我必须添加 Bearer 授权,但 Swagger 具有以下定义:

swagger: "2.0"
info:
    version: 1.0.0
    title: My API documentation
    description: >
        My API documentation

host: localhost:5000
basePath: "/v1"
schemes:
    - http
securityDefinitions:
    Bearer:
        type: apiKey
        description: "Value: Bearer "
        name: Authorization
        in: header
paths:
    /users:
        get:
            responses:
                "200":
                    description: "Will send `Authenticated`"
                "403":
                    description: "You do not have necessary permissions for the resource"
Run Code Online (Sandbox Code Playgroud)

测试请求时(我单击右上角的“授权”按钮并输入我的令牌),出现以下错误:

“错误”:“未找到授权标头。

为什么Authorization请求中不包含标头?

Hel*_*len 3

securityDefinitions单独使用还不够,您还需要security在根级别或操作级别添加密钥才能实际应用安全性。

security:
  - Bearer: []
Run Code Online (Sandbox Code Playgroud)