mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
Support setting examples for response
Add helper method `response_examples` to inject response examples to swagger
This commit is contained in:
parent
3506fee3d0
commit
10dd37896f
@ -61,6 +61,10 @@ module Rswag
|
|||||||
metadata[:response][:headers][name] = attributes
|
metadata[:response][:headers][name] = attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def response_examples(example)
|
||||||
|
metadata[:response][:examples] = example
|
||||||
|
end
|
||||||
|
|
||||||
def run_test!
|
def run_test!
|
||||||
# NOTE: rspec 2.x support
|
# NOTE: rspec 2.x support
|
||||||
if RSPEC_VERSION < 3
|
if RSPEC_VERSION < 3
|
||||||
|
|||||||
@ -52,6 +52,12 @@ describe 'Blogs API', type: :request, swagger_doc: 'v1/swagger.json' do
|
|||||||
response '200', 'blog found' do
|
response '200', 'blog found' do
|
||||||
schema '$ref' => '#/definitions/blog'
|
schema '$ref' => '#/definitions/blog'
|
||||||
|
|
||||||
|
response_examples 'application/json' => {
|
||||||
|
id: 1,
|
||||||
|
title: 'Hello world!',
|
||||||
|
content: 'Hello world and hello universe. Thank you all very much!!!'
|
||||||
|
}
|
||||||
|
|
||||||
let(:blog) { Blog.create(title: 'foo', content: 'bar') }
|
let(:blog) { Blog.create(title: 'foo', content: 'bar') }
|
||||||
let(:id) { blog.id }
|
let(:id) { blog.id }
|
||||||
run_test!
|
run_test!
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user