通过Swagger UI调用api时未设置api_key

问题描述 投票:0回答:1

我正在使用Swagger UI生成api文档,并希望在此页面中为api调用api。我将security_definitions设置如下:

add_swagger_documentation(
  hide_documentation_path: true,
  doc_version: '18.0',
  mount_path: '/api_doc',
  add_version: true,
  hide_format: true,
  info: {
  title: "Search API documentation"
  },
  security_definitions: {
      ApiKeyAuth:{
        type: "apiKey",
        name: "X-Auth-Token",
        in: "header",
        description: "Requests should pass an api_key header."
      }
  },
  security: {
    ApiKeyAuth: []
  }
)

但是当输入值并发送请求时,请求标头中没有值。

Set the apikey value

calling the api

swagger-ui swagger-2.0 grape-api auth-token
1个回答
0
投票

security是一个阵列所以它应该是

security: [{ ApiKeyAuth: [] }]
© www.soinside.com 2019 - 2024. All rights reserved.