openapi_first 2.8.0 → 2.9.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 +17 -0
- data/README.md +8 -0
- data/lib/openapi_first/failure.rb +1 -1
- data/lib/openapi_first/router.rb +4 -1
- data/lib/openapi_first/test/configuration.rb +3 -1
- data/lib/openapi_first/test.rb +9 -0
- 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: 6b40040b17718d7e8f1c98bfbdc1182e0d1bb454ff3e2c6c54424c8acdf40ca0
|
4
|
+
data.tar.gz: f41d5ab780eb888cdec6edbc9bd7d017368af07148ca65a1c09139c88ce9cad9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 178a990a3ad830e51f1ef9e2fdc15154722ec21ce7d03d9f9592be04226acc45c357a10a956dec8aeb341daaef95bf24c955004800d22ed53b4460111656aeb3
|
7
|
+
data.tar.gz: c6784c5566dd25bc9e633793aa63574d5e663c135169542d5d3c7137f6cdec6f50892059a5f20cad5fba17ba353339f4b23cd654820accaaa5450417ade30bb9
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,23 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 2.9.1
|
6
|
+
|
7
|
+
- Fix OpenapiFirst::Test's request validation to not always raise an error, but only for unknown requests
|
8
|
+
|
9
|
+
## 2.9.0
|
10
|
+
|
11
|
+
- OpenapiFirst::Test now raises an error for unknown requests. You can deactivate with:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
OpenapiFirst::Test.setup do |test|
|
15
|
+
# ...
|
16
|
+
test.ignore_unknown_request = true
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
- NotFoundError#message now includes the requested path
|
21
|
+
|
5
22
|
## 2.8.0
|
6
23
|
|
7
24
|
### OpenapiFirst::Test is now stricter and more configurable
|
data/README.md
CHANGED
@@ -77,6 +77,14 @@ Here is how to set it up:
|
|
77
77
|
|
78
78
|
(✷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.
|
79
79
|
|
80
|
+
OpenapiFirst' request validation raises an error when a request is not defined. You can deactivate this during testing:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
OpenapiFirst::Test.setup do |test|
|
84
|
+
test.ignore_unknown_requests = true
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
80
88
|
## Rack Middlewares
|
81
89
|
|
82
90
|
### Request validation
|
@@ -5,7 +5,7 @@ module OpenapiFirst
|
|
5
5
|
# This returned in ValidatedRequest#error and ValidatedResponse#error.
|
6
6
|
class Failure
|
7
7
|
TYPES = {
|
8
|
-
not_found: [NotFoundError, '
|
8
|
+
not_found: [NotFoundError, 'Not found.'],
|
9
9
|
method_not_allowed: [RequestInvalidError, 'Request method is not defined.'],
|
10
10
|
unsupported_media_type: [RequestInvalidError, 'Request content type is not defined.'],
|
11
11
|
invalid_body: [RequestInvalidError, 'Request body invalid:'],
|
data/lib/openapi_first/router.rb
CHANGED
@@ -54,7 +54,10 @@ module OpenapiFirst
|
|
54
54
|
# Return all request objects that match the given path and request method
|
55
55
|
def match(request_method, path, content_type: nil)
|
56
56
|
path_item, params = find_path_item(path)
|
57
|
-
|
57
|
+
unless path_item
|
58
|
+
message = "Request path #{path} is not defined in API description."
|
59
|
+
return NOT_FOUND.with(error: Failure.new(:not_found, message:))
|
60
|
+
end
|
58
61
|
|
59
62
|
contents = path_item.dig(request_method, :requests)
|
60
63
|
return NOT_FOUND.with(error: Failure.new(:method_not_allowed)) unless contents
|
@@ -12,6 +12,7 @@ module OpenapiFirst
|
|
12
12
|
@response_raise_error = true
|
13
13
|
@ignored_unknown_status = [404]
|
14
14
|
@report_coverage = true
|
15
|
+
@ignore_unknown_requests = false
|
15
16
|
@registry = {}
|
16
17
|
@apps = {}
|
17
18
|
end
|
@@ -28,7 +29,8 @@ module OpenapiFirst
|
|
28
29
|
@apps[api] = app
|
29
30
|
end
|
30
31
|
|
31
|
-
attr_accessor :coverage_formatter_options, :coverage_formatter, :response_raise_error, :minimum_coverage
|
32
|
+
attr_accessor :coverage_formatter_options, :coverage_formatter, :response_raise_error, :minimum_coverage,
|
33
|
+
:ignore_unknown_requests
|
32
34
|
attr_reader :registry, :apps, :report_coverage, :ignored_unknown_status
|
33
35
|
|
34
36
|
# Configure report coverage
|
data/lib/openapi_first/test.rb
CHANGED
@@ -100,6 +100,8 @@ module OpenapiFirst
|
|
100
100
|
|
101
101
|
OpenapiFirst.configure do |config|
|
102
102
|
@after_request_validation = config.after_request_validation do |validated_request, oad|
|
103
|
+
raise validated_request.error.exception if raise_request_error?(validated_request)
|
104
|
+
|
103
105
|
Coverage.track_request(validated_request, oad)
|
104
106
|
end
|
105
107
|
|
@@ -114,6 +116,13 @@ module OpenapiFirst
|
|
114
116
|
@installed = true
|
115
117
|
end
|
116
118
|
|
119
|
+
def self.raise_request_error?(validated_request)
|
120
|
+
return false if validated_request.valid?
|
121
|
+
return false if validated_request.known?
|
122
|
+
|
123
|
+
!configuration.ignore_unknown_requests
|
124
|
+
end
|
125
|
+
|
117
126
|
def self.raise_response_error?(validated_response)
|
118
127
|
configuration.response_raise_error && !configuration.ignored_unknown_status.include?(validated_response.status)
|
119
128
|
end
|