Search code examples
ruby-on-railsdocumentationapipie

How to create api documentation using apipie outside the controller


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?


Solution

  • 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