【发布时间】:2016-02-23 21:48:21
【问题描述】:
下面是我使用Grape构建API的配置。
但我无法使用 Swagger 构建文档
宝石:
gem 'grape'
grape-0.13.0
gem 'grape-swagger-rails'
grape-swagger-rails-0.1.0
gem 'rack-cors', :require => 'rack/cors'
rack-cors-0.4.0
config/application.rb
require 'rack/cors'
config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
config.autoload_paths += Dir[Rails.root.join('app', 'api', '**', '*.rb')]
config/initializers/swagger.rb
GrapeSwaggerRails.options.url = '/swagger_doc.json'
GrapeSwaggerRails.options.app_url = "http://api.lvh.me:3000"
config/routes.rb
constraints(subdomain: 'api') do
mount API::Base => '/'
end
mount GrapeSwaggerRails::Engine, at: "/apidocs"
app/api/api/base.rb
require 'grape-swagger'
module API
class Base < Grape::API
default_format :json
mount API::V1::Base
add_swagger_documentation(
api_version: "v1",
hide_documentation_path: true,
mount_path: "/",
hide_format: true
)
end
end
问题:
当我点击http://lvh.me:3000/apidocs。我在绿色导航栏下方出现错误。
无法从 http://api.lvh.me:3000/swagger_doc.json 读取 swagger JSON
当我点击http://api.lvh.me:3000/swagger_doc.json。得到以下响应。
{"error":"Not Found"}
我无法弄清楚做错了什么。在使用葡萄框架渲染 Swagger 文档方面需要帮助。
【问题讨论】:
标签: ruby-on-rails json swagger swagger-ui grape-api