Skip to content

Commit fdf1ea8

Browse files
authored
Add support for response links (#11)
* Remove duplicate ExampleGroupHelpers spec example * Add support for response links
1 parent 8dc68ef commit fdf1ea8

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

‎rswag-specs/lib/open_api/rswag/specs/example_group_helpers.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ def header(name, attributes)
176176
metadata[:response][:headers][name] = attributes
177177
end
178178

179+
def link(name, attributes)
180+
metadata[:response][:links] ||= {}
181+
metadata[:response][:links][name] = attributes
182+
end
183+
179184
# NOTE: Similar to 'description', 'examples' need to handle the case when
180185
# being invoked with no params to avoid overriding 'examples' method of
181186
# rspec-core ExampleGroup

‎rswag-specs/spec/rswag/specs/example_group_helpers_spec.rb‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,6 @@ module Specs
3636
end
3737
end
3838

39-
describe '#tags|description|operationId|consumes|produces|schemes|deprecated(value)' do
40-
before do
41-
subject.tags('Blogs', 'Admin')
42-
subject.description('Some description')
43-
subject.operationId('createBlog')
44-
subject.consumes('application/json', 'application/xml')
45-
subject.produces('application/json', 'application/xml')
46-
subject.schemes('http', 'https')
47-
subject.deprecated(true)
48-
end
49-
let(:api_metadata) { { operation: {} } }
50-
51-
it "adds to the 'operation' metadata" do
52-
expect(api_metadata[:operation]).to match(
53-
tags: %w[Blogs Admin],
54-
description: 'Some description',
55-
operationId: 'createBlog',
56-
consumes: ['application/json', 'application/xml'],
57-
produces: ['application/json', 'application/xml'],
58-
schemes: %w[http https],
59-
deprecated: true
60-
)
61-
end
62-
end
63-
6439
describe '#tags|description|operationId|consumes|produces|schemes|deprecated|security(value)' do
6540
before do
6641
subject.tags('Blogs', 'Admin')
@@ -195,6 +170,22 @@ module Specs
195170
end
196171
end
197172

173+
describe '#link(name, attributes)' do
174+
before do
175+
subject.link('GetUserByUserId', '$ref' => '#/components/links/GetUserByUserId')
176+
subject.link('GetUserByReference', '$ref' => '#/components/links/GetUserByReference')
177+
end
178+
179+
let(:api_metadata) { { response: {} } }
180+
181+
it "adds to the 'response links' metadata" do
182+
expect(api_metadata[:response][:links]).to match(
183+
'GetUserByUserId' => { '$ref' => '#/components/links/GetUserByUserId' },
184+
'GetUserByReference' => { '$ref' => '#/components/links/GetUserByReference' }
185+
)
186+
end
187+
end
188+
198189
describe '#examples(example)' do
199190
let(:json_example) do
200191
{

0 commit comments

Comments
 (0)