首页 文章

处理使用1时调用的多个Swagger SecurityHandler定义?

提问于
浏览
2

我已将Swagger 2.0配置为具有多个可选的安全性定义 . 当用户调用和支持多个定义并使用其中一个定义的 endpoints 时,将调用所有已配置的处理程序 .
如何处理没有参数的处理程序的请求,并确保使用参数调用至少1个安全处理程序?

我在swagger.yaml中有两个单独的API密钥定义

securityDefinitions:
  apiKeyQuery:
    type: "apiKey"
    name: "api_key"
    in: "query"
  apiKeyHeader:
    type: "apiKey"
    name: "API-KEY"
    in: "header"

我希望其中任何一个都可以工作,所以这是我的 endpoints 安全性定义:

security:
  - apiKeyQuery: []
  - apiKeyHeader: []

我的app.js有两个处理程序:

appRoot: __dirname,
swaggerSecurityHandlers: {
  apiKeyQuery: function(req, res, next) { console.log('Query Called!');},
  apiKeyHeader: function(req, res, next) {console.log('Header Called!');}
}

预期:

Input: curl -X GET --header 'Accept: application/json' 'http://localhost:3000/api/v1/users?api_key=asdfg'
Output: Query Called!

实际:

Input: curl -X GET --header 'Accept: application/json' 'http://localhost:3000/api/v1/users?api_key=asdfg'
Output: Query Called!  Header Called!

似乎两个安全处理程序请求都是异步的,并且swagger首先使用哪个回调触发来确定下一步 .

1 回答

相关问题