-
Notifications
You must be signed in to change notification settings - Fork 22
Support running Test Validation after Request Handling #434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support running Test Validation after Request Handling #434
Conversation
|
Hi! I am wondering if this should be the default behavior during tests. 🤔 I think this behavior might be useful, because it allows you to start a debugger in your controller code to debug invalid requests. I would rather make this the default and not introduce another configuration option. Do you have any thoughts on that? |
I'm not opposed! I went to config so as not to affect other consumer's existing functionality, but if you think it should be default than I'm all for it. |
|
Merged as part of #436 |
- Changed OpenapiFirst::Test to track the request _after_ the app has handled the request. See [PR #434](#434). You can restore the old behavior with ```ruby include OpenapiFirst::Test::Methods[MyApp, validate_request_before_handling: true] ``` - Added `OpenapiFirst::ValidatedRequest#unknown?` and `OpenapiFirst::ValidatedResponse#unknown?` - Added support for a static `path_prefix` value to be set on the creation of a Definition. See [PR #432](#432): ```ruby OpenapiFirst.configure do |config| config.register('openapi/openapi.yaml' path_prefix: '/weather') end ``` - Added `OpenapiFirst::Test::Configuration#ignore_response_error` and `OpenapiFirst::Test::Configuration#ignore_request_error` to configure which request/response errors should not raise an error during testing: ```ruby OpenapiFirst::Test.setup do |test| test.ignore_request_error do |validated_request| # Ignore unknown requests on certain paths validated_request.path.start_with?('/api/v1') && validated_request.unknown? end test.ignore_response_error do |validated_response, rack_request| # Ignore invalid response bodies on certain paths validated_request.path.start_with?('/api/legacy/stuff') && validated_request.error.type == :invalid_body end end ```
- Changed OpenapiFirst::Test to track the request _after_ the app has handled the request. See [PR #434](#434). You can restore the old behavior with ```ruby include OpenapiFirst::Test::Methods[MyApp, validate_request_before_handling: true] ``` - Added `OpenapiFirst::ValidatedRequest#unknown?` and `OpenapiFirst::ValidatedResponse#unknown?` - Added support for a static `path_prefix` value to be set on the creation of a Definition. See [PR #432](#432): ```ruby OpenapiFirst.configure do |config| config.register('openapi/openapi.yaml' path_prefix: '/weather') end ``` - Added `OpenapiFirst::Test::Configuration#ignore_response_error` and `OpenapiFirst::Test::Configuration#ignore_request_error` to configure which request/response errors should not raise an error during testing: ```ruby OpenapiFirst::Test.setup do |test| test.ignore_request_error do |validated_request| # Ignore unknown requests on certain paths validated_request.path.start_with?('/api/v1') && validated_request.unknown? end test.ignore_response_error do |validated_response, rack_request| # Ignore invalid response bodies on certain paths validated_request.path.start_with?('/api/legacy/stuff') && validated_request.error.type == :invalid_body end end ```
In a Rails app, there is some data that gets added to the Rack Request
envby the app itself while the request is handled (such as which controller and action actually handled the request after it was routed).If you want to access any of this information in any
openapi_firsthooks, than you need to be able to configure tests to do the request validation only after the request has been handled.