【问题标题】:Swagger file security scheme defined but not in useSwagger 文件安全方案已定义但未使用
【发布时间】:2021-11-28 19:13:41
【问题描述】:

我有一个 Swagger 2.0 文件,该文件定义了身份验证机制,但出现错误,告诉我我们没有使用它。确切的错误消息是“安全方案已定义但从未使用”。

如何确保使用我创建的身份验证保护我的端点?我尝试了很多不同的方法,但似乎没有任何效果。

我不确定是否定义了实际的安全方案,我认为这是因为我们在生产中使用它。

我真的很想在这方面得到一些帮助,因为我担心我们的竞争对手可能会利用它来窃取我们的一些数据。

swagger: "2.0"

# basic info is basic
info:
  version: 1.0.0
  title: Das ERP

# host config info
# Added by API Auto Mocking Plugin
host: virtserver.swaggerhub.com
basePath: /rossja/whatchamacallit/1.0.0
#host: whatchamacallit.lebonboncroissant.com
#basePath: /v1

# always be schemin'
schemes:
- https

# we believe in security!
securityDefinitions:
  api_key:
    type: apiKey
    name: api_key
    in: header
    description: API Key
  
# a maze of twisty passages all alike
paths:
  /dt/invoicestatuses:
    get:
      tags:
        - invoice
      summary: Returns a list of invoice statuses
      produces:
        - application/json
      operationId: listInvoiceStatuses
      responses:
        200:
          description: OK
          schema:
            type: object
            properties:
              code:
                type: integer
              value:
                type: string

【问题讨论】:

  • 您的方案是https,但您的网址不是,也许这就是问题所在?

标签: api security authentication openapi swagger-2.0


【解决方案1】:

securityDefinitions 是不够的,本节定义了可用的安全方案,但不应用它们

要将安全方案实际应用于您的 API,您需要在根级别或单个操作中添加 security 要求。

security:
  - api_key: []

有关详细信息,请参阅API Keys 指南。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 2022-06-14
    • 2019-10-04
    • 2012-07-27
    • 2018-03-26
    • 1970-01-01
    • 2019-06-15
    相关资源
    最近更新 更多