class Napa::Ext::SwaggerDoc
Attributes
api_doc_path[R]
app[R]
Public Class Methods
new(app, api_doc_path: '/api_doc')
click to toggle source
# File lib/napa/ext/swagger_doc.rb, line 4 def initialize app, api_doc_path: '/api_doc' @app = app @api_doc_path = api_doc_path end
Public Instance Methods
call(env)
click to toggle source
# File lib/napa/ext/swagger_doc.rb, line 9 def call env if enabled? && api_doc?(env) [ '301', { 'Location' => target_swagger_url(env), 'Content-Type' => 'text/html' }, [] ] else app.call env end end
Private Instance Methods
api_doc?(env)
click to toggle source
# File lib/napa/ext/swagger_doc.rb, line 25 def api_doc? env env['PATH_INFO'] == api_doc_path end
enabled?()
click to toggle source
# File lib/napa/ext/swagger_doc.rb, line 29 def enabled? ENV.key? 'SWAGGER_UI_URL' end
target_swagger_url(env)
click to toggle source
# File lib/napa/ext/swagger_doc.rb, line 33 def target_swagger_url env swagger_api_uri = "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}/swagger_doc" "#{ENV['SWAGGER_UI_URL']}?swagger_doc=#{swagger_api_uri}" end