Class: Webspicy::Web::Openapi::Reporter

Inherits:
Tester::Reporter show all
Includes:
Utils
Defined in:
lib/webspicy/web/openapi/reporter.rb

Constant Summary

Constants inherited from Tester::Reporter

Tester::Reporter::ErrorCount, Tester::Reporter::HOOKS

Instance Attribute Summary

Attributes inherited from Tester::Reporter

#io, #tester

Instance Method Summary collapse

Methods included from Utils

#actual_body_schema, #actual_input_schema, #actual_output_schema, #actual_parameters_schema, #base_path_for, #base_request_body_for, #base_request_example_for, #base_request_response_for, #base_verb_for, #content_type_for, #downcase_verb, #empty_schema?, #extract_request_body_info_for, #into_service_request_body, #into_service_responses, #into_service_verb, #into_specification_path, #parameters_for, #standardize, #tags_for

Methods inherited from Tester::Reporter

#find, #init

Methods included from Support::Colorize

colorize, colorize_error, colorize_highlight, colorize_section, colorize_success

Constructor Details

#initialize(base, output_file) ⇒ Reporter

Returns a new instance of Reporter.



7
8
9
10
# File 'lib/webspicy/web/openapi/reporter.rb', line 7

def initialize(base, output_file)
  @base = base
  @output_file = output_file
end

Instance Method Details

#after_eachObject



16
17
18
19
20
21
22
23
# File 'lib/webspicy/web/openapi/reporter.rb', line 16

def after_each
  @datastruct.ensure_tags(tags_for(specification))
  @datastruct.ensure_path(base_path_for(specification))
  @datastruct.ensure_path(base_verb_for(test_case))
  @datastruct.ensure_path(base_request_body_for(service))
  @datastruct.ensure_path(base_request_example_for(test_case))
  @datastruct.ensure_path(base_request_response_for(invocation))
end

#before_allObject



12
13
14
# File 'lib/webspicy/web/openapi/reporter.rb', line 12

def before_all
  @datastruct = DataStruct.new
end

#reportObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/webspicy/web/openapi/reporter.rb', line 25

def report
  json = DataStruct::MERGER.deep_merge(
    @base,
    @datastruct.to_openapi_data,
  )
  order = ["get", "post", "patch", "delete"]
  json["paths"].keys.each do |path|
    sorted = {}
    json["paths"][path]
      .keys
      .sort_by{|k| order.index(k) || -1 }
      .each do |k|
        sorted[k] = json["paths"][path][k]
      end
    json["paths"][path] = sorted
  end
  @output_file.write(JSON.pretty_generate(json))
end