Class: Rswag3::Api::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rswag3/api/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, config) ⇒ Middleware

Returns a new instance of Middleware.



7
8
9
10
# File 'lib/rswag3/api/middleware.rb', line 7

def initialize(app, config)
  @app = app
  @config = config
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rswag3/api/middleware.rb', line 12

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