openapi_first 0.7.0.alpha1 → 3.1.0.beta1

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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +585 -2
  3. data/LICENSE.txt +21 -0
  4. data/README.md +360 -114
  5. data/lib/openapi_first/builder.rb +214 -0
  6. data/lib/openapi_first/child_configuration.rb +26 -0
  7. data/lib/openapi_first/configuration.rb +76 -0
  8. data/lib/openapi_first/definition.rb +98 -13
  9. data/lib/openapi_first/error_response.rb +40 -0
  10. data/lib/openapi_first/error_responses/default.rb +74 -0
  11. data/lib/openapi_first/error_responses/jsonapi.rb +60 -0
  12. data/lib/openapi_first/errors.rb +40 -0
  13. data/lib/openapi_first/failure.rb +77 -0
  14. data/lib/openapi_first/file_loader.rb +22 -0
  15. data/lib/openapi_first/header.rb +9 -0
  16. data/lib/openapi_first/json.rb +25 -0
  17. data/lib/openapi_first/middlewares/request_validation.rb +58 -0
  18. data/lib/openapi_first/middlewares/response_validation.rb +41 -0
  19. data/lib/openapi_first/parsed_request.rb +5 -0
  20. data/lib/openapi_first/ref_resolver.rb +193 -0
  21. data/lib/openapi_first/registry.rb +44 -0
  22. data/lib/openapi_first/request.rb +79 -0
  23. data/lib/openapi_first/request_body_parsers.rb +64 -0
  24. data/lib/openapi_first/request_validator.rb +32 -0
  25. data/lib/openapi_first/response.rb +43 -0
  26. data/lib/openapi_first/response_body_parsers.rb +31 -0
  27. data/lib/openapi_first/response_parser.rb +50 -0
  28. data/lib/openapi_first/response_validator.rb +16 -48
  29. data/lib/openapi_first/router/find_content.rb +17 -0
  30. data/lib/openapi_first/router/find_response.rb +53 -0
  31. data/lib/openapi_first/router/path_template.rb +48 -0
  32. data/lib/openapi_first/router.rb +84 -57
  33. data/lib/openapi_first/schema/hash.rb +39 -0
  34. data/lib/openapi_first/schema/validation_error.rb +45 -0
  35. data/lib/openapi_first/schema/validation_result.rb +30 -0
  36. data/lib/openapi_first/test/app.rb +30 -0
  37. data/lib/openapi_first/test/callable.rb +25 -0
  38. data/lib/openapi_first/test/configuration.rb +76 -0
  39. data/lib/openapi_first/test/coverage/covered_request.rb +11 -0
  40. data/lib/openapi_first/test/coverage/covered_response.rb +11 -0
  41. data/lib/openapi_first/test/coverage/plan.rb +77 -0
  42. data/lib/openapi_first/test/coverage/request_task.rb +42 -0
  43. data/lib/openapi_first/test/coverage/response_task.rb +42 -0
  44. data/lib/openapi_first/test/coverage/route_task.rb +13 -0
  45. data/lib/openapi_first/test/coverage/terminal_formatter.rb +115 -0
  46. data/lib/openapi_first/test/coverage/tracker.rb +32 -0
  47. data/lib/openapi_first/test/coverage.rb +102 -0
  48. data/lib/openapi_first/test/methods.rb +62 -0
  49. data/lib/openapi_first/test/minitest_helpers.rb +28 -0
  50. data/lib/openapi_first/test/observe.rb +37 -0
  51. data/lib/openapi_first/test/observer_middleware.rb +23 -0
  52. data/lib/openapi_first/test/plain_helpers.rb +31 -0
  53. data/lib/openapi_first/test.rb +171 -0
  54. data/lib/openapi_first/validated_request.rb +79 -0
  55. data/lib/openapi_first/validated_response.rb +53 -0
  56. data/lib/openapi_first/validators/request_body.rb +25 -0
  57. data/lib/openapi_first/validators/request_parameters.rb +49 -0
  58. data/lib/openapi_first/validators/response_body.rb +27 -0
  59. data/lib/openapi_first/validators/response_headers.rb +40 -0
  60. data/lib/openapi_first/version.rb +1 -1
  61. data/lib/openapi_first.rb +67 -35
  62. metadata +99 -133
  63. data/.github/CODEOWNERS +0 -1
  64. data/.gitignore +0 -11
  65. data/.rspec +0 -3
  66. data/.rubocop.yml +0 -14
  67. data/.travis.yml +0 -8
  68. data/Gemfile +0 -11
  69. data/Gemfile.lock +0 -126
  70. data/Rakefile +0 -15
  71. data/benchmarks/Gemfile +0 -13
  72. data/benchmarks/Gemfile.lock +0 -144
  73. data/benchmarks/apps/committee.ru +0 -30
  74. data/benchmarks/apps/grape.ru +0 -21
  75. data/benchmarks/apps/hanami_router.ru +0 -14
  76. data/benchmarks/apps/openapi.yaml +0 -86
  77. data/benchmarks/apps/openapi_first.ru +0 -22
  78. data/benchmarks/apps/openapi_first_resolve_only.ru +0 -23
  79. data/benchmarks/apps/sinatra.ru +0 -26
  80. data/benchmarks/apps/syro.ru +0 -25
  81. data/benchmarks/benchmarks.rb +0 -46
  82. data/bin/console +0 -15
  83. data/bin/setup +0 -8
  84. data/examples/README.md +0 -13
  85. data/examples/app.rb +0 -12
  86. data/examples/config.ru +0 -7
  87. data/examples/openapi.yaml +0 -29
  88. data/lib/openapi_first/app.rb +0 -27
  89. data/lib/openapi_first/coverage.rb +0 -28
  90. data/lib/openapi_first/operation.rb +0 -48
  91. data/lib/openapi_first/operation_resolver.rb +0 -43
  92. data/lib/openapi_first/request_validation.rb +0 -144
  93. data/lib/openapi_first/utils.rb +0 -31
  94. data/lib/openapi_first/validation.rb +0 -15
  95. data/lib/openapi_first/validation_format.rb +0 -31
  96. data/openapi_first.gemspec +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4885473ec6373b0fcfd9baace6175296f362099ba8ee73de0b8c1538b3420504
4
- data.tar.gz: 5a72ae579e67bcb17c33debb3adbcae1cdaae09ad98ccc0e1158a59719d00115
3
+ metadata.gz: 5d07efa6286183d4d90a9126e3b5082e27fad9efa966f9aa7623ca280b51c6f8
4
+ data.tar.gz: 8c6e34a8dffd1b1dd7f8e71cfbb85ded8dd260d2f96631c8e7b91944ddb4033b
5
5
  SHA512:
6
- metadata.gz: d2783c23798622b8bcc6c6f9520272d0477760d405f9879d4dc39e94b1d361b3873a87147ccef81e0ba3ec5c59e67941f645e41caf52dd221ddb915167140c6d
7
- data.tar.gz: d540387f504454feca50ea746ef87745aed68e841bc5eb734c8d2e3419676e221a8dd93404601f010e3725152cd0e0e9a2775a1646690b8f4e5b62fbd8d7ca93
6
+ metadata.gz: f60e8101c9a716ae9dbaf27dc9a815d6c44988f65e7d3cef73d93630f668ca664d13f1a0d356d777a6ba75dd0888a3baf44ad5a28716f4d93a02556c331bf46f
7
+ data.tar.gz: d9161ef397b3f8974f2540d37b12bf07d1b6ff2acb55413504a8fd541c3e91bde36a34712609ef0ef48f93cda59fb6898f4856a0a8c67ce8923351d06ef61709
data/CHANGELOG.md CHANGED
@@ -2,23 +2,606 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.1.0.beta1
6
+
7
+ ### openapi_first/test
8
+
9
+ #### Changed
10
+ - Test now raises `OpenapiFirst::Test::UnknownQueryParameterError` when it sees unknown query parameters. Note that `OpenapiFirst` ("core") still allows unknown query parameters.
11
+ - Test does not track requests/responses unless the OAD was registered via Test.register (or OpenapiFirst.register)
12
+
13
+ ## 3.0.1
14
+ - Add missing gem dependency "drb", which is no longer installed by default with newer rubies. This is used in openapi_first/test to make parallel tests work.
15
+
16
+ ## 3.0.0
17
+
18
+ ### openapi_first
19
+
20
+ #### Changed
21
+ - Breaking: Trailing slashes are no longer ignored in dynamic paths. See [#403](https://github.com/ahx/openapi_first/issues/403).
22
+ Before this change `GET /things/24/` matched `/things/{id}:`, but it no longer does.
23
+ - Breaking: Failure type `:response_not_found` was split into two more specific types `:response_content_type_not_found` and `:response_status_not_found`. This should be mostly internal stuff. So if your custom error response used `response_not_found`, you will have to adapt.
24
+ - Deprecated configuration fields `request_validation_raise_error` and `response_validation_raise_error`. Please pass the `raise_error:` option to the middlewares directly.
25
+
26
+ #### Added
27
+ - Added support to register OADs globally via:
28
+ ```ruby
29
+ OpenapiFirst.configure { |config| config.register('openapi.yaml') }
30
+ ```
31
+ This makes the `spec` argument in middlewares optional and removes the necessity to load the OAD in the same place where you use the middlewares and adds a cache for parsed OADs.
32
+
33
+ #### Removed
34
+ - Removed deprecated methods which produced a warning since 2.0.0.
35
+ - Removed `OpenapiFirst::Configuration#clone`. Use `#child` instead.
36
+ - It's no longer supported to remove locally added hooks during runtime.
37
+
38
+ #### Fixed
39
+ - Update dependency `openapi_parameters` to >= 0.7.0, because that version supports unpacking parameters the use `style: deepObject` with `explode: true`.
40
+ - Make `OpenapiFirst::Test.setup` more robust by adding `OpenapiFirst::Configuration#child` so it does not matter if you load our OAD before callig `OpenapiFirst::Test.setup`.
41
+
42
+ ### openapi_first/test
43
+
44
+ #### Changed
45
+ - `OpenapiFirst::Test.app` now returns an instance of `OpenapiFirst::Test::App`, instead of `Rack::Builer` and delegates methods other than `#call` to the original app. This wrapper adds validated requests, responses to the rack env at `env[OpenapiFirst::Test::REQUEST]`, `env[OpenapiFirst::Test::RESPONSE]`. This makes it possible to test Rails engines. Thanks to Josh! See [#410](https://github.com/ahx/openapi_first/issues/410).
46
+ - `OpenapiFirst::Test` now falls back to using globally registered OADs if nothing was registered inside `OpenapiFirst::Test.setup`.
47
+ - 401er and 500er status are okay to not be described.
48
+
49
+ #### Added
50
+ - The Coverage feature in `OpenapiFirst::Test` now supports parallel tests via a DRB client/sever. Thanks to Richard! See [#394](https://github.com/ahx/openapi_first/issues/394).
51
+ - Added `OpenapiFirst::Test` Configuration options which are useful when adopting OpenAPI:
52
+ - `ignore_unknown_response_status = true` to make API coverage no longer complain about undefined response statuses it sees during a test run.
53
+ - `minimum_coverage=` is no longer deprecated. This is useful when gradually adopting OpenAPI
54
+ - `ignored_unknown_status=` to overwrite the whole list of ignored unknown status at once
55
+
56
+ #### Removed
57
+ - Removed internally used `Test::Coverage.current_run, .plans, .install, .uninstall`. If you are using these, use `OpenapiFirst::Test.setup` instead.
58
+
59
+ #### Fixed
60
+ - Make `OpenapiFirst::Test.setup` more robust by adding `OpenapiFirst::Configuration#child` so it does not matter if you load our OAD before callig `OpenapiFirst::Test.setup`.
61
+
62
+ ## 2.11.1
63
+
64
+ - OpenapiFirst can now route requests correctly for paths like `/stuffs` and `/stuffs{format}` (https://github.com/ahx/openapi_first/issues/386)
65
+
66
+ ## 2.11.0
67
+
68
+ - OpenapiFirst::Test.observe now works with `Rack::URLMap` (returned by `Rack::Builder.app`) and probably all objects that respond to `.call`
69
+
70
+ ## 2.10.1
71
+
72
+ - Don't try to track coverage for skipped requests
73
+ - Add Test::Configuration#skip_coverage to skip test coverage for specific paths + request methods and all responses
74
+ - Deprecate setting minimum_coverage value. Use skip_response_coverage, ignored_unknown_status to configure coverage instead.
75
+ - Update openapi_parameters to make parsing array query parameters more consistent.
76
+ Now parsing empty array query parameter like `ids=&` or `ids&` both result in an empty array value (`[]`) instead of `nil` or `""`.
77
+ - Fix Test::Coverage.result returning < 100 even if plan is fully covered
78
+
79
+ ## 2.10.0 (yanked)
80
+
81
+ ## 2.9.3
82
+
83
+ - Fix OpenapiFirst.load when MultiJson is configured to return symbol keys
84
+
85
+ ## 2.9.2
86
+
87
+ - OpenapiFirst::Test reports all non-covered requests now
88
+ - Response validation: Improve content type mismatch exception message
89
+
90
+ ## 2.9.1
91
+
92
+ - Fix OpenapiFirst::Test's request validation to not always raise an error, but only for unknown requests
93
+
94
+ ## 2.9.0
95
+
96
+ - OpenapiFirst::Test now raises an error for unknown requests. You can deactivate with:
97
+
98
+ ```ruby
99
+ OpenapiFirst::Test.setup do |test|
100
+ # ...
101
+ test.ignore_unknown_request = true
102
+ end
103
+ ```
104
+
105
+ - NotFoundError#message now includes the requested path
106
+
107
+ ## 2.8.0
108
+
109
+ ### OpenapiFirst::Test is now stricter and more configurable
110
+
111
+ Changes:
112
+ - Changed OpenapiFirst::Test to raises an "invalid response" error if it sees an invalid response (https://github.com/ahx/openapi_first/issues/366).
113
+ You can change this back to the old behavior by setting `OpenapiFirst::Test::Configuration#response_raise_error = false` (but you shouldn't).
114
+ - 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
115
+ - 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.
116
+ - 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`
117
+
118
+ ## 2.7.4
119
+
120
+ - Return 400 if Rack cannot parse query string instead of raising an exception. Fixes https://github.com/ahx/openapi_first/issues/372
121
+
122
+ ## 2.7.3
123
+
124
+ - Accept loading OAD documents with numeric status codes. Fixes "Unknown reference" error. https://github.com/ahx/openapi_first/issues/367
125
+
126
+ - Support QUERY request method
127
+ OpenAPI 3.0, 3.1 does not support that, but this does
128
+
129
+ ## 2.7.2
130
+
131
+ - Fix $ref-resolving for referenced arrays.
132
+ This fixes loading something like this:
133
+ ```yaml
134
+ parameters:
135
+ $ref: 'my-paramters.yaml'
136
+ ```
137
+
138
+ ## 2.7.1
139
+
140
+ - Speedup loading very large OADs by deferring creation of JSONSchemer::Schema instances.
141
+
142
+ ## 2.7.0
143
+
144
+ - Allow to override path for schema matching with `config.path = ->(request) { '/prefix' + request.path } ` (https://github.com/ahx/openapi_first/issues/349)
145
+ - Support passing in a Definition instance when registering an OAD for tests (https://github.com/ahx/openapi_first/issues/353)
146
+ - Fix registering multiple APIs for testing (https://github.com/ahx/openapi_first/issues/352)
147
+
148
+ ## 2.6.0
149
+
150
+ - Middlewares now accept the OAD as a first positional argument instead of `:spec` inside the options hash.
151
+ - No longer merge parameter schemas of the same location (for example "query") in order to fix [#320](https://github.com/ahx/openapi_first/issues/320).
152
+ - `OpenapiFirst::Test::Methods[MyApplication]` returns a Module which adds an `app` method to be used by rack-test alonside the `assert_api_conform` method.
153
+ - Make default coverage report less verbose
154
+ The default formatter (TerminalFormatter) no longer prints all un-requested requests by default. You can set `test.coverage_formatter_options = { focused: false }` to get back the old behavior
155
+
156
+ ## 2.5.1
157
+
158
+ - Fix skipping skipped responses during coverage tracking
159
+
160
+ ## 2.5.0
161
+
162
+ ### New feature
163
+ - Add option to skip certain responses in coverage calculation
164
+ ```ruby
165
+ require 'openapi_first'
166
+ OpenapiFirst::Test.setup do |s|
167
+ test.register('openapi/openapi.yaml')
168
+ test.skip_response_coverage { it.status == '401' }
169
+ end
170
+ ```
171
+
172
+ ### Minor changes
173
+ - OpenapiFirst::Test.report_coverage now includes fractional digits when returning a coverage value to avoid reporting "0% / no requests made" even though some requests have been made.
174
+ - Show details about invalid requests / responses in coverage report
175
+
176
+ ## 2.4.0
177
+
178
+ - Support less verbose test setup without the need to call `OpenapiFirst::Test.report_coverage`, which will be called `at_exit`:
179
+ ```ruby
180
+ OpenapiFirst::Test.setup do |test|
181
+ test.register('openapi/openapi.yaml')
182
+ test.minimum_coverage = 100 # Setting this will lead to an `exit 2` if coverage is below minimum
183
+ end
184
+ ```
185
+ - Add `OpenapiFirst::Test::Setup#minimum_coverage=` to control exit behaviour (exit 2 if coverage is below minimum)
186
+ - Add `verbose` option to `OpenapiFirst::Test.report_coverage(verbose: true)`
187
+ to see all passing requests/responses
188
+
189
+ ## 2.3.0
190
+
191
+ ### New feature
192
+ - Add OpenapiFirst::Test::Coverage to track request/response coverage for your API descriptions. (https://github.com/ahx/openapi_first/pull/327)
193
+
194
+ ## 2.2.4
195
+
196
+ - Fix request validation file uploads in multipart/form-data requests with nested fields (https://github.com/ahx/openapi_first/issues/324)
197
+ - Add more error details to validation result (https://github.com/ahx/openapi_first/pull/322)
198
+
199
+ ## 2.2.3
200
+
201
+ - Respect global JSONSchemer configuration (https://github.com/ahx/openapi_first/pull/318)
202
+
203
+ ## 2.2.2
204
+
205
+ - Fix parsing parameters with referenced schemas (https://github.com/ahx/openapi_first/issues/316)
206
+
207
+ ## 2.2.1
208
+
209
+ - Fix issue with $ref resolving paths poiting outside directories `$ref: '../a/b.yaml'` (https://github.com/ahx/openapi_first/issues/313)
210
+ - Remove warning about missing assertions when using assert_api_conform ([https://github.com/ahx/openapi_first/issues/313](https://github.com/ahx/openapi_first/issues/312))
211
+
212
+ ## 2.2.0
213
+
214
+ - Fix support for discriminator in response bodies if no mapping is defined (https://github.com/ahx/openapi_first/issues/285)
215
+ - Fix support for discriminator in request bodies if no mapping is defined
216
+ - Replace bundled json_refs fork with own code
217
+ - Better error messages when OpenAPI file has invalid references ("$ref")
218
+ - Autoload OpenapiFirst::Test module. There is no need to `require 'openapi_first/test'` anymore.
219
+ - Remove multi_json dependency. openapi_first uses multi_json if available or the default json gem otherwise.
220
+ If you want to use multi_json, make sure to add it to your Gemfile.
221
+
222
+ ## 2.1.1
223
+
224
+ - Fix issue with non file downloads / JSON responses https://github.com/ahx/openapi_first/issues/281
225
+
226
+ ## 2.1.0
227
+
228
+ - Added `OpenapiFirst::Definition#[]` to access the raw Hash representation of the OAS document. Example: `api['components'].fetch('schemas', 'Stations')`
229
+
230
+ ## 2.0.4
231
+
232
+ - Fix issue with parsing reponse body when using Rails https://github.com/ahx/openapi_first/issues/281
233
+
234
+ ## 2.0.3
235
+
236
+ - Fix `OpenapiFirst::Test.register` https://github.com/ahx/openapi_first/issues/276
237
+
238
+ - Request validation middleware now accepts `error_response: false` do disable rendering a response. This is useful if you just want to collect metrics (via hooks) during a migration phase.
239
+
240
+ ## 2.0.2
241
+
242
+ - Fix setting custom error response (thanks @gobijan)
243
+
244
+ ## 2.0.1 (Janked)
245
+
246
+ ## 2.0.0
247
+
248
+ ### New Features
249
+ - Test Assertions! 📋 You can now use `assert_api_conform` for contract testing in your rack-test / Rails integration tests. See Readme for details.
250
+
251
+ - New option for `Middlewares::ResponseValidation`: `:raise_error` (default: true). If set to `false`, the middleware will not aise an error if the response is invalid. 🤫
252
+
253
+ - Hooks 🪝🪝 (see Readme for details). You can use these to collect metrics, write error logs etc.:
254
+ - `after_request_validation`
255
+ - `after_response_validation`
256
+ - `after_request_body_property_validation`
257
+ - `after_request_parameter_property_validation`
258
+
259
+ - Exceptions such as `OpenapiFirst::ResponseInvalidError` not respond to `#request` to get information about the validated request 💁🏻
260
+
261
+ - Performance improvements 🚴🏻‍♀️
262
+
263
+ - Validation failures returned by `ValidatedRequest#error` always returns a `#message`. So you can call `my_validated_request.error.message if validated_request.invalid?` and always get a human-readable error message. 😴
264
+
265
+ ### Breaking Changes
266
+
267
+ #### Manual validation
268
+ - `Definition#request.validate` was removed. Please use `Definition#validate_request` instead.
269
+ - `Definition#validate_request` returns a `ValidatedRequest` which delgates all methods to the original (rack) request, except for `#valid?` `#parsed_body`. `#parsed_query`, `#operation` etc. See Readme for details.
270
+ - The `Operation` class was removed. `ValidatedRequest#operation` now returns the OpenAPI 3 operation object as a plain Hash. So you can still call `ValidatedRequest#operation['x-foo']`. You can call `ValidatedRequest#operation_id` if you just need the _operationId_.
271
+ -
272
+
273
+ #### Inspecting OpenAPI files
274
+
275
+ - `Definition#operations` has been removed. Please use `Definition#routes`, which returns a list of routes. Routes have a `#path`, `#request_method`, `#requests` and `#responses`.
276
+ A route has one path and one request method, but can have multiple requests (one for each supported content-type) and responses (statuses + content-type).
277
+
278
+ - Several internal changes to make the code more maintainable, more performant , support hooks and prepare for OpenAPI 4. If you have monkey-patched OpenapiFirst, you might need to adjust your code. Please contact me if you need help.
279
+
280
+ ### Deprecations
281
+
282
+ #### Custom error responses
283
+
284
+ - `ValidationError#error`, `#instance_location` and `#schema_location` have been deprecated. Use `ValidationError#message`, `#data_pointer` and `#schema_pointer` instead.
285
+ - `Failure#error_type` has been deprecated. Use `#type` instead
286
+
287
+ ## 1.4.3
288
+
289
+ - Allow using json_schemer 2...3
290
+
291
+ ## 1.4.2
292
+
293
+ - Fix Rack 2 compatibility
294
+
295
+ ## 1.4.1
296
+
297
+ - Fixed: Don't call deprecated methods in middlewares
298
+
299
+ ## 1.4.0
300
+
301
+ ### Changed
302
+
303
+ Some redundant methods to validate or inspect requests/responses will be removed in 2.0. So this release deprecates these methods.
304
+
305
+ - Deprecate `OpenapiFirst::RuntimeRequest#validate`, `#validate!`, `#validate_response`, `#response`.
306
+ Use `OpenapiFirst.load('openapi.yaml').validate_request(rack_request, raise_error: true/false)` instead
307
+ - Deprecate `OpenapiFirst::RuntimeResponse#validate`.
308
+ Use `OpenapiFirst.load('openapi.yaml').validate_response(rack_request, rack_response, raise_error: true/false)` instead.
309
+
310
+ ## 1.3.6
311
+
312
+ - Fixed Rack 2 / Rails 6 compatibility ([#246](https://github.com/ahx/openapi_first/issues/246)
313
+
314
+ ## 1.3.5
315
+
316
+ - Added support for `/some/{kebab-cased}` path parameters ([#245](https://github.com/ahx/openapi_first/issues/245))
317
+
318
+ ## 1.3.4
319
+
320
+ - Fixed handling "binary" format in optional multipart file uploads
321
+ - Cache the resolved OAD. This especially makes things run faster in tests.
322
+ - Internally used `Operation#query_parameters`, `Operation#path_parameters` etc. now only returns parameters that are defined on the operation level not on the PathItem. Use `PathItem#query_parameters` to get those.
323
+
324
+ ## 1.3.3 (yanked)
325
+
326
+ ## 1.3.2
327
+
328
+ ### Changed
329
+
330
+ - The response definition is found even if the status is defined as an Integer instead of a String. This is not provided for in the OAS specification, but is often done this way, because of YAML.
331
+
332
+ ### Fixed
333
+
334
+ - Reduced initial load time for composed API descriptions [#232](https://github.com/ahx/openapi_first/pull/232)
335
+ - Chore: Add Readme back to gem. Add link to docs.
336
+
337
+ ## 1.3.1
338
+
339
+ - Fixed warning about duplicated constant
340
+
341
+ ## 1.3.0
342
+
343
+ No breaking changes
344
+
345
+ New features:
346
+
347
+ - Added new API: `Definition#validate_request`, `Definition#validate_response`, `RuntimeRequest#validate_response` (see readme) [#222](https://github.com/ahx/openapi_first/pull/222)
348
+
349
+ Fixes:
350
+
351
+ - Manual response validation (without the middleware) just works in Rails' request tests now. [#224](https://github.com/ahx/openapi_first/pull/224)
352
+
353
+ ## 1.2.0
354
+
355
+ No breaking changes
356
+
357
+ - Added `OpenapiFirst.parse(hash)` to load ("parse") a resolved/de-referenced Hash
358
+ - Added support for unescaped special characters in the path params (https://github.com/ahx/openapi_first/pull/217)
359
+ - Added `operation` to `RuntimeRequest` by [@MrBananaLord](https://github.com/ahx/openapi_first/pull/216)
360
+
361
+ ## 1.1.1
362
+
363
+ - Fix reading response body for example when running Rails (`ActionDispatch::Response::RackBody`)
364
+ - Add `known?`, `status`, `body`, `headers`, `content_type` methods to inspect the parsed response (`RuntimeResponse`)
365
+ - Add `OpenapiFirst::ParseError` which is raised by low-level interfaces like `request.body` if the body could not be parsed.
366
+ - Add "code" field to errors in JSON:API error response
367
+
368
+ ## 1.1.0 (yanked)
369
+
370
+ ## 1.0.0
371
+
372
+ - Breaking: The default error uses application/problem+json content-type
373
+ - Breaking: Moved rack middlewares to OpenapiFirst::Middlewares
374
+ - Breaking: Rename OpenapiFirst::ResponseInvalid to OpenapiFirst::ResponseInvalidError
375
+ - Breaking: Remove OpenapiFirst::Router
376
+ - Breaking: Remove `env[OpenapiFirst::OPERATION]`. Use `env[OpenapiFirst::REQUEST]` instead.
377
+ - Breaking: Remove `env[OpenapiFirst::REQUEST_BODY]`, `env[OpenapiFirst::PARAMS]`. Use `env[OpenapiFirst::REQUEST].body env[OpenapiFirst::REQUEST].params` instead.
378
+ - Add interface to validate requests / responses without middlewares (see "Manual validation" in README)
379
+ - Add OpenapiFirst.configure
380
+ - Add OpenapiFirst.register, OpenapiFirst.plugin
381
+ - Fix response header validation with Rack 3
382
+ - Fixed: Add support for paths like `/{a}..{b}`
383
+
384
+ ## 1.0.0.beta6
385
+
386
+ - Fix: Make response header validation work with rack 3
387
+ - Refactor router
388
+ - Remove dependency hanami-router
389
+ - PathItem and Operation for a request can be found by calling methods on the Definitnion
390
+ - Fixed https://github.com/ahx/openapi_first/issues/155
391
+ - Breaking / Regression: A paths like /pets/{from}-{to} if there is a path "/pets/{id}"
392
+
393
+ ## 1.0.0.beta5
394
+
395
+ - Added: `OpenapiFirst::Config.default_options=` to set default options globally
396
+ - Added: You can define custom error responses by subclassing `OpenapiFirst::ErrorResponse` and register it via `OpenapiFirst.register_error_response(name, MyCustomErrorResponse)`
397
+
398
+ ## 1.0.0.beta4
399
+
400
+ - Update json_schemer to version 2.0
401
+ - Breaking: Requires Ruby 3.1 or later
402
+ - Added: Parameters are available at `env[OpenapiFirst::PATH_PARAMS]`, `env[OpenapiFirst::QUERY_PARAMS]`, `env[OpenapiFirst::HEADER_PARAMS]`, `env[OpenapiFirst::COOKIE_PARAMS]` in case you need to access them separately. Merged path and query parameters are still available at `env[OpenapiFirst::PARAMS]`
403
+ - Breaking / Added: ResponseValidation now validates response headers
404
+ - Breaking / Added: RequestValidation now validates cookie, path and header parameters
405
+ - Breaking: multipart File uploads are now read and then validated
406
+ - Breaking: Remove OpenapiFirst.env method
407
+ - Breaking: Request validation returns 400 instead of 415 if request body is required, but empty
408
+
409
+ ## 1.0.0.beta3
410
+
411
+ - Remove obsolete dependency: deep_merge
412
+ - Remove obsolete dependency: hanami-utils
413
+
414
+ ## 1.0.0.beta2
415
+
416
+ - Fixed dependencies. Remove unused code.
417
+
418
+ ## 1.0.0.beta1
419
+
420
+ - Removed: `OpenapiFirst::Responder` and `OpenapiFirst::RackResponder`
421
+ - Removed: `OpenapiFirst.app` and `OpenapiFirst.middleware`
422
+ - Removed: `OpenapiFirst::Coverage`
423
+ - Breaking: Parsed query and path parameters are available at `env[OpenapiFirst::PARAMS]`(or `env['openapi.params']`) instead of `OpenapiFirst::PARAMETERS`.
424
+ - Breaking: Request body and parameters now use string keys instead of symbols!
425
+ - Breaking: Query parameters are now parsed exactly like in the API description via the openapi_parameters gem. This means a couple of things:
426
+ - Query parameters now support `explode: true` (default) and `explode: false` for array and object parameters.
427
+ - Query parameters with brackets like 'filter[tag]' are no longer deconstructed into nested hashes, but accessible via the `filter[tag]` key.
428
+ - Query parameters are no longer interpreted as `style: deepObject` by default. If you want to use `style: deepObject`, for example to pass a nested hash as a query parameter like `filter[tag]`, you have to set `style: deepObject` explicitly.
429
+ - Path parameters are now parsed exactly as in the API description via the openapi_parameters gem.
430
+
431
+ ## 0.21.0
432
+
433
+ - Fix: Query parameter validation does not fail if header parameters are defined (Thanks to [JF Lalonde](https://github.com/JF-Lalonde))
434
+ - Update Ruby dependency to >= 3.0.5
435
+ - Handle simple form-data in request bodies (see https://github.com/ahx/openapi_first/issues/149)
436
+ - Update to hanami-router 2.0.0 stable
437
+
438
+ ## 0.20.0
439
+
440
+ - You can pass a filepath to `spec:` now so you no longer have to call `OpenapiFirst.load` anymore.
441
+ - Router is optional now.
442
+ You no longer have to add `Router` to your middleware stack. You still can add it to customize behaviour by setting options, but you no longer have to add it.
443
+ If you don't add the Router, make sure you pass `spec:` to your request/response validation middleware.
444
+ - Support "4xx" and "4XX" response definitions.
445
+ (4XX is defined in the standard, but 2xx is used in the wild as well 🦁.)
446
+ - Removed warning about missing operationId, because operationId is not used until the Responder is used.
447
+ - Raise HandlerNotFoundError when handler cannot be found
448
+
449
+ ## 0.19.0
450
+
451
+ - Add `RackResponder`
452
+
453
+ - BREAKING CHANGE: Handler classes are now instantiated only once without any arguments and the same instance is called on each following call/request.
454
+
455
+ ## 0.18.0
456
+
457
+ Yanked. No useful changes.
458
+
459
+ ## 0.17.0
460
+
461
+ - BREAKING CHANGE: Use a Hash instead of named arguments for middleware options for better compatibility
462
+ Using named arguments is actually not supported in Rack.
463
+
464
+ ## 0.16.1
465
+
466
+ - Pin hanami-router version, because alpha6 is broken.
467
+
468
+ ## 0.16.0
469
+
470
+ - Support status code wildcards like "2XX", "4XX"
471
+
472
+ ## 0.15.0
473
+
474
+ - Populate default parameter values
475
+
476
+ ## 0.14.3
477
+
478
+ - Use json_refs to resolve OpenAPI file. This removes oas_parser and ActiveSupport from list of dependencies
479
+
480
+ ## 0.14.2
481
+
482
+ - Empty query parameters are parsed and request validation returns 400 if an empty string is not allowed. Note that this does not look at `allowEmptyValue` in any way, because allowEmptyValue is deprecated.
483
+
484
+ ## 0.14.1
485
+
486
+ - Fix: Don't mix path- and operation-level parameters for request validation
487
+
488
+ ## 0.14.0
489
+
490
+ - Handle custom x-handler field in the API description to find a handler method not based on operationId
491
+ - Add `resolver` option to provide a custom resolver to find a handler method
492
+
493
+ ## 0.13.3
494
+
495
+ - Better error message if string does not match format
496
+ - readOnly and writeOnly just works when used inside allOf
497
+
498
+ ## 0.13.2
499
+
500
+ - Return indicator (`source: { parameter: 'list/1' }`) in error response body when array item in query parameter is invalid
501
+
502
+ ## 0.13.0
503
+
504
+ - Add support for arrays in query parameters (style: form, explode: false)
505
+ - Remove warning when handler is not implemented
506
+
507
+ ## 0.12.5
508
+
509
+ - Add `not_found: :continue` option to Router to make it do nothing if request is unknown
510
+
511
+ ## 0.12.4
512
+
513
+ - content-type is found while ignoring additional content-type parameters (`application/json` is found when request/response content-type is `application/json; charset=UTF8`)
514
+ - Support wildcard mime-types when finding the content-type
515
+
516
+ ## 0.12.3
517
+
518
+ - Add `response_validation:`, `router_raise_error` options to standalone mode.
519
+
520
+ ## 0.12.2
521
+
522
+ - Allow response to have no media type object specified
523
+
524
+ ## 0.12.1
525
+
526
+ - Fix response when handler returns 404 or 405
527
+ - Don't validate the response content if status is 204 (no content)
528
+
529
+ ## 0.12.0
530
+
531
+ - Change `ResponseValidator` to raise an exception if it found a problem
532
+ - Params have symbolized keys now
533
+ - Remove `not_found` option from Router. Return 405 if HTTP verb is not allowed (via Hanami::Router)
534
+ - Add `raise_error` option to OpenapiFirst.app (false by default)
535
+ - Add ResponseValidation to OpenapiFirst.app if raise_error option is true
536
+ - Rename `raise` option to `raise_error`
537
+ - Add `raise_error` option to RequestValidation middleware
538
+ - Raise error if handler could not be found by Responder
539
+ - Add `Operation#name` that returns a human readable name for an operation
540
+
541
+ ## 0.11.0
542
+
543
+ - Raise error if you forgot to add the Router middleware
544
+ - Make OpenapiFirst.app raise an error in test env when request path is not specified
545
+ - Rename OperationResolver to Responder
546
+ - Add ResponseValidation middleware that validates the response body
547
+ - Add `raise` option to Router middleware to raise an error if request could not be found in the API description similar to committee's raise option.
548
+ - Move namespace option from Router to OperationResolver
549
+
550
+ ## 0.10.2
551
+
552
+ - Return 400 if request body has invalid JSON ([issue](https://github.com/ahx/openapi_first/issues/73)) thanks Thomas Frütel
553
+
554
+ ## 0.10.1
555
+
556
+ - Fix duplicated key in `required` when generating JSON schema for `some[thing]` parameters
557
+
558
+ ## 0.10.0
559
+
560
+ - Add support for query parameters named `"some[thing]"` ([issue](https://github.com/ahx/openapi_first/issues/40))
561
+
562
+ ## 0.9.0
563
+
564
+ - Make request validation usable standalone
565
+
566
+ ## 0.8.0
567
+
568
+ - Add merged parameter and request body available to env at `env[OpenapiFirst::INBOX]` in request validation
569
+ - Path and query parameters with `type: boolean` now get converted to `true`/`false`
570
+ - Rename `OpenapiFirst::PARAMS` to `OpenapiFirst::PARAMETERS`
571
+
572
+ ## 0.7.1
573
+
574
+ - Add missing `require` to work with new version of `oas_parser`
575
+
576
+ ## 0.7.0
577
+
5
578
  - Make use of hanami-router, because it's fast
6
- - Remove OpenapiFirst::Coverage
7
579
  - Remove option `allow_unknown_query_paramerters`
8
580
  - Move the namespace option to Router
9
- - Convert numeric parameters to `Integer` or `Float`
581
+ - Convert numeric path and query parameters to `Integer` or `Float`
582
+ - Pass the Rack env if your action class' initializers accepts an argument
583
+ - Respec rack's `env['SCRIPT_NAME']` in router
584
+ - Add MIT license
585
+
586
+ ## 0.6.10
587
+
588
+ - Bugfix: params.env['unknown'] now returns `nil` as expected. Thanks @tristandruyen.
10
589
 
11
590
  ## 0.6.9
591
+
12
592
  - Removed radix tree, because of a bug (https://github.com/namusyaka/r2ree-ruby/issues/2)
13
593
 
14
594
  ## 0.6.8
595
+
15
596
  - Performance: About 25% performance increase (i/s) with help of c++ based radix-tree and some optimizations
16
597
  - Update dependencies
17
598
 
18
599
  ## 0.6.7
600
+
19
601
  - Fix: version number of oas_parser
20
602
 
21
603
  ## 0.6.6
604
+
22
605
  - Remove warnings for Ruby 2.7
23
606
 
24
607
  ## 0.6.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Andreas Haller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.