swagcov 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83f05163f3408b08db9f9810e5eb82a4285877d9e7b7af60a83e44386eab5c04
4
- data.tar.gz: 76b1bf03e51bc42e516f5b77536d1ae38685dd642823094a0ac8e67fa8c67ac3
3
+ metadata.gz: 820849bdcc13ddb85e1ff404bcc881dbe8f8154090bb6111d0afbdbdd286ce4f
4
+ data.tar.gz: 90de5bb3a335673d58524344dd871182e06c1eb3185192a92026be5be0ce372e
5
5
  SHA512:
6
- metadata.gz: 82610986597a8a832173354fb452a4d63c7c0a22a342ec10fd2ac6bcb3eef845d306c6d37225ac837b22febcb12a0ba093167b71d3acc94aaabb8394789b77a7
7
- data.tar.gz: a1cdf7691af9fce07dfc50711a748bcbfe903ef0f5f5b94e3d1b3d7fd605ac125de92db23121a8ccdb8622494bfba431f7f3710e55f6392a20160e5c2bfd4e4f
6
+ metadata.gz: b49673a8bfca29bb64ece42acc8c1a85f34339b4aa643036c72f4c1849e6e061a933c6471df2502da4e5ba4676c4f75cec559518c87242c7a3a31d6c0e817000
7
+ data.tar.gz: 1b60f5d474d4be3c5c51a6180cb0343b380bca69a4fa99fe0c55063e7037a4f1134d3cbd284a411aa2a9b6ef257898df55facdf99b8827fe2fde3c069c8222be
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Swagcov
2
- See coverage report for openapi docs for Rails Routes.
2
+ [![Gem Version](https://img.shields.io/gem/v/swagcov)](https://rubygems.org/gems/swagcov)
3
+ ![Gem Downloads](https://img.shields.io/gem/dt/swagcov)
4
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
5
+ [![GitHub License](https://img.shields.io/github/license/smridge/swagcov.svg)](https://github.com/smridge/swagcov/blob/main/LICENSE)
6
+
7
+ See OpenAPI documentation coverage report for Rails Routes.
3
8
 
4
9
  ## Installation
5
10
  Add this line to your application's Gemfile:
@@ -34,7 +39,6 @@ Create a `.swagcov.yml` in root of your Rails application.
34
39
  paths:
35
40
  ignore:
36
41
  - /v1/foobar/:token
37
- - /sidekiq
38
42
  ```
39
43
 
40
44
  - Example `.swagcov.yml` Config File:
@@ -49,7 +53,6 @@ Create a `.swagcov.yml` in root of your Rails application.
49
53
  - ^/v1
50
54
  ignore:
51
55
  - /v1/foobar/:token
52
- - /sidekiq
53
56
  ```
54
57
 
55
58
  Execute:
@@ -57,6 +60,44 @@ Execute:
57
60
  bundle exec rake swagcov
58
61
  ```
59
62
 
63
+ ## Example configurations and output from running `bundle exec rake swagcov` from the root of your Rails Application:
64
+ - All Routes (minimal configuration):
65
+ ```yml
66
+ docs:
67
+ paths:
68
+ - swagger.yaml
69
+ ```
70
+ <img src="https://raw.githubusercontent.com/smridge/swagcov/main/images/all-endpoints.png">
71
+
72
+
73
+ - With `only` endpoint configuration:
74
+ ```yml
75
+ docs:
76
+ paths:
77
+ - swagger.yaml
78
+
79
+ routes:
80
+ paths:
81
+ only:
82
+ - ^/v2
83
+ ```
84
+ <img src="https://raw.githubusercontent.com/smridge/swagcov/main/images/only-endpoints.png">
85
+
86
+ - With `ignore` and `only` endpoint configurations:
87
+ ```yml
88
+ docs:
89
+ paths:
90
+ - swagger/v1/swagger.yaml
91
+
92
+ routes:
93
+ paths:
94
+ only:
95
+ - ^/v2
96
+ ignore:
97
+ - /v2/users
98
+ ```
99
+ <img src="https://raw.githubusercontent.com/smridge/swagcov/main/images/ignore-and-only-endpoints.png">
100
+
60
101
  ## Development
61
102
  ```shell
62
103
  git clone git@github.com:smridge/swagcov.git
@@ -72,6 +113,18 @@ gem "swagcov", path: "../swagcov"
72
113
  bundle
73
114
  ```
74
115
 
116
+ Run Tests
117
+ ```
118
+ bundle exec rspec spec --exclude-pattern spec/sandbox_5_2/**/*_spec.rb
119
+ ```
120
+
121
+ ### Test via Sandbox Application
122
+ For Rails 5
123
+ - `cd spec/sandbox_5_2/`
124
+ - Run tests: `bundle exec rspec spec`
125
+ - Run `bundle exec rake swagcov`
126
+ - This will run against any changes made to your branch.
127
+
75
128
  ## Publish (internal)
76
129
  > Note: Publishing a new version of this gem is only meant for maintainers.
77
130
  - Ensure you have access to publish on [rubygems](https://rubygems.org/gems/swagcov).
@@ -84,7 +137,7 @@ bundle
84
137
  ## TODO
85
138
  - Add specs
86
139
  - Test against different rails versions
87
- - Create Sandbox Apps for Rails 5 & 6
140
+ - Create Sandbox App for Rails 6
88
141
  - Add autogeneration of ignore paths
89
142
  - Add `CONTRIBUTING.md`
90
143
  - Add GitHub Actions for specs/linting
@@ -2,31 +2,39 @@
2
2
 
3
3
  module Swagcov
4
4
  class Coverage
5
- def initialize
5
+ attr_reader :total, :covered, :ignored, :routes_not_covered, :routes_covered, :routes_ignored
6
+
7
+ def initialize dotfile: Swagcov::Dotfile.new, routes: ::Rails.application.routes.routes
6
8
  @total = 0
7
9
  @covered = 0
8
10
  @ignored = 0
9
11
  @routes_not_covered = []
10
12
  @routes_covered = []
11
13
  @routes_ignored = []
12
- @dotfile = Swagcov::Dotfile.new
14
+ @dotfile = dotfile
15
+ @routes = routes
13
16
  end
14
17
 
15
18
  def report
16
- Rails.application.routes.routes.each do |route|
17
- # https://github.com/rails/rails/blob/48f3c3e201b57a4832314b2c957a3b303e89bfea/actionpack/lib/action_dispatch/routing/inspector.rb#L105-L107
18
- # Skips route paths like ["/rails/info/properties", "/rails/info", "/rails/mailers"]
19
- next if route.internal
19
+ collect_coverage
20
+ routes_output(@routes_covered, "green")
21
+ routes_output(@routes_ignored, "yellow")
22
+ routes_output(@routes_not_covered, "red")
20
23
 
21
- # Skips routes like "/sidekiq"
22
- next unless route.verb.present?
24
+ final_output
25
+
26
+ exit @total - @covered
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :dotfile
23
32
 
33
+ def collect_coverage
34
+ @routes.each do |route|
24
35
  path = route.path.spec.to_s.sub(/\(\.:format\)$/, "")
25
36
 
26
- # Exclude routes that are part of the rails gem that you would not write documentation for
27
- # https://github.com/rails/rails/tree/main/activestorage/app/controllers/active_storage
28
- # https://github.com/rails/rails/tree/main/actionmailbox/app/controllers/action_mailbox
29
- next if path.include?("/active_storage/") || path.include?("/action_mailbox/")
37
+ next if third_party_route?(route, path)
30
38
 
31
39
  if dotfile.ignore_path?(path)
32
40
  @ignored += 1
@@ -37,7 +45,7 @@ module Swagcov
37
45
  next if dotfile.only_path_mismatch?(path)
38
46
 
39
47
  @total += 1
40
- regex = Regexp.new("#{path.gsub(%r{:[^/]+}, '\\{[^/]+\\}')}(\\.[^/]+)?$")
48
+ regex = Regexp.new("^#{path.gsub(%r{:[^/]+}, '\\{[^/]+\\}')}(\\.[^/]+)?$")
41
49
  matching_keys = docs_paths.keys.select { |k| regex.match?(k) }
42
50
 
43
51
  if (doc = docs_paths.dig(matching_keys.first, route.verb.downcase))
@@ -47,14 +55,6 @@ module Swagcov
47
55
  @routes_not_covered << { verb: route.verb, path: path, status: "none" }
48
56
  end
49
57
  end
50
-
51
- routes_output(@routes_covered, "green")
52
- routes_output(@routes_ignored, "yellow")
53
- routes_output(@routes_not_covered, "red")
54
-
55
- final_output
56
-
57
- exit @total - @covered
58
58
  end
59
59
 
60
60
  def docs_paths
@@ -63,15 +63,25 @@ module Swagcov
63
63
  end
64
64
  end
65
65
 
66
- private
66
+ def third_party_route? route, path
67
+ # https://github.com/rails/rails/blob/48f3c3e201b57a4832314b2c957a3b303e89bfea/actionpack/lib/action_dispatch/routing/inspector.rb#L105-L107
68
+ # Skips route paths like ["/rails/info/properties", "/rails/info", "/rails/mailers"]
69
+ route.internal ||
67
70
 
68
- attr_reader :dotfile
71
+ # Skips routes like "/sidekiq"
72
+ route.verb.blank? ||
73
+
74
+ # Exclude routes that are part of the rails gem that you would not write documentation for
75
+ # https://github.com/rails/rails/tree/main/activestorage/app/controllers/active_storage
76
+ # https://github.com/rails/rails/tree/main/actionmailbox/app/controllers/action_mailbox
77
+ path.include?("/active_storage/") || path.include?("/action_mailbox/")
78
+ end
69
79
 
70
80
  def routes_output routes, status_color
71
81
  routes.each do |route|
72
82
  $stdout.puts(
73
83
  format(
74
- "%<verb>10s %<path>-90s %<status>s",
84
+ "%<verb>10s %<path>-90s %<status>s",
75
85
  { verb: route[:verb], path: route[:path], status: route[:status].send(status_color) }
76
86
  )
77
87
  )
@@ -5,12 +5,13 @@ module Swagcov
5
5
  end
6
6
 
7
7
  class Dotfile
8
- def initialize
9
- pathname = Rails.root.join(".swagcov.yml")
10
- raise BadConfigurationError, "Missing .swagcov.yml" unless pathname.exist?
8
+ DEFAULT_CONFIG_FILE_NAME = ".swagcov.yml"
9
+
10
+ def initialize pathname: Rails.root.join(DEFAULT_CONFIG_FILE_NAME)
11
+ raise BadConfigurationError, "Missing config file (#{DEFAULT_CONFIG_FILE_NAME})" unless pathname.exist?
11
12
 
12
13
  @dotfile = YAML.load_file(pathname)
13
- raise BadConfigurationError, "Invalid .swagcov.yml" unless valid?
14
+ raise BadConfigurationError, "Invalid config file (#{DEFAULT_CONFIG_FILE_NAME})" unless valid?
14
15
  end
15
16
 
16
17
  def ignore_path? path
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Swagcov
4
- VERSION = "0.2.4"
4
+ VERSION = "0.2.5"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagcov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarah Ridge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-30 00:00:00.000000000 Z
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rspec
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  description:
70
98
  email:
71
99
  - sarahmarie@hey.com
@@ -106,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
134
  - !ruby/object:Gem::Version
107
135
  version: '0'
108
136
  requirements: []
109
- rubygems_version: 3.1.4
137
+ rubygems_version: 3.2.3
110
138
  signing_key:
111
139
  specification_version: 4
112
140
  summary: Open API docs coverage for Rails Routes