【发布时间】:2015-05-27 05:45:41
【问题描述】:
我正在尝试使用grape-swagger gem 为我的Grape API 创建自动生成的文档。
使用'grape' gem 我创建了一些 API。
示例:
http://localhost:9292/api/v1/charges
此 API 运行良好。
根据 'grape-sagger' 的文档,我无法正确生成 API 文档。
我的步骤:
1) 我在 gemfile 下面添加了
gem 'grape-swagger'
2) 我还使用 rack-cors 通过在 config.ru 中添加以下内容来启用 CORS
require 'rack/cors'
use Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: [ :get, :post, :put, :delete, :options ]
end
end
也在 gemfile 的下方添加。
gem 'rack-cors', :require => 'rack/cors'
3) 我还在 API 类的末尾添加了以下内容
add_swagger_documentation
但是当我运行http://localhost:9292/api/v1/swagger_doc 时,我没有得到正确的路径。 我需要像http://localhost:9292/api/v1/charges 这样的API 路径,但它返回为http://localhost:9292/api/v1/swagger_doc/charges
我需要设置任何其他配置吗?
【问题讨论】:
标签: ruby-on-rails ruby swagger grape