mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 15:22:56 +00:00
Support parameters provided at the 'path' level
This commit is contained in:
@@ -87,10 +87,21 @@ module Rswag
|
||||
end
|
||||
|
||||
describe '#parameter(attributes)' do
|
||||
let(:api_metadata) { { operation: {} } }
|
||||
|
||||
context 'always' do
|
||||
context "when called at the 'path' level" do
|
||||
before { subject.parameter(name: :blog, in: :body, schema: { type: 'object' }) }
|
||||
let(:api_metadata) { { path_item: {} } } # i.e. operation not defined yet
|
||||
|
||||
it "adds to the 'path_item parameters' metadata" do
|
||||
expect(api_metadata[:path_item][:parameters]).to match(
|
||||
[ name: :blog, in: :body, schema: { type: 'object' } ]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "when called at the 'operation' level" do
|
||||
before { subject.parameter(name: :blog, in: :body, schema: { type: 'object' }) }
|
||||
let(:api_metadata) { { path_item: {}, operation: {} } } # i.e. operation defined
|
||||
|
||||
it "adds to the 'operation parameters' metadata" do
|
||||
expect(api_metadata[:operation][:parameters]).to match(
|
||||
@@ -101,6 +112,7 @@ module Rswag
|
||||
|
||||
context "'path' parameter" do
|
||||
before { subject.parameter(name: :id, in: :path) }
|
||||
let(:api_metadata) { { operation: {} } }
|
||||
|
||||
it "automatically sets the 'required' flag" do
|
||||
expect(api_metadata[:operation][:parameters]).to match(
|
||||
|
||||
@@ -125,6 +125,17 @@ module Rswag
|
||||
expect(path).to eq('/foobar/blogs/1/comments/2')
|
||||
end
|
||||
end
|
||||
|
||||
context "defined at the 'path' level" do
|
||||
before do
|
||||
api_metadata[:path_item][:parameters] = [ { name: :blog_id, in: :path } ]
|
||||
api_metadata[:operation][:parameters] = [ { name: :id, in: :path } ]
|
||||
end
|
||||
|
||||
it "builds path from parameters defined at path and operation levels" do
|
||||
expect(path).to eq('/blogs/1/comments/2')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#build_body(example)' do
|
||||
|
||||
Reference in New Issue
Block a user