Class: Swagui::YAMLDocHandler
- Inherits:
-
Object
- Object
- Swagui::YAMLDocHandler
- Defined in:
- lib/swagui/yaml_doc_handler.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ YAMLDocHandler
constructor
A new instance of YAMLDocHandler.
Constructor Details
#initialize(app) ⇒ YAMLDocHandler
Returns a new instance of YAMLDocHandler.
6 7 8 9 10 11 |
# File 'lib/swagui/yaml_doc_handler.rb', line 6 def initialize(app) @app = app api_docs_content = @app.call("REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/api-docs.yml") v = ''; api_docs_content[2].each {|x| v = v + x} @api_json_template = YAML.load(v)['template'] # used to store the template settings that applies to all apis end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/swagui/yaml_doc_handler.rb', line 13 def call(env) env['HTTP_IF_MODIFIED_SINCE'] = nil # disable Last-Modified caching @app.call(env).tap do |response| if response[0] == 200 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 << f end json_string = YAML::load(body.join('')).tap do |response_hash| if response[2].path.end_with?('api-docs.yml') process_api_docs_api_listing(response_hash, response[2].path ) else process_schemas(response_hash) process_base_path(response_hash, response[2].path, env) end end.to_json response[2] = [json_string] response[1].merge!("Content-Length"=> json_string.size.to_s) end end end end |