openapi_first 2.9.3 → 2.10.1

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: ef8ea95833884daf36e8a33742ce4a6eddfb9343b67de0b5e787ebc377c0691d
4
- data.tar.gz: b63916918c1d1116d99c2e071c3e8e752b1cce66cd431dceb5076a3e70688c10
3
+ metadata.gz: 79f9fda1c73303674f66f87ff97d6749e085fb6a01ca1f9d604e53a9f9a1abd7
4
+ data.tar.gz: b15c401b9e9b83fc091e597b09765a3ec518005c79f4406af4abe4fa1a8b7735
5
5
  SHA512:
6
- metadata.gz: 3cbf77e0a4a51b213a90458c1181bd29474f378195210cf76466c24ef832195b32e4cbd8aec7ba97ece0bd7d9a97b6022e02b5288600d8879b82401c398d1ddc
7
- data.tar.gz: 8789c3dadcff66b6cbb831dfae948da5adcbcd2788ff40765f39d4a1a0ba238cef1d7df609b4dd57e8ba71653103e21f9fb6a7e1f0a212e45c02d4f8c5e41e39
6
+ metadata.gz: 84bbbc5bf681ec5f62ef7b66d68be805add8a4b013ea87d9081718677bcf617c89ffab7d61d660d1b498f99532b05106591837353d62a3355febaa739a80e631
7
+ data.tar.gz: 9c5771ee2b8a55e85d2841ce5d0e0058eec81df545f5eaf168176c41cd6e66c83436fffc19b6de156f444e1f58c010e8e443b0736fe6d08940774311c1ed87a3
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.10.1
6
+
7
+ - Don't try to track coverage for skipped requests
8
+ - Add Test::Configuration#skip_coverage to skip test coverage for specific paths + request methods and all responses
9
+ - Deprecate setting minimum_coverage value. Use skip_response_coverage, ignored_unknown_status to configure coverage instead.
10
+ - Update openapi_parameters to make parsing array query parameters more consistent.
11
+ Now parsing empty array query parameter like `ids=&` or `ids&` both result in an empty array value (`[]`) instead of `nil` or `""`.
12
+ - Fix Test::Coverage.result returning < 100 even if plan is fully covered
13
+
14
+ ## 2.10.0 (yanked)
15
+
5
16
  ## 2.9.3
6
17
 
7
18
  - Fix OpenapiFirst.load when MultiJson is configured to return symbol keys
data/README.md CHANGED
@@ -70,9 +70,9 @@ Here is how to set it up:
70
70
  end
71
71
  ```
72
72
  - Or inject a Module to wrap (prepend) the `call` method of your Rack app Class.
73
-
73
+
74
74
  NOTE: This is still work in progress. It works with basic Sinatra apps, but does not work with Hanami or Rails out of the box, yet. PRs welcome 🤗
75
-
75
+
76
76
  ```ruby
77
77
  OpenapiFirst::Test.observe(MyApplication)
78
78
  ```
@@ -80,14 +80,39 @@ Here is how to set it up:
80
80
 
81
81
  (✷1): It does not matter what method of openapi_first you use to validate requests/responses. Instead of using `OpenapiFirstTest.app` to wrap your application, you could also use the [middlewares](#rack-middlewares) or [test assertion method](#test-assertions), but you would have to do that for all requests/responses defined in your API description to make coverage work.
82
82
 
83
- OpenapiFirst' request validation raises an error when a request is not defined. You can deactivate this during testing:
83
+ ### Configure test coverage
84
+
85
+ OpenapiFirst::Test raises an error when a request is not defined. You can deactivate this with:
84
86
 
85
87
  ```ruby
86
88
  OpenapiFirst::Test.setup do |test|
89
+ # …
87
90
  test.ignore_unknown_requests = true
88
91
  end
89
92
  ```
90
93
 
94
+ Exclude certain _responses_ from coverage with `skip_coverage`:
95
+
96
+ ```ruby
97
+ OpenapiFirst::Test.setup do |test|
98
+ # …
99
+ test.skip_response_coverage do |response_definition|
100
+ response_definition.status == '5XX'
101
+ end
102
+ end
103
+ ```
104
+
105
+ Skip coverage for a request and all responses alltogether of a route with `skip_coverage`:
106
+
107
+ ```ruby
108
+ OpenapiFirst::Test.setup do |test|
109
+ # …
110
+ test.skip_coverage do |path, request_method|
111
+ path == '/bookings/{bookingId}' && requests_method == 'DELETE'
112
+ end
113
+ end
114
+ ```
115
+
91
116
  ## Rack Middlewares
92
117
 
93
118
  ### Request validation
@@ -9,6 +9,7 @@ module OpenapiFirst
9
9
  @coverage_formatter = Coverage::TerminalFormatter
10
10
  @coverage_formatter_options = {}
11
11
  @skip_response_coverage = nil
12
+ @skip_coverage = nil
12
13
  @response_raise_error = true
13
14
  @ignored_unknown_status = [404]
14
15
  @report_coverage = true
@@ -29,9 +30,9 @@ module OpenapiFirst
29
30
  @apps[api] = app
30
31
  end
31
32
 
32
- attr_accessor :coverage_formatter_options, :coverage_formatter, :response_raise_error, :minimum_coverage,
33
+ attr_accessor :coverage_formatter_options, :coverage_formatter, :response_raise_error,
33
34
  :ignore_unknown_requests
34
- attr_reader :registry, :apps, :report_coverage, :ignored_unknown_status
35
+ attr_reader :registry, :apps, :report_coverage, :ignored_unknown_status, :minimum_coverage
35
36
 
36
37
  # Configure report coverage
37
38
  # @param [Boolean, :warn] value Whether to report coverage or just warn.
@@ -44,11 +45,24 @@ module OpenapiFirst
44
45
  @report_coverage = value
45
46
  end
46
47
 
48
+ # @deprecated Use skip_response_coverage, ignored_unknown_status or skip_coverage to configure coverage
49
+ def minimum_coverage=(value)
50
+ warn 'OpenapiFirst::Test::Configuration#minimum_coverage= is deprecated. ' \
51
+ 'Use skip_response_coverage, ignored_unknown_status to configure coverage instead.'
52
+ @minimum_coverage = value
53
+ end
54
+
47
55
  def skip_response_coverage(&block)
48
56
  return @skip_response_coverage unless block_given?
49
57
 
50
58
  @skip_response_coverage = block
51
59
  end
60
+
61
+ def skip_coverage(&block)
62
+ return @skip_coverage unless block_given?
63
+
64
+ @skip_coverage = block
65
+ end
52
66
  end
53
67
  end
54
68
  end
@@ -12,9 +12,11 @@ module OpenapiFirst
12
12
  class Plan
13
13
  class UnknownRequestError < StandardError; end
14
14
 
15
- def self.for(oad, skip_response: nil)
15
+ def self.for(oad, skip_response: nil, skip_route: nil)
16
16
  plan = new(definition_key: oad.key, filepath: oad.filepath)
17
- oad.routes.each do |route|
17
+ routes = oad.routes
18
+ routes = routes.reject { |route| skip_route[route.path, route.request_method] } if skip_route
19
+ routes.each do |route|
18
20
  responses = skip_response ? route.responses.reject(&skip_response) : route.responses
19
21
  plan.add_route request_method: route.request_method,
20
22
  path: route.path,
@@ -35,7 +37,7 @@ module OpenapiFirst
35
37
  private attr_reader :index
36
38
 
37
39
  def track_request(validated_request)
38
- index[validated_request.request_definition.key].track(validated_request) if validated_request.known?
40
+ index[validated_request.request_definition.key]&.track(validated_request) if validated_request.known?
39
41
  end
40
42
 
41
43
  def track_response(validated_response)
@@ -51,6 +53,8 @@ module OpenapiFirst
51
53
  return 0 if done.zero?
52
54
 
53
55
  all = tasks.count
56
+ return 100 if done == all
57
+
54
58
  (done / (all.to_f / 100))
55
59
  end
56
60
 
@@ -19,9 +19,9 @@ module OpenapiFirst
19
19
 
20
20
  def install = Test.install
21
21
 
22
- def start(skip_response: nil)
22
+ def start(skip_response: nil, skip_route: nil)
23
23
  @current_run = Test.definitions.values.to_h do |oad|
24
- plan = Plan.for(oad, skip_response:)
24
+ plan = Plan.for(oad, skip_response:, skip_route:)
25
25
  [oad.key, plan]
26
26
  end
27
27
  end
@@ -41,7 +41,7 @@ module OpenapiFirst
41
41
 
42
42
  configuration.registry.each { |name, oad| register(oad, as: name) }
43
43
  configuration.apps.each { |name, app| observe(app, api: name) }
44
- Coverage.start(skip_response: configuration.skip_response_coverage)
44
+ Coverage.start(skip_response: configuration.skip_response_coverage, skip_route: configuration.skip_coverage)
45
45
 
46
46
  if definitions.empty?
47
47
  raise NotRegisteredError,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '2.9.3'
4
+ VERSION = '2.10.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_first
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.3
4
+ version: 2.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Haller
@@ -49,7 +49,7 @@ dependencies:
49
49
  requirements:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 0.5.1
52
+ version: 0.6.1
53
53
  - - "<"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '2.0'
@@ -59,7 +59,7 @@ dependencies:
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 0.5.1
62
+ version: 0.6.1
63
63
  - - "<"
64
64
  - !ruby/object:Gem::Version
65
65
  version: '2.0'