Skip to content

Commit 078bb34

Browse files
committed
fix: Use mount_path to narrow down urls_for
1 parent b75ce7f commit 078bb34

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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)