Swagger UI - 尝试一下!返回整个Swagger文档

时间:2016-07-12 07:32:56

标签: ruby-on-rails swagger swagger-ui

当我运行以下命令时:

.save()

它为每个控制器返回正确的JSON文件。

当我访问swagger-ui时,它给了我正确的页面:

enter image description here

但是当我点击Try it Out!时,它会返回完整的JSON,如下所示:

enter image description here

我是Swagger的新手。有人可以帮帮我,我哪里错了?

更新: 我的公共目录结构:

enter image description here

UPDATE trucks.json:

rake swagger:docs

1 个答案:

答案 0 :(得分:0)

找出解决方案。发布,以便任何人偶然发现可以尝试。

我的swagger文档配置如下所示:

Swagger::Docs::Config.register_apis({
   'v1' =>{
      :api_extension_type => :json,
      :api_file_path => "public",
      :base_path => 'http://localhost:3000',
      :parent_controller => ApplicationController,
      :base_api_controller => ActionController::Base,
      :camelize_model_properties => false,
      :clean_directory => true,
      :attributes => {
            :info => {
              "title" => "Swagger Yattya",
              "description" => "Yattya api documentation",
              "termsOfServiceUrl" => "http://helloreverb.com/terms/",
              "contact" => "apiteam@wordnik.com",
              "license" => "Apache 2.0",
              "licenseUrl" => "http://www.apache.org/licenses/LICENSE-2.0.html"
        }
        }
    }
  })

第一行不是必需的:

:api_extension_type => :json

从配置中删除了这一行并像魅力一样工作!