2017-01-14 6 views
1

私はthis Swagger tutorialに従っていました。私はsample app's repoのすべての関連する問題を見ましたが、どれも私のために働いていませんでした。Rails 5、Swagger UIがコントローラ用のドキュメントjsonファイルを生成しない

私がrake swagger:docsを実行すると、それはの下にusers.jsonというファイルを生成するはずです。ファイルはapi-docs.jsonです。 また、端末でメッセージ1.0: 0 processed/4 skippedを出します。

問題を解決しなかったSwagger::Docs::Config.base_api_controller = ActionController::APIを追加しようとしました。

基本ファイルの共有。さらなる情報が必要な場合は、喜んでそれらをあなたと共有します。あなたが本当にここにこだわってくれることを願っています。ありがとうございました。

swagger_docs.rb

# config/initializers/swagger-docs.rb 
Swagger::Docs::Config.base_api_controller = ActionController::API 

Swagger::Docs::Config.register_apis({ 
    "1.0" => { 
    :api_file_path => "public/", 
    :base_path => "http://localhost:3000", 
    :clean_directory => true, 
    :base_api_controller => ActionController::API, 
    :attributes => { 
     :info => { 
     "title" => "Swagger Doc", 
     "description" => "Sample app shows how to setup swagger for your Ruby APIs", 
     "contact" => "[email protected]", 
     "license" => "Apache 2.0", 
     "licenseUrl" => "http://www.apache.org/licenses/LICENSE-2.0.html" 
     } 
    } 
    } 
}) 

users_controller.rb

class Api::V1::UsersController < ApplicationController 
    swagger_controller :users, "User Management" 

# /api/v1/users create documentation 
    swagger_api :create do 
    summary "To create user" 
    notes "Implementation notes, such as required params, example queries for apis are written here." 
    param :form, "user[name]", :string, :required, "Name of user" 
    param :form, "user[age]", :integer, :optional, "Age of user" 
    param_list :form, "user[status]", :string, :required, "Status of user, can be active or inactive" 
    response :success 
    response :unprocessable_entity 
    response :500, "Internal Error" 
    end 

    # POST /api/v1/users 
    def create 
    ... 
    end 
... 
end 

そしてここapi-docs.json

{ 
    "apiVersion": "1.0", 
    "swaggerVersion": "1.2", 
    "basePath": "http://localhost:3000", 
    "apis": [ 

    ], 
    "authorizations": null, 
    "info": { 
    "title": "Swagger Doc", 
    "description": "Sample app shows how to setup swagger for your Ruby APIs", 
    "contact": "[email protected]", 
    "license": "Apache 2.0", 
    "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.html" 
    } 
} 
生成だけです

答えて

1

実行中のアプリケーションと私の問題を比較しています。唯一の違いはroutes.rbファイルでした。明らかに私とRailsは、routes.rbのユーザモデルのネストされたルートを生成するステップをスキップしています。 routes.rbに下記を追加した後、問題は解決しました。

namespace :api do 
    namespace :v1 do 
     resources :users 
    end 
end 

希望します。

0

あなたswagger_docs.rb

include Swagger::Docs::ImpotentMethods 

# Swagger::Docs::Config.register_apis({}) 

class Swagger::Docs::Config 
    def self.base_api_controller 
    ActionController::API 
    end 
end 

それともroutes.rb

Swagger::Docs::Config.base_api_controller = ActionController::API 
include Swagger::Docs::ImpotentMethods 
の上部にこれを置くことでこれを試してみてください
関連する問題