2017-01-14 3 views
1

swagger 환경 및 API 문서화에 익숙해지기 위해 this Swagger tutorial을 따라했습니다. sample app's repo에 관련된 모든 문제를 살펴 보았지만 어느 것도 나를 위해 일하지 않았습니다.Rails 5, 컨트롤러에 대한 문서 json 파일을 생성하지 않는 UI가 희미합니다.

rake swagger:docs을 실행하면 아래에 users.json 파일이 생성됩니다. 파일은 api-docs.json입니다. 또한 터미널에서 메시지 1.0: 0 processed/4 skipped을 제공합니다.

Swagger::Docs::Config.base_api_controller = ActionController::API을 추가하여 문제를 해결하지 못했습니다.

기본 파일 공유. 추가 정보가 필요하면 기꺼이 그 정보를 알려 드리겠습니다. 당신이 도울 수 있기를 바랍니다. 정말로 여기에 붙어 있습니다. 고맙습니다. 여기

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 

그리고

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" 
     } 
    } 
    } 
}) 
유일한 생성 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 파일입니다. 분명히 I와 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 
의 상단에 이러는