swagcov 0.8.1 → 0.10.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: f8b15b82b2a87742868a94cd6964469cb4aff857259d3752fe258e595f0dcfc1
4
- data.tar.gz: cc35beef6a1b53c6f418337d1a59b48ce7d5152e1abf9746a0847fda08721bfc
3
+ metadata.gz: 8f7e8120c6da2d859ae0712f523ee0586e9e800c842594ef89c7fdaed3a28ee0
4
+ data.tar.gz: c884efd95e1dc61fba493ba731633087baf546612a00a83489f3d4abc7c38cff
5
5
  SHA512:
6
- metadata.gz: 4c1c0133c991c4dea09e0120aa54eab71b59746c5a9ec4e1718a2fc21d86802dec7b51039bfde1638fd9055932d1fc93a958285400fa9cb777378e5c02e91851
7
- data.tar.gz: 00c4c6b3508b19cb0f2c89debfc920c6aa234a4e9ec5142a11cc5995fed34d255eb70000e482d47c50a7d4f88ab026b27592b7cd1f143add31d777c48898533a
6
+ metadata.gz: d000402186ba36251cbdc689374979e863dce7b23f154837eba4e177bc484de337bf4928cc8d547bd71d20b7db323ab08cc378590871b2502c72a2398b8749e6
7
+ data.tar.gz: 74144d434fd8ba835564b3fc92a9a63b318b74c438390213a9cd62cfba0705666464d3363d3d732eff05b46ddacb9105547352310ffeb7e166e5a5834efccba3
data/CHANGELOG.md CHANGED
@@ -2,6 +2,35 @@
2
2
  ## main (unreleased)
3
3
  -
4
4
 
5
+ ## 0.10.0 (2025-05-08)
6
+ ### Enhancement
7
+ - Added executable for streamlined command line usage ([#120](https://github.com/smridge/swagcov/pull/120))
8
+ - The below options are now available:
9
+ ```
10
+ swagcov
11
+ swagcov --init
12
+ swagcov --todo
13
+ swagcov --help
14
+ ```
15
+ - **Note**: This is experimental as it may not work for all use cases. Use `rake swagcov` as a fallback
16
+ - Added command line options to the existing `rake swagcov` task ([#121](https://github.com/smridge/swagcov/pull/121), [#122](https://github.com/smridge/swagcov/pull/122), [#123](https://github.com/smridge/swagcov/pull/123))
17
+ - The below options are now available:
18
+ ```
19
+ rake swagcov
20
+ rake swagcov -- --init
21
+ rake swagcov -- --todo
22
+ rake swagcov -- --help
23
+ ```
24
+ - **Note**: This refactor involved `BREAKING CHANGES`:
25
+ - `rake swagcov:generate_todo` is now `rake swagcov -- --todo`
26
+ - `rake swagcov:install` is now `rake swagcov -- --init`
27
+
28
+ ## 0.9.0 (2025-05-07)
29
+ ### Enhancement
30
+ - Add support for `.json` OpenAPI file types ([#112](https://github.com/smridge/swagcov/pull/112), [#113](https://github.com/smridge/swagcov/pull/113))
31
+ - Update rake task descriptions ([#114](https://github.com/smridge/swagcov/pull/114))
32
+ - Improve performance of OpenAPI response key matching for route paths ([#115](https://github.com/smridge/swagcov/pull/115))
33
+
5
34
  ## 0.8.1 (2025-04-29)
6
35
  ### Fix
7
36
  - Performance of coverage output by memoizing path string length ([#108](https://github.com/smridge/swagcov/pull/108))
data/README.md CHANGED
@@ -9,17 +9,32 @@
9
9
  ![CodeQL Build](https://github.com/smridge/swagcov/actions/workflows/codeql-analysis.yml/badge.svg)
10
10
  [![Coverage Status](https://coveralls.io/repos/github/smridge/swagcov/badge.svg?branch=main)](https://coveralls.io/github/smridge/swagcov?branch=main)
11
11
 
12
- See OpenAPI documentation coverage report for Rails Routes.
12
+ OpenAPI documentation coverage report for Rails Routes.
13
13
 
14
14
  ## Usages
15
15
  - See overview of different endpoints covered, missing and what you choose to ignore.
16
- - Add pass/fail to your build pipeline when missing Documentation Coverage.
16
+ - Add pass/fail to your build pipeline when missing documentation coverage.
17
17
 
18
- | `rake task` | `rails console` | Description |
19
- | :--- | :--- | :--- |
20
- | `rake swagcov` | `Swagcov::Command::ReportCoverage.new.run` | Check documentation coverage |
21
- | `rake swagcov:install` | `Swagcov::Command::GenerateDotfile.new.run` | Install required `.swagcov.yml` config file |
22
- | `rake swagcov:generate_todo` | `Swagcov::Command::GenerateTodoFile.new.run` | Generate `.swagcov_todo.yml` |
18
+ **Check OpenAPI documentation coverage for Rails Route endpoints**
19
+ | `executable ` | `rake task ` | `rails console ` |
20
+ | :--- | :--- | :--- |
21
+ | `swagcov` | `rake swagcov` | `Swagcov::Command::ReportCoverage.new.run` |
22
+
23
+ **Generate required `.swagcov.yml` config file**
24
+ | `executable ` | `rake task ` | `rails console ` |
25
+ | :--- | :--- | :--- |
26
+ | `swagcov --init` | `rake swagcov -- --init` | `Swagcov::Command::GenerateDotfile.new.run` |
27
+
28
+
29
+ **Generate optional `.swagcov_todo.yml` config file**
30
+ | `executable ` | `rake task ` | `rails console ` |
31
+ | :--- | :--- | :--- |
32
+ | `swagcov --todo` | `rake swagcov -- --todo` | `Swagcov::Command::GenerateTodoFile.new.run` |
33
+
34
+ **See command line usage options**
35
+ | `executable ` | `rake task ` | `rails console ` |
36
+ | :--- | :--- | :--- |
37
+ | `swagcov --help` | `rake swagcov -- --help` | n/a |
23
38
 
24
39
  ## Ruby and Rails Version Support
25
40
  Versioning support from a test coverage perspective, see [tests.yml](/.github/workflows/tests.yml) for detail
@@ -51,11 +66,12 @@ Create a `.swagcov.yml` in root of your Rails application. Alternatively, run:
51
66
  bundle exec rake swagcov:install
52
67
  ```
53
68
 
54
- - Add the paths of your `openapi` yml files (**required**):
69
+ - Add the paths of your OpenAPI `.yml` and/or `.json` files (**required**):
55
70
  ```yml
56
71
  docs:
57
72
  paths:
58
73
  - swagger.yaml
74
+ - swagger.json
59
75
  ```
60
76
 
61
77
  - Add `only` routes (**optional**) :
data/exe/swagcov ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Experimental executable
5
+ #
6
+ # Booting rails approach should work for most applications
7
+ # Rake task option as an alternative should always work as expected
8
+
9
+ # Load logger before rails
10
+ # Fix for booting rails 6.0-7.0 apps (uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger)
11
+ require "logger"
12
+
13
+ require "swagcov"
14
+
15
+ RAILS_APP_PATH = File.expand_path("config/application", Dir.pwd)
16
+
17
+ def boot_rails_application!
18
+ require RAILS_APP_PATH
19
+ Rails.application.initialize!
20
+ rescue LoadError, NoMethodError
21
+ warn "Unable to load Rails application, try running `rake swagcov` instead"
22
+ exit Swagcov::STATUS_ERROR
23
+ end
24
+
25
+ boot_rails_application!
26
+
27
+ Swagcov::Runner.new(args: ARGV).run
@@ -19,10 +19,11 @@ module Swagcov
19
19
  dotfile,
20
20
  <<~YAML
21
21
  ## Required field:
22
- # List your OpenAPI documentation files
22
+ # List your OpenAPI documentation file(s) (accepts json or yaml)
23
23
  docs:
24
24
  paths:
25
25
  - swagger.yaml
26
+ - swagger.json
26
27
 
27
28
  ## Optional fields:
28
29
  # routes:
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Swagcov
4
4
  class Dotfile
5
- DEFAULT_CONFIG_FILE_NAME = ".swagcov.yml"
6
- TODO_CONFIG_FILE_NAME = ".swagcov_todo.yml"
5
+ DEFAULT_CONFIG_FILE_NAME = ::ENV.fetch("SWAGCOV_DOTFILE", ".swagcov.yml")
6
+ TODO_CONFIG_FILE_NAME = ::ENV.fetch("SWAGCOV_TODOFILE", ".swagcov_todo.yml")
7
7
 
8
8
  def initialize basename: DEFAULT_CONFIG_FILE_NAME, todo_basename: TODO_CONFIG_FILE_NAME, skip_todo: false
9
9
  @dotfile = load_yaml(basename, required: true)
@@ -5,13 +5,14 @@ module Swagcov
5
5
  def initialize filepaths:
6
6
  @filepaths = filepaths
7
7
  @openapi_paths = load_yamls
8
+ @openapi_path_keys = @openapi_paths.keys
8
9
  end
9
10
 
10
11
  def find_response_keys path:, route_verb:
11
12
  # replace :id with {id}
12
13
  regex = ::Regexp.new("^#{path.gsub(%r{:[^/]+}, '\\{[^/]+\\}')}?$")
13
14
 
14
- matching_paths_key = @openapi_paths.keys.grep(regex).first
15
+ matching_paths_key = @openapi_path_keys.grep(regex).first
15
16
  matching_request_method_key = @openapi_paths.dig(matching_paths_key, route_verb.downcase)
16
17
 
17
18
  matching_request_method_key["responses"].keys.map(&:to_s).sort if matching_request_method_key
@@ -26,8 +27,8 @@ module Swagcov
26
27
  end
27
28
 
28
29
  def load_yaml filepath
29
- ::YAML.load_file(filepath)["paths"]
30
- rescue ::Psych::SyntaxError
30
+ ::YAML.load_file(filepath)["paths"] # loads yaml or json
31
+ rescue ::Psych::SyntaxError, ::JSON::ParserError
31
32
  raise ::Swagcov::Errors::BadConfiguration, "Malformed openapi file (#{filepath})"
32
33
  end
33
34
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+
5
+ module Swagcov
6
+ class Options
7
+ def initialize args: ::ARGV
8
+ @args = args
9
+ end
10
+
11
+ def define
12
+ options = {}
13
+
14
+ ::OptionParser.new do |opts|
15
+ opts.banner = <<~MESSAGE
16
+ Usage:
17
+ * as executable: swagcov [options]
18
+ * as rake task: rake swagcov -- [options]
19
+ MESSAGE
20
+
21
+ opts.on("-i", "--init", "Generate required .swagcov.yml config file") do |opt|
22
+ options[:init] = opt
23
+ end
24
+
25
+ opts.on("-t", "--todo", "Generate optional .swagcov_todo.yml config file") do |opt|
26
+ options[:todo] = opt
27
+ end
28
+ end.parse!(@args)
29
+
30
+ options
31
+ rescue ::OptionParser::InvalidOption => e
32
+ warn e.message
33
+ warn "For usage information, use --help"
34
+ exit ::Swagcov::STATUS_ERROR
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Swagcov
4
+ class Runner
5
+ attr_reader :options
6
+
7
+ def initialize args: ::ARGV
8
+ @args = args
9
+ @options = ::Swagcov::Options.new(args: @args).define
10
+ end
11
+
12
+ def run
13
+ exit ::Swagcov::Command::GenerateDotfile.new.run if options[:init]
14
+ exit ::Swagcov::Command::GenerateTodoFile.new.run if options[:todo]
15
+ exit ::Swagcov::Command::ReportCoverage.new.run
16
+ end
17
+ end
18
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Swagcov
4
4
  module Version
5
- STRING = "0.8.1"
5
+ STRING = "0.10.0"
6
6
  end
7
7
  end
data/lib/swagcov.rb CHANGED
@@ -11,7 +11,9 @@ require "swagcov/coverage"
11
11
  require "swagcov/dotfile"
12
12
  require "swagcov/errors"
13
13
  require "swagcov/openapi_files"
14
+ require "swagcov/options"
14
15
  require "swagcov/railtie"
16
+ require "swagcov/runner"
15
17
  require "swagcov/version"
16
18
 
17
19
  module Swagcov
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- desc "check documentation coverage for endpoints"
3
+ desc "Check OpenAPI documentation coverage for Rails Route endpoints"
4
4
  task swagcov: :environment do
5
- exit Swagcov::Command::ReportCoverage.new.run
5
+ args = ARGV.drop(2) # Remove "swagcov" and "--" to ignore standard rake arguments
6
+ Swagcov::Runner.new(args: args).run
6
7
  end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swagcov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarah Ridge
8
- bindir: bin
8
+ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
@@ -25,13 +25,15 @@ dependencies:
25
25
  version: '4.2'
26
26
  email:
27
27
  - sarahmarie@hey.com
28
- executables: []
28
+ executables:
29
+ - swagcov
29
30
  extensions: []
30
31
  extra_rdoc_files: []
31
32
  files:
32
33
  - CHANGELOG.md
33
34
  - LICENSE
34
35
  - README.md
36
+ - exe/swagcov
35
37
  - lib/swagcov.rb
36
38
  - lib/swagcov/command/generate_dotfile.rb
37
39
  - lib/swagcov/command/generate_todo_file.rb
@@ -42,11 +44,11 @@ files:
42
44
  - lib/swagcov/errors.rb
43
45
  - lib/swagcov/formatter/console.rb
44
46
  - lib/swagcov/openapi_files.rb
47
+ - lib/swagcov/options.rb
45
48
  - lib/swagcov/railtie.rb
49
+ - lib/swagcov/runner.rb
46
50
  - lib/swagcov/version.rb
47
51
  - lib/tasks/swagcov.rake
48
- - lib/tasks/swagcov/generate_todo.rake
49
- - lib/tasks/swagcov/install.rake
50
52
  homepage: https://github.com/smridge/swagcov
51
53
  licenses:
52
54
  - MIT
@@ -72,5 +74,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  requirements: []
73
75
  rubygems_version: 3.6.8
74
76
  specification_version: 4
75
- summary: OpenAPI documentation coverage for Rails Routes
77
+ summary: OpenAPI documentation coverage report for Rails Route endpoints
76
78
  test_files: []
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- namespace :swagcov do
4
- desc "generate todo config file"
5
- task generate_todo: :environment do
6
- exit Swagcov::Command::GenerateTodoFile.new.run
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- namespace :swagcov do
4
- desc "create config file"
5
- task install: :environment do
6
- exit Swagcov::Command::GenerateDotfile.new.run
7
- end
8
- end