我已经部署了测试Grape REST API,我正在尝试使用Swagger UI进行测试。
问题是,当Swagger UI加载API规范时,它会在后缀中添加括号:http://arcane-shore-2642.herokuapp.com/api/v1/todos(.json)
这会导致404错误,因为(.json)后缀无效。
它调用的网址应如下所示:http://arcane-shore-2642.herokuapp.com/api/v1/todos
或者:http://arcane-shore-2642.herokuapp.com/api/v1/todos.json
我该如何解决这个问题?
更有效的路线:
http://arcane-shore-2642.herokuapp.com/api/v1/todos/1
http://arcane-shore-2642.herokuapp.com/api/v1/items/1
http://arcane-shore-2642.herokuapp.com/api/v1/todos/1/items
http://arcane-shore-2642.herokuapp.com/api/v1/todos/1.json
http://arcane-shore-2642.herokuapp.com/api/v1/items/1.json
http://arcane-shore-2642.herokuapp.com/api/v1/todos/1/items.json
答案 0 :(得分:1)
我今天遇到了同样的问题。这是因为来自grape-swagger
gem的原始API规范数据具有"(。json)" (或格式化)后缀。
{
apiVersion: "0.1",
swaggerVersion: "1.2",
resourcePath: "/hotels",
produces: [
"application/json"
],
apis: [
{
path: "/hotels.{format}",
operations: [
...
hide_format
的配置设置为add_swagger_documentation
,可以隐藏格式后缀。但是,选项hide_format
在grape-swagger
(0.10.1)的最新发布版本中仍然存在最新grape
(0.12.0)的问题。
因此,我们需要指定开发grape-swagger
,然后设置hide_format
。
的Gemfile
gem 'grape-swagger', github: "tim-vandecasteele/grape-swagger"
您的根API
add_swagger_documentation hide_format: true