swagger没有显示资源中的各个端点

时间:2015-12-22 03:18:09

标签: ruby-on-rails ruby swagger

我第一次使用Swagger而且我无法获得单个端点的详细信息以显示在资源中的json响应中。

简化,我有:

# api.rb
require 'grape-swagger'
module API
  class Base < Grape::API
  version 'v1', using: :path
  format :json

  resource :items do
    desc 'Operations about items'
    get '/:id' do
      desc 'retrieve data for a single item'
      # do something here
    end
  end
end

在输出中,我希望看到类似的内容:

{
  "apiVersion": "0.1",
  "swaggerVersion": "1.2",
  "produces": 
  [
    "name": "application/json",
  ],
  "resources": 
  [ 
    {          
       "name": "items",
       "description": "Operations about items",
       "apis": [
         {
           "path": "/items/:id.{format}",
           "description": "retrieve data for a  single item"
         }
       ]
    }
  ]
}

相反,我得到:

{
  "apiVersion": "0.1",
  "swaggerVersion": "1.2",
  "produces": 
  [
     "application/json"
  ],
  "apis": 
  [
    {
      "path": "/items.{format}",
      "description": "Operations about items"
    }
  ]
}
我做错了什么? (使用Rails 4.2,Ruby 2.1)

1 个答案:

答案 0 :(得分:1)

您必须先安装资源

mount Items