在 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
Run Code Online (Sandbox Code Playgroud)
然后使给定端点可公开访问(不受保护)
paths:
/unprotected/path:
get:
security: []
Run Code Online (Sandbox Code Playgroud)
或者应该以另一种方式完成?
更新这个问题被标记为重复,但另一个问题处理有关 Swagger 2.x 的问题,并且由于语法不同,我认为这个问题和答案应该保留。
您确实可以覆盖 OA3 中路径基础的安全性,如下所示:
paths:
/unprotected/path:
get:
security: []
Run Code Online (Sandbox Code Playgroud)