Class: Swagcov::OpenapiFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/swagcov/openapi_files.rb

Instance Method Summary collapse

Constructor Details

#initialize(filepaths:) ⇒ OpenapiFiles

Returns a new instance of OpenapiFiles.



5
6
7
8
# File 'lib/swagcov/openapi_files.rb', line 5

def initialize filepaths:
  @filepaths = filepaths
  @openapi_paths = load_yamls
end

Instance Method Details

#find_response_keys(path:, route_verb:) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/swagcov/openapi_files.rb', line 10

def find_response_keys path:, route_verb:
  # replace :id with {id}
  regex = Regexp.new("^#{path.gsub(%r{:[^/]+}, '\\{[^/]+\\}')}?$")

  matching_paths_key = @openapi_paths.keys.grep(regex).first
  matching_request_method_key = @openapi_paths.dig(matching_paths_key, route_verb.downcase)

  matching_request_method_key["responses"].keys.map(&:to_s).sort if matching_request_method_key
end