/grape-swagger

Add swagger compliant documentation to your grape API

Primary LanguageRubyMIT LicenseMIT

grape-swagger

What is grape-swagger?

grape-swagger provides an autogenerated documentation for your grape-API. The generated documentation is Swagger-compliant, meaning it can easily be discovered in Swagger UI

Related projects

Installation

grape-swagger is available as a gem, install it simply via the commandline:

gem install grape-swagger

or add to your Gemfile:

gem 'grape-swagger'

Usage

Once you have the gem installed, mount all your different APIs (with Grape::API superclass) on a root node. In the root class definition, also include add_swagger_documentation, this sets up the system and registers the documentation on '/swagger_doc.json'. Setup done, you can restart your local server now.

require 'grape-swagger'

module API
  class Root < Grape::API
    mount API::Cats
    mount API::Dogs
    mount API::Pirates
    add_swagger_documentation
  end
end

To explore your API, either download Swagger UI and set it up yourself or go to the online swagger demo and enter your localhost url documentation root in the url field (probably something in the line of http://localhost:3000/swagger_doc.json)

Configure

You can pass a hash with some configuration possibilities to add_swagger_documentation, all of these are optional:

  • :mount_path The path were the API documentation is loaded, default '/swagger_doc'
  • :api_version Version of the API that's being exposed
  • :base_path Basepath of the API that's being exposed

Contributing to grape-swagger

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2012 Tim Vandecasteele. See LICENSE.txt for further details.