security - OpenApi 3.0:覆盖全局安全性
问题描述
在 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 并且由于语法不同,我认为这个问题和答案应该保留。
解决方案
您确实可以覆盖 OA3 中路径库的安全性,如下所示:
paths:
/unprotected/path:
get:
security: []
推荐阅读
- python - google or-tools 无法获得最佳 LP 结果,如 gurobi 示例
- c# - Visual Studio 将自动对以下项目进行功能更改以打开它们
- javascript - 编写 JavaScript 时缺少 Visual Studio 的 IntelliSense
- python - 在 Python 中循环一个函数
- excel - 将分隔文本转换为 csv
- java - 我可以在构建它的 CellValueFactory 时检查 TableCell 的内容是否会溢出
- wpf - 文本块问题上的圆形边框
- angular - Angular:当计数器变量值为0时调用方法
- vb.net - 双重转义转义 - 使用字节
- excel - 如何仅通过可见选项卡运行代码?