以下是我使用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
配置/ 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')]
配置/初始化/ swagger.rb
GrapeSwaggerRails.options.url = '/swagger_doc.json'
GrapeSwaggerRails.options.app_url = "http://api.lvh.me:3000"
配置/ routes.rb中
constraints(subdomain: 'api') do
mount API::Base => '/'
end
mount GrapeSwaggerRails::Engine, at: "/apidocs"
应用程序/ 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
时。我在绿色导航栏下面出现以下错误。
中读取招摇的JSON
当我点击http://api.lvh.me:3000/swagger_doc.json
时。低于响应。
{"error":"Not Found"}
我无法弄清楚到底出了什么问题。需要帮助使用葡萄框架渲染Swagger文档。
答案 0 :(得分:1)
在config/initializers/swagger.rb
中,您将架构的网址设置为/swagger_doc.json
,并将方法mount_path
中的add_swagger_documentation
设置为'/'
。 Shoudn&#tttt /swagger_doc
?