swagcov 1.2.1 → 1.3.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: fb55596ee15206a5ba5a5fbaa04d144009235149b970fc788b6ea946bc7f39c0
4
- data.tar.gz: f90f351fa04e94c7081bb43023aff7136951a5420aafd9af8b5d4e1cffb01aa6
3
+ metadata.gz: 4524e4731ad8f843011f1134d56d67cc9fda049aa3febb0ec06e0bfcb9206b2f
4
+ data.tar.gz: 8606e3d882d27cb59290576ecd56903e36703c71a22a6d5a39cbc972de637824
5
5
  SHA512:
6
- metadata.gz: a12f6f18ba12054de906aa9a006d8ed85211c66dfd008b8d3f9e8d5e5a016d342a63d3de07773616ff58e9f0e4f63681f15794f1d16200031a0e08858b67e8e8
7
- data.tar.gz: c0accc6bc9f422d9e23d29d37a49d8db6c58afb00288a31916095d4b343637293f5550b2a3a920972334f70834387302a8a5180a978efaefb43b61ddcd6e248b
6
+ metadata.gz: a52559ea8b4693348515e2ac128fa14ef8b3e8d53fbddc94691bea609abc9c4e39451089bf0e52a9de1c9b6c2e6888fb71e908359558226c0447bd8f6380893b
7
+ data.tar.gz: 1e15fe68b40ffdb582adf54eef5e9796b0555f702dec58c4dca7429cd77e0d4c10067e09566f99177466a89f1c67b433c04b91c6e76ec75cc34f7ce3c35cdb72
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
  ## main (unreleased)
3
3
  -
4
4
 
5
+ ## 1.3.0 (2026-10-18)
6
+ ### Fixes
7
+ - Fix Coverage percentage when there are no routes (NaN) ([#195](https://github.com/smridge/swagcov/pull/195))
8
+ - Fix Route processing with optional segements (`RegexpError` resolved) ([#202](https://github.com/smridge/swagcov/pull/202)) - _[@aaronlippold](https://github.com/aaronlippold)_ and _[@smridge](https://github.com/smridge)_
9
+ - For example, the below `routes route` will now process as expected with `/health_check(/:checks)`
10
+
11
+ ```
12
+ Prefix Verb URI Pattern Controller#Action
13
+ GET|POST /health_check(/:checks)(.:format) health_check/health_check#index {format: "txt"}
14
+ ```
15
+
16
+ ### Enhancements
17
+ - Add support for Ruby 4.1 ([#209](https://github.com/smridge/swagcov/pull/209))
18
+ - Improve path width calculation for output ([#196](https://github.com/smridge/swagcov/pull/196))
19
+ - Improve route output performance ([#197](https://github.com/smridge/swagcov/pull/197))
20
+
5
21
  ## 1.2.1 (2026-01-03)
6
22
  ### Fix
7
23
  - Load ordering for executable (safely removed unnecessary `logger` requirement) ([#190](https://github.com/smridge/swagcov/pull/190))
@@ -10,11 +26,11 @@
10
26
  - Update `LICENSE` copyright year range (2021-2026) ([#191](https://github.com/smridge/swagcov/pull/191))
11
27
 
12
28
  ## 1.2.0 (2025-12-20)
13
- ### Fix
29
+ ### Fixes
14
30
  - Improve check for skipping mounted applications for Rails 4.2 applications ([#179](https://github.com/smridge/swagcov/pull/179))
15
31
  - Resolve constants for loading rake task ([#181](https://github.com/smridge/swagcov/pull/181))
16
32
 
17
- ### Enhancement
33
+ ### Enhancements
18
34
  - Update dotfile template generated for install with better suggestions for ignoring certain endpoints ([#184](https://github.com/smridge/swagcov/pull/184))
19
35
  - Add support for Ruby 4.0 ([#176](https://github.com/smridge/swagcov/pull/176))
20
36
  - Add support for Rails 8.1 ([#167](https://github.com/smridge/swagcov/pull/167))
@@ -24,7 +40,7 @@
24
40
  - Improve matching for non api and turbo related routes ([#161](https://github.com/smridge/swagcov/pull/161))
25
41
 
26
42
  ## 1.1.0 (2025-08-08)
27
- ### Enhancement
43
+ ### Enhancements
28
44
  - Exclude `new` and `edit` controller action routes that are non api routes by rails defaults/convention ([#155](https://github.com/smridge/swagcov/pull/155))
29
45
  - For example the below routes are now automatically skipped since these are _generally_ `html` formats.
30
46
  ```
@@ -51,7 +67,7 @@
51
67
  - 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))
52
68
 
53
69
  ## 0.10.0 (2025-05-08)
54
- ### Enhancement
70
+ ### Enhancements
55
71
  - Add executable for streamlined command line usage ([#120](https://github.com/smridge/swagcov/pull/120))
56
72
  - The below options are now available:
57
73
  ```
@@ -74,7 +90,7 @@
74
90
  - `rake swagcov:install` is now `rake swagcov -- --init`
75
91
 
76
92
  ## 0.9.0 (2025-05-07)
77
- ### Enhancement
93
+ ### Enhancements
78
94
  - Add support for `.json` OpenAPI file types ([#112](https://github.com/smridge/swagcov/pull/112), [#113](https://github.com/smridge/swagcov/pull/113))
79
95
  - Update rake task descriptions ([#114](https://github.com/smridge/swagcov/pull/114))
80
96
  - Improve performance of OpenAPI response key matching for route paths ([#115](https://github.com/smridge/swagcov/pull/115))
@@ -84,7 +100,7 @@
84
100
  - Performance of coverage output by memoizing path string length ([#108](https://github.com/smridge/swagcov/pull/108))
85
101
 
86
102
  ## 0.8.0 (2025-04-22)
87
- ### Enhancement
103
+ ### Enhancements
88
104
  - Reduce gem dependencies by replacing `rails` with `railties` ([#101](https://github.com/smridge/swagcov/pull/101))
89
105
  - Remove unnecessary file from gem package ([#105](https://github.com/smridge/swagcov/pull/105))
90
106
 
@@ -96,7 +112,7 @@
96
112
  bundle exec rake swagcov:generate_todo
97
113
  ```
98
114
 
99
- ### Refactor
115
+ ### Refactors
100
116
  - Add `Swagcov.project_root` method ([#86](https://github.com/smridge/swagcov/pull/86))
101
117
  - Separate coverage collection and output ([#83](https://github.com/smridge/swagcov/pull/83))
102
118
  - Replace ActiveSupport string method with ruby string method ([#85](https://github.com/smridge/swagcov/pull/85))
@@ -104,7 +120,7 @@
104
120
  - Rename `Swagcov::Install` to `Swagcov::Command::GenerateDotfile` ([#88](https://github.com/smridge/swagcov/pull/88))
105
121
  - Refactor `GenerateDotfile` to be consistent with `GenerateTodoFile` ([#97](https://github.com/smridge/swagcov/pull/97))
106
122
 
107
- ### Fix
123
+ ### Fixes
108
124
  - Add exit code to install task + update messaging ([#87](https://github.com/smridge/swagcov/pull/87))
109
125
  - Ignored path verb matching when duplicate path keys are present ([#92](https://github.com/smridge/swagcov/pull/92))
110
126
  - Fix exit code error handling ([#95](https://github.com/smridge/swagcov/pull/95))
data/README.md CHANGED
@@ -67,6 +67,7 @@ For example `SWAGCOV_DOTFILE=".openapi_coverage_config.yml" bundle exec swagcov`
67
67
  Versioning support from a test coverage perspective, see [tests.yml](/.github/workflows/tests.yml) for detail
68
68
  | `ruby -v` | `rails 8.1` | `rails 8.0` | `rails 7.2` | `rails 7.1` | `rails 7.0` | `rails 6.1` | `rails 6.0` | `rails 5.2` | `rails 5.1` | `rails 5.0` | `rails 4.2` |
69
69
  | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
70
+ | `4.1` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
70
71
  | `4.0` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
71
72
  | `3.4` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
72
73
  | `3.3` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
@@ -206,8 +207,8 @@ Configurations and output from running `swagcov` / `rake swagcov` from the root
206
207
  ## Contributing
207
208
  See [CONTRIBUTING.md](CONTRIBUTING.md) for detail
208
209
 
209
- ### Credit
210
- To [@lonelyelk](https://github.com/lonelyelk) for initial development!
210
+ ### Backstory
211
+ We had a need to determine what our documentation coverage looked like. [@lonelyelk](https://github.com/lonelyelk) created an initial internal script and [@smridge](https://github.com/smridge) converted it to a configurable open source package.
211
212
 
212
213
  ### Contributors
213
214
  <a href="https://github.com/smridge/swagcov/graphs/contributors">
@@ -3,14 +3,15 @@
3
3
  module Swagcov
4
4
  module Formatter
5
5
  class Console
6
- attr_reader :data
6
+ attr_reader :data, :min_path_width, :route_format
7
7
 
8
8
  def initialize data: ::Swagcov::Coverage.new.collect
9
9
  @data = data
10
+ @min_path_width = calc_min_path_width
11
+ @route_format = format_route
10
12
  end
11
13
 
12
14
  def run
13
- min_path_width
14
15
  routes_output(data[:covered], "green")
15
16
  routes_output(data[:ignored], "yellow")
16
17
  routes_output(data[:uncovered], "red")
@@ -21,34 +22,38 @@ module Swagcov
21
22
 
22
23
  private
23
24
 
25
+ def calc_min_path_width
26
+ paths = data.values_at(:covered, :ignored, :uncovered).flat_map { |routes| routes.map { |route| route[:path] } }
27
+ paths.max_by(&:length)&.size.to_i + 1
28
+ end
29
+
30
+ def format_route
31
+ "%<verb>10s %<path>-#{min_path_width}s %<status>s"
32
+ end
33
+
24
34
  def routes_output routes, status_color
25
35
  routes.each do |route|
26
36
  $stdout.puts(
27
37
  format(
28
- "%<verb>10s %<path>-#{@min_path_width}s %<status>s",
38
+ route_format,
29
39
  { verb: route[:verb], path: route[:path], status: route[:status].send(status_color) }
30
40
  )
31
41
  )
32
42
  end
33
43
  end
34
44
 
35
- def min_path_width
36
- strings = []
37
-
38
- %i[covered ignored uncovered].each { |key| data[key].each { |hash| strings << hash[:path] } }
39
-
40
- @min_path_width ||= strings.max_by(&:length)&.size.to_i + 1
41
- end
42
-
43
45
  def final_output
46
+ total_count = data[:total_count]
47
+ covered_count = data[:covered_count]
48
+
44
49
  $stdout.puts
45
50
  $stdout.puts(
46
51
  format(
47
52
  "OpenAPI documentation coverage %<percentage>.2f%% (%<covered>d/%<total>d)",
48
53
  {
49
- percentage: 100.0 * data[:covered_count] / data[:total_count],
50
- covered: data[:covered_count],
51
- total: data[:total_count]
54
+ percentage: total_count.zero? ? 0.0 : 100.0 * covered_count / total_count,
55
+ covered: covered_count,
56
+ total: total_count
52
57
  }
53
58
  )
54
59
  )
@@ -10,7 +10,7 @@ module Swagcov
10
10
 
11
11
  def find_response_keys path:, route_verb:
12
12
  # replace :id with {id}
13
- regex = ::Regexp.new("^#{path.gsub(%r{:[^/]+}, '\\{[^/]+\\}')}?$")
13
+ regex = ::Regexp.new("^#{path.gsub(%r{:([^/.?]+)}, '{\1}')}?$")
14
14
 
15
15
  matching_paths_key = @openapi_path_keys.grep(regex).first
16
16
  matching_request_method_key = @openapi_paths.dig(matching_paths_key, route_verb.downcase)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Swagcov
4
4
  module Version
5
- STRING = "1.2.1"
5
+ STRING = "1.3.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,79 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagcov
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Sarah Ridge
7
+ - Sarah Ridge
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: railties
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - ">="
17
- - !ruby/object:Gem::Version
18
- version: '4.2'
19
- type: :runtime
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: '4.2'
12
+ - !ruby/object:Gem::Dependency
13
+ name: railties
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: "4.2"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: "4.2"
26
28
  email:
27
- - sarahmarie@hey.com
29
+ - sarahmarie@hey.com
28
30
  executables:
29
- - swagcov
31
+ - swagcov
30
32
  extensions: []
31
33
  extra_rdoc_files: []
32
34
  files:
33
- - CHANGELOG.md
34
- - LICENSE
35
- - README.md
36
- - exe/swagcov
37
- - lib/swagcov.rb
38
- - lib/swagcov/command/generate_dotfile.rb
39
- - lib/swagcov/command/generate_todo_file.rb
40
- - lib/swagcov/command/report_coverage.rb
41
- - lib/swagcov/command/report_version.rb
42
- - lib/swagcov/core_ext/string.rb
43
- - lib/swagcov/coverage.rb
44
- - lib/swagcov/dotfile.rb
45
- - lib/swagcov/errors.rb
46
- - lib/swagcov/formatter/console.rb
47
- - lib/swagcov/openapi_files.rb
48
- - lib/swagcov/options.rb
49
- - lib/swagcov/railtie.rb
50
- - lib/swagcov/runner.rb
51
- - lib/swagcov/version.rb
52
- - lib/tasks/swagcov.rake
53
- homepage: https://github.com/smridge/swagcov
35
+ - CHANGELOG.md
36
+ - LICENSE
37
+ - README.md
38
+ - exe/swagcov
39
+ - lib/swagcov.rb
40
+ - lib/swagcov/command/generate_dotfile.rb
41
+ - lib/swagcov/command/generate_todo_file.rb
42
+ - lib/swagcov/command/report_coverage.rb
43
+ - lib/swagcov/command/report_version.rb
44
+ - lib/swagcov/core_ext/string.rb
45
+ - lib/swagcov/coverage.rb
46
+ - lib/swagcov/dotfile.rb
47
+ - lib/swagcov/errors.rb
48
+ - lib/swagcov/formatter/console.rb
49
+ - lib/swagcov/openapi_files.rb
50
+ - lib/swagcov/options.rb
51
+ - lib/swagcov/railtie.rb
52
+ - lib/swagcov/runner.rb
53
+ - lib/swagcov/version.rb
54
+ - lib/tasks/swagcov.rake
55
+ homepage: "https://github.com/smridge/swagcov"
54
56
  licenses:
55
- - MIT
57
+ - MIT
56
58
  metadata:
57
- allowed_push_host: https://rubygems.org
58
- homepage_uri: https://github.com/smridge/swagcov
59
- source_code_uri: https://github.com/smridge/swagcov
60
- changelog_uri: https://github.com/smridge/swagcov/blob/main/CHANGELOG.md
61
- rubygems_mfa_required: 'true'
59
+ allowed_push_host: "https://rubygems.org"
60
+ homepage_uri: "https://github.com/smridge/swagcov"
61
+ source_code_uri: "https://github.com/smridge/swagcov"
62
+ changelog_uri: "https://github.com/smridge/swagcov/blob/main/CHANGELOG.md"
63
+ rubygems_mfa_required: "true"
62
64
  rdoc_options: []
63
65
  require_paths:
64
- - lib
66
+ - lib
65
67
  required_ruby_version: !ruby/object:Gem::Requirement
66
68
  requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 2.5.0
69
+ -
70
+ - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.5.0
70
73
  required_rubygems_version: !ruby/object:Gem::Requirement
71
74
  requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- version: '0'
75
+ -
76
+ - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
75
79
  requirements: []
76
- rubygems_version: 4.0.3
80
+ rubygems_version: 4.1.0.beta2
77
81
  specification_version: 4
78
82
  summary: OpenAPI documentation coverage report for Rails Route endpoints
79
83
  test_files: []