openapi_first 2.9.0 → 2.9.2
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 +9 -0
- data/README.md +2 -0
- data/lib/openapi_first/router/find_response.rb +13 -9
- data/lib/openapi_first/test/coverage/terminal_formatter.rb +5 -2
- data/lib/openapi_first/test.rb +1 -3
- data/lib/openapi_first/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77ee23a7f40889116a6ae239e51711460c21c9f134f7e85bef5c2869d91d7d26
|
4
|
+
data.tar.gz: 5b541d1727e879c8e1ace187679bd6bc708054e2675d127dfca718fc963fb10b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68e0311f5a70192b54a4d3c3654e1910b39bdfc420db4c5abcce38ba4dc2d2f4e78a278ac35be8a9796c59ba42428c3b67912adb08c1aeb469ba5d08f8223800
|
7
|
+
data.tar.gz: e43db82ccea7aeca33f58fa705f16844080f672dc0b157f72f10aa1e5fdf7ca4a71d6146c93622b46b226811b6e9cd09c61fa72fec6fb16831edfc606668089b
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 2.9.2
|
6
|
+
|
7
|
+
- OpenapiFirst::Test reports all non-covered requests now
|
8
|
+
- Response validation: Improve content type mismatch exception message
|
9
|
+
|
10
|
+
## 2.9.1
|
11
|
+
|
12
|
+
- Fix OpenapiFirst::Test's request validation to not always raise an error, but only for unknown requests
|
13
|
+
|
5
14
|
## 2.9.0
|
6
15
|
|
7
16
|
- OpenapiFirst::Test now raises an error for unknown requests. You can deactivate with:
|
data/README.md
CHANGED
@@ -368,6 +368,8 @@ use OpenapiFirst::Middlewares::RequestValidation, oad
|
|
368
368
|
|
369
369
|
## Development
|
370
370
|
|
371
|
+
Run `git submodule update --init` to initialize the git submodules.
|
372
|
+
|
371
373
|
Run `bin/setup` to install dependencies.
|
372
374
|
|
373
375
|
See `bundle exec rake` to run the linter and the tests.
|
@@ -16,20 +16,24 @@ module OpenapiFirst
|
|
16
16
|
return Match.new(error: Failure.new(:response_not_found, message:), response: nil)
|
17
17
|
end
|
18
18
|
response = FindContent.call(contents, content_type)
|
19
|
-
|
20
|
-
message = "#{content_error(content_type, request_method:,
|
21
|
-
path:)} Content-Type should be #{contents.keys.join(' or ')}."
|
22
|
-
return Match.new(error: Failure.new(:response_not_found, message:), response: nil)
|
23
|
-
end
|
19
|
+
return response_not_found(content_type:, contents:, request_method:, path:) unless response
|
24
20
|
|
25
21
|
Match.new(response:, error: nil)
|
26
22
|
end
|
27
23
|
|
28
|
-
def self.
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
def self.response_not_found(content_type:, contents:, request_method:, path:)
|
25
|
+
empty_content = content_type.nil? || content_type.empty?
|
26
|
+
message =
|
27
|
+
"Content-Type should be #{contents.keys.join(' or ')}, " \
|
28
|
+
"but was #{empty_content ? 'empty' : content_type} for " \
|
29
|
+
"#{request_method.upcase} #{path}"
|
30
|
+
|
31
|
+
Match.new(
|
32
|
+
error: Failure.new(:response_not_found, message:),
|
33
|
+
response: nil
|
34
|
+
)
|
32
35
|
end
|
36
|
+
private_class_method :response_not_found
|
33
37
|
|
34
38
|
def self.find_status(responses, status)
|
35
39
|
# According to OAS status has to be a string,
|
@@ -33,14 +33,17 @@ module OpenapiFirst
|
|
33
33
|
@out.print(string)
|
34
34
|
end
|
35
35
|
|
36
|
-
def format_plan(plan)
|
36
|
+
def format_plan(plan) # rubocop:disable Metrics/PerceivedComplexity
|
37
37
|
puts ['', "API validation coverage for #{plan.api_identifier}: #{plan.coverage}%"]
|
38
38
|
return if plan.done? && !verbose
|
39
39
|
|
40
|
+
requested_routes_count = plan.routes.count { |route| route.requests.any?(&:requested?) }
|
41
|
+
focused_route = requested_routes_count <= 1 && focused
|
42
|
+
|
40
43
|
plan.routes.each do |route|
|
41
44
|
next if route.finished? && !verbose
|
42
45
|
|
43
|
-
next if route.requests.none?(&:requested?) &&
|
46
|
+
next if route.requests.none?(&:requested?) && focused_route
|
44
47
|
|
45
48
|
format_requests(route.requests)
|
46
49
|
|
data/lib/openapi_first/test.rb
CHANGED
@@ -102,8 +102,6 @@ module OpenapiFirst
|
|
102
102
|
@after_request_validation = config.after_request_validation do |validated_request, oad|
|
103
103
|
raise validated_request.error.exception if raise_request_error?(validated_request)
|
104
104
|
|
105
|
-
configuration.ignore_unknown_requests && validated_request.known?
|
106
|
-
|
107
105
|
Coverage.track_request(validated_request, oad)
|
108
106
|
end
|
109
107
|
|
@@ -120,7 +118,7 @@ module OpenapiFirst
|
|
120
118
|
|
121
119
|
def self.raise_request_error?(validated_request)
|
122
120
|
return false if validated_request.valid?
|
123
|
-
return
|
121
|
+
return false if validated_request.known?
|
124
122
|
|
125
123
|
!configuration.ignore_unknown_requests
|
126
124
|
end
|