通过Swagger UI调用api时,不设置api_key

时间:2018-02-28 09:47:04

标签: swagger-ui swagger-2.0 grape-api auth-token

我正在使用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

1 个答案:

答案 0 :(得分:0)

security是一个数组,所以它应该是

security: [{ ApiKeyAuth: [] }]