You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,17 @@
2
2
3
3
## Unreleased
4
4
5
+
## 2.8.0
6
+
7
+
### OpenapiFirst::Test is now stricter and more configurable
8
+
9
+
Changes:
10
+
- Changed OpenapiFirst::Test to raises an "invalid response" error if it sees an invalid response (https://github.com/ahx/openapi_first/issues/366).
11
+
You can change this back to the old behavior by setting `OpenapiFirst::Test::Configuration#response_raise_error = false` (but you shouldn't).
12
+
- Added `Test.setup { it.observe(MyApp) }`, `Test.observe(App, api: :my_api)` and internal `Test::Callable[]` to inject request/response validation in rack app as an alternative to overwrite the `app` method in a test
13
+
- Added `Test::Configuration#ignored_unknown_status` to configure response status(es) that do not have to be descriped in the API description. 404 statuses are ignored by default.
14
+
- Changed `OpenapiFirst::Test` to make tests fail if API description is not covered by tests. You can adapt this behavior via `OpenapiFirst::Test.setup` / `skip_response_coverage` or deactivate coverage with `OpenapiFirst::Test::Configuration#report_coverage = false` or `report_coverage = :warn`
15
+
5
16
## 2.7.4
6
17
7
18
- Return 400 if Rack cannot parse query string instead of raising an exception. Fixes https://github.com/ahx/openapi_first/issues/372
Copy file name to clipboardExpand all lines: README.md
+38-21Lines changed: 38 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,24 @@
1
1
# openapi_first
2
2
3
-
openapi_first is a Ruby gem for request / response validation and contract-testing against an [OpenAPI](https://www.openapis.org/) 3.0 or 3.1 API description. It makes an APIFirst workflow easy and reliable.
3
+
openapi_first is a Ruby gem for request / response validation and contract-testing against an [OpenAPI](https://www.openapis.org/) 3.0 or 3.1 Openapi API description (OAD). It makes an APIFirst workflow easy and reliable.
4
4
5
-
You can use openapi_first on production for [request validation](#request-validation) and in your [tests](#contract-testing) to avoid API drift with it's request/response validation and coverage features.
5
+
## Usage
6
+
7
+
Use an OAD to validate incoming requests in production:
8
+
```ruby
9
+
use OpenapiFirst::Middlewares::RequestValidation, 'openapi/openapi.yaml'
10
+
```
11
+
12
+
Turn your request tests into contract tests against an OAD:
13
+
```ruby
14
+
# spec_helper.rb
15
+
require'openapi_first'
16
+
OpenapiFirst::Test.setup do |config|
17
+
config.register('openapi/openapi.yaml')
18
+
end
19
+
require'application'# Load Application code
20
+
OpenapiFirst::Test.observe(Application)
21
+
```
6
22
7
23
## Contents
8
24
@@ -35,27 +51,28 @@ Here is how to set it up:
35
51
This should go at the top of your test helper file before loading your application code.
36
52
```ruby
37
53
require 'openapi_first'
38
-
OpenapiFirst::Test.setup do |test|
39
-
test.register('openapi/openapi.yaml')
40
-
# Optional: Make tests fail if coverage is below minimum
41
-
test.minimum_coverage = 100
42
-
# Optional: Skip certain responses, which are described in your API description, but need no test coverage
2. Add an `app` method to your tests by including a Module. This `app` method wraps your application with silent request / response validation. This validates all requests/responses in your test run. (✷1)
3. Run your tests. TheCoverage feature will tell you about missing or invalid requests/responses.
60
77
61
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.
0 commit comments