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

Version Path
rswag-api-2.1.1 lib/rswag/api/middleware.rb
rswag-api-2.1.0 lib/rswag/api/middleware.rb
rswag-api-2.0.6 lib/rswag/api/middleware.rb
rswagger-api-2.0.7 lib/rswag/api/middleware.rb
rswagger-api-2.0.6 lib/rswag/api/middleware.rb
rswag3-api-0.0.0 lib/rswag/api/middleware.rb
rswag-api-2.0.5 lib/rswag/api/middleware.rb
rswag-api-2.0.4 lib/rswag/api/middleware.rb
rswag-api-2.0.3 lib/rswag/api/middleware.rb
rswag-api-2.0.2 lib/rswag/api/middleware.rb
rswag-api-2.0.1 lib/rswag/api/middleware.rb
rswag-api-2.0.0 lib/rswag/api/middleware.rb
rswag-api-1.6.0 lib/rswag/api/middleware.rb
rswag-api-1.5.2 lib/rswag/api/middleware.rb
rswag-api-1.5.1 lib/rswag/api/middleware.rb
rswag-api-1.5.0 lib/rswag/api/middleware.rb
rswag-api-1.4.0 lib/rswag/api/middleware.rb
rswag-api-1.3.0 lib/rswag/api/middleware.rb
rswag-api-1.2.1 lib/rswag/api/middleware.rb
rswag-api-1.2.0 lib/rswag/api/middleware.rb