update Readme

This commit is contained in:
Greg Myers 2020-04-05 00:53:04 +01:00
parent a96a466205
commit 4ab432080b

View File

@ -591,11 +591,22 @@ end
### Enable auto generation examples from responses ###
This is now enabled by default in rswag.
To enable examples generation from responses add callback above run_test! like:
```
after do |example|
example.metadata[:response][:examples] = { 'application/json' => JSON.parse(response.body, symbolize_names: true) }
end
```
You need to disable --dry-run option for Rspec > 3
<!-- This is now enabled by default in rswag.
You need to set the ``` config.swagger_dry_run = false``` value in the spec/spec_helper.rb file.
This is one of the more powerful features of rswag. When rswag runs your integration test suite via ```bundle exec rspec```, it will capture the request and response bodies and output those values in the examples section.
These integration tests are usually written with ```let``` variables for post body parameters, and since its an integration test the service is returning actual values.
We might as well re-use these values and embed them into the generated swagger to provide a more real world example for request/response examples.
We might as well re-use these values and embed them into the generated swagger to provide a more real world example for request/response examples. -->
Add to config/environments/test.rb:
```ruby
@ -633,7 +644,7 @@ describe 'Blogs API', document: false do
```
##### rswag helper methods #####
<!--
There are some helper methods to help with documenting request bodies.
```ruby
describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do
@ -761,7 +772,7 @@ capturing the response from the execution of the integration test. Again 3.0 swa
}
}
```
-->
### Route Prefix for Swagger JSON Endpoints ###
The functionality to expose Swagger files, such as those generated by rswag-specs, as JSON endpoints is implemented as a Rails Engine. As with any Engine, you can change it's mount prefix in _routes.rb_: