HFX
HFX

Reputation: 592

How to document RESTful API?

I am new to RoR.

Is there any way to document RESTful api like Django REST Swagger?

Then i found the apipie-rails to document my api.

But when i try to integrate it with Spree, i got the following error:

Unable to autoload constant BaseControllerDecorator, expected /${PATH}/base_controller_decorator.rb to define it.

base_controller_decorator.rb

Spree::Api::BaseController.class_eval do

    # Some overrided functions

end

I found the following code in lib/apipie/application.rb:

def load_controller_from_file(controller_file)
  controller_class_name = controller_file.gsub(/\A.*\/app\/controllers\//,"").gsub(/\.\w*\Z/,"").camelize
  controller_class_name.constantize
end

It seems to instantiate the controller in decorator file, how to work it out?

Upvotes: 1

Views: 317

Answers (1)

everyman
everyman

Reputation: 3407

If you are using Grape API Framework with Rails (which I prefer), you can get automatic swagger docs with https://github.com/ruby-grape/grape-swagger - It will parse the definitions and creates docs on the fly.

If you don't need/want to use Grape on Rails or in Sinatra or plain Ruby, I would suggest https://github.com/fotinakis/swagger-blocks. Powerful, but you need to write the definitions manually.

Upvotes: 2

Related Questions