Skip to content

Commit

Permalink
Merge pull request #725 from JohnnyKei/fix/query_param_encoding
Browse files Browse the repository at this point in the history
fix: encode query params when use schema type
  • Loading branch information
romanblanco authored Sep 19, 2024
2 parents 1982941 + 85e032c commit 0705197
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed

- Allow vendor-specific MIME types for JSON payloads (https://github.com/rswag/rswag/pull/769)
- Fix escaping of schema in path parameters for openapi spec >= 3.0.0 (https://github.com/rswag/rswag/pull/725)

## [2.14.0] - 2024-08-13

Expand Down
2 changes: 1 addition & 1 deletion rswag-specs/lib/rswag/specs/request_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def build_query_string_part(param, value, swagger_doc)
return "#{escaped_name}=" + value.to_a.flatten.map{|v| CGI.escape(v.to_s) }.join(separator)
end
else
return "#{name}=#{value}"
return "#{escaped_name}=#{CGI.escape(value.to_s)}"
end
end

Expand Down
14 changes: 14 additions & 0 deletions rswag-specs/spec/rswag/specs/request_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ module Specs
expect(request[:path]).to eq('/blogs?date_time=2001-02-03T04%3A05%3A06-07%3A00')
end
end

context 'openapi spec >= 3.0.0' do
let(:openapi_spec) { { swagger: '3.0' } }
before do
allow(example).to receive(:date_time).and_return(date_time)
end

it 'formats the datetime properly when type is defined in schema' do
metadata[:operation][:parameters] = [
{ name: 'date_time', in: :query, schema: { type: :string }, format: :datetime, }
]
expect(request[:path]).to eq('/blogs?date_time=2001-02-03T04%3A05%3A06-07%3A00')
end
end
end

context "'query' parameters of type 'object'" do
Expand Down

0 comments on commit 0705197

Please sign in to comment.