Skip to content

Commit ed07baf

Browse files
Jack12816LeFnord
andauthored
Corrected the related parameter lookup on request params. (#822)
Signed-off-by: Hermann Mayer <[email protected]> Co-authored-by: peter scholz <[email protected]>
1 parent 82fca50 commit ed07baf

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#### Fixes
1111

1212
* Your contribution here.
13-
13+
* [#822](https://github.com/ruby-grape/grape-swagger/pull/822): Corrected the related parameter lookup on request params - [@Jack12816](https://github.com/Jack12816).
1414

1515
### 1.3.1 (November 1, 2020)
1616

lib/grape-swagger/doc_methods/format_data.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class << self
77
def to_format(parameters)
88
parameters.reject { |parameter| parameter[:in] == 'body' }.each do |b|
99
related_parameters = parameters.select do |p|
10-
p[:name] != b[:name] && p[:name].to_s.include?("#{b[:name].to_s.gsub(/\[\]\z/, '')}[")
10+
p[:name] != b[:name] && p[:name].to_s.start_with?("#{b[:name].to_s.gsub(/\[\]\z/, '')}[")
1111
end
1212
parameters.reject! { |p| p[:name] == b[:name] } if move_down(b, related_parameters)
1313
end

spec/lib/format_data_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,29 @@
8787
expect(subject.to_format(params)).to eq expected_params
8888
end
8989
end
90+
91+
context 'when array params are not related' do
92+
let(:params) do
93+
[
94+
{ name: 'id', required: true, type: 'string' },
95+
{ name: 'description', required: false, type: 'string' },
96+
{ name: 'ids[]', required: true, type: 'array', items: { type: 'string' } },
97+
{ name: 'user_ids[]', required: true, type: 'array', items: { type: 'string' } }
98+
]
99+
end
100+
101+
let(:expected_params) do
102+
[
103+
{ name: 'id', required: true, type: 'string' },
104+
{ name: 'description', required: false, type: 'string' },
105+
{ name: 'ids[]', required: true, type: 'array', items: { type: 'string' } },
106+
{ name: 'user_ids[]', required: true, type: 'array', items: { type: 'string' } }
107+
]
108+
end
109+
110+
it 'parses params correctly and adds array type all concerned elements' do
111+
expect(subject.to_format(params)).to eq expected_params
112+
end
113+
end
90114
end
91115
end

0 commit comments

Comments
 (0)