Your SecurityDefintions
对象看起来不错。当心
security: [ { userEmail: [], clientId: [] } ]
意味着 API 客户端必须使用userEmail
身份验证与clientId
一次认证!你的意思可能是:
security: [ { userEmail: [] }, { clientId: [] } ]
这意味着 API 客户端必须使用userEmail
身份验证或clientId
验证。
为了避免一遍又一遍地重复这个定义,你可以使用全局security
适用于所有没有自己的路径的属性security
object:
security: [ { userEmail: [] }, { clientId: [] } ]
paths:
"/foo":
get:
post:
或者为了明确性或多个共同值而使用参考:
paths:
"/foo":
get:
security:
"$ref": "#/definitions/lowSecurity"
post:
security:
"$ref": "#/definitions/highSecurity"
definitions:
lowSecurity: [ { foo: [] }, { bar: [] } ]
highSecurity: [ { foo: [] } ]
参考
Swagger2 规范如下操作对象 http://swagger.io/specification/#operationObject:
security
:
[安全需求对象 http://swagger.io/specification/#securityRequirementObject]
对此操作应用哪些安全方案的声明。值列表描述了可以使用的替代安全方案(即,安全要求之间存在逻辑“或”)。此定义覆盖任何声明的顶级安全性。要删除顶级安全声明,可以使用空数组。
The 安全需求对象 http://swagger.io/specification/#securityRequirementObject是这样描述的:
列出执行此操作所需的安全方案。该对象可以在其中声明多个安全方案,这些方案都是必需的(即方案之间存在逻辑 AND)。
每个属性使用的名称必须对应于安全定义中声明的安全方案。