Skip to content

Commit ceebbd3

Browse files
authored
fix: Use mount_path to narrow down urls_for (#924)
1 parent b75ce7f commit ceebbd3

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* Your contribution here.
1010
* [#922](https://github.com/ruby-grape/grape-swagger/pull/922): Force request body to be an schema object - [@numbata](https://github.com/numbata)
1111
* [#923](https://github.com/ruby-grape/grape-swagger/pull/923): Enabled schema definitions for body parameters in DELETE requests - [@numbata](https://github.com/numbata)
12+
* [#924](https://github.com/ruby-grape/grape-swagger/pull/924): fix: Use mount_path to narrow down urls_for - [@chibicco](https://github.com/chibicco)
1213

1314
### 2.0.2 (Februar 2, 2024)
1415

lib/grape-swagger/rake/oapi_tasks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def make_request(url)
9595
def urls_for(api_class)
9696
api_class.routes
9797
.map(&:path)
98-
.select { |e| e.include?('doc') }
98+
.grep(/#{GrapeSwagger::DocMethods.class_variable_get(:@@mount_path)}/)
9999
.reject { |e| e.include?(':name') }
100100
.map { |e| format_path(e) }
101101
.map { |e| [e, ENV.fetch('resource', nil)].join('/').chomp('/') }

spec/lib/oapi_tasks_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class Item < Grape::API
1414
namespace :otherItem do
1515
get '/'
1616
end
17+
18+
namespace :my_doc do
19+
get '/'
20+
end
1721
end
1822

1923
class Base < Grape::API
@@ -115,7 +119,7 @@ class Base < Grape::API
115119
end
116120

117121
it 'returns complete doc' do
118-
expect(response['paths'].length).to eql 2
122+
expect(response['paths'].length).to eql 3
119123
end
120124
end
121125
end
@@ -132,6 +136,14 @@ class Base < Grape::API
132136
end
133137
end
134138

139+
describe '#urls_for' do
140+
describe 'match only the path to mount_path' do
141+
it do
142+
expect(subject.send(:urls_for, api_class)).to match_array ['/api/swagger_doc']
143+
end
144+
end
145+
end
146+
135147
describe '#file' do
136148
describe 'no store given' do
137149
it 'returns swagger_doc.json' do

0 commit comments

Comments
 (0)