Swaggerpath的特定安全性

我有一个Node.js API,我想在其中添加swagger文档。 客户通过智威汤逊授权,所以我添加到安全:

securityDefinitions: UserSecurity: type: apiKey description: User is logged in in: header name: Authorization 

比我可以添加到不同的path告诉客户端,要做到这一点,你需要login。

 /user/{userId} get: security: - UserSecurity: [] 

但是,如何添加更具体的安全约束呢? 就像用户只能以该用户身份login时才能编辑configuration文件。 或者,如果用户具有superadmin状态,或者如果他是董事会的董事会成员,则用户可以编辑评论,评论发布在OR上或作为创build此评论的用户login。

AFAIK,没有直接的方式来添加“angular色”的大举文件。

我做了什么,是我添加一个自定义部分到swagger文件x-scope

 get: operationId: getToken x-scope: - merchant security: - token: [] 

然后在代码中,我检查path中提供的用户angular色:

 authorize: (req, def, token, callback) => { let scopes = req.swagger.operation["x-scope"]; //scopes will contain ["merchant"] array return verifyUserAndRoles(token, scopes); }