Sha256: fb1c00c543b09a3ebabe3fe42da76236977b0728aded83374efc5f9ea4274ef2
Contents?: true
Size: 783 Bytes
Versions: 25
Compression:
Stored size: 783 Bytes
Contents
require 'json' module Rswag module Api class Middleware def initialize(app, config) @app = app @config = config end def call(env) path = env['PATH_INFO'] filename = "#{@config.resolve_swagger_root(env)}/#{path}" if env['REQUEST_METHOD'] == 'GET' && File.file?(filename) swagger = load_json(filename) @config.swagger_filter.call(swagger, env) unless @config.swagger_filter.nil? return [ '200', { 'Content-Type' => 'application/json' }, [ JSON.dump(swagger) ] ] end return @app.call(env) end private def load_json(filename) JSON.parse(File.read(filename)) end end end end
Version data entries
25 entries across 25 versions & 3 rubygems