Module: Docit::DocFile
- Defined in:
- lib/docit/doc_file.rb
Overview
DocFile lets you define API documentation in separate files, keeping your controllers clean. Extend any module with DocFile, then use ‘doc :action_name do … end` to define docs.
Usage:
# app/docs/users_docs.rb
module UsersDocs
extend Docit::DocFile
doc :index do
summary "List users"
"Users"
response 200, "Users retrieved"
end
doc :create do
summary "Create a user"
"Users"
request_body required: true do
property :email, type: :string, required: true
end
response 201, "User created"
end
end
# app/controllers/users_controller.rb
class UsersController < ApplicationController
use_docs UsersDocs
def index; end
def create; end
end
Class Method Summary collapse
Instance Method Summary collapse
- #[](action) ⇒ Object
- #actions ⇒ Object
-
#doc(action, &block) ⇒ Object
The block receives the same DSL as swagger_doc.
Class Method Details
.extended(base) ⇒ Object
39 40 41 |
# File 'lib/docit/doc_file.rb', line 39 def self.extended(base) base.instance_variable_set(:@_docs, {}) end |
Instance Method Details
#[](action) ⇒ Object
48 49 50 |
# File 'lib/docit/doc_file.rb', line 48 def [](action) @_docs[action.to_sym] end |
#actions ⇒ Object
52 53 54 |
# File 'lib/docit/doc_file.rb', line 52 def actions @_docs.keys end |
#doc(action, &block) ⇒ Object
The block receives the same DSL as swagger_doc.
44 45 46 |
# File 'lib/docit/doc_file.rb', line 44 def doc(action, &block) @_docs[action.to_sym] = block end |