Swagger不在Rails Api工作

时间:2015-10-28 14:26:57

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

gem' swagger-docs'

rake swagger:docs

rails服务器

我的控制器位于app / controller / API / user_controller.rb

    module Api
    class UserController < ApplicationController

    swagger_controller :users, "Users"
    swagger_api :create do
        summary "Creates a new User"
        param :form, :name, :string, :required, "Name"
        response :unauthorized
        response :not_acceptable
    end

    def create
            render json: {message: "success"},status: 401
    end

end

但是当我进入

http://localhost:3000/api-docs.json

它无法正常工作。它不能显示正确的布局。比它提供的json代码。

{
"apiVersion": "1.0",
"swaggerVersion": "1.2",
"basePath": "/",
"apis": [
 {
   "path": "api/user.{format}",
  "description": "Users"
 }
]
 }

1 个答案:

答案 0 :(得分:0)

返回JSON是swagger-docs的默认行为。如果您想查看此screenshot的布局,您还需要使用swagger-ui。请参阅此处的示例https://github.com/richhollis/swagger-docs-sample/tree/c33e1e788b8ef5a71c86610fffbb145b243a725b/public/api

希望这会有所帮助:)