mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 15:22:56 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7c29267fe | ||
|
|
8ede7f78f1 | ||
|
|
8b937e3585 | ||
|
|
1515ce4fcb |
@@ -20,6 +20,8 @@ module Rswag
|
||||
|
||||
def build_query_string(example)
|
||||
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])) }
|
||||
.join('&')
|
||||
|
||||
|
||||
@@ -40,13 +40,12 @@ module Rswag
|
||||
response_schema = @api_metadata[:response][:schema]
|
||||
return if response_schema.nil?
|
||||
|
||||
begin
|
||||
validation_schema = response_schema
|
||||
.merge('$schema' => 'http://tempuri.org/rswag/specs/extended_schema')
|
||||
.merge(@global_metadata.slice(:definitions))
|
||||
JSON::Validator.validate!(validation_schema, body)
|
||||
rescue JSON::Schema::ValidationError => ex
|
||||
raise UnexpectedResponse, "Expected response body to match schema: #{ex.message}"
|
||||
validation_schema = response_schema
|
||||
.merge('$schema' => 'http://tempuri.org/rswag/specs/extended_schema')
|
||||
.merge(@global_metadata.slice(:definitions))
|
||||
error_messages = JSON::Validator.fully_validate(validation_schema, body)
|
||||
if error_messages.any?
|
||||
raise UnexpectedResponse, "Expected response body to match schema: #{error_messages[0]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -48,6 +48,22 @@ module Rswag
|
||||
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
|
||||
before do
|
||||
api_metadata[:operation][:parameters] << {
|
||||
|
||||
Reference in New Issue
Block a user