Skip to content

Commit 57e9bab

Browse files
committed
fix: Grape::Endpoint#merge_params now returns correct object (#943)
1 parent 7ec7bed commit 57e9bab

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#### Fixes
88

9+
* [#943](https://github.com/ruby-grape/grape-swagger/pull/943): Fix route_param documentation and type - [@4ndv](https://github.com/4ndv)
910
* Your contribution here.
1011

1112

lib/grape-swagger/endpoint.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def merge_params(route)
377377
route_params[key] = path.merge(params)
378378
end
379379

380-
route.params.delete_if { |key| key.is_a?(String) && param_keys.include?(key.to_sym) }.to_a
380+
route_params.delete_if { |key| key.is_a?(String) && param_keys.include?(key.to_sym) }.to_a
381381
end
382382

383383
# Iterates over namespaces recursively

spec/issues/942_route_params.rb

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe '#942 route param documentation' do
6+
let(:documentation) { { format: 'uuid' } }
7+
8+
let(:app) do
9+
docs = documentation
10+
11+
another_app = Class.new(Grape::API) do
12+
get '/list' do
13+
[]
14+
end
15+
end
16+
17+
Class.new(Grape::API) do
18+
route_param :account_id, type: String, desc: 'id of account', documentation: docs do
19+
mount another_app
20+
21+
get '/another-list' do
22+
[]
23+
end
24+
end
25+
26+
add_swagger_documentation
27+
end
28+
end
29+
30+
subject do
31+
get '/swagger_doc'
32+
JSON.parse(last_response.body)
33+
end
34+
35+
context 'when documenting route_param of mounted endpoint' do
36+
let(:parameters) { subject['paths']['/{account_id}/list']['get']['parameters'] }
37+
38+
specify do
39+
account_id_param = parameters.find { |param| param['name'] == 'account_id' }
40+
expect(account_id_param['type']).to eq 'string'
41+
expect(account_id_param['format']).to eq 'uuid'
42+
expect(account_id_param['description']).to eq 'id of account'
43+
end
44+
end
45+
46+
context 'when documenting route_param of nested endpoint' do
47+
let(:parameters) { subject['paths']['/{account_id}/another-list']['get']['parameters'] }
48+
49+
specify do
50+
account_id_param = parameters.find { |param| param['name'] == 'account_id' }
51+
expect(account_id_param['type']).to eq 'string'
52+
expect(account_id_param['format']).to eq 'uuid'
53+
expect(account_id_param['description']).to eq 'id of account'
54+
end
55+
end
56+
57+
context 'when documentation overrides description' do
58+
let(:documentation) { { desc: 'another description' } }
59+
60+
let(:parameters) { subject['paths']['/{account_id}/list']['get']['parameters'] }
61+
62+
specify do
63+
account_id_param = parameters.find { |param| param['name'] == 'account_id' }
64+
expect(account_id_param['type']).to eq 'string'
65+
expect(account_id_param['description']).to eq 'another description'
66+
end
67+
end
68+
end

0 commit comments

Comments
 (0)