openapi_first 2.11.0 → 2.11.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 +4 -0
- data/README.md +23 -6
- data/lib/openapi_first/configuration.rb +1 -1
- data/lib/openapi_first/router/find_response.rb +1 -1
- data/lib/openapi_first/router.rb +7 -2
- 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: 0c84ae6fc48433fbbe1845ff66ed2315b58a47ff3ba17ea6756bb6c276db5ed3
|
4
|
+
data.tar.gz: 3b584da97ce9b7ea712dc66ac55e39a16c1631254dd719551d27a4df9bc13e4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 863d5ea4124958e81d62e7a72efef17e6fe5326fe4db6d34bc6fe97e8ec863c09dd8d138eaf9b249ce94ce490dad937297cd9d15b98dc73a6c01f30c6f6da2f7
|
7
|
+
data.tar.gz: 7c5c264ce6f969788986bbaf71cb6060b998ae5819cf5551ddf4f82ab2069c87afda22e97fa9c8aa03ea91bb6133cbf579d63b35a12c0eb30a7e17a774508ec7
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## 2.11.1
|
6
|
+
|
7
|
+
- OpenapiFirst can now route requests correctly for paths like `/stuffs` and `/stuffs{format}` (https://github.com/ahx/openapi_first/issues/386)
|
8
|
+
|
5
9
|
## 2.11.0
|
6
10
|
|
7
11
|
- OpenapiFirst::Test.observe now works with `Rack::URLMap` (returned by `Rack::Builder.app`) and probably all objects that respond to `.call`
|
data/README.md
CHANGED
@@ -168,7 +168,7 @@ Here is how to set it up:
|
|
168
168
|
end
|
169
169
|
```
|
170
170
|
2. Observe your application. You can do this in multiple ways:
|
171
|
-
- Add an `app` method to your tests
|
171
|
+
- Add an `app` method to your tests (which is called by rack-test) that wraps your application with silent request / response validation.
|
172
172
|
```ruby
|
173
173
|
module RequestSpecHelpers
|
174
174
|
def app
|
@@ -188,18 +188,26 @@ Here is how to set it up:
|
|
188
188
|
config.include OpenapiFirst::Test::Methods[MyApp], type: :request
|
189
189
|
end
|
190
190
|
```
|
191
|
-
4. Run your tests. The Coverage feature will tell you about missing or invalid requests/responses
|
191
|
+
4. Run your tests. The Coverage feature will tell you about missing or invalid requests/responses:
|
192
|
+
```
|
193
|
+
✓ GET /stations
|
194
|
+
✓ 200(application/json)
|
195
|
+
❌ 200(application/xml) – No responses tracked!
|
196
|
+
❌ 400(application/problem+json) – No responses tracked!
|
197
|
+
```
|
192
198
|
|
193
|
-
|
199
|
+
Now add tests for all those "❌" to make them "✓" and you're green!
|
200
|
+
|
201
|
+
> [!NOTE]
|
202
|
+
> Check out [faraday-openapi](https://codeberg.org/ahx/faraday-openapi) to have your API _client_ validate request/responses against an OAD, which is useful to validate HTTP mocks during testing.
|
194
203
|
|
195
204
|
### Configure test coverage
|
196
205
|
|
197
|
-
OpenapiFirst::Test raises an error when a
|
206
|
+
OpenapiFirst::Test raises an error when a response status is not defined. You can deactivate this with:
|
198
207
|
|
199
208
|
```ruby
|
200
209
|
OpenapiFirst::Test.setup do |test|
|
201
|
-
|
202
|
-
test.ignore_unknown_requests = true
|
210
|
+
[403, 401].each { test.ignored_unknown_status << it }
|
203
211
|
end
|
204
212
|
```
|
205
213
|
|
@@ -225,6 +233,15 @@ OpenapiFirst::Test.setup do |test|
|
|
225
233
|
end
|
226
234
|
```
|
227
235
|
|
236
|
+
OpenapiFirst::Test raises an error when a request is not defined. You can deactivate this with:
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
OpenapiFirst::Test.setup do |test|
|
240
|
+
# …
|
241
|
+
test.ignore_unknown_requests = true
|
242
|
+
end
|
243
|
+
```
|
244
|
+
|
228
245
|
### Test assertions
|
229
246
|
|
230
247
|
openapi_first ships with a simple but powerful Test method to run request and response validation in your tests without using the middlewares. This is designed to be used with rack-test or Ruby on Rails integration tests or request specs.
|
@@ -14,7 +14,7 @@ module OpenapiFirst
|
|
14
14
|
@request_validation_error_response = OpenapiFirst.find_error_response(:default)
|
15
15
|
@request_validation_raise_error = false
|
16
16
|
@response_validation_raise_error = true
|
17
|
-
@hooks =
|
17
|
+
@hooks = HOOKS.to_h { [_1, Set.new] }
|
18
18
|
@path = nil
|
19
19
|
end
|
20
20
|
|
@@ -11,7 +11,7 @@ module OpenapiFirst
|
|
11
11
|
def self.call(responses, status, content_type, request_method:, path:)
|
12
12
|
contents = find_status(responses, status)
|
13
13
|
if contents.nil?
|
14
|
-
message = "Status #{status} is not defined for #{request_method} #{path}. " \
|
14
|
+
message = "Status #{status} is not defined for #{request_method.upcase} #{path}. " \
|
15
15
|
"Defined statuses are: #{responses.keys.join(', ')}."
|
16
16
|
return Match.new(error: Failure.new(:response_not_found, message:), response: nil)
|
17
17
|
end
|
data/lib/openapi_first/router.rb
CHANGED
@@ -97,10 +97,15 @@ module OpenapiFirst
|
|
97
97
|
found = @static[request_path]
|
98
98
|
return [found, {}] if found
|
99
99
|
|
100
|
-
@dynamic.
|
100
|
+
matches = @dynamic.filter_map do |_path, path_item|
|
101
101
|
params = path_item[:template].match(request_path)
|
102
|
-
|
102
|
+
next unless params
|
103
|
+
|
104
|
+
[path_item, params]
|
103
105
|
end
|
106
|
+
return matches.first if matches.length == 1
|
107
|
+
|
108
|
+
matches&.min_by { |match| match[1].values.sum(&:length) }
|
104
109
|
end
|
105
110
|
end
|
106
111
|
end
|