mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
Merge pull request #76 from ahobson/bugfix-optional-query-params
Support optional query parameters
This commit is contained in:
commit
8b937e3585
@ -20,6 +20,8 @@ module Rswag
|
|||||||
|
|
||||||
def build_query_string(example)
|
def build_query_string(example)
|
||||||
query_string = parameters_in(:query)
|
query_string = parameters_in(:query)
|
||||||
|
.select { |p| p.fetch(:required, true) ||
|
||||||
|
example.respond_to?(p[:name]) }
|
||||||
.map { |p| build_query_string_part(p, example.send(p[:name])) }
|
.map { |p| build_query_string_part(p, example.send(p[:name])) }
|
||||||
.join('&')
|
.join('&')
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,22 @@ module Rswag
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "optional 'query' parameters" do
|
||||||
|
before do
|
||||||
|
api_metadata[:operation][:parameters] << { name: 'q1', in: :query, type: 'string' }
|
||||||
|
api_metadata[:operation][:parameters] << { name: 'q2', in: :query, type: 'string', required: true }
|
||||||
|
api_metadata[:operation][:parameters] << { name: 'q3', in: :query, type: 'string', required: false }
|
||||||
|
api_metadata[:operation][:parameters] << { name: 'q4', in: :query, type: 'string', required: false }
|
||||||
|
allow(example).to receive(:q1).and_return('foo')
|
||||||
|
allow(example).to receive(:q2).and_return('bar')
|
||||||
|
allow(example).to receive(:q3).and_return('baz')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "appends a query string using metadata and example values" do
|
||||||
|
expect(path).to eq('/blogs/1/comments/2?q1=foo&q2=bar&q3=baz')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "'query' parameter of type 'array'" do
|
context "'query' parameter of type 'array'" do
|
||||||
before do
|
before do
|
||||||
api_metadata[:operation][:parameters] << {
|
api_metadata[:operation][:parameters] << {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user