Skip to content

Commit

Permalink
fix: Use mount_path to narrow down urls_for
Browse files Browse the repository at this point in the history
  • Loading branch information
chibicco committed Apr 21, 2024
1 parent 262cdb9 commit e8d0776
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/grape-swagger/rake/oapi_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def make_request(url)
def urls_for(api_class)
api_class.routes
.map(&:path)
.select { |e| e.include?('doc') }
.grep(/#{GrapeSwagger::DocMethods.class_variable_get(:@@mount_path)}\(\.json\)$/)
.reject { |e| e.include?(':name') }
.map { |e| format_path(e) }
.map { |e| [e, ENV.fetch('resource', nil)].join('/').chomp('/') }
Expand Down
15 changes: 14 additions & 1 deletion spec/lib/oapi_tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class Item < Grape::API
namespace :otherItem do
get '/'
end

namespace :my_doc do
get '/'
end
end

class Base < Grape::API
Expand Down Expand Up @@ -115,7 +119,7 @@ class Base < Grape::API
end

it 'returns complete doc' do
expect(response['paths'].length).to eql 2
expect(response['paths'].length).to eql 3
end
end
end
Expand All @@ -132,6 +136,15 @@ class Base < Grape::API
end
end

describe '#urls_for' do
require 'pry'
describe 'match only the path to mount_path' do
it do
expect(subject.send(:urls_for, api_class)).to match_array ['/api/swagger_doc']
end
end
end

describe '#file' do
describe 'no store given' do
it 'returns swagger_doc.json' do
Expand Down

0 comments on commit e8d0776

Please sign in to comment.