Class: SwaggerCoverage::Parser
- Inherits:
-
Object
- Object
- SwaggerCoverage::Parser
- Defined in:
- lib/swagger_cov.rb
Instance Method Summary collapse
- #check_request_types ⇒ Object
- #check_routes(api = false) ⇒ Object
- #compare_routes(code_routes, swagger_routes, public_api_routes) ⇒ Object
-
#initialize(output, swagger_docs) ⇒ Parser
constructor
A new instance of Parser.
- #source_api_routes ⇒ Object
- #source_routes ⇒ Object
- #swagger_api_routes ⇒ Object
Constructor Details
#initialize(output, swagger_docs) ⇒ Parser
Returns a new instance of Parser.
8 9 10 11 12 13 |
# File 'lib/swagger_cov.rb', line 8 def initialize(output, swagger_docs) @output = output @swagger_docs = swagger_docs @swagger_parser = SwaggerParser.new(@swagger_docs) @code_parser = CodeParser.new(output) end |
Instance Method Details
#check_request_types ⇒ Object
15 16 17 18 19 |
# File 'lib/swagger_cov.rb', line 15 def check_request_types code_request_types = @code_parser.http_requests swagger_request_types = @swagger_parser.http_requests request_types_diff = compare_routes(code_request_types, swagger_request_types) end |
#check_routes(api = false) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/swagger_cov.rb', line 21 def check_routes(api = false) code_endpoints = @code_parser.api_endpoints(@output) public_api_endpoints = @code_parser.public_api_endpoints(@output).uniq.sort swagger_endpoints = @swagger_parser.api_endpoints.uniq.sort routes_diff = compare_routes(code_endpoints, swagger_endpoints, public_api_endpoints) end |
#compare_routes(code_routes, swagger_routes, public_api_routes) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/swagger_cov.rb', line 28 def compare_routes(code_routes, swagger_routes, public_api_routes) endpoints_match = code_routes.eql?(swagger_routes) || public_api_routes.eql?(swagger_routes) endpoint_diff = [] if !endpoints_match if code_routes.size() > swagger_routes.size() endpoint_diff = code_routes - swagger_routes #raise "DOCUMENTATION DOES NOT CONTAIN THE FOLLOWING ROUTES FROM SOURCE: #{endpoint_diff}" else endpoint_diff = swagger_routes - code_routes #raise "SOURCE CODE CONTAINS THE FOLLOWING ROUTES NOT FOUND IN DOCUMENTATION: #{endpoint_diff}" end end endpoint_diff end |
#source_api_routes ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/swagger_cov.rb', line 43 def source_api_routes output = @output endpoints = [] @code_parser.parsed_routes(output).each do |route| if route[:route] != nil endpoints << route[:route] if route[:route].include?('/api') end end endpoints.sort end |
#source_routes ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/swagger_cov.rb', line 54 def source_routes output = @output endpoints = [] @code_parser.parsed_routes(ouput) do |route| endpoints << route[:route] if route[:route] != nil end endpoints.sort end |
#swagger_api_routes ⇒ Object
63 64 65 66 |
# File 'lib/swagger_cov.rb', line 63 def swagger_api_routes swagger_routes = @swagger_parser.api_endpoints swagger_routes.sort end |