swagcov 0.4.1 → 0.5.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: a9d919e84a0746826d0688b1624f11e8218c8e7ec9cfd4e7ae6457368672a275
4
- data.tar.gz: ca13f5821ffc64ec599c4a171e6e15d019a6edbae43b3e765ef7d2fe101b0186
3
+ metadata.gz: 10f7019116f2fb27f9bcf01ed15450bb26e715778722c26448571ed006fb1675
4
+ data.tar.gz: 35d038789bbdb47d93720fa0ab5e07d95eefc92810145e083fb3076e6f151e13
5
5
  SHA512:
6
- metadata.gz: b6e6ef15038466cbede2c5299bbffc4c72fafaccf61ea6a3771538f48ccf6102eb7a2458f8f195ee20146b01ed39534f2b46a1186cf7e41afb687d1242e3389a
7
- data.tar.gz: 8a2eb6ade077b3f1d955d3053a35f3754560a87395df2a7f90177d69a94d061933db93c9fbb0afc170bd9ad2426bd49e0f4a08e6fc97b2db9a5192be589271f9
6
+ metadata.gz: 53e051e7b1c1b50b1cf23f0774fdd13aad99619463e7838ef8c5834d7e172fb5948e682813787ac22bfac8db64452dc4405ebc436d0266a99935915b012ebc90
7
+ data.tar.gz: bc67b90db65336931ba6895ad5ee51f63ad3aea5855b2e44f53e05a6c7b7cc57746f483f5d2c24bb651841f437b4c6d5c09bfec77d419cb0cf5e15f7b119f53d
data/CHANGELOG.md ADDED
@@ -0,0 +1,77 @@
1
+ # CHANGELOG
2
+ ## main (unreleased)
3
+ -
4
+
5
+ ## 0.5.0 (2025-03-26)
6
+ ### Enhancement
7
+ - Add rake task for configuration installation ([#59](https://github.com/smridge/swagcov/pull/59))
8
+ ```shell
9
+ bundle exec rake swagcov:install
10
+ ```
11
+ - Extend `ignore` routes configuration to exclude only specific actions ([#60](https://github.com/smridge/swagcov/pull/60))
12
+ ```yml
13
+ routes:
14
+ paths:
15
+ ignore:
16
+ - /v2/users # existing configuration that ignores all associated actions (verbs)
17
+ - /v2/users/:id: # new option to extend to specific actions
18
+ - GET
19
+ ```
20
+
21
+ ## 0.4.1 (2025-03-18)
22
+ ### Fix
23
+ - Output width for better layout alignment ([#48](https://github.com/smridge/swagcov/pull/48))
24
+
25
+ ### Code Coverage
26
+ - Added official support for ruby 3.3 and 3.4 and rails 7.1, 7.2, 8.0. See [unit_tests.yml](/.github/workflows/unit_tests.yml) and [system_tests.yml](/.github/workflows/system_tests.yml) for detail
27
+
28
+ ## 0.4.0 (2022-08-11)
29
+ - Improve OpenAPI file processing ([#26](https://github.com/smridge/swagcov/pull/26))
30
+
31
+ ## 0.3.0 (2022-02-21)
32
+ ### Enhancement
33
+ - Raise specific `Swagcov::BadConfigurationError` for malinformed yaml files ([#23](https://github.com/smridge/swagcov/pull/23))
34
+
35
+ ### Security
36
+ - Require Multi-Factor Authentication for RubyGems privileged operations ([#16](https://github.com/smridge/swagcov/pull/16))
37
+
38
+ ### Code Coverage
39
+ - Add Sandbox Application and specs for Rails 5.1 ([#20](https://github.com/smridge/swagcov/pull/20))
40
+ - Add specs for Rails 5.2 ([#7](https://github.com/smridge/swagcov/pull/7)), ([#14](https://github.com/smridge/swagcov/pull/14))
41
+ - Add Sandbox Application and specs for Rails 6.0 ([#17](https://github.com/smridge/swagcov/pull/17))
42
+ - Add Sandbox Application and specs for Rails 6.1 ([#22](https://github.com/smridge/swagcov/pull/22))
43
+ - Add GitHub Actions to run specs ([#18](https://github.com/smridge/swagcov/pull/18))
44
+ - Add GitHub CodeQL ([#13](https://github.com/smridge/swagcov/pull/13))
45
+
46
+ ### Refactor
47
+ - Move `SystemExit` to rake task for easier testing ([#24](https://github.com/smridge/swagcov/pull/24))
48
+ - Reduce complexity when matching routes ([#15](https://github.com/smridge/swagcov/pull/15))
49
+
50
+ ## 0.2.5 (2021-09-14)
51
+ ### Fix
52
+ - Matching routes against swagger paths. Previously, partial paths could result in a match ([#12](https://github.com/smridge/swagcov/pull/12))
53
+
54
+ ## 0.2.4 (2021-04-30)
55
+ ### Fix
56
+ - If a route path does not start with "^" match the entire path ([#5](https://github.com/smridge/swagcov/pull/5))
57
+ ### Enhancement
58
+ - Raise specific `Swagcov::BadConfigurationError` error if bad or missing configuration ([#5](https://github.com/smridge/swagcov/pull/5))
59
+
60
+ ## 0.2.3 (2021-04-23)
61
+ ### Fix
62
+ - Exclude ActiveStorage and ActionMailer routes ([#3](https://github.com/smridge/swagcov/pull/3))
63
+
64
+ ## 0.2.2 (2021-04-22)
65
+ ### Fix
66
+ - Exclude Rails Internal Routes and Mounted Applications ([#2](https://github.com/smridge/swagcov/pull/2))
67
+
68
+ ## 0.2.1 (2021-04-21)
69
+ ### Fix
70
+ - Exceptions caused by missing dependency for strings. ([#1](https://github.com/smridge/swagcov/pull/1))
71
+
72
+ ## 0.2.0 (2021-04-20)
73
+ ### Enhancement
74
+ - Add Exit status to easily build a pass/fail into build pipeline
75
+
76
+ ## 0.1.0 (2021-02-24)
77
+ - Create Rake Task for checking documentation coverage (rails only)
data/README.md CHANGED
@@ -21,7 +21,11 @@ Execute:
21
21
  bundle
22
22
  ```
23
23
 
24
- Create a `.swagcov.yml` in root of your Rails application.
24
+ Create a `.swagcov.yml` in root of your Rails application. Alternatively, run:
25
+ ```shell
26
+ bundle exec rake swagcov:install
27
+ ```
28
+
25
29
  - Add the paths of your `openapi` yml files (**required**):
26
30
  ```yml
27
31
  docs:
@@ -99,57 +103,21 @@ bundle exec rake swagcov
99
103
  - ^/v2
100
104
  ignore:
101
105
  - /v2/users
106
+ - /v2/users/:id:
107
+ - GET
102
108
  ```
103
109
  <img src="https://raw.githubusercontent.com/smridge/swagcov/main/images/ignore-and-only-endpoints.png">
104
110
 
105
- ## Development
106
- ```shell
107
- git clone git@github.com:smridge/swagcov.git
108
- ```
109
-
110
- Add this line to your application's Gemfile:
111
- ```ruby
112
- # Use the relative path from your application, to the swagcov folder
113
- gem "swagcov", path: "../swagcov"
114
- ```
115
-
116
- ```shell
117
- bundle
118
- ```
119
-
120
- Run Tests
121
- ```
122
- bundle exec rspec spec --exclude-pattern spec/sandbox_**/**/*_spec.rb
123
- ```
124
-
125
- ### Test via Sandbox Application
126
- - Go to any sandbox application within the `spec` directory
127
- - For example, `cd spec/sandbox_5_2/`
128
- - Install the ruby version specified in `.ruby-version` file
129
- - Install gems: `bundle install`
130
- - Run tests: `bundle exec rspec spec`
131
- - Run `bundle exec rake swagcov`
132
- - This will run against any changes made to your branch.
133
-
134
- ## Publish (internal)
135
- > Note: Publishing a new version of this gem is only meant for maintainers.
136
- - Ensure you have access to publish on [rubygems](https://rubygems.org/gems/swagcov).
137
- - Update [CHANGELOG](https://github.com/smridge/swagcov/blob/main/CHANGELOG.md).
138
- - Update [`VERSION`](https://github.com/smridge/swagcov/blob/main/lib/swagcov/version.rb).
139
- - Run `bundle update` for each sandbox application to reflect new swagcov version in each `Gemfile.lock`
140
- - Open a Pull Request to ensure all specs pass, then merge to `main`.
141
- - Checkout the latest `main` on your machine.
142
- - Run: `rake release`
143
- - 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).
144
-
145
111
  ## TODO
146
112
  - Add autogeneration of ignore paths
147
- - Add `CONTRIBUTING.md`
148
113
 
149
- ## Credit
114
+ ## Contributing
115
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for detail
116
+
117
+ ### Credit
150
118
  To [@lonelyelk](https://github.com/lonelyelk) for initial development!
151
119
 
152
- ## Contributors
120
+ ### Contributors
153
121
  <a href="https://github.com/smridge/swagcov/graphs/contributors">
154
122
  <img src="https://contrib.rocks/image?repo=smridge/swagcov" />
155
123
  </a>
@@ -38,7 +38,7 @@ module Swagcov
38
38
 
39
39
  next if third_party_route?(route, path)
40
40
 
41
- if dotfile.ignore_path?(path)
41
+ if dotfile.ignore_path?(path, verb: route.verb)
42
42
  @ignored += 1
43
43
  @routes_ignored << { verb: route.verb, path: path, status: "ignored" }
44
44
  next
@@ -13,8 +13,14 @@ module Swagcov
13
13
  raise BadConfigurationError, "Invalid config file (#{DEFAULT_CONFIG_FILE_NAME})" unless valid?
14
14
  end
15
15
 
16
- def ignore_path? path
17
- ignored_regex&.match?(path)
16
+ def ignore_path? path, verb:
17
+ ignore_all_path_actions = ignored_regex&.match?(path)
18
+
19
+ ignored_verbs = ignored_config&.find { |config| config[path] }
20
+
21
+ return ignore_all_path_actions unless ignored_verbs.is_a?(::Hash)
22
+
23
+ ignored_verbs.values.flatten.map(&:downcase).any?(verb.downcase)
18
24
  end
19
25
 
20
26
  def only_path_mismatch? path
@@ -38,7 +44,11 @@ module Swagcov
38
44
  end
39
45
 
40
46
  def ignored_regex
41
- @ignored_regex ||= path_config_regex(dotfile.dig("routes", "paths", "ignore"))
47
+ @ignored_regex ||= path_config_regex(ignored_config)
48
+ end
49
+
50
+ def ignored_config
51
+ @ignored_config ||= dotfile.dig("routes", "paths", "ignore")
42
52
  end
43
53
 
44
54
  def only_regex
@@ -48,7 +58,14 @@ module Swagcov
48
58
  def path_config_regex path_config
49
59
  return unless path_config
50
60
 
51
- config = path_config.map { |path| path.first == "^" ? path : "^#{path}$" }
61
+ config =
62
+ path_config.map do |path|
63
+ if path.is_a?(::Hash)
64
+ "^#{path.keys.first}$"
65
+ else
66
+ path.first == "^" ? path : "^#{path}$"
67
+ end
68
+ end
52
69
 
53
70
  /#{config.join('|')}/
54
71
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swagcov
4
+ class Install
5
+ attr_reader :dotfile
6
+
7
+ def initialize pathname: ::Rails.root.join(::Swagcov::Dotfile::DEFAULT_CONFIG_FILE_NAME).to_s
8
+ @dotfile = pathname
9
+ end
10
+
11
+ def generate_dotfile
12
+ if ::File.exist?(dotfile)
13
+ $stdout.puts "#{dotfile} already exists"
14
+ return
15
+ end
16
+
17
+ ::File.write(
18
+ dotfile,
19
+ <<~YAML
20
+ ## Required field:
21
+ # List your OpenAPI documentation files
22
+ docs:
23
+ paths:
24
+ - swagger.yaml
25
+
26
+ ## Optional fields:
27
+ # routes:
28
+ # paths:
29
+ # only:
30
+ # - ^/v2 # only track v2 endpoints
31
+ # ignore:
32
+ # - /v2/users # do not track certain endpoints
33
+ # - /v2/users/:id: # ignore only certain actions (verbs)
34
+ # - GET
35
+ YAML
36
+ )
37
+
38
+ $stdout.puts "created #{::Swagcov::Dotfile::DEFAULT_CONFIG_FILE_NAME}"
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Swagcov
4
- VERSION = "0.4.1"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/swagcov.rb CHANGED
@@ -7,6 +7,7 @@ if defined?(Rails)
7
7
  require "swagcov/dotfile"
8
8
  require "swagcov/coverage"
9
9
  require "swagcov/openapi_files"
10
+ require "swagcov/install"
10
11
  end
11
12
 
12
13
  require "swagcov/core_ext/string"
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :swagcov do
4
+ desc "create config file"
5
+ task install: :environment do
6
+ Swagcov::Install.new.generate_dotfile
7
+ end
8
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagcov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarah Ridge
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-18 00:00:00.000000000 Z
10
+ date: 2025-03-26 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -29,6 +29,7 @@ executables: []
29
29
  extensions: []
30
30
  extra_rdoc_files: []
31
31
  files:
32
+ - CHANGELOG.md
32
33
  - LICENSE
33
34
  - README.md
34
35
  - Rakefile
@@ -36,9 +37,11 @@ files:
36
37
  - lib/swagcov/core_ext/string.rb
37
38
  - lib/swagcov/coverage.rb
38
39
  - lib/swagcov/dotfile.rb
40
+ - lib/swagcov/install.rb
39
41
  - lib/swagcov/openapi_files.rb
40
42
  - lib/swagcov/railtie.rb
41
43
  - lib/swagcov/version.rb
44
+ - lib/tasks/swagcov/install.rake
42
45
  - lib/tasks/swagcove.rake
43
46
  homepage: https://github.com/smridge/swagcov
44
47
  licenses: