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"
}
}
입니다