mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-23 06:16:42 +00:00
Merge pull request #255 from fooki/skip-documentation
Allow tests to be run without generating docs
This commit is contained in:
commit
e6bfba23d7
28
README.md
28
README.md
@ -454,12 +454,30 @@ end
|
|||||||
|
|
||||||
### Running tests without documenting ###
|
### Running tests without documenting ###
|
||||||
|
|
||||||
If you want to use Rswag for testing without adding it to you swagger docs, you can simply nullify the response metadata after the test run.
|
If you want to use Rswag for testing without adding it to you swagger docs, you can provide the document tag:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
after do |example|
|
describe 'Blogs API' do
|
||||||
example.metadata[:response] = null
|
path '/blogs/{blog_id}' do
|
||||||
end
|
get 'Retrieves a blog' do
|
||||||
|
# documentation is now disabled for this response only
|
||||||
|
response 200, 'blog found', document: false do
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also reenable documentation for specific responses only:
|
||||||
|
```ruby
|
||||||
|
# documentation is now disabled
|
||||||
|
describe 'Blogs API', document: false do
|
||||||
|
path '/blogs/{blog_id}' do
|
||||||
|
get 'Retrieves a blog' do
|
||||||
|
# documentation is reenabled for this response only
|
||||||
|
response 200, 'blog found', document: true do
|
||||||
|
...
|
||||||
|
end
|
||||||
|
|
||||||
|
response 401, 'special case' do
|
||||||
|
...
|
||||||
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
### Route Prefix for Swagger JSON Endpoints ###
|
### Route Prefix for Swagger JSON Endpoints ###
|
||||||
|
|||||||
@ -25,7 +25,11 @@ module Rswag
|
|||||||
metadata = notification.metadata
|
metadata = notification.metadata
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# !metadata[:document] won't work, since nil means we should generate
|
||||||
|
# docs.
|
||||||
|
return if metadata[:document] == false
|
||||||
return unless metadata.has_key?(:response)
|
return unless metadata.has_key?(:response)
|
||||||
|
|
||||||
swagger_doc = @config.get_swagger_doc(metadata[:swagger_doc])
|
swagger_doc = @config.get_swagger_doc(metadata[:swagger_doc])
|
||||||
swagger_doc.deep_merge!(metadata_to_swagger(metadata))
|
swagger_doc.deep_merge!(metadata_to_swagger(metadata))
|
||||||
end
|
end
|
||||||
|
|||||||
@ -26,23 +26,37 @@ module Rswag
|
|||||||
{
|
{
|
||||||
path_item: { template: '/blogs' },
|
path_item: { template: '/blogs' },
|
||||||
operation: { verb: :post, summary: 'Creates a blog' },
|
operation: { verb: :post, summary: 'Creates a blog' },
|
||||||
response: { code: '201', description: 'blog created' }
|
response: { code: '201', description: 'blog created' },
|
||||||
|
document: document
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'converts to swagger and merges into the corresponding swagger doc' do
|
context 'with the document tag set to false' do
|
||||||
expect(swagger_doc).to match(
|
let(:document) { false }
|
||||||
paths: {
|
|
||||||
'/blogs' => {
|
it 'does not update the swagger doc' do
|
||||||
post: {
|
expect(swagger_doc).to be_empty
|
||||||
summary: 'Creates a blog',
|
end
|
||||||
responses: {
|
end
|
||||||
'201' => { description: 'blog created' }
|
|
||||||
|
context 'with the document tag set to anything but false' do
|
||||||
|
# anything works, including its absence when specifying responses.
|
||||||
|
let(:document) { nil }
|
||||||
|
|
||||||
|
it 'converts to swagger and merges into the corresponding swagger doc' do
|
||||||
|
expect(swagger_doc).to match(
|
||||||
|
paths: {
|
||||||
|
'/blogs' => {
|
||||||
|
post: {
|
||||||
|
summary: 'Creates a blog',
|
||||||
|
responses: {
|
||||||
|
'201' => { description: 'blog created' }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user