Class: Swagui::YAMLDocHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/swagui/yaml_doc_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ YAMLDocHandler

Returns a new instance of YAMLDocHandler.



6
7
8
9
# File 'lib/swagui/yaml_doc_handler.rb', line 6

def initialize(app)
  @app = app
  @api_json_template = nil # used to store the template settings that applies to all apis
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/swagui/yaml_doc_handler.rb', line 11

def call(env)
  @app.call(env).tap do |response|

    response[1].merge!("Content-Type"=>"application/json") # response is always json content

    if yaml_response?(response) # yml response needs to be re=processed.
      body = []
      response[2].each do |f|
        body << YAML::load(f).tap do |response_hash|
          process_api_docs_api_listing(response_hash, response[2].path )
          process_schemas(response_hash)
          process_base_path(response_hash, response[2].path, env)
        end.to_json
      end

      response[2] = body

      response[1].merge!("Content-Length"=> body.first.size.to_s)
    end
  end
end