Class: Rack::JsonSchema::Docs

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/json_schema/docs.rb

Defined Under Namespace

Classes: DocumentGenerator

Constant Summary collapse

DEFAULT_PATH =
"/docs"

Instance Method Summary collapse

Constructor Details

#initialize(app, path: nil, schema: nil) ⇒ Docs

Behaves as a rack-middleware

Parameters:

  • app (Object)

    Rack application

  • path (String, nil) (defaults to: nil)

    URL path to return document (default: /docs)

  • schema (Hash) (defaults to: nil)

    Schema object written in JSON schema format



10
11
12
13
14
15
# File 'lib/rack/json_schema/docs.rb', line 10

def initialize(app, path: nil, schema: nil)
  @app = app
  @path = path
  @markdown = Jdoc::Generator.call(schema)
  @html = Jdoc::Generator.call(schema, html: true)
end

Instance Method Details

#call(env) ⇒ Object

Returns rendered document for document request

Parameters:

  • env (Hash)

    Rack env



19
20
21
22
23
24
25
26
27
# File 'lib/rack/json_schema/docs.rb', line 19

def call(env)
  DocumentGenerator.call(
    app: @app,
    env: env,
    html: @html,
    markdown: @markdown,
    path: path,
  )
end