swagcov 0.11.0 → 1.1.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: 3102d52e8495c610e219ad58a32c75a3575cbd0460f1fddefdb5d427ff4e9f5e
4
- data.tar.gz: 7f64fbc51d03dec663fea9dec838615f12d287d7f6a83f813e1f5411e6f11f8a
3
+ metadata.gz: 25a95a511f8848ad55e88aba10b52e91b98b4a763f3c459e8d7167115846b9b0
4
+ data.tar.gz: 8ef18bdf421bf494882c799d76146804af7dc5b92fc8333c26c80c087231cec2
5
5
  SHA512:
6
- metadata.gz: 233f4668cb3e3ffa15b8354543c17f6879d50e5d077cf9aa55ea3aeb3c7d0f0f42bd7de4a7d5383987268377734ba90ac737f7bd3e02bb17a0d337ab3f348a96
7
- data.tar.gz: b420010ec3553036c2ea18ceb3d14d1f080b3af9ced0daa432a3d7a47d70a0d9beaee4baacc1dc0747df4701d7b447088177d27d8f415d7486480d89c73dffe0
6
+ metadata.gz: 37f8c1fb82a83466f03c3c12026d23f749a8fb6fc84a643030d7e11c9ac44299dc628642a2f2742ca7decd54103aaf2e3567c775378ad940028dac192b329558
7
+ data.tar.gz: 84e0bc9fb5808202680ab6f7ac740f61c8b16edacf7b4b362483ccd727df41e80ac17bf5f3b0f1eb6be8811d7cb027b2c84c2bea7c76686feced9446416e5826
data/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
  ## main (unreleased)
3
3
  -
4
4
 
5
+ ## 1.1.0 (2025-08-07)
6
+ ### Enhancement
7
+ - Exclude `new` and `edit` controller action routes that are non api routes by rails defaults/convention ([#155](https://github.com/smridge/swagcov/pull/155))
8
+ - For example the below routes are now automatically skipped since these are _generally_ `html` formats.
9
+ ```
10
+ Prefix Verb URI Pattern Controller#Action
11
+ new_article GET /articles/new(.:format) articles#new
12
+ edit_article GET /articles/:id/edit(.:format) articles#edit
13
+ ```
14
+ - Exclude `turbo-rails` related routes (part of rails frameworks that are not considered part of your OpenAPI documentation) ([#156](https://github.com/smridge/swagcov/pull/156))
15
+
16
+ ## 1.0.0 (2025-05-20)
17
+ ### Refactor
18
+ - Default Environment Variable approach ([#143](https://github.com/smridge/swagcov/pull/143))
19
+ - `swagcov` is considered tested and stable for a version 1.0.0 release, see [README](/README.md) for documentation
20
+
5
21
  ## 0.11.0 (2025-05-13)
6
22
  ### Enhancement
7
23
  - Add swagcov `version` option ([#134](https://github.com/smridge/swagcov/pull/134))
@@ -113,7 +129,7 @@
113
129
  ### Code Coverage
114
130
  - Added official support for ruby 3.3 and 3.4 and rails 7.1, 7.2, 8.0. See [tests.yml](/.github/workflows/tests.yml) for detail
115
131
 
116
- ## 0.4.0 (2022-08-11)
132
+ ## 0.4.0 (2022-08-12)
117
133
  - Improve OpenAPI file processing ([#26](https://github.com/smridge/swagcov/pull/26))
118
134
 
119
135
  ## 0.3.0 (2022-02-21)
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Swagcov
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)
2
+ [![Gem Version](https://img.shields.io/gem/v/swagcov?logo=rubygems)](https://rubygems.org/gems/swagcov)
3
+ [![GitHub Top Language](https://img.shields.io/github/languages/top/smridge/swagcov)](https://rubygems.org/gems/swagcov)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/swagcov)](https://rubygems.org/gems/swagcov)
4
5
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop-hq/rubocop)
5
6
  [![GitHub License](https://img.shields.io/github/license/smridge/swagcov.svg)](https://github.com/smridge/swagcov/blob/main/LICENSE)
6
7
 
@@ -47,6 +48,21 @@ The approaches below are listed in the following order:
47
48
  - `rake swagcov -- --help`
48
49
  - `Swagcov::Runner.new(args: ["--help"]).run`
49
50
 
51
+ ### Environment Variables
52
+ The following default environment variables are automatically set (and can optionally be changed to your needs)
53
+ | Key | Value |
54
+ | :--- | :--- |
55
+ | `SWAGCOV_DOTFILE` | `.swagcov.yml` |
56
+ | `SWAGCOV_TODOFILE` | `.swagcov_todo.yml` |
57
+
58
+ For example `SWAGCOV_DOTFILE=".openapi_coverage_config.yml" bundle exec swagcov`
59
+
60
+ ### Exit Codes
61
+ `swagcov` exits with the following status codes:
62
+ - `0` - (`success`) if no missing documentation coverage is detected
63
+ - `1` - (`offenses`) if missing documentation coverage is detected
64
+ - `2` - (`error`) if abnormal termination due to invalid configuration, cli options, or an internal error
65
+
50
66
  ## Ruby and Rails Version Support
51
67
  Versioning support from a test coverage perspective, see [tests.yml](/.github/workflows/tests.yml) for detail
52
68
  | `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` |
@@ -62,68 +78,87 @@ Versioning support from a test coverage perspective, see [tests.yml](/.github/wo
62
78
  | `3.5` | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
63
79
 
64
80
  ## Installation
65
- Add this line to your application's Gemfile:
66
- ```ruby
67
- gem "swagcov"
68
- ```
69
-
70
- Execute:
71
- ```shell
72
- bundle
73
- ```
74
-
75
- Create a `.swagcov.yml` in root of your Rails application. Alternatively, run:
76
- ```shell
77
- bundle exec rake swagcov:install
78
- ```
79
-
80
- - Add the paths of your OpenAPI `.yml` and/or `.json` files (**required**):
81
- ```yml
82
- docs:
83
- paths:
84
- - swagger.yaml
85
- - swagger.json
81
+ - Add this line to your application's Gemfile:
82
+ ```ruby
83
+ gem "swagcov"
86
84
  ```
87
85
 
88
- - Add `only` routes (**optional**) :
89
- ```yml
90
- routes:
91
- paths:
92
- only:
93
- - ^/v1
94
- ```
86
+ - Execute `bundle install` to install the gem
95
87
 
96
- - Add `ignore` routes (**optional**) :
97
- ```yml
98
- routes:
99
- paths:
100
- ignore:
101
- - /v1/foobar/:token
88
+ - Generate the required `.swagcov.yml` configuration file in the root of your Rails application by executing one of the following commands:
89
+ ```
90
+ bundle exec swagcov --init
91
+ bundle exec rake swagcov -- --init
102
92
  ```
103
93
 
104
- - Full Example `.swagcov.yml` Config File:
105
- ```yml
94
+ You should now see the following file to configure to your needs:
95
+ ```yaml
96
+ ## Required field:
97
+ # List your OpenAPI documentation file(s) (accepts json or yaml)
106
98
  docs:
107
99
  paths:
108
100
  - swagger.yaml
101
+ - swagger.json
109
102
 
110
- routes:
111
- paths:
112
- only:
113
- - ^/v1
114
- ignore:
115
- - /v1/foobar/:token
116
- - /v1/foobar:
117
- - GET
103
+ ## Optional fields:
104
+ # routes:
105
+ # paths:
106
+ # only:
107
+ # - ^/v2 # only track v2 endpoints
108
+ # ignore:
109
+ # - /v2/users # do not track certain endpoints
110
+ # - /v2/users/:id: # ignore only certain actions (verbs)
111
+ # - GET
118
112
  ```
119
113
 
120
- Execute:
121
- ```shell
122
- bundle exec rake swagcov
123
- ```
114
+ - Execute one of the following commands:
115
+ ```
116
+ bundle exec swagcov
117
+ bundle exec rake swagcov
118
+ ```
119
+
120
+ Example Output:
121
+ ```
122
+ GET /articles 200
123
+ PATCH /articles/:id 200
124
+ DELETE /articles/:id 204
125
+ GET /users 200
126
+ POST /users 201
127
+ GET /users/:id 200
128
+ PUT /users/:id 200
129
+ DELETE /users/:id 204
130
+ GET /v1/articles 200
131
+ POST /v1/articles 201
132
+ GET /v1/articles/:id 200
133
+ PATCH /v1/articles/:id 200
134
+ PUT /v1/articles/:id 200
135
+ DELETE /v1/articles/:id 204
136
+ GET /v2/articles 200
137
+ POST /v2/articles 201
138
+ PATCH /v2/articles/:id 200
139
+ DELETE /v2/articles/:id 204
140
+ GET /v2/articles/:id ignored
141
+ PUT /v2/articles/:id ignored
142
+ POST /articles none
143
+ GET /articles/:id none
144
+ PUT /articles/:id none
145
+ PATCH /users/:id none
146
+
147
+ OpenAPI documentation coverage 81.82% (18/22)
148
+ 2 ignored endpoints
149
+ 22 total endpoints
150
+ 18 covered endpoints
151
+ 4 uncovered endpoints
152
+ ```
153
+
154
+ - Optionally generate a `.swagcov_todo.yml` config file acting as a TODO list
155
+ ```
156
+ bundle exec swagcov --todo
157
+ bundle exec rake swagcov -- --todo
158
+ ```
124
159
 
125
160
  ## Examples
126
- Configurations and output from running `bundle exec rake swagcov` from the root of your Rails Application
161
+ Configurations and output from running `swagcov` / `rake swagcov` from the root of your Rails Application
127
162
  - All Routes (minimal configuration):
128
163
  ```yml
129
164
  docs:
@@ -5,7 +5,7 @@ module Swagcov
5
5
  class GenerateDotfile
6
6
  attr_reader :dotfile
7
7
 
8
- def initialize basename: ::Swagcov::Dotfile::DEFAULT_CONFIG_FILE_NAME
8
+ def initialize basename: ::Swagcov::DOTFILE
9
9
  @dotfile = ::Swagcov.project_root.join(basename)
10
10
  end
11
11
 
@@ -3,7 +3,7 @@
3
3
  module Swagcov
4
4
  module Command
5
5
  class GenerateTodoFile
6
- def initialize basename: ::Swagcov::Dotfile::TODO_CONFIG_FILE_NAME,
6
+ def initialize basename: ::Swagcov::TODOFILE,
7
7
  data: ::Swagcov::Coverage.new(dotfile: ::Swagcov::Dotfile.new(skip_todo: true)).collect[:uncovered]
8
8
  @dotfile = ::Swagcov.project_root.join(basename)
9
9
  @data = data
@@ -23,7 +23,7 @@ module Swagcov
23
23
  path = route_path(route)
24
24
  verb = route_verb(route)
25
25
 
26
- next if third_party_route?(route, path)
26
+ next if default_skipped_route?(route, path)
27
27
 
28
28
  if dotfile.ignore_path?(path, verb: verb)
29
29
  update_data(:ignored, verb, path, "ignored")
@@ -56,6 +56,10 @@ module Swagcov
56
56
  rails_version > "5" ? route.verb : route.verb.inspect.gsub(%r{[$^/]}, "")
57
57
  end
58
58
 
59
+ def default_skipped_route? route, path
60
+ third_party_route?(route, path) || non_api_route?(route, path)
61
+ end
62
+
59
63
  def third_party_route? route, path
60
64
  # https://github.com/rails/rails/blob/48f3c3e201b57a4832314b2c957a3b303e89bfea/actionpack/lib/action_dispatch/routing/inspector.rb#L105-L107
61
65
  # Skips route paths like ["/rails/info/properties", "/rails/info", "/rails/mailers"]
@@ -64,10 +68,10 @@ module Swagcov
64
68
  # Skips routes like "/sidekiq"
65
69
  route.verb.blank? ||
66
70
 
67
- # Exclude routes that are part of the rails gem that you would not write documentation for
68
- # https://github.com/rails/rails/tree/main/activestorage/app/controllers/active_storage
69
- # https://github.com/rails/rails/tree/main/actionmailbox/app/controllers/action_mailbox
70
- path.include?("/active_storage/") || path.include?("/action_mailbox/")
71
+ # Exclude routes that are part of the rails frameworks that you would not write documentation for
72
+ path.include?("/active_storage/") ||
73
+ path.include?("/action_mailbox/") ||
74
+ turbo_rails_route?(route, path)
71
75
  end
72
76
 
73
77
  def internal_rails_route? route
@@ -78,6 +82,16 @@ module Swagcov
78
82
  end
79
83
  end
80
84
 
85
+ def turbo_rails_route? route, path
86
+ # TODO: add route.source_location.include?("turbo-rails") - working on local machine but not in test env
87
+ path.include?("_historical_location") && route.name.include?("turbo_")
88
+ end
89
+
90
+ def non_api_route? route, path
91
+ # By default/convention these are non api routes generated by rails
92
+ %w[new edit].include?(route.defaults[:action]) && (path.include?("/new") || path.include?("/edit"))
93
+ end
94
+
81
95
  def update_data key, verb, path, status
82
96
  @data[:"#{key}_count"] += 1
83
97
  @data[key] << { verb: verb, path: path, status: status }
@@ -2,13 +2,10 @@
2
2
 
3
3
  module Swagcov
4
4
  class Dotfile
5
- DEFAULT_CONFIG_FILE_NAME = ::ENV.fetch("SWAGCOV_DOTFILE", ".swagcov.yml")
6
- TODO_CONFIG_FILE_NAME = ::ENV.fetch("SWAGCOV_TODOFILE", ".swagcov_todo.yml")
7
-
8
- def initialize basename: DEFAULT_CONFIG_FILE_NAME, todo_basename: TODO_CONFIG_FILE_NAME, skip_todo: false
5
+ def initialize basename: ::Swagcov::DOTFILE, todo_basename: ::Swagcov::TODOFILE, skip_todo: false
9
6
  @dotfile = load_yaml(basename, required: true)
10
7
 
11
- raise ::Swagcov::Errors::BadConfiguration, "Invalid config file (#{DEFAULT_CONFIG_FILE_NAME})" unless valid?
8
+ raise ::Swagcov::Errors::BadConfiguration, "Invalid config file (#{::Swagcov::DOTFILE})" unless valid?
12
9
 
13
10
  @todo_file = load_yaml(todo_basename) unless skip_todo
14
11
  @ignored_regex = path_config_regex(ignored_config)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Swagcov
4
4
  module Version
5
- STRING = "0.11.0"
5
+ STRING = "1.1.0"
6
6
  end
7
7
  end
data/lib/swagcov.rb CHANGED
@@ -24,6 +24,9 @@ module Swagcov
24
24
  STATUS_OFFENSES = 1
25
25
  STATUS_ERROR = 2
26
26
 
27
+ DOTFILE = ENV["SWAGCOV_DOTFILE"] ||= ".swagcov.yml"
28
+ TODOFILE = ENV["SWAGCOV_TODOFILE"] ||= ".swagcov_todo.yml"
29
+
27
30
  def project_root
28
31
  ::Rails.root || ::Pathname.new(::FileUtils.pwd)
29
32
  end
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.11.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarah Ridge
@@ -73,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  requirements: []
76
- rubygems_version: 3.6.8
76
+ rubygems_version: 3.7.0.dev
77
77
  specification_version: 4
78
78
  summary: OpenAPI documentation coverage report for Rails Route endpoints
79
79
  test_files: []