swagcov 0.1.0 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/swagcov.rb +3 -0
- data/lib/swagcov/core_ext/string.rb +17 -0
- data/lib/swagcov/coverage.rb +18 -31
- data/lib/swagcov/dotfile.rb +52 -0
- data/lib/swagcov/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83f05163f3408b08db9f9810e5eb82a4285877d9e7b7af60a83e44386eab5c04
|
4
|
+
data.tar.gz: 76b1bf03e51bc42e516f5b77536d1ae38685dd642823094a0ac8e67fa8c67ac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82610986597a8a832173354fb452a4d63c7c0a22a342ec10fd2ac6bcb3eef845d306c6d37225ac837b22febcb12a0ba093167b71d3acc94aaabb8394789b77a7
|
7
|
+
data.tar.gz: a1cdf7691af9fce07dfc50711a748bcbfe903ef0f5f5b94e3d1b3d7fd605ac125de92db23121a8ccdb8622494bfba431f7f3710e55f6392a20160e5c2bfd4e4f
|
data/README.md
CHANGED
@@ -72,10 +72,22 @@ gem "swagcov", path: "../swagcov"
|
|
72
72
|
bundle
|
73
73
|
```
|
74
74
|
|
75
|
+
## Publish (internal)
|
76
|
+
> Note: Publishing a new version of this gem is only meant for maintainers.
|
77
|
+
- Ensure you have access to publish on [rubygems](https://rubygems.org/gems/swagcov).
|
78
|
+
- Update [CHANGELOG](https://github.com/smridge/swagcov/blob/main/CHANGELOG.md).
|
79
|
+
- Update [`VERSION`](https://github.com/smridge/swagcov/blob/main/lib/swagcov/version.rb).
|
80
|
+
- Commit changes to `main` branch locally.
|
81
|
+
- Run: `rake release`
|
82
|
+
- This command builds the gem, creates a tag and publishes to rubygems, see [bundler docs](https://bundler.io/guides/creating_gem.html#releasing-the-gem).
|
83
|
+
|
75
84
|
## TODO
|
76
85
|
- Add specs
|
77
86
|
- Test against different rails versions
|
87
|
+
- Create Sandbox Apps for Rails 5 & 6
|
78
88
|
- Add autogeneration of ignore paths
|
89
|
+
- Add `CONTRIBUTING.md`
|
90
|
+
- Add GitHub Actions for specs/linting
|
79
91
|
|
80
92
|
## Credit
|
81
93
|
To [@lonelyelk](https://github.com/lonelyelk) for initial development!
|
data/lib/swagcov.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class String
|
4
|
+
COLORS = {
|
5
|
+
red: 31,
|
6
|
+
green: 32,
|
7
|
+
yellow: 33,
|
8
|
+
blue: 34
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
# returns bold colors
|
12
|
+
COLORS.each_pair do |color, value|
|
13
|
+
define_method(color) do
|
14
|
+
"\e[1;#{value}m#{self}\e[0m"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/swagcov/coverage.rb
CHANGED
@@ -9,19 +9,32 @@ module Swagcov
|
|
9
9
|
@routes_not_covered = []
|
10
10
|
@routes_covered = []
|
11
11
|
@routes_ignored = []
|
12
|
+
@dotfile = Swagcov::Dotfile.new
|
12
13
|
end
|
13
14
|
|
14
15
|
def report
|
15
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
|
20
|
+
|
21
|
+
# Skips routes like "/sidekiq"
|
22
|
+
next unless route.verb.present?
|
23
|
+
|
16
24
|
path = route.path.spec.to_s.sub(/\(\.:format\)$/, "")
|
17
25
|
|
18
|
-
|
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/")
|
30
|
+
|
31
|
+
if dotfile.ignore_path?(path)
|
19
32
|
@ignored += 1
|
20
33
|
@routes_ignored << { verb: route.verb, path: path, status: "ignored" }
|
21
34
|
next
|
22
35
|
end
|
23
36
|
|
24
|
-
next if only_path_mismatch?(path)
|
37
|
+
next if dotfile.only_path_mismatch?(path)
|
25
38
|
|
26
39
|
@total += 1
|
27
40
|
regex = Regexp.new("#{path.gsub(%r{:[^/]+}, '\\{[^/]+\\}')}(\\.[^/]+)?$")
|
@@ -41,44 +54,18 @@ module Swagcov
|
|
41
54
|
|
42
55
|
final_output
|
43
56
|
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
def dotfile
|
48
|
-
@dotfile ||= YAML.load_file(Rails.root.join(".swagcov.yml"))
|
57
|
+
exit @total - @covered
|
49
58
|
end
|
50
59
|
|
51
60
|
def docs_paths
|
52
|
-
@docs_paths ||= Dir.glob(dotfile
|
61
|
+
@docs_paths ||= Dir.glob(dotfile.doc_paths).reduce({}) do |acc, docspath|
|
53
62
|
acc.merge(YAML.load_file(docspath)["paths"])
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
57
66
|
private
|
58
67
|
|
59
|
-
|
60
|
-
ignored_regex&.match?(path)
|
61
|
-
end
|
62
|
-
|
63
|
-
def ignored_regex
|
64
|
-
@ignored_regex ||= path_config_regex(dotfile.dig("routes", "paths", "ignore"))
|
65
|
-
end
|
66
|
-
|
67
|
-
def only_path_mismatch? path
|
68
|
-
only_regex && !only_regex.match?(path)
|
69
|
-
end
|
70
|
-
|
71
|
-
def only_regex
|
72
|
-
@only_regex ||= path_config_regex(dotfile.dig("routes", "paths", "only"))
|
73
|
-
end
|
74
|
-
|
75
|
-
def path_config_regex path_config
|
76
|
-
return unless path_config
|
77
|
-
|
78
|
-
config = path_config.map { |path| path.first == "^" ? path : "#{path}$" }
|
79
|
-
|
80
|
-
/#{config.join('|')}/
|
81
|
-
end
|
68
|
+
attr_reader :dotfile
|
82
69
|
|
83
70
|
def routes_output routes, status_color
|
84
71
|
routes.each do |route|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Swagcov
|
4
|
+
class BadConfigurationError < RuntimeError
|
5
|
+
end
|
6
|
+
|
7
|
+
class Dotfile
|
8
|
+
def initialize
|
9
|
+
pathname = Rails.root.join(".swagcov.yml")
|
10
|
+
raise BadConfigurationError, "Missing .swagcov.yml" unless pathname.exist?
|
11
|
+
|
12
|
+
@dotfile = YAML.load_file(pathname)
|
13
|
+
raise BadConfigurationError, "Invalid .swagcov.yml" unless valid?
|
14
|
+
end
|
15
|
+
|
16
|
+
def ignore_path? path
|
17
|
+
ignored_regex&.match?(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def only_path_mismatch? path
|
21
|
+
only_regex && !only_regex.match?(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def doc_paths
|
25
|
+
dotfile.dig("docs", "paths")
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :dotfile
|
31
|
+
|
32
|
+
def ignored_regex
|
33
|
+
@ignored_regex ||= path_config_regex(dotfile.dig("routes", "paths", "ignore"))
|
34
|
+
end
|
35
|
+
|
36
|
+
def only_regex
|
37
|
+
@only_regex ||= path_config_regex(dotfile.dig("routes", "paths", "only"))
|
38
|
+
end
|
39
|
+
|
40
|
+
def path_config_regex path_config
|
41
|
+
return unless path_config
|
42
|
+
|
43
|
+
config = path_config.map { |path| path.first == "^" ? path : "^#{path}$" }
|
44
|
+
|
45
|
+
/#{config.join('|')}/
|
46
|
+
end
|
47
|
+
|
48
|
+
def valid?
|
49
|
+
dotfile && doc_paths
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
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.
|
4
|
+
version: 0.2.4
|
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-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -77,7 +77,9 @@ files:
|
|
77
77
|
- README.md
|
78
78
|
- Rakefile
|
79
79
|
- lib/swagcov.rb
|
80
|
+
- lib/swagcov/core_ext/string.rb
|
80
81
|
- lib/swagcov/coverage.rb
|
82
|
+
- lib/swagcov/dotfile.rb
|
81
83
|
- lib/swagcov/railtie.rb
|
82
84
|
- lib/swagcov/version.rb
|
83
85
|
- lib/tasks/swagcove.rake
|
@@ -104,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
106
|
- !ruby/object:Gem::Version
|
105
107
|
version: '0'
|
106
108
|
requirements: []
|
107
|
-
rubygems_version: 3.
|
109
|
+
rubygems_version: 3.1.4
|
108
110
|
signing_key:
|
109
111
|
specification_version: 4
|
110
112
|
summary: Open API docs coverage for Rails Routes
|