mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-24 23:06:41 +00:00
example group helper adjustment
This commit is contained in:
parent
9c297317b2
commit
1ff396fb56
@ -72,9 +72,16 @@ module Rswag
|
|||||||
def examples(example = nil)
|
def examples(example = nil)
|
||||||
return super() if example.nil?
|
return super() if example.nil?
|
||||||
|
|
||||||
metadata[:response][:examples] = example
|
metadata[:response][:content] =
|
||||||
|
example.each_with_object({}) do |(mime, example_object), memo|
|
||||||
|
memo[mime] = { example: example_object }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# example.metadata[:response][:content] = {
|
||||||
|
# 'application/json' => { example: json }
|
||||||
|
# }
|
||||||
|
|
||||||
def run_test!(&block)
|
def run_test!(&block)
|
||||||
# NOTE: rspec 2.x support
|
# NOTE: rspec 2.x support
|
||||||
if RSPEC_VERSION < 3
|
if RSPEC_VERSION < 3
|
||||||
|
|||||||
@ -137,9 +137,10 @@ module Rswag
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe '#examples(example)' do
|
describe '#examples(example)' do
|
||||||
|
let(:mime) { 'application/json' }
|
||||||
let(:json_example) do
|
let(:json_example) do
|
||||||
{
|
{
|
||||||
'application/json' => {
|
mime => {
|
||||||
foo: 'bar'
|
foo: 'bar'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,7 +152,11 @@ module Rswag
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "adds to the 'response examples' metadata" do
|
it "adds to the 'response examples' metadata" do
|
||||||
expect(api_metadata[:response][:examples]).to eq(json_example)
|
expect(api_metadata[:response][:content]).to match(
|
||||||
|
mime => {
|
||||||
|
example: json_example[mime]
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user