Class: Openapi::Rswag::Api::Middleware
- Inherits:
-
Object
- Object
- Openapi::Rswag::Api::Middleware
- Defined in:
- lib/openapi/rswag/api/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, config) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, config) ⇒ Middleware
Returns a new instance of Middleware.
10 11 12 13 |
# File 'lib/openapi/rswag/api/middleware.rb', line 10 def initialize(app, config) @app = app @config = config end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/openapi/rswag/api/middleware.rb', line 15 def call(env) path = env['PATH_INFO'] filename = "#{@config.resolve_swagger_root(env)}/#{path}" if env['REQUEST_METHOD'] == 'GET' && File.file?(filename) swagger = parse_file(filename) @config.swagger_filter.call(swagger, env) unless @config.swagger_filter.nil? mime = Rack::Mime.mime_type(::File.extname(path), 'text/plain') body = unload_swagger(filename, swagger) return [ '200', { 'Content-Type' => mime }, [ body ] ] end return @app.call(env) end |