Swagger - 将多个安全参数添加到同一架构定义中 [英] Swagger - Adding multiple security parameters to the same schema definition
问题描述
目标
在 API 内发出的每个请求中包含多个安全标头
To include multiple security headers to every request made within the API
问题
我正在尝试向 Swagger YAML 安全定义添加多个标头.我已经通过 API 进行了拖网,但运气不佳但是我发现在进行尝试此操作"时我需要选择一个.而不是能够同时使用两者.这是正确的还是我做错了什么?
I am trying to add multiple headers to my Swagger YAML security definitions. I have trawled though the API but not have alot of luck But am finding that when making the 'Try-This-Operation' I am required to select one. Rather than able to use both. Is this correct or am I doing something incorrectly?
片段
securityDefinitions:
userEmail:
type: apiKey
name: User Email
in: header
clientId:
type: apiKey
name: Client Id
in: header
security: [ { userEmail: [], clientId: [] } ]
替代方案?
如果我试图做到这一点是不可能的......是否可以将这些参数指定为 swagger 文档中所有其余路径的默认值?
If I am trying to do this impossible ... Is it possible to specify these parameters as default for all the rest paths within the swagger document?
这周我是 Swagger 的新手,我发现其他一切都没有问题……但我找不到任何很好的例子.
I am new to Swagger this week any have found everything else without problem ... but I cannot find any good example of this.
如果可以提供任何指导,那将非常有帮助非常感谢
If any guidance could be given that would be incredibly helpful Many thanks
推荐答案
OAS 3: https://swagger.io/docs/specification/authentication/
某些 REST API 支持多种身份验证类型.security
部分让您可以使用逻辑 OR 和 AND 组合安全要求,以实现所需的结果.security
使用以下逻辑:
Using Multiple Authentication Types
Some REST APIs support several authentication types. The
security
section lets you combine the security requirements using logical OR and AND to achieve the desired result.security
uses the following logic:
security: # A OR B
- A
- B
security: # A AND B
- A
B
security: # (A AND B) OR (C AND D)
- A
B
- C
D
这篇关于Swagger - 将多个安全参数添加到同一架构定义中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!