Class: MiniApivore::SwaggerChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_apivore/swagger_checker.rb

Constant Summary collapse

PATH_TO_CHECKER_MAP =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#responseObject

Returns the value of attribute response.



58
59
60
# File 'lib/mini_apivore/swagger_checker.rb', line 58

def response
  @response
end

#swaggerObject (readonly)

Returns the value of attribute swagger.



58
59
60
# File 'lib/mini_apivore/swagger_checker.rb', line 58

def swagger
  @swagger
end

#swagger_pathObject (readonly)

Returns the value of attribute swagger_path.



58
59
60
# File 'lib/mini_apivore/swagger_checker.rb', line 58

def swagger_path
  @swagger_path
end

Class Method Details

.instance_for(path, schema = '') ⇒ Object



7
8
9
# File 'lib/mini_apivore/swagger_checker.rb', line 7

def self.instance_for(path, schema = '' )
  PATH_TO_CHECKER_MAP[path] ||= new(path, schema)
end

Instance Method Details

#base_pathObject



50
51
52
# File 'lib/mini_apivore/swagger_checker.rb', line 50

def base_path
  @swagger.base_path
end

#fragment(path, verb, code) ⇒ Object



33
34
35
36
# File 'lib/mini_apivore/swagger_checker.rb', line 33

def fragment(path, verb, code)
  path_fragment = mappings[path][verb.to_s][code.to_s]
  path_fragment.dup unless path_fragment.nil?
end

#has_matching_document_for(path, verb, code, body) ⇒ Object



27
28
29
30
31
# File 'lib/mini_apivore/swagger_checker.rb', line 27

def has_matching_document_for(path, verb, code, body)
  JSON::Validator.fully_validate(
    swagger, body, fragment: fragment(path, verb, code)
  )
end

#has_method_at_path?(path, verb) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/mini_apivore/swagger_checker.rb', line 15

def has_method_at_path?(path, verb)
  mappings[path].has_key?(verb)
end

#has_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/mini_apivore/swagger_checker.rb', line 11

def has_path?(path)
  mappings.has_key?(path)
end

#has_response_code_for_path?(path, verb, code) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/mini_apivore/swagger_checker.rb', line 19

def has_response_code_for_path?(path, verb, code)
  mappings[path][verb].has_key?(code.to_s)
end

#remove_tested_end_point_response(path, verb, code) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mini_apivore/swagger_checker.rb', line 38

def remove_tested_end_point_response(path, verb, code)
  return if untested_mappings[path].nil? ||
    untested_mappings[path][verb].nil?
  untested_mappings[path][verb].delete(code.to_s)
  if untested_mappings[path][verb].size == 0
    untested_mappings[path].delete(verb)
    if untested_mappings[path].size == 0
      untested_mappings.delete(path)
    end
  end
end

#response_codes_for_path(path, verb) ⇒ Object



23
24
25
# File 'lib/mini_apivore/swagger_checker.rb', line 23

def response_codes_for_path(path, verb)
  mappings[path][verb].keys.join(", ")
end

#untested_mappingsObject



60
# File 'lib/mini_apivore/swagger_checker.rb', line 60

def untested_mappings; @untested_mappings end

#untested_mappings=(other) ⇒ Object



61
# File 'lib/mini_apivore/swagger_checker.rb', line 61

def untested_mappings=( other ); @untested_mappings = other end