swagcov 0.9.0 → 0.11.0
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/CHANGELOG.md +34 -0
- data/README.md +44 -18
- data/exe/swagcov +27 -0
- data/lib/swagcov/command/report_version.rb +13 -0
- data/lib/swagcov/coverage.rb +18 -11
- data/lib/swagcov/dotfile.rb +2 -2
- data/lib/swagcov/formatter/console.rb +3 -4
- data/lib/swagcov/options.rb +41 -0
- data/lib/swagcov/runner.rb +26 -0
- data/lib/swagcov/version.rb +1 -1
- data/lib/swagcov.rb +3 -0
- data/lib/tasks/swagcov.rake +2 -1
- metadata +9 -6
- data/lib/tasks/swagcov/generate_todo.rake +0 -8
- data/lib/tasks/swagcov/install.rake +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3102d52e8495c610e219ad58a32c75a3575cbd0460f1fddefdb5d427ff4e9f5e
|
4
|
+
data.tar.gz: 7f64fbc51d03dec663fea9dec838615f12d287d7f6a83f813e1f5411e6f11f8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 233f4668cb3e3ffa15b8354543c17f6879d50e5d077cf9aa55ea3aeb3c7d0f0f42bd7de4a7d5383987268377734ba90ac737f7bd3e02bb17a0d337ab3f348a96
|
7
|
+
data.tar.gz: b420010ec3553036c2ea18ceb3d14d1f080b3af9ced0daa432a3d7a47d70a0d9beaee4baacc1dc0747df4701d7b447088177d27d8f415d7486480d89c73dffe0
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,40 @@
|
|
2
2
|
## main (unreleased)
|
3
3
|
-
|
4
4
|
|
5
|
+
## 0.11.0 (2025-05-13)
|
6
|
+
### Enhancement
|
7
|
+
- Add swagcov `version` option ([#134](https://github.com/smridge/swagcov/pull/134))
|
8
|
+
```
|
9
|
+
swagcov -v
|
10
|
+
rake swagcov -- -v
|
11
|
+
```
|
12
|
+
|
13
|
+
### Refactor
|
14
|
+
- Reduce `Metrics/AbcSize` for better maintainability ([#138](https://github.com/smridge/swagcov/pull/138), [#139](https://github.com/smridge/swagcov/pull/139), [#140](https://github.com/smridge/swagcov/pull/140))
|
15
|
+
|
16
|
+
## 0.10.0 (2025-05-08)
|
17
|
+
### Enhancement
|
18
|
+
- Add executable for streamlined command line usage ([#120](https://github.com/smridge/swagcov/pull/120))
|
19
|
+
- The below options are now available:
|
20
|
+
```
|
21
|
+
swagcov
|
22
|
+
swagcov --init
|
23
|
+
swagcov --todo
|
24
|
+
swagcov --help
|
25
|
+
```
|
26
|
+
- **Note**: This is experimental as it may not work for all use cases. Use `rake swagcov` as a fallback
|
27
|
+
- Add command line options to the existing `rake swagcov` task ([#121](https://github.com/smridge/swagcov/pull/121), [#122](https://github.com/smridge/swagcov/pull/122), [#123](https://github.com/smridge/swagcov/pull/123))
|
28
|
+
- The below options are now available:
|
29
|
+
```
|
30
|
+
rake swagcov
|
31
|
+
rake swagcov -- --init
|
32
|
+
rake swagcov -- --todo
|
33
|
+
rake swagcov -- --help
|
34
|
+
```
|
35
|
+
- **Note**: This refactor involved `BREAKING CHANGES`:
|
36
|
+
- `rake swagcov:generate_todo` is now `rake swagcov -- --todo`
|
37
|
+
- `rake swagcov:install` is now `rake swagcov -- --init`
|
38
|
+
|
5
39
|
## 0.9.0 (2025-05-07)
|
6
40
|
### Enhancement
|
7
41
|
- Add support for `.json` OpenAPI file types ([#112](https://github.com/smridge/swagcov/pull/112), [#113](https://github.com/smridge/swagcov/pull/113))
|
data/README.md
CHANGED
@@ -9,31 +9,57 @@
|
|
9
9
|

|
10
10
|
[](https://coveralls.io/github/smridge/swagcov?branch=main)
|
11
11
|
|
12
|
-
|
12
|
+
OpenAPI documentation coverage report for Rails Routes.
|
13
13
|
|
14
14
|
## Usages
|
15
15
|
- See overview of different endpoints covered, missing and what you choose to ignore.
|
16
|
-
- Add pass/fail to your build pipeline when missing
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
- Add pass/fail to your build pipeline when missing documentation coverage.
|
17
|
+
|
18
|
+
### Usage Options
|
19
|
+
`swagcov` can be used with a few different approachs.
|
20
|
+
The approaches below are listed in the following order:
|
21
|
+
- via executable
|
22
|
+
- via rake task
|
23
|
+
- via rails console
|
24
|
+
|
25
|
+
#### View OpenAPI documentation coverage report for Rails Route endpoints
|
26
|
+
- `swagcov`
|
27
|
+
- `rake swagcov`
|
28
|
+
- `Swagcov::Runner.new.run`
|
29
|
+
|
30
|
+
#### Generate required `.swagcov.yml` config file
|
31
|
+
- `swagcov --init`
|
32
|
+
- `rake swagcov -- --init`
|
33
|
+
- `Swagcov::Runner.new(args: ["--init"]).run`
|
34
|
+
|
35
|
+
#### Generate optional `.swagcov_todo.yml` config file
|
36
|
+
- `swagcov --todo`
|
37
|
+
- `rake swagcov -- --todo`
|
38
|
+
- `Swagcov::Runner.new(args: ["--todo"]).run`
|
39
|
+
|
40
|
+
#### View `swagcov` version
|
41
|
+
- `swagcov -v`
|
42
|
+
- `rake swagcov -- -v`
|
43
|
+
- `Swagcov::Runner.new(args: ["-v"]).run`
|
44
|
+
|
45
|
+
#### View command line usage options
|
46
|
+
- `swagcov --help`
|
47
|
+
- `rake swagcov -- --help`
|
48
|
+
- `Swagcov::Runner.new(args: ["--help"]).run`
|
23
49
|
|
24
50
|
## Ruby and Rails Version Support
|
25
51
|
Versioning support from a test coverage perspective, see [tests.yml](/.github/workflows/tests.yml) for detail
|
26
52
|
| `ruby -v` | `rails 4.2` | `rails 5.0` | `rails 5.1` | `rails 5.2` | `rails 6.0` | `rails 6.1` | `rails 7.0` | `rails 7.1` | `rails 7.2` | `rails 8.0` |
|
27
|
-
| ---
|
28
|
-
| `2.5`
|
29
|
-
| `2.6`
|
30
|
-
| `2.7`
|
31
|
-
| `3.0`
|
32
|
-
| `3.1`
|
33
|
-
| `3.2`
|
34
|
-
| `3.3`
|
35
|
-
| `3.4`
|
36
|
-
| `3.5`
|
53
|
+
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
|
54
|
+
| `2.5` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
55
|
+
| `2.6` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
|
56
|
+
| `2.7` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
57
|
+
| `3.0` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
|
58
|
+
| `3.1` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
|
59
|
+
| `3.2` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
60
|
+
| `3.3` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
61
|
+
| `3.4` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
62
|
+
| `3.5` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
37
63
|
|
38
64
|
## Installation
|
39
65
|
Add this line to your application's Gemfile:
|
data/exe/swagcov
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Experimental executable
|
5
|
+
#
|
6
|
+
# Booting rails approach should work for most applications
|
7
|
+
# Rake task option as an alternative should always work as expected
|
8
|
+
|
9
|
+
# Load logger before rails
|
10
|
+
# Fix for booting rails 6.0-7.0 apps (uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger)
|
11
|
+
require "logger"
|
12
|
+
|
13
|
+
require "swagcov"
|
14
|
+
|
15
|
+
RAILS_APP_PATH = File.expand_path("config/application", Dir.pwd)
|
16
|
+
|
17
|
+
def boot_rails_application!
|
18
|
+
require RAILS_APP_PATH
|
19
|
+
Rails.application.initialize!
|
20
|
+
rescue LoadError, NoMethodError
|
21
|
+
warn "Unable to load Rails application, try running `rake swagcov` instead"
|
22
|
+
exit Swagcov::STATUS_ERROR
|
23
|
+
end
|
24
|
+
|
25
|
+
boot_rails_application!
|
26
|
+
|
27
|
+
Swagcov::Runner.new(args: ARGV).run
|
data/lib/swagcov/coverage.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
module Swagcov
|
4
4
|
class Coverage
|
5
|
-
attr_reader :dotfile
|
6
|
-
|
7
5
|
def initialize dotfile: ::Swagcov::Dotfile.new, routes: ::Swagcov.project_routes
|
8
6
|
@dotfile = dotfile
|
7
|
+
@openapi_files = ::Swagcov::OpenapiFiles.new(filepaths: @dotfile.docs_config)
|
9
8
|
@routes = routes
|
9
|
+
@rails_version = ::Rails::VERSION::STRING
|
10
10
|
@data = {
|
11
11
|
covered: [],
|
12
12
|
ignored: [],
|
@@ -19,14 +19,11 @@ module Swagcov
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def collect
|
22
|
-
openapi_files = ::Swagcov::OpenapiFiles.new(filepaths: dotfile.docs_config)
|
23
|
-
rails_version = ::Rails::VERSION::STRING
|
24
|
-
|
25
22
|
@routes.each do |route|
|
26
|
-
path = route
|
27
|
-
verb =
|
23
|
+
path = route_path(route)
|
24
|
+
verb = route_verb(route)
|
28
25
|
|
29
|
-
next if third_party_route?(route, path
|
26
|
+
next if third_party_route?(route, path)
|
30
27
|
|
31
28
|
if dotfile.ignore_path?(path, verb: verb)
|
32
29
|
update_data(:ignored, verb, path, "ignored")
|
@@ -49,10 +46,20 @@ module Swagcov
|
|
49
46
|
|
50
47
|
private
|
51
48
|
|
52
|
-
|
49
|
+
attr_reader :dotfile, :openapi_files, :rails_version
|
50
|
+
|
51
|
+
def route_path route
|
52
|
+
route.path.spec.to_s.chomp("(.:format)")
|
53
|
+
end
|
54
|
+
|
55
|
+
def route_verb route
|
56
|
+
rails_version > "5" ? route.verb : route.verb.inspect.gsub(%r{[$^/]}, "")
|
57
|
+
end
|
58
|
+
|
59
|
+
def third_party_route? route, path
|
53
60
|
# https://github.com/rails/rails/blob/48f3c3e201b57a4832314b2c957a3b303e89bfea/actionpack/lib/action_dispatch/routing/inspector.rb#L105-L107
|
54
61
|
# Skips route paths like ["/rails/info/properties", "/rails/info", "/rails/mailers"]
|
55
|
-
internal_rails_route?(route
|
62
|
+
internal_rails_route?(route) ||
|
56
63
|
|
57
64
|
# Skips routes like "/sidekiq"
|
58
65
|
route.verb.blank? ||
|
@@ -63,7 +70,7 @@ module Swagcov
|
|
63
70
|
path.include?("/active_storage/") || path.include?("/action_mailbox/")
|
64
71
|
end
|
65
72
|
|
66
|
-
def internal_rails_route? route
|
73
|
+
def internal_rails_route? route
|
67
74
|
if rails_version > "5"
|
68
75
|
route.internal
|
69
76
|
else
|
data/lib/swagcov/dotfile.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Swagcov
|
4
4
|
class Dotfile
|
5
|
-
DEFAULT_CONFIG_FILE_NAME = ".swagcov.yml"
|
6
|
-
TODO_CONFIG_FILE_NAME = ".swagcov_todo.yml"
|
5
|
+
DEFAULT_CONFIG_FILE_NAME = ::ENV.fetch("SWAGCOV_DOTFILE", ".swagcov.yml")
|
6
|
+
TODO_CONFIG_FILE_NAME = ::ENV.fetch("SWAGCOV_TODOFILE", ".swagcov_todo.yml")
|
7
7
|
|
8
8
|
def initialize basename: DEFAULT_CONFIG_FILE_NAME, todo_basename: TODO_CONFIG_FILE_NAME, skip_todo: false
|
9
9
|
@dotfile = load_yaml(basename, required: true)
|
@@ -33,10 +33,9 @@ module Swagcov
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def min_path_width
|
36
|
-
strings =
|
37
|
-
|
38
|
-
|
39
|
-
data[:uncovered].map { |hash| hash[:path] }
|
36
|
+
strings = []
|
37
|
+
|
38
|
+
%i[covered ignored uncovered].each { |key| data[key].each { |hash| strings << hash[:path] } }
|
40
39
|
|
41
40
|
@min_path_width ||= strings.max_by(&:length)&.size.to_i + 1
|
42
41
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
module Swagcov
|
6
|
+
class Options
|
7
|
+
def initialize args: ::ARGV
|
8
|
+
@args = args
|
9
|
+
end
|
10
|
+
|
11
|
+
def define
|
12
|
+
options = {}
|
13
|
+
|
14
|
+
::OptionParser.new do |opts|
|
15
|
+
opts.banner = <<~MESSAGE
|
16
|
+
Usage:
|
17
|
+
* as executable: swagcov [options]
|
18
|
+
* as rake task: rake swagcov -- [options]
|
19
|
+
MESSAGE
|
20
|
+
|
21
|
+
opts.on("-i", "--init", "Generate required .swagcov.yml config file") do |opt|
|
22
|
+
options[:init] = opt
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-t", "--todo", "Generate optional .swagcov_todo.yml config file") do |opt|
|
26
|
+
options[:todo] = opt
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-v", "--version", "Display version") do |opt|
|
30
|
+
options[:version] = opt
|
31
|
+
end
|
32
|
+
end.parse!(@args)
|
33
|
+
|
34
|
+
options
|
35
|
+
rescue ::OptionParser::InvalidOption => e
|
36
|
+
warn e.message
|
37
|
+
warn "For usage information, use --help"
|
38
|
+
exit ::Swagcov::STATUS_ERROR
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Swagcov
|
4
|
+
class Runner
|
5
|
+
attr_reader :options
|
6
|
+
|
7
|
+
def initialize args: ::ARGV
|
8
|
+
@args = args
|
9
|
+
@options = ::Swagcov::Options.new(args: @args).define
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
exit runner
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def runner
|
19
|
+
return ::Swagcov::Command::GenerateDotfile.new.run if options[:init]
|
20
|
+
return ::Swagcov::Command::GenerateTodoFile.new.run if options[:todo]
|
21
|
+
return ::Swagcov::Command::ReportVersion.new.run if options[:version]
|
22
|
+
|
23
|
+
::Swagcov::Command::ReportCoverage.new.run
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/swagcov/version.rb
CHANGED
data/lib/swagcov.rb
CHANGED
@@ -5,13 +5,16 @@ require "rails"
|
|
5
5
|
require "swagcov/command/generate_dotfile"
|
6
6
|
require "swagcov/command/generate_todo_file"
|
7
7
|
require "swagcov/command/report_coverage"
|
8
|
+
require "swagcov/command/report_version"
|
8
9
|
require "swagcov/core_ext/string"
|
9
10
|
require "swagcov/formatter/console"
|
10
11
|
require "swagcov/coverage"
|
11
12
|
require "swagcov/dotfile"
|
12
13
|
require "swagcov/errors"
|
13
14
|
require "swagcov/openapi_files"
|
15
|
+
require "swagcov/options"
|
14
16
|
require "swagcov/railtie"
|
17
|
+
require "swagcov/runner"
|
15
18
|
require "swagcov/version"
|
16
19
|
|
17
20
|
module Swagcov
|
data/lib/tasks/swagcov.rake
CHANGED
@@ -2,5 +2,6 @@
|
|
2
2
|
|
3
3
|
desc "Check OpenAPI documentation coverage for Rails Route endpoints"
|
4
4
|
task swagcov: :environment do
|
5
|
-
|
5
|
+
args = ARGV.drop(2) # Remove "swagcov" and "--" to ignore standard rake arguments
|
6
|
+
Swagcov::Runner.new(args: args).run
|
6
7
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagcov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sarah Ridge
|
8
|
-
bindir:
|
8
|
+
bindir: exe
|
9
9
|
cert_chain: []
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
@@ -25,28 +25,31 @@ dependencies:
|
|
25
25
|
version: '4.2'
|
26
26
|
email:
|
27
27
|
- sarahmarie@hey.com
|
28
|
-
executables:
|
28
|
+
executables:
|
29
|
+
- swagcov
|
29
30
|
extensions: []
|
30
31
|
extra_rdoc_files: []
|
31
32
|
files:
|
32
33
|
- CHANGELOG.md
|
33
34
|
- LICENSE
|
34
35
|
- README.md
|
36
|
+
- exe/swagcov
|
35
37
|
- lib/swagcov.rb
|
36
38
|
- lib/swagcov/command/generate_dotfile.rb
|
37
39
|
- lib/swagcov/command/generate_todo_file.rb
|
38
40
|
- lib/swagcov/command/report_coverage.rb
|
41
|
+
- lib/swagcov/command/report_version.rb
|
39
42
|
- lib/swagcov/core_ext/string.rb
|
40
43
|
- lib/swagcov/coverage.rb
|
41
44
|
- lib/swagcov/dotfile.rb
|
42
45
|
- lib/swagcov/errors.rb
|
43
46
|
- lib/swagcov/formatter/console.rb
|
44
47
|
- lib/swagcov/openapi_files.rb
|
48
|
+
- lib/swagcov/options.rb
|
45
49
|
- lib/swagcov/railtie.rb
|
50
|
+
- lib/swagcov/runner.rb
|
46
51
|
- lib/swagcov/version.rb
|
47
52
|
- lib/tasks/swagcov.rake
|
48
|
-
- lib/tasks/swagcov/generate_todo.rake
|
49
|
-
- lib/tasks/swagcov/install.rake
|
50
53
|
homepage: https://github.com/smridge/swagcov
|
51
54
|
licenses:
|
52
55
|
- MIT
|
@@ -72,5 +75,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
75
|
requirements: []
|
73
76
|
rubygems_version: 3.6.8
|
74
77
|
specification_version: 4
|
75
|
-
summary: OpenAPI documentation coverage for Rails
|
78
|
+
summary: OpenAPI documentation coverage report for Rails Route endpoints
|
76
79
|
test_files: []
|