openapi_first 3.3.1 → 3.4.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 +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +1 -0
- data/lib/openapi_first/builder.rb +5 -2
- data/lib/openapi_first/configuration.rb +6 -0
- data/lib/openapi_first/definition.rb +43 -9
- data/lib/openapi_first/middlewares/request_validation.rb +21 -2
- data/lib/openapi_first/middlewares/response_validation.rb +2 -1
- data/lib/openapi_first/plugins/x_public.rb +29 -0
- data/lib/openapi_first/plugins.rb +44 -0
- data/lib/openapi_first/registry.rb +2 -2
- data/lib/openapi_first/request.rb +28 -15
- data/lib/openapi_first/request_body_parsers.rb +40 -8
- data/lib/openapi_first/request_validator.rb +5 -1
- data/lib/openapi_first/response.rb +2 -12
- data/lib/openapi_first/response_body_parsers.rb +2 -2
- data/lib/openapi_first/response_parser.rb +6 -3
- data/lib/openapi_first/response_validator.rb +4 -3
- data/lib/openapi_first/schema/hash.rb +1 -1
- data/lib/openapi_first/test/configuration.rb +45 -4
- data/lib/openapi_first/test/coverage/html_reporter/context.rb +89 -0
- data/lib/openapi_first/test/coverage/html_reporter.css +179 -0
- data/lib/openapi_first/test/coverage/html_reporter.html.erb +87 -0
- data/lib/openapi_first/test/coverage/html_reporter.rb +30 -0
- data/lib/openapi_first/test/coverage/plan.rb +4 -3
- data/lib/openapi_first/test/coverage/route_task.rb +5 -0
- data/lib/openapi_first/test/coverage/{terminal_formatter.rb → terminal_reporter.rb} +25 -33
- data/lib/openapi_first/test/coverage.rb +15 -7
- data/lib/openapi_first/test/logger.rb +17 -0
- data/lib/openapi_first/test/observe.rb +1 -1
- data/lib/openapi_first/test.rb +16 -6
- data/lib/openapi_first/validators/request_body.rb +3 -2
- data/lib/openapi_first/validators/request_parameters.rb +4 -4
- data/lib/openapi_first/validators/response_body.rb +2 -2
- data/lib/openapi_first/validators/response_headers.rb +4 -3
- data/lib/openapi_first/version.rb +1 -1
- data/lib/openapi_first.rb +8 -0
- metadata +11 -4
data/lib/openapi_first/test.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'logger'
|
|
3
4
|
require_relative 'test/configuration'
|
|
4
5
|
require_relative 'registry'
|
|
5
6
|
|
|
@@ -30,6 +31,10 @@ module OpenapiFirst
|
|
|
30
31
|
super.empty? ? OpenapiFirst.definitions : super
|
|
31
32
|
end
|
|
32
33
|
|
|
34
|
+
def self.logger
|
|
35
|
+
configuration.logger
|
|
36
|
+
end
|
|
37
|
+
|
|
33
38
|
def self.configuration
|
|
34
39
|
@configuration ||= Configuration.new
|
|
35
40
|
end
|
|
@@ -72,8 +77,8 @@ module OpenapiFirst
|
|
|
72
77
|
return unless configuration.report_coverage
|
|
73
78
|
|
|
74
79
|
report_coverage(
|
|
75
|
-
|
|
76
|
-
**configuration.
|
|
80
|
+
reporter: configuration.coverage_reporter,
|
|
81
|
+
**configuration.coverage_reporter_options
|
|
77
82
|
)
|
|
78
83
|
return unless configuration.report_coverage == true
|
|
79
84
|
|
|
@@ -86,10 +91,15 @@ module OpenapiFirst
|
|
|
86
91
|
end
|
|
87
92
|
|
|
88
93
|
# Print the coverage report
|
|
89
|
-
# @param
|
|
90
|
-
# @
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
# @param reporter A reporter class to render the report.
|
|
95
|
+
# @param formatter @deprecated Alias for `reporter:`.
|
|
96
|
+
# @return [IO] An output where to puts the report.
|
|
97
|
+
def self.report_coverage(reporter: Coverage::TerminalReporter, formatter: nil, **)
|
|
98
|
+
if formatter
|
|
99
|
+
warn 'DEPRECATION WARNING: Test.report_coverage(formatter:) is deprecated, use reporter: instead.'
|
|
100
|
+
reporter = formatter
|
|
101
|
+
end
|
|
102
|
+
reporter.new(**).report(Coverage.result)
|
|
93
103
|
end
|
|
94
104
|
|
|
95
105
|
# Returns the Rack app wrapped with silent request, response validation
|
|
@@ -11,14 +11,15 @@ module OpenapiFirst
|
|
|
11
11
|
def call(parsed_request)
|
|
12
12
|
body = parsed_request.body
|
|
13
13
|
if body.nil?
|
|
14
|
-
Failure.
|
|
14
|
+
return Failure.new(:invalid_body, message: 'Request body must not be empty') if @required
|
|
15
|
+
|
|
15
16
|
return
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
validation = Schema::ValidationResult.new(
|
|
19
20
|
@schema.validate(body, access_mode: 'write')
|
|
20
21
|
)
|
|
21
|
-
Failure.
|
|
22
|
+
Failure.new(:invalid_body, errors: validation.errors) if validation.error?
|
|
22
23
|
end
|
|
23
24
|
end
|
|
24
25
|
end
|
|
@@ -6,28 +6,28 @@ module OpenapiFirst
|
|
|
6
6
|
RequestHeaders = Data.define(:schema) do
|
|
7
7
|
def call(parsed_request)
|
|
8
8
|
validation = schema.validate(parsed_request.headers)
|
|
9
|
-
Failure.
|
|
9
|
+
Failure.new(:invalid_header, errors: validation.errors) if validation.error?
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
Path = Data.define(:schema) do
|
|
14
14
|
def call(parsed_request)
|
|
15
15
|
validation = schema.validate(parsed_request.path)
|
|
16
|
-
Failure.
|
|
16
|
+
Failure.new(:invalid_path, errors: validation.errors) if validation.error?
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
Query = Data.define(:schema) do
|
|
21
21
|
def call(parsed_request)
|
|
22
22
|
validation = schema.validate(parsed_request.query)
|
|
23
|
-
Failure.
|
|
23
|
+
Failure.new(:invalid_query, errors: validation.errors) if validation.error?
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
RequestCookies = Data.define(:schema) do
|
|
28
28
|
def call(parsed_request)
|
|
29
29
|
validation = schema.validate(parsed_request.cookies)
|
|
30
|
-
Failure.
|
|
30
|
+
Failure.new(:invalid_cookie, errors: validation.errors) if validation.error?
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -15,12 +15,12 @@ module OpenapiFirst
|
|
|
15
15
|
begin
|
|
16
16
|
parsed_body = response.body
|
|
17
17
|
rescue ParseError => e
|
|
18
|
-
Failure.
|
|
18
|
+
return Failure.new(:invalid_response_body, message: e.message)
|
|
19
19
|
end
|
|
20
20
|
validation = Schema::ValidationResult.new(
|
|
21
21
|
schema.validate(parsed_body, access_mode: 'read')
|
|
22
22
|
)
|
|
23
|
-
Failure.
|
|
23
|
+
Failure.new(:invalid_response_body, errors: validation.errors) if validation.error?
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
@@ -17,10 +17,11 @@ module OpenapiFirst
|
|
|
17
17
|
validation_errors = header.schema.validate(header_value)
|
|
18
18
|
next unless validation_errors.any?
|
|
19
19
|
|
|
20
|
-
Failure.
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
return Failure.new(:invalid_response_header,
|
|
21
|
+
errors: [error_for(data_pointer: "/#{header.name}", value: header_value,
|
|
22
|
+
error: validation_errors.first)])
|
|
23
23
|
end
|
|
24
|
+
nil
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
private
|
data/lib/openapi_first.rb
CHANGED
|
@@ -7,6 +7,7 @@ require_relative 'openapi_first/registry'
|
|
|
7
7
|
require_relative 'openapi_first/configuration'
|
|
8
8
|
require_relative 'openapi_first/child_configuration'
|
|
9
9
|
require_relative 'openapi_first/definition'
|
|
10
|
+
require_relative 'openapi_first/plugins'
|
|
10
11
|
require_relative 'openapi_first/version'
|
|
11
12
|
require_relative 'openapi_first/middlewares/response_validation'
|
|
12
13
|
require_relative 'openapi_first/middlewares/request_validation'
|
|
@@ -53,6 +54,13 @@ module OpenapiFirst
|
|
|
53
54
|
end
|
|
54
55
|
end
|
|
55
56
|
|
|
57
|
+
# Load a plugin into the global configuration.
|
|
58
|
+
# @param name [Symbol] Plugin name. Looks up OpenapiFirst::Plugins::<Name> or requires "openapi_first/plugins/<name>".
|
|
59
|
+
# @param opts [Hash] Options forwarded to the plugin's .configure method.
|
|
60
|
+
def self.plugin(name, **)
|
|
61
|
+
configuration.plugin(name, **)
|
|
62
|
+
end
|
|
63
|
+
|
|
56
64
|
# Load and dereference an OpenAPI spec file or return the Definition if it's already loaded
|
|
57
65
|
# @param filepath_or_definition [String, Definition] The path to the file or a Definition object
|
|
58
66
|
# @param only [Proc, nil] An optional proc to filter paths. It is called with the path string and should return
|
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: 3.
|
|
4
|
+
version: 3.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andreas Haller
|
|
@@ -63,7 +63,7 @@ dependencies:
|
|
|
63
63
|
requirements:
|
|
64
64
|
- - ">="
|
|
65
65
|
- !ruby/object:Gem::Version
|
|
66
|
-
version: 0.
|
|
66
|
+
version: 0.12.0
|
|
67
67
|
- - "<"
|
|
68
68
|
- !ruby/object:Gem::Version
|
|
69
69
|
version: '2.0'
|
|
@@ -73,7 +73,7 @@ dependencies:
|
|
|
73
73
|
requirements:
|
|
74
74
|
- - ">="
|
|
75
75
|
- !ruby/object:Gem::Version
|
|
76
|
-
version: 0.
|
|
76
|
+
version: 0.12.0
|
|
77
77
|
- - "<"
|
|
78
78
|
- !ruby/object:Gem::Version
|
|
79
79
|
version: '2.0'
|
|
@@ -122,6 +122,8 @@ files:
|
|
|
122
122
|
- lib/openapi_first/middlewares/request_validation.rb
|
|
123
123
|
- lib/openapi_first/middlewares/response_validation.rb
|
|
124
124
|
- lib/openapi_first/parsed_request.rb
|
|
125
|
+
- lib/openapi_first/plugins.rb
|
|
126
|
+
- lib/openapi_first/plugins/x_public.rb
|
|
125
127
|
- lib/openapi_first/ref_resolver.rb
|
|
126
128
|
- lib/openapi_first/registry.rb
|
|
127
129
|
- lib/openapi_first/request.rb
|
|
@@ -145,12 +147,17 @@ files:
|
|
|
145
147
|
- lib/openapi_first/test/coverage.rb
|
|
146
148
|
- lib/openapi_first/test/coverage/covered_request.rb
|
|
147
149
|
- lib/openapi_first/test/coverage/covered_response.rb
|
|
150
|
+
- lib/openapi_first/test/coverage/html_reporter.css
|
|
151
|
+
- lib/openapi_first/test/coverage/html_reporter.html.erb
|
|
152
|
+
- lib/openapi_first/test/coverage/html_reporter.rb
|
|
153
|
+
- lib/openapi_first/test/coverage/html_reporter/context.rb
|
|
148
154
|
- lib/openapi_first/test/coverage/plan.rb
|
|
149
155
|
- lib/openapi_first/test/coverage/request_task.rb
|
|
150
156
|
- lib/openapi_first/test/coverage/response_task.rb
|
|
151
157
|
- lib/openapi_first/test/coverage/route_task.rb
|
|
152
|
-
- lib/openapi_first/test/coverage/
|
|
158
|
+
- lib/openapi_first/test/coverage/terminal_reporter.rb
|
|
153
159
|
- lib/openapi_first/test/coverage/tracker.rb
|
|
160
|
+
- lib/openapi_first/test/logger.rb
|
|
154
161
|
- lib/openapi_first/test/methods.rb
|
|
155
162
|
- lib/openapi_first/test/minitest_helpers.rb
|
|
156
163
|
- lib/openapi_first/test/observe.rb
|