Module: Rack::Swagger

Defined in:
lib/rack/swagger.rb,
lib/rack/swagger/version.rb,
lib/rack/swagger/json_server.rb,
lib/rack/swagger/asset_server.rb,
lib/rack/swagger/server_helpers.rb,
lib/rack/swagger/sinatra_helpers.rb,
lib/rack/swagger/routes_to_models.rb,
lib/rack/swagger/index_page_server.rb

Defined Under Namespace

Modules: RoutesToModels, ServerHelpers, SinatraHelpers Classes: AssetServer, IndexPageServer, JsonServer

Constant Summary collapse

VERSION =
"0.0.6"

Class Method Summary collapse

Class Method Details

.app(docs_dir, opts = {}) ⇒ Object

Rack app for serving the swagger-ui front-end and your JSON-formatted Swagger doc files.

Description:

The app will serve the swagger-ui front-end at /docs/, and redirect
requests for /docs to /docs/. It will serve the root Swagger doc
file at /docs/api-docs, and resource files in a subpath of /docs/api-docs,
such as /docs/api-docs/pet for the "pet" resource. This mimics the way
the Pet Store demo is set up.

See: http://petstore.swagger.wordnik.com/

Parameters:

docs_dir: a String containing the path to the directory with your root
Swagger JSON doc file (called swagger.json) and all resource-specific
doc files (for example, pet.json for the "pet" resource).

Usage:

In your config.ru, add:

run Rack::Swagger.app(File.expand_path("../docs/", __FILE__))


33
34
35
36
37
38
39
# File 'lib/rack/swagger.rb', line 33

def self.app(docs_dir, opts={})
  Rack::Cascade.new([
    JsonServer.new(docs_dir, opts),
    IndexPageServer.new,
    AssetServer.new
  ])
end