Sha256: 09caf99a790895badc7a397e79be65e69a2e95e76ea73e1b362cc7ce4a2cfd21
Contents?: true
Size: 842 Bytes
Versions: 1
Compression:
Stored size: 842 Bytes
Contents
module Napa module Ext class SwaggerDoc def initialize app, api_doc_path: '/api_doc' @app = app @api_doc_path = api_doc_path end 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 attr_reader :app, :api_doc_path def api_doc? env env['PATH_INFO'] == api_doc_path end def enabled? ENV.key? 'SWAGGER_UI_URL' end 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
napa-ext-0.0.6 | lib/napa/ext/swagger_doc.rb |