3

I am using apipie for API documentation. The problem I am facing now is that the large amount of information to be provided for documentation is ruining my code structure in the controller.

How can I write the documentation outside the controller file, so that the code structure will be readable?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Bala Karthik
  • 1,353
  • 2
  • 17
  • 26

2 Answers2

2

You can find nice explanation on how to use apipie outside controller in this document https://ilyabylich.svbtle.com/apipie-amazing-tool-for-documenting-your-rails-api

To sum things up (example from link):

# app/docs/users_doc.rb
module UsersDoc
 # we need the DSL, right?
 extend Apipie::DSL::Concern

 api :GET, '/users', 'List users'
 def show
  # Nothing here, it's just a stub
 end
end

# app/controller/users_controller.rb
class UsersController < ApplicationController
  include UsersDoc

  def show
    # Application code goes here
    # and it overrides blank method
    # from the module
  end
end
  • Thanks for your reference and example, i have a sample application with a controller post when i am implementing apipie as per your guide lines i am getting a error like uninitialized constant PostController::PostDoc. – Bala Karthik May 20 '16 at 04:42
0

super also needs to be included in the stubbed actions in the docs. In my app I created a controller that inherits from an existing controller defined in a gem, and if I don't include super in the stubbed action, I get unexpected behavior.

So:

# app/docs/users_doc.rb
module UsersDoc
 # we need the DSL, right?
 extend Apipie::DSL::Concern

 api :GET, '/users', 'List users'
 def show
   super
 end
end

# app/controller/users_controller.rb
class UsersController < ApplicationController
  include UsersDoc

  def show
    # Application code goes here
  end
end
Sophy Lee
  • 11
  • 2