【问题标题】:OpenApi 3.0: override global securityOpenApi 3.0:覆盖全局安全性
【发布时间】:2019-09-12 16:56:18
【问题描述】:

在 OpenAPI 3 中,是否可以在全局级别定义 SecurityScheme,然后在某些端点覆盖它以不使用安全性(对于公共可访问端点)?

例如(取自https://swagger.io/docs/specification/authentication/bearer-authentication/

openapi: 3.0.0
...
# 1) Define the security scheme type (HTTP bearer)
components:
  securitySchemes:
    bearerAuth:            # arbitrary name for the security scheme
      type: http
      scheme: bearer
      bearerFormat: JWT    # optional, arbitrary value for documentation purposes
# 2) Apply the security globally to all operations
security:
  - bearerAuth: []         # use the same name as above

然后使给定的端点可公开访问(不受保护)

paths:
  /unprotected/path:
    get:
      security: []

还是应该以其他方式完成?

更新这个问题被标记为重复,但另一个问题处理关于 Swagger 2.x 并且由于语法不同,我认为这个问题和答案应该保留。

【问题讨论】:

标签: security openapi


【解决方案1】:

您确实可以在 OA3 中覆盖路径库的安全性,如下所示:

paths:
  /unprotected/path:
    get:
      security: []

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 2013-05-27
    • 2019-07-14
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    相关资源
    最近更新 更多