openapi_first 4.4.0 → 4.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/.yardopts +7 -0
- data/CHANGELOG.md +6 -0
- data/README.md +79 -10
- data/lib/openapi_first/builder.rb +25 -24
- data/lib/openapi_first/child_configuration.rb +1 -0
- data/lib/openapi_first/configuration.rb +80 -2
- data/lib/openapi_first/definition.rb +3 -2
- data/lib/openapi_first/error_response.rb +18 -3
- data/lib/openapi_first/failure.rb +27 -7
- data/lib/openapi_first/file_loader.rb +1 -1
- data/lib/openapi_first/json.rb +1 -1
- data/lib/openapi_first/middlewares/request_validation.rb +2 -0
- data/lib/openapi_first/middlewares/response_validation.rb +2 -0
- data/lib/openapi_first/parameter/converter/array_converter.rb +1 -1
- data/lib/openapi_first/parameter/converter/object_converter.rb +1 -1
- data/lib/openapi_first/parameter/converter.rb +1 -1
- data/lib/openapi_first/parameter/unpackers.rb +1 -1
- data/lib/openapi_first/parameter.rb +3 -0
- data/lib/openapi_first/parameters_parser.rb +1 -1
- data/lib/openapi_first/parsed_request.rb +1 -0
- data/lib/openapi_first/path_template.rb +1 -1
- data/lib/openapi_first/plugins/x_public.rb +3 -0
- data/lib/openapi_first/query_string_parser.rb +1 -1
- data/lib/openapi_first/ref_resolver.rb +16 -11
- data/lib/openapi_first/registry.rb +2 -4
- data/lib/openapi_first/request_body_parsers.rb +1 -1
- data/lib/openapi_first/{request.rb → request_definition.rb} +27 -1
- data/lib/openapi_first/request_headers.rb +1 -1
- data/lib/openapi_first/request_validator.rb +1 -0
- data/lib/openapi_first/response_body_parsers.rb +1 -1
- data/lib/openapi_first/{response.rb → response_definition.rb} +19 -4
- data/lib/openapi_first/response_parser.rb +3 -1
- data/lib/openapi_first/response_validator.rb +1 -0
- data/lib/openapi_first/router/find_content.rb +1 -1
- data/lib/openapi_first/router/find_response.rb +1 -1
- data/lib/openapi_first/router/path_trie.rb +1 -1
- data/lib/openapi_first/router/segment_pattern.rb +1 -1
- data/lib/openapi_first/router.rb +1 -0
- data/lib/openapi_first/schema/hash.rb +15 -1
- data/lib/openapi_first/schema/validation_result.rb +1 -0
- data/lib/openapi_first/sinatra.rb +2 -2
- data/lib/openapi_first/test/app.rb +3 -0
- data/lib/openapi_first/test/callable.rb +1 -0
- data/lib/openapi_first/test/configuration.rb +6 -4
- data/lib/openapi_first/test/coverage/covered_request.rb +1 -0
- data/lib/openapi_first/test/coverage/covered_response.rb +1 -0
- data/lib/openapi_first/test/coverage/html_reporter/context.rb +1 -0
- data/lib/openapi_first/test/coverage/html_reporter.rb +2 -0
- data/lib/openapi_first/test/coverage/plan.rb +1 -0
- data/lib/openapi_first/test/coverage/request_task.rb +1 -1
- data/lib/openapi_first/test/coverage/response_task.rb +1 -1
- data/lib/openapi_first/test/coverage/route_task.rb +1 -0
- data/lib/openapi_first/test/coverage/skipped_summary.rb +1 -0
- data/lib/openapi_first/test/coverage/terminal_reporter.rb +2 -0
- data/lib/openapi_first/test/coverage/tracker.rb +1 -0
- data/lib/openapi_first/test/coverage.rb +11 -4
- data/lib/openapi_first/test/methods.rb +14 -1
- data/lib/openapi_first/test/minitest_helpers.rb +5 -2
- data/lib/openapi_first/test/observe.rb +2 -1
- data/lib/openapi_first/test/observer_middleware.rb +1 -0
- data/lib/openapi_first/test/plain_helpers.rb +7 -4
- data/lib/openapi_first/test.rb +30 -3
- data/lib/openapi_first/utils.rb +1 -1
- data/lib/openapi_first/validated_request.rb +4 -4
- data/lib/openapi_first/validated_response.rb +5 -3
- data/lib/openapi_first/validators/multipart_request_body.rb +1 -0
- data/lib/openapi_first/validators/request_body.rb +1 -0
- data/lib/openapi_first/validators/request_parameters.rb +1 -1
- data/lib/openapi_first/validators/response_body.rb +1 -0
- data/lib/openapi_first/validators/response_headers.rb +1 -0
- data/lib/openapi_first/version.rb +1 -1
- data/lib/openapi_first.rb +7 -2
- metadata +4 -3
|
@@ -16,6 +16,9 @@ module OpenapiFirst
|
|
|
16
16
|
# OpenapiFirst.plugin :x_public, field: 'x-visible'
|
|
17
17
|
# OpenapiFirst.plugin :x_public, if: ->(req) { req.host == 'api.example.com' }
|
|
18
18
|
module XPublic
|
|
19
|
+
# @param config [Configuration]
|
|
20
|
+
# @param field [String] The OpenAPI extension field to check
|
|
21
|
+
# @return [void]
|
|
19
22
|
def self.configure(config, field: 'x-public', **opts)
|
|
20
23
|
condition = opts[:if]
|
|
21
24
|
config.before_request_validation do |request, request_definition|
|
|
@@ -4,7 +4,7 @@ require 'json_schemer'
|
|
|
4
4
|
|
|
5
5
|
module OpenapiFirst
|
|
6
6
|
# This is here to give traverse an OAD while keeping $refs intact
|
|
7
|
-
# @
|
|
7
|
+
# @api private
|
|
8
8
|
class RefResolver
|
|
9
9
|
def initialize(file_loader:)
|
|
10
10
|
@file_loader = file_loader
|
|
@@ -41,7 +41,7 @@ module OpenapiFirst
|
|
|
41
41
|
self.for(value, filepath: filepath, context: file_contents)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
-
# @
|
|
44
|
+
# @api private
|
|
45
45
|
module Diggable
|
|
46
46
|
def dig(*keys)
|
|
47
47
|
keys.inject(self) do |result, key|
|
|
@@ -52,7 +52,7 @@ module OpenapiFirst
|
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
55
|
-
# @
|
|
55
|
+
# @api private
|
|
56
56
|
module Resolvable
|
|
57
57
|
def initialize(value, ref_resolver:, context: value, filepath: nil)
|
|
58
58
|
@value = value
|
|
@@ -84,7 +84,7 @@ module OpenapiFirst
|
|
|
84
84
|
def resolve_ref(pointer)
|
|
85
85
|
if pointer.start_with?('#')
|
|
86
86
|
value = Hana::Pointer.new(pointer[1..]).eval(context)
|
|
87
|
-
raise "Unknown reference #{pointer.inspect} in #{
|
|
87
|
+
raise "Unknown reference #{pointer.inspect} in #{ref_location}. Nothing exists at that pointer." unless value
|
|
88
88
|
|
|
89
89
|
return ref_resolver.for(value, filepath:, context:)
|
|
90
90
|
end
|
|
@@ -94,7 +94,10 @@ module OpenapiFirst
|
|
|
94
94
|
return ref_resolver.load(full_path) unless file_pointer
|
|
95
95
|
|
|
96
96
|
resolved = ref_resolver.file_at(full_path, file_pointer)
|
|
97
|
-
|
|
97
|
+
unless resolved
|
|
98
|
+
raise "Unknown reference #{pointer.inspect} in #{ref_location}. " \
|
|
99
|
+
"Nothing exists at #{"##{file_pointer}".inspect} in #{full_path.inspect}."
|
|
100
|
+
end
|
|
98
101
|
|
|
99
102
|
resolved
|
|
100
103
|
rescue OpenapiFirst::FileNotFoundError => e
|
|
@@ -105,10 +108,12 @@ module OpenapiFirst
|
|
|
105
108
|
|
|
106
109
|
private
|
|
107
110
|
|
|
111
|
+
def ref_location = filepath ? File.absolute_path(filepath).inspect : 'the API description'
|
|
112
|
+
|
|
108
113
|
def mark(visited) = (visited || []) + [value.object_id]
|
|
109
114
|
end
|
|
110
115
|
|
|
111
|
-
# @
|
|
116
|
+
# @api private
|
|
112
117
|
class Simple
|
|
113
118
|
include Resolvable
|
|
114
119
|
|
|
@@ -117,7 +122,7 @@ module OpenapiFirst
|
|
|
117
122
|
def dereferenced(_visited = nil) = value
|
|
118
123
|
end
|
|
119
124
|
|
|
120
|
-
# @
|
|
125
|
+
# @api private
|
|
121
126
|
class Hash
|
|
122
127
|
include Resolvable
|
|
123
128
|
include Diggable
|
|
@@ -171,7 +176,7 @@ module OpenapiFirst
|
|
|
171
176
|
end
|
|
172
177
|
end
|
|
173
178
|
|
|
174
|
-
# @
|
|
179
|
+
# @api private
|
|
175
180
|
# Defers initialization JSONSchemer::Schema, because that takes time.
|
|
176
181
|
class Schema
|
|
177
182
|
extend Forwardable
|
|
@@ -187,7 +192,7 @@ module OpenapiFirst
|
|
|
187
192
|
# This class is here to monkey-patch JSONSchemer::Schema when we are passing
|
|
188
193
|
# an instance to sub-schemas. It skips stringifying all keys of the passed object to
|
|
189
194
|
# allocate fewer objects. We don't have to stringify the keys, because they are already stringified upstream.
|
|
190
|
-
# @
|
|
195
|
+
# @api private
|
|
191
196
|
class DocumentRootSchema < JSONSchemer::Schema
|
|
192
197
|
private
|
|
193
198
|
|
|
@@ -204,7 +209,7 @@ module OpenapiFirst
|
|
|
204
209
|
|
|
205
210
|
attr_reader :value, :context, :base_uri, :options
|
|
206
211
|
|
|
207
|
-
def_delegators :schema, :validate, :valid
|
|
212
|
+
def_delegators :schema, :validate, :valid?, :parsed
|
|
208
213
|
|
|
209
214
|
def schema
|
|
210
215
|
@schema ||= begin
|
|
@@ -228,7 +233,7 @@ module OpenapiFirst
|
|
|
228
233
|
end
|
|
229
234
|
end
|
|
230
235
|
|
|
231
|
-
# @
|
|
236
|
+
# @api private
|
|
232
237
|
class Array
|
|
233
238
|
include Enumerable
|
|
234
239
|
include Resolvable
|
|
@@ -4,15 +4,13 @@ module OpenapiFirst
|
|
|
4
4
|
class NotRegisteredError < Error; end
|
|
5
5
|
class AlreadyRegisteredError < Error; end
|
|
6
6
|
|
|
7
|
-
# @
|
|
7
|
+
# @api private
|
|
8
8
|
module Registry
|
|
9
|
+
# @return [Hash<Symbol, Definition>] The registered API descriptions by name
|
|
9
10
|
def definitions
|
|
10
11
|
@definitions ||= {}
|
|
11
12
|
end
|
|
12
13
|
|
|
13
|
-
# Register an OpenAPI definition for testing
|
|
14
|
-
# @param path_or_definition [String, Definition] Path to the OpenAPI file or a Definition object
|
|
15
|
-
# @param as [Symbol] Name to register the API definition as
|
|
16
14
|
def register(path_or_definition, as: :default, &)
|
|
17
15
|
if definitions.key?(as) && as == :default
|
|
18
16
|
raise(
|
|
@@ -11,7 +11,8 @@ module OpenapiFirst
|
|
|
11
11
|
# Note that this is not the same as an OpenAPI 3.x Operation.
|
|
12
12
|
# An 3.x Operation object can accept multiple requests, because it can handle multiple content-types.
|
|
13
13
|
# This class represents one of those requests.
|
|
14
|
-
class
|
|
14
|
+
class RequestDefinition
|
|
15
|
+
# @api private
|
|
15
16
|
def initialize(path:, request_method:, operation_object:, # rubocop:disable Metrics/MethodLength,Metrics/ParameterLists
|
|
16
17
|
parameters:, content_type:, content_schema:, required_body:, key:, encoding: nil)
|
|
17
18
|
@path = path
|
|
@@ -38,19 +39,40 @@ module OpenapiFirst
|
|
|
38
39
|
)
|
|
39
40
|
end
|
|
40
41
|
|
|
42
|
+
# @!attribute [r] content_type
|
|
43
|
+
# @return [String, nil] The request content type, or nil if the operation defines no request body
|
|
44
|
+
# @!attribute [r] content_schema
|
|
45
|
+
# @return [#value, nil] The schema of the request body. Its `value` is the JSON Schema Hash.
|
|
46
|
+
# @!attribute [r] operation
|
|
47
|
+
# @return [Hash] The raw OpenAPI 3 operation object
|
|
48
|
+
# @!attribute [r] request_method
|
|
49
|
+
# @return [String] The lowercase HTTP method, e.g. "get"
|
|
50
|
+
# @!attribute [r] path
|
|
51
|
+
# @return [String] The OpenAPI path template, e.g. "/pets/{petId}"
|
|
52
|
+
# @!attribute [r] key
|
|
53
|
+
# @return [String] A unique key of this request definition
|
|
54
|
+
# @!attribute [r] parameters
|
|
55
|
+
# @return [Array<Parameter>] The parameters in the order path, query, header, cookie
|
|
41
56
|
attr_reader :content_type, :content_schema, :operation, :request_method, :path, :key, :parameters
|
|
42
57
|
private attr_reader :query_parser
|
|
43
58
|
|
|
59
|
+
# @return [Boolean] true if a request without a body is valid
|
|
44
60
|
def allow_empty_content?
|
|
45
61
|
@allow_empty_content
|
|
46
62
|
end
|
|
47
63
|
|
|
64
|
+
# @api private
|
|
65
|
+
# Use {Definition#validate_request} to validate a request.
|
|
66
|
+
# @param request [Rack::Request]
|
|
67
|
+
# @param route_params [Hash<String, String>] The path parameters extracted by the router
|
|
68
|
+
# @return [ValidatedRequest]
|
|
48
69
|
def validate(request, route_params:)
|
|
49
70
|
parsed_request, error = parse_request(request, route_params:)
|
|
50
71
|
error ||= @validator.call(parsed_request) if parsed_request
|
|
51
72
|
ValidatedRequest.new(request, parsed_request:, error:, request_definition: self, query_parser:)
|
|
52
73
|
end
|
|
53
74
|
|
|
75
|
+
# @return [String, nil] The OpenAPI 3 operationId
|
|
54
76
|
def operation_id
|
|
55
77
|
@operation['operationId']
|
|
56
78
|
end
|
|
@@ -92,4 +114,8 @@ module OpenapiFirst
|
|
|
92
114
|
RequestBodyParsers[content_type, { encoding: encoding || {} }]
|
|
93
115
|
end
|
|
94
116
|
end
|
|
117
|
+
|
|
118
|
+
# @deprecated Use {RequestDefinition}
|
|
119
|
+
Request = RequestDefinition
|
|
120
|
+
deprecate_constant :Request
|
|
95
121
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module OpenapiFirst
|
|
4
4
|
# A wrapper around the Rack env hash that allows accessing headers by header name
|
|
5
|
-
# @
|
|
5
|
+
# @api private
|
|
6
6
|
class RequestHeaders
|
|
7
7
|
# This was copied from this Rack::Request PR: https://github.com/rack/rack/pull/1881
|
|
8
8
|
def initialize(env)
|
|
@@ -8,7 +8,8 @@ module OpenapiFirst
|
|
|
8
8
|
# Represents a response definition in the OpenAPI document.
|
|
9
9
|
# This is not a direct reflecton of the OpenAPI 3.X response definition, but a combination of
|
|
10
10
|
# status, content type and content schema.
|
|
11
|
-
class
|
|
11
|
+
class ResponseDefinition
|
|
12
|
+
# @api private
|
|
12
13
|
def initialize(status:, headers:, content_type:, content_schema:, key:)
|
|
13
14
|
@status = status
|
|
14
15
|
@content_type = content_type
|
|
@@ -19,15 +20,29 @@ module OpenapiFirst
|
|
|
19
20
|
@validator = ResponseValidator.new(content_schema:, headers:)
|
|
20
21
|
end
|
|
21
22
|
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
23
|
+
# @!attribute [r] status
|
|
24
|
+
# @return [String] The status as written in the API description, e.g. "200", "4XX" or "default"
|
|
25
|
+
# @!attribute [r] content_type
|
|
26
|
+
# @return [String, nil] Content type of this response
|
|
27
|
+
# @!attribute [r] content_schema
|
|
28
|
+
# @return [#value, nil] The schema of the response body. Its `value` is the JSON Schema Hash.
|
|
29
|
+
# @!attribute [r] headers
|
|
30
|
+
# @return [Array<ResponseHeader>, nil] The response headers defined in the API description
|
|
31
|
+
# @!attribute [r] key
|
|
32
|
+
# @return [String] A unique key of this response definition
|
|
25
33
|
attr_reader :status, :content_type, :content_schema, :headers, :key
|
|
26
34
|
|
|
35
|
+
# Validates a response against this response definition.
|
|
36
|
+
# @param response [Rack::Response]
|
|
37
|
+
# @return [ValidatedResponse]
|
|
27
38
|
def validate(response)
|
|
28
39
|
parsed_values, error = @parser.parse(response)
|
|
29
40
|
error ||= @validator.call(parsed_values) if parsed_values
|
|
30
41
|
ValidatedResponse.new(response, parsed_values:, error:, response_definition: self)
|
|
31
42
|
end
|
|
32
43
|
end
|
|
44
|
+
|
|
45
|
+
# @deprecated Use {ResponseDefinition}
|
|
46
|
+
Response = ResponseDefinition
|
|
47
|
+
deprecate_constant :Response
|
|
33
48
|
end
|
|
@@ -4,9 +4,11 @@ require_relative 'parameters_parser'
|
|
|
4
4
|
require_relative 'response_body_parsers'
|
|
5
5
|
|
|
6
6
|
module OpenapiFirst
|
|
7
|
+
# @api private
|
|
7
8
|
ParsedResponse = Data.define(:body, :headers)
|
|
8
9
|
|
|
9
10
|
# Parse a response
|
|
11
|
+
# @api private
|
|
10
12
|
class ResponseParser
|
|
11
13
|
def initialize(headers:, content_type:)
|
|
12
14
|
@headers_parser = build_headers_parser(headers)
|
|
@@ -34,7 +36,7 @@ module OpenapiFirst
|
|
|
34
36
|
end
|
|
35
37
|
rack_response.body
|
|
36
38
|
rescue TypeError
|
|
37
|
-
raise Error, "Cannot
|
|
39
|
+
raise Error, "Cannot read response body. Response is not string-like, but is a #{rack_response.body.class}."
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
def build_headers_parser(headers)
|
|
@@ -5,7 +5,7 @@ require_relative '../path_template'
|
|
|
5
5
|
module OpenapiFirst
|
|
6
6
|
class Router
|
|
7
7
|
# Matches one path segment against a segment of a path template that mixes literals and variables
|
|
8
|
-
# @
|
|
8
|
+
# @api private
|
|
9
9
|
class SegmentPattern
|
|
10
10
|
def initialize(segment)
|
|
11
11
|
@pattern = build_pattern(segment)
|
data/lib/openapi_first/router.rb
CHANGED
|
@@ -7,6 +7,7 @@ require_relative 'router/find_response'
|
|
|
7
7
|
|
|
8
8
|
module OpenapiFirst
|
|
9
9
|
# Router can map requests / responses to their API definition
|
|
10
|
+
# @api private
|
|
10
11
|
class Router
|
|
11
12
|
# Returned by {#match}
|
|
12
13
|
RequestMatch = Data.define(:request_definition, :params, :error, :responses) do
|
|
@@ -5,6 +5,7 @@ require_relative 'validation_error'
|
|
|
5
5
|
module OpenapiFirst
|
|
6
6
|
module Schema
|
|
7
7
|
# A hash of Schemas
|
|
8
|
+
# @api private
|
|
8
9
|
class Hash
|
|
9
10
|
# @param schemas Hash of schemas
|
|
10
11
|
# @param required Array of required keys
|
|
@@ -19,7 +20,7 @@ module OpenapiFirst
|
|
|
19
20
|
def validate(root_value)
|
|
20
21
|
validation = @root_schema.validate(root_value)
|
|
21
22
|
validations = @schemas.reduce(validation) do |enum, (key, schema)|
|
|
22
|
-
root_value
|
|
23
|
+
insert_default(root_value, key, schema) unless root_value.key?(key)
|
|
23
24
|
next enum unless root_value.key?(key)
|
|
24
25
|
|
|
25
26
|
value = root_value[key]
|
|
@@ -33,6 +34,19 @@ module OpenapiFirst
|
|
|
33
34
|
end
|
|
34
35
|
ValidationResult.new(validations)
|
|
35
36
|
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def insert_default(root_value, key, schema)
|
|
41
|
+
default = default_keyword(schema.parsed)
|
|
42
|
+
root_value[key] = default.value if default
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def default_keyword(parsed)
|
|
46
|
+
parsed.fetch('default') do
|
|
47
|
+
parsed.each_value.filter_map { default_keyword(_1.ref_schema.parsed) if _1.respond_to?(:ref_schema) }.first
|
|
48
|
+
end
|
|
49
|
+
end
|
|
36
50
|
end
|
|
37
51
|
end
|
|
38
52
|
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# :
|
|
3
|
+
# simplecov:disable
|
|
4
4
|
begin
|
|
5
5
|
require 'sinatra/base'
|
|
6
6
|
rescue LoadError
|
|
7
7
|
raise LoadError, 'openapi_first/sinatra needs the `sinatra` gem. Add `gem "sinatra"` to your Gemfile.'
|
|
8
8
|
end
|
|
9
|
-
# :
|
|
9
|
+
# simplecov:disable
|
|
10
10
|
|
|
11
11
|
require 'did_you_mean'
|
|
12
12
|
require 'openapi_first'
|
|
@@ -4,11 +4,14 @@ require_relative 'observe'
|
|
|
4
4
|
|
|
5
5
|
module OpenapiFirst
|
|
6
6
|
module Test
|
|
7
|
+
# @api private
|
|
7
8
|
REQUEST = 'openapi.test.request'
|
|
9
|
+
# @api private
|
|
8
10
|
RESPONSE = 'openapi.test.response'
|
|
9
11
|
|
|
10
12
|
# A wrapper of the original app
|
|
11
13
|
# with silent request/response validation to track requests/responses.
|
|
14
|
+
# @api private
|
|
12
15
|
class App < SimpleDelegator
|
|
13
16
|
def initialize(app, api:, validate_request_before_handling:)
|
|
14
17
|
super(app)
|
|
@@ -4,6 +4,7 @@ module OpenapiFirst
|
|
|
4
4
|
module Test
|
|
5
5
|
# Return a Module with a call method that wrapps silent request/response validation to monitor a Rack app
|
|
6
6
|
# This is used by Openapi::Test.observe
|
|
7
|
+
# @api private
|
|
7
8
|
module Callable
|
|
8
9
|
# Returns a Module with a `call(env)` method that wraps super inside silent request/response validation
|
|
9
10
|
# You can use `Application.prepend(OpenapiFirst::Test::Callable[oad])` to monitor your app during testing.
|
|
@@ -58,9 +58,9 @@ module OpenapiFirst
|
|
|
58
58
|
# Ignore certain errors for certain requests
|
|
59
59
|
# @param block A Proc that will be called with [OpenapiFirst::ValidatedRequest]
|
|
60
60
|
def ignore_request_error(&block)
|
|
61
|
-
# :
|
|
61
|
+
# simplecov:disable
|
|
62
62
|
raise ArgumentError, 'You have to pass a block' unless block_given?
|
|
63
|
-
# :
|
|
63
|
+
# simplecov:disable
|
|
64
64
|
|
|
65
65
|
@ignore_request_error = block
|
|
66
66
|
end
|
|
@@ -68,9 +68,9 @@ module OpenapiFirst
|
|
|
68
68
|
# Ignore certain errors for certain responses
|
|
69
69
|
# @param block A Proc that will be called with [OpenapiFirst::ValidatedResponse, Rack::Request]
|
|
70
70
|
def ignore_response_error(&block)
|
|
71
|
-
# :
|
|
71
|
+
# simplecov:disable
|
|
72
72
|
raise ArgumentError, 'You have to pass a block' unless block_given?
|
|
73
|
-
# :
|
|
73
|
+
# simplecov:disable
|
|
74
74
|
|
|
75
75
|
@ignore_response_error = block
|
|
76
76
|
end
|
|
@@ -82,6 +82,8 @@ module OpenapiFirst
|
|
|
82
82
|
@skip_response_coverage = block
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
+
# @param block A Proc that will be called with the path template and the request method of each route.
|
|
86
|
+
# Return true to exclude the route and its responses from coverage.
|
|
85
87
|
def skip_coverage(&block)
|
|
86
88
|
return @skip_coverage unless block_given?
|
|
87
89
|
|
|
@@ -16,6 +16,8 @@ module OpenapiFirst
|
|
|
16
16
|
@logger = logger
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
+
# Writes the HTML report to the output file
|
|
20
|
+
# @param coverage_result [Coverage::Result]
|
|
19
21
|
def report(coverage_result)
|
|
20
22
|
html = TEMPLATE.result(Context.new(coverage_result, @verbose).get_binding)
|
|
21
23
|
FileUtils.mkdir_p(File.dirname(@output))
|