openapi_first 2.8.0 → 2.9.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/CHANGELOG.md +13 -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 +11 -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: c4ae98a82d67480a49874eaec264d200b53685f1fd7d28e09e4e3faf2fc86075
|
4
|
+
data.tar.gz: e8d1166f2876dc7f5e909fe9290a03f0f8c530bc6469822a3c88583fa0a29047
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd927a3a8a9167e69b1fd2f795b333b232581cc1fb2ee805105f89d82125d58eddd951660fb06d300ac41555ef7ce6cfc2b680feda2d809c8fe64eebc8537b1b
|
7
|
+
data.tar.gz: 456f6f1ccffc43d20b3ab51cdd4d392ac4dacf00e403bb92f8829f88e97c63fd48ac1ba316d5dc89662e1d32509f2ee6a92c60b7f327b261d428125bf8e2ec99
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,19 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 2.9.0
|
6
|
+
|
7
|
+
- OpenapiFirst::Test now raises an error for unknown requests. You can deactivate with:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
OpenapiFirst::Test.setup do |test|
|
11
|
+
# ...
|
12
|
+
test.ignore_unknown_request = true
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
- NotFoundError#message now includes the requested path
|
17
|
+
|
5
18
|
## 2.8.0
|
6
19
|
|
7
20
|
### 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,10 @@ 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
|
+
|
105
|
+
configuration.ignore_unknown_requests && validated_request.known?
|
106
|
+
|
103
107
|
Coverage.track_request(validated_request, oad)
|
104
108
|
end
|
105
109
|
|
@@ -114,6 +118,13 @@ module OpenapiFirst
|
|
114
118
|
@installed = true
|
115
119
|
end
|
116
120
|
|
121
|
+
def self.raise_request_error?(validated_request)
|
122
|
+
return false if validated_request.valid?
|
123
|
+
return true if validated_request.known?
|
124
|
+
|
125
|
+
!configuration.ignore_unknown_requests
|
126
|
+
end
|
127
|
+
|
117
128
|
def self.raise_response_error?(validated_response)
|
118
129
|
configuration.response_raise_error && !configuration.ignored_unknown_status.include?(validated_response.status)
|
119
130
|
end
|