Create Swagger endpoint for your Sinatra application.
This Sinatra extension enable you to add metadata to your code and to expose your API as a Swagger endpoint.
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 or contribute.
Design choices
-
All the declarations are validated when the server is started
-
The declarations are defined to look as ruby-ish as possible
To use it in your app :
require 'sinatra/swagger-exposer/swagger-exposer'
class MyApp < Sinatra::Base
register Sinatra::SwaggerExposer
general_info(
{
version: '0.0.1',
title: 'May app',
description: 'My wonderful app',
license: {
name: 'MIT',
url: 'http://opensource.org/licenses/MIT'
}
}
)
type 'Status',
{
:properties => {
:status => {
:type => String,
:example => 'OK,
},
},
:required => [:status]
}
endpoint_description 'Base method to ping'
endpoint_response 200, 'Standard response', 'Status'
endpoint_tags 'Ping'
get '/' do
json({'status' => 'OK'})
end
end
The swagger json endpoint will be exposed at /swagger_doc.json
.
Detailed example
A more complete example is available here.
Resources
License
This software is released under the MIT license.