Code status Build Status Coverage Status

Create Swagger endpoint for your Sinatra application.

This Sinatra extension enable you to add metadata to your code to

  • expose your API as a Swagger endpoint.

  • validate and enrich the invocation parameters

I’m adding features as I need them and it currently doesn’t use all the Swagger options, so if you need one that is missing please open an issue.

Design choices

  • All the declarations are validated when the server is started

  • The declarations are defined to look as ruby-ish as possible

  • Declarations are used for parameters validation and enrichment


To use it in your app :

require 'sinatra/swagger-exposer/swagger-exposer'

class MyApp < Sinatra::Base

  register Sinatra::SwaggerExposer

          version: '0.0.1',
          title: 'My app',
          description: 'My wonderful app',
          license: {
              name: 'MIT',
              url: ''

  type 'Status',
                   :properties => {
                       :status => {
                           :type => String,
                           :example => 'OK,
                   :required => [:status]

  endpoint_description 'Base method to ping'
  endpoint_response 200, 'Status', 'Standard response'
  endpoint_tags 'Ping'
  get '/' do
    json({'status' => 'OK'})


The swagger json endpoint will be exposed at /swagger_doc.json.

Detailed example

A more complete example is available here.


Changelog is here.


  • More parameters taken into account

  • More validations where possible


This software is released under the MIT license.