【问题标题】:Swagger not working in Rails ApiSwagger 在 Rails Api 中不起作用
【发布时间】:2015-10-28 14:26:56
【问题描述】:

gem 'swagger-docs'

rake swagger:文档

轨道服务器

我的控制器在 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"
 }
]
 }

【问题讨论】:

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


    【解决方案1】:

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

    希望这会有所帮助:)

    【讨论】:

    • 它是 gem 还是 js 文件,请只清除这个。谢谢:)
    • 它是 JavaScript。您还需要包含 css、图像和其他 js 库。
    猜你喜欢
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-25
    • 1970-01-01
    相关资源
    最近更新 更多