葡萄大摇大摆的文件没有加载

Grape swagger documentation not loading

以下是我使用 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的时候。我在绿色导航栏下方遇到错误。

Can't read swagger JSON from http://api.lvh.me:3000/swagger_doc.json

当我点击 http://api.lvh.me:3000/swagger_doc.json 时。低于响应。

{"error":"Not Found"}

我不知道哪里做错了。在使用 grape 框架渲染 Swagger 文档时需要帮助。

config/initializers/swagger.rb 中,您将架构的 URL 设置为 /swagger_doc.json 并在方法 add_swagger_documentation 中将 mount_path 设置为 '/' .不应该是/swagger_doc吗?