【发布时间】: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 并且由于语法不同,我认为这个问题和答案应该保留。
【问题讨论】:
-
你的例子是正确的。
-
@mvermand 考虑回答您自己的问题,因为您的示例是正确的。