葡萄招摇文件没有加载

时间:2015-11-21 11:58:47

标签: ruby-on-rails json swagger swagger-ui grape-api

以下是我使用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时。我在绿色导航栏下面出现以下错误。

  

无法从http://api.lvh.me:3000/swagger_doc.json

中读取招摇的JSON

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

{"error":"Not Found"}

我无法弄清楚到底出了什么问题。需要帮助使用葡萄框架渲染Swagger文档。

1 个答案:

答案 0 :(得分:1)

config/initializers/swagger.rb中,您将架构的网址设置为/swagger_doc.json,并将方法mount_path中的add_swagger_documentation设置为'/'。 Shoudn&#tttt /swagger_doc