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 +4 -4
- data/README.md +57 -4
- data/lib/swagcov/coverage.rb +34 -24
- data/lib/swagcov/dotfile.rb +5 -4
- data/lib/swagcov/version.rb +1 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 820849bdcc13ddb85e1ff404bcc881dbe8f8154090bb6111d0afbdbdd286ce4f
|
4
|
+
data.tar.gz: 90de5bb3a335673d58524344dd871182e06c1eb3185192a92026be5be0ce372e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b49673a8bfca29bb64ece42acc8c1a85f34339b4aa643036c72f4c1849e6e061a933c6471df2502da4e5ba4676c4f75cec559518c87242c7a3a31d6c0e817000
|
7
|
+
data.tar.gz: 1b60f5d474d4be3c5c51a6180cb0343b380bca69a4fa99fe0c55063e7037a4f1134d3cbd284a411aa2a9b6ef257898df55facdf99b8827fe2fde3c069c8222be
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Swagcov
|
2
|
-
|
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
|
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
|
data/lib/swagcov/coverage.rb
CHANGED
@@ -2,31 +2,39 @@
|
|
2
2
|
|
3
3
|
module Swagcov
|
4
4
|
class Coverage
|
5
|
-
|
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 =
|
14
|
+
@dotfile = dotfile
|
15
|
+
@routes = routes
|
13
16
|
end
|
14
17
|
|
15
18
|
def report
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
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
|
-
|
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("
|
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
|
-
|
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
|
-
|
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
|
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
|
)
|
data/lib/swagcov/dotfile.rb
CHANGED
@@ -5,12 +5,13 @@ module Swagcov
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class Dotfile
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
14
|
+
raise BadConfigurationError, "Invalid config file (#{DEFAULT_CONFIG_FILE_NAME})" unless valid?
|
14
15
|
end
|
15
16
|
|
16
17
|
def ignore_path? path
|
data/lib/swagcov/version.rb
CHANGED
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
|
+
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-
|
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.
|
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
|