swagcov 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f7e8120c6da2d859ae0712f523ee0586e9e800c842594ef89c7fdaed3a28ee0
4
- data.tar.gz: c884efd95e1dc61fba493ba731633087baf546612a00a83489f3d4abc7c38cff
3
+ metadata.gz: 3102d52e8495c610e219ad58a32c75a3575cbd0460f1fddefdb5d427ff4e9f5e
4
+ data.tar.gz: 7f64fbc51d03dec663fea9dec838615f12d287d7f6a83f813e1f5411e6f11f8a
5
5
  SHA512:
6
- metadata.gz: d000402186ba36251cbdc689374979e863dce7b23f154837eba4e177bc484de337bf4928cc8d547bd71d20b7db323ab08cc378590871b2502c72a2398b8749e6
7
- data.tar.gz: 74144d434fd8ba835564b3fc92a9a63b318b74c438390213a9cd62cfba0705666464d3363d3d732eff05b46ddacb9105547352310ffeb7e166e5a5834efccba3
6
+ metadata.gz: 233f4668cb3e3ffa15b8354543c17f6879d50e5d077cf9aa55ea3aeb3c7d0f0f42bd7de4a7d5383987268377734ba90ac737f7bd3e02bb17a0d337ab3f348a96
7
+ data.tar.gz: b420010ec3553036c2ea18ceb3d14d1f080b3af9ced0daa432a3d7a47d70a0d9beaee4baacc1dc0747df4701d7b447088177d27d8f415d7486480d89c73dffe0
data/CHANGELOG.md CHANGED
@@ -2,9 +2,20 @@
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
+
5
16
  ## 0.10.0 (2025-05-08)
6
17
  ### Enhancement
7
- - Added executable for streamlined command line usage ([#120](https://github.com/smridge/swagcov/pull/120))
18
+ - Add executable for streamlined command line usage ([#120](https://github.com/smridge/swagcov/pull/120))
8
19
  - The below options are now available:
9
20
  ```
10
21
  swagcov
@@ -13,7 +24,7 @@
13
24
  swagcov --help
14
25
  ```
15
26
  - **Note**: This is experimental as it may not work for all use cases. Use `rake swagcov` as a fallback
16
- - Added 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))
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))
17
28
  - The below options are now available:
18
29
  ```
19
30
  rake swagcov
data/README.md CHANGED
@@ -15,40 +15,51 @@ OpenAPI documentation coverage report for Rails Routes.
15
15
  - See overview of different endpoints covered, missing and what you choose to ignore.
16
16
  - Add pass/fail to your build pipeline when missing documentation coverage.
17
17
 
18
- **Check OpenAPI documentation coverage for Rails Route endpoints**
19
- | `executable ` | `rake task ` | `rails console ` |
20
- | :--- | :--- | :--- |
21
- | `swagcov` | `rake swagcov` | `Swagcov::Command::ReportCoverage.new.run` |
22
-
23
- **Generate required `.swagcov.yml` config file**
24
- | `executable ` | `rake task ` | `rails console ` |
25
- | :--- | :--- | :--- |
26
- | `swagcov --init` | `rake swagcov -- --init` | `Swagcov::Command::GenerateDotfile.new.run` |
27
-
28
-
29
- **Generate optional `.swagcov_todo.yml` config file**
30
- | `executable ` | `rake task ` | `rails console ` |
31
- | :--- | :--- | :--- |
32
- | `swagcov --todo` | `rake swagcov -- --todo` | `Swagcov::Command::GenerateTodoFile.new.run` |
33
-
34
- **See command line usage options**
35
- | `executable ` | `rake task ` | `rails console ` |
36
- | :--- | :--- | :--- |
37
- | `swagcov --help` | `rake swagcov -- --help` | n/a |
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`
38
49
 
39
50
  ## Ruby and Rails Version Support
40
51
  Versioning support from a test coverage perspective, see [tests.yml](/.github/workflows/tests.yml) for detail
41
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` |
42
- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
43
- | `2.5` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
44
- | `2.6` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
45
- | `2.7` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
46
- | `3.0` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
47
- | `3.1` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
48
- | `3.2` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
49
- | `3.3` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
50
- | `3.4` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
51
- | `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` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
52
63
 
53
64
  ## Installation
54
65
  Add this line to your application's Gemfile:
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swagcov
4
+ module Command
5
+ class ReportVersion
6
+ def run
7
+ $stdout.puts ::Swagcov::Version::STRING
8
+
9
+ ::Swagcov::STATUS_SUCCESS
10
+ end
11
+ end
12
+ end
13
+ end
@@ -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.path.spec.to_s.chomp("(.:format)")
27
- verb = rails_version > "5" ? route.verb : route.verb.inspect.gsub(%r{[$^/]}, "")
23
+ path = route_path(route)
24
+ verb = route_verb(route)
28
25
 
29
- next if third_party_route?(route, path, rails_version)
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
- def third_party_route? route, path, rails_version
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, rails_version) ||
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, rails_version
73
+ def internal_rails_route? route
67
74
  if rails_version > "5"
68
75
  route.internal
69
76
  else
@@ -33,10 +33,9 @@ module Swagcov
33
33
  end
34
34
 
35
35
  def min_path_width
36
- strings =
37
- data[:covered].map { |hash| hash[:path] } +
38
- data[:ignored].map { |hash| hash[:path] } +
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
@@ -25,6 +25,10 @@ module Swagcov
25
25
  opts.on("-t", "--todo", "Generate optional .swagcov_todo.yml config file") do |opt|
26
26
  options[:todo] = opt
27
27
  end
28
+
29
+ opts.on("-v", "--version", "Display version") do |opt|
30
+ options[:version] = opt
31
+ end
28
32
  end.parse!(@args)
29
33
 
30
34
  options
@@ -10,9 +10,17 @@ module Swagcov
10
10
  end
11
11
 
12
12
  def run
13
- exit ::Swagcov::Command::GenerateDotfile.new.run if options[:init]
14
- exit ::Swagcov::Command::GenerateTodoFile.new.run if options[:todo]
15
- exit ::Swagcov::Command::ReportCoverage.new.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
16
24
  end
17
25
  end
18
26
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Swagcov
4
4
  module Version
5
- STRING = "0.10.0"
5
+ STRING = "0.11.0"
6
6
  end
7
7
  end
data/lib/swagcov.rb CHANGED
@@ -5,6 +5,7 @@ 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"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagcov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarah Ridge
@@ -38,6 +38,7 @@ files:
38
38
  - lib/swagcov/command/generate_dotfile.rb
39
39
  - lib/swagcov/command/generate_todo_file.rb
40
40
  - lib/swagcov/command/report_coverage.rb
41
+ - lib/swagcov/command/report_version.rb
41
42
  - lib/swagcov/core_ext/string.rb
42
43
  - lib/swagcov/coverage.rb
43
44
  - lib/swagcov/dotfile.rb