swagcov 0.4.0 → 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 +4 -4
- data/CHANGELOG.md +77 -0
- data/README.md +12 -46
- data/lib/swagcov/coverage.rb +11 -2
- data/lib/swagcov/dotfile.rb +21 -4
- data/lib/swagcov/install.rb +41 -0
- data/lib/swagcov/version.rb +1 -1
- data/lib/swagcov.rb +1 -0
- data/lib/tasks/swagcov/install.rake +8 -0
- metadata +7 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10f7019116f2fb27f9bcf01ed15450bb26e715778722c26448571ed006fb1675
|
4
|
+
data.tar.gz: 35d038789bbdb47d93720fa0ab5e07d95eefc92810145e083fb3076e6f151e13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,59 +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
|
-
- Create Rails 7 / Ruby 3.1 Sandbox
|
147
112
|
- Add autogeneration of ignore paths
|
148
|
-
- Add `CONTRIBUTING.md`
|
149
|
-
- Add GitHub Action for linting
|
150
113
|
|
151
|
-
##
|
114
|
+
## Contributing
|
115
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for detail
|
116
|
+
|
117
|
+
### Credit
|
152
118
|
To [@lonelyelk](https://github.com/lonelyelk) for initial development!
|
153
119
|
|
154
|
-
|
120
|
+
### Contributors
|
155
121
|
<a href="https://github.com/smridge/swagcov/graphs/contributors">
|
156
122
|
<img src="https://contrib.rocks/image?repo=smridge/swagcov" />
|
157
123
|
</a>
|
data/lib/swagcov/coverage.rb
CHANGED
@@ -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
|
@@ -75,13 +75,22 @@ module Swagcov
|
|
75
75
|
routes.each do |route|
|
76
76
|
$stdout.puts(
|
77
77
|
format(
|
78
|
-
"%<verb>10s %<path
|
78
|
+
"%<verb>10s %<path>-#{min_width(:path) + 1}s %<status>s",
|
79
79
|
{ verb: route[:verb], path: route[:path], status: route[:status].send(status_color) }
|
80
80
|
)
|
81
81
|
)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
def min_width key
|
86
|
+
strings =
|
87
|
+
@routes_covered.map { |hash| hash[key] } +
|
88
|
+
@routes_ignored.map { |hash| hash[key] } +
|
89
|
+
@routes_not_covered.map { |hash| hash[key] }
|
90
|
+
|
91
|
+
strings.max_by(&:length).size
|
92
|
+
end
|
93
|
+
|
85
94
|
def final_output
|
86
95
|
$stdout.puts
|
87
96
|
$stdout.puts(
|
data/lib/swagcov/dotfile.rb
CHANGED
@@ -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(
|
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 =
|
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
|
data/lib/swagcov/version.rb
CHANGED
data/lib/swagcov.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swagcov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sarah Ridge
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-26 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rails
|
@@ -24,83 +23,13 @@ dependencies:
|
|
24
23
|
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '5'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: pry-byebug
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rubocop-performance
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rubocop-rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
description:
|
98
26
|
email:
|
99
27
|
- sarahmarie@hey.com
|
100
28
|
executables: []
|
101
29
|
extensions: []
|
102
30
|
extra_rdoc_files: []
|
103
31
|
files:
|
32
|
+
- CHANGELOG.md
|
104
33
|
- LICENSE
|
105
34
|
- README.md
|
106
35
|
- Rakefile
|
@@ -108,9 +37,11 @@ files:
|
|
108
37
|
- lib/swagcov/core_ext/string.rb
|
109
38
|
- lib/swagcov/coverage.rb
|
110
39
|
- lib/swagcov/dotfile.rb
|
40
|
+
- lib/swagcov/install.rb
|
111
41
|
- lib/swagcov/openapi_files.rb
|
112
42
|
- lib/swagcov/railtie.rb
|
113
43
|
- lib/swagcov/version.rb
|
44
|
+
- lib/tasks/swagcov/install.rake
|
114
45
|
- lib/tasks/swagcove.rake
|
115
46
|
homepage: https://github.com/smridge/swagcov
|
116
47
|
licenses:
|
@@ -121,7 +52,6 @@ metadata:
|
|
121
52
|
source_code_uri: https://github.com/smridge/swagcov
|
122
53
|
changelog_uri: https://github.com/smridge/swagcov/blob/main/CHANGELOG.md
|
123
54
|
rubygems_mfa_required: 'true'
|
124
|
-
post_install_message:
|
125
55
|
rdoc_options: []
|
126
56
|
require_paths:
|
127
57
|
- lib
|
@@ -136,8 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
66
|
- !ruby/object:Gem::Version
|
137
67
|
version: '0'
|
138
68
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
140
|
-
signing_key:
|
69
|
+
rubygems_version: 3.6.6
|
141
70
|
specification_version: 4
|
142
|
-
summary:
|
71
|
+
summary: OpenAPI documentation coverage for Rails Routes
|
143
72
|
test_files: []
|