swagcov 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 820849bdcc13ddb85e1ff404bcc881dbe8f8154090bb6111d0afbdbdd286ce4f
4
- data.tar.gz: 90de5bb3a335673d58524344dd871182e06c1eb3185192a92026be5be0ce372e
3
+ metadata.gz: 5aaf6a7a919c70669dc24a129159b2ce961aa237495d57cfd1d94350bbad526f
4
+ data.tar.gz: e312bf832ceca1bc66017b131c958ab9f70ea4efddc32fac9bda0fcb369d7696
5
5
  SHA512:
6
- metadata.gz: b49673a8bfca29bb64ece42acc8c1a85f34339b4aa643036c72f4c1849e6e061a933c6471df2502da4e5ba4676c4f75cec559518c87242c7a3a31d6c0e817000
7
- data.tar.gz: 1b60f5d474d4be3c5c51a6180cb0343b380bca69a4fa99fe0c55063e7037a4f1134d3cbd284a411aa2a9b6ef257898df55facdf99b8827fe2fde3c069c8222be
6
+ metadata.gz: 14de18f74737e418b16153aea8c9f107545b9445fc5956dd0617ddbae4a0ad78be83017d6df8f442724186d38fd44a47b8462d4dc7ce2590c2b7aae26aaff201
7
+ data.tar.gz: b22dc442442935535df66b494d9f24f4475517eb36468208d24a3ad3b43f49202eb6ada1679efc1657804ea2e789b62b8dac030009ad1bf282fc9b6b3cfa1853
data/README.md CHANGED
@@ -6,6 +6,10 @@
6
6
 
7
7
  See OpenAPI documentation coverage report for Rails Routes.
8
8
 
9
+ ## Usages
10
+ - See overview of different endpoints covered, missing and what you choose to ignore.
11
+ - Add pass/fail to your build pipeline when missing Documentation Coverage.
12
+
9
13
  ## Installation
10
14
  Add this line to your application's Gemfile:
11
15
  ```ruby
@@ -41,7 +45,7 @@ Create a `.swagcov.yml` in root of your Rails application.
41
45
  - /v1/foobar/:token
42
46
  ```
43
47
 
44
- - Example `.swagcov.yml` Config File:
48
+ - Full Example `.swagcov.yml` Config File:
45
49
  ```yml
46
50
  docs:
47
51
  paths:
@@ -60,7 +64,7 @@ Execute:
60
64
  bundle exec rake swagcov
61
65
  ```
62
66
 
63
- ## Example configurations and output from running `bundle exec rake swagcov` from the root of your Rails Application:
67
+ ### Example configurations and output from running `bundle exec rake swagcov` from the root of your Rails Application:
64
68
  - All Routes (minimal configuration):
65
69
  ```yml
66
70
  docs:
@@ -115,12 +119,14 @@ bundle
115
119
 
116
120
  Run Tests
117
121
  ```
118
- bundle exec rspec spec --exclude-pattern spec/sandbox_5_2/**/*_spec.rb
122
+ bundle exec rspec spec --exclude-pattern spec/sandbox_**/**/*_spec.rb
119
123
  ```
120
124
 
121
125
  ### Test via Sandbox Application
122
- For Rails 5
123
- - `cd spec/sandbox_5_2/`
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`
124
130
  - Run tests: `bundle exec rspec spec`
125
131
  - Run `bundle exec rake swagcov`
126
132
  - This will run against any changes made to your branch.
@@ -135,12 +141,15 @@ For Rails 5
135
141
  - 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).
136
142
 
137
143
  ## TODO
138
- - Add specs
139
- - Test against different rails versions
140
- - Create Sandbox App for Rails 6
144
+ - Create Rails 7 / Ruby 3.1 Sandbox
141
145
  - Add autogeneration of ignore paths
142
146
  - Add `CONTRIBUTING.md`
143
- - Add GitHub Actions for specs/linting
147
+ - Add GitHub Action for linting
144
148
 
145
149
  ## Credit
146
150
  To [@lonelyelk](https://github.com/lonelyelk) for initial development!
151
+
152
+ ## Contributors
153
+ <a href="https://github.com/smridge/swagcov/graphs/contributors">
154
+ <img src="https://contrib.rocks/image?repo=smridge/swagcov" />
155
+ </a>
@@ -23,7 +23,7 @@ module Swagcov
23
23
 
24
24
  final_output
25
25
 
26
- exit @total - @covered
26
+ @total - @covered
27
27
  end
28
28
 
29
29
  private
@@ -46,7 +46,7 @@ module Swagcov
46
46
 
47
47
  @total += 1
48
48
  regex = Regexp.new("^#{path.gsub(%r{:[^/]+}, '\\{[^/]+\\}')}(\\.[^/]+)?$")
49
- matching_keys = docs_paths.keys.select { |k| regex.match?(k) }
49
+ matching_keys = docs_paths.keys.grep(regex)
50
50
 
51
51
  if (doc = docs_paths.dig(matching_keys.first, route.verb.downcase))
52
52
  @covered += 1
@@ -59,10 +59,16 @@ module Swagcov
59
59
 
60
60
  def docs_paths
61
61
  @docs_paths ||= Dir.glob(dotfile.doc_paths).reduce({}) do |acc, docspath|
62
- acc.merge(YAML.load_file(docspath)["paths"])
62
+ acc.merge(load_yaml(docspath))
63
63
  end
64
64
  end
65
65
 
66
+ def load_yaml docspath
67
+ YAML.load_file(docspath)["paths"]
68
+ rescue Psych::SyntaxError
69
+ raise BadConfigurationError, "Malinformed openapi file (#{docspath})"
70
+ end
71
+
66
72
  def third_party_route? route, path
67
73
  # https://github.com/rails/rails/blob/48f3c3e201b57a4832314b2c957a3b303e89bfea/actionpack/lib/action_dispatch/routing/inspector.rb#L105-L107
68
74
  # Skips route paths like ["/rails/info/properties", "/rails/info", "/rails/mailers"]
@@ -7,10 +7,9 @@ module Swagcov
7
7
  class Dotfile
8
8
  DEFAULT_CONFIG_FILE_NAME = ".swagcov.yml"
9
9
 
10
- def initialize pathname: Rails.root.join(DEFAULT_CONFIG_FILE_NAME)
11
- raise BadConfigurationError, "Missing config file (#{DEFAULT_CONFIG_FILE_NAME})" unless pathname.exist?
10
+ def initialize pathname: ::Rails.root.join(DEFAULT_CONFIG_FILE_NAME)
11
+ @dotfile = load_yaml(pathname)
12
12
 
13
- @dotfile = YAML.load_file(pathname)
14
13
  raise BadConfigurationError, "Invalid config file (#{DEFAULT_CONFIG_FILE_NAME})" unless valid?
15
14
  end
16
15
 
@@ -30,6 +29,14 @@ module Swagcov
30
29
 
31
30
  attr_reader :dotfile
32
31
 
32
+ def load_yaml pathname
33
+ raise BadConfigurationError, "Missing config file (#{DEFAULT_CONFIG_FILE_NAME})" unless pathname.exist?
34
+
35
+ YAML.load_file(pathname)
36
+ rescue Psych::SyntaxError
37
+ raise BadConfigurationError, "Malinformed config file (#{DEFAULT_CONFIG_FILE_NAME})"
38
+ end
39
+
33
40
  def ignored_regex
34
41
  @ignored_regex ||= path_config_regex(dotfile.dig("routes", "paths", "ignore"))
35
42
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Swagcov
4
- VERSION = "0.2.5"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  desc "check documentation coverage for endpoints"
4
4
  task swagcov: :environment do
5
- Swagcov::Coverage.new.report
5
+ exit Swagcov::Coverage.new.report
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagcov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarah Ridge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-14 00:00:00.000000000 Z
11
+ date: 2022-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -119,6 +119,7 @@ metadata:
119
119
  homepage_uri: https://github.com/smridge/swagcov
120
120
  source_code_uri: https://github.com/smridge/swagcov
121
121
  changelog_uri: https://github.com/smridge/swagcov/blob/main/CHANGELOG.md
122
+ rubygems_mfa_required: 'true'
122
123
  post_install_message:
123
124
  rdoc_options: []
124
125
  require_paths:
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  - !ruby/object:Gem::Version
135
136
  version: '0'
136
137
  requirements: []
137
- rubygems_version: 3.2.3
138
+ rubygems_version: 3.2.32
138
139
  signing_key:
139
140
  specification_version: 4
140
141
  summary: Open API docs coverage for Rails Routes