fix: Use mount_path to narrow down urls_for (#924)

This commit is contained in:
Suzuki Eiji 2024-04-26 14:10:24 +09:00 committed by GitHub
parent b75ce7f77d
commit ceebbd3469
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View File

@ -9,6 +9,7 @@
* Your contribution here.
* [#922](https://github.com/ruby-grape/grape-swagger/pull/922): Force request body to be an schema object - [@numbata](https://github.com/numbata)
* [#923](https://github.com/ruby-grape/grape-swagger/pull/923): Enabled schema definitions for body parameters in DELETE requests - [@numbata](https://github.com/numbata)
* [#924](https://github.com/ruby-grape/grape-swagger/pull/924): fix: Use mount_path to narrow down urls_for - [@chibicco](https://github.com/chibicco)
### 2.0.2 (Februar 2, 2024)

View File

@ -95,7 +95,7 @@ module GrapeSwagger
def urls_for(api_class)
api_class.routes
.map(&:path)
.select { |e| e.include?('doc') }
.grep(/#{GrapeSwagger::DocMethods.class_variable_get(:@@mount_path)}/)
.reject { |e| e.include?(':name') }
.map { |e| format_path(e) }
.map { |e| [e, ENV.fetch('resource', nil)].join('/').chomp('/') }

View File

@ -14,6 +14,10 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
namespace :otherItem do
get '/'
end
namespace :my_doc do
get '/'
end
end
class Base < Grape::API
@ -115,7 +119,7 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
end
it 'returns complete doc' do
expect(response['paths'].length).to eql 2
expect(response['paths'].length).to eql 3
end
end
end
@ -132,6 +136,14 @@ RSpec.describe GrapeSwagger::Rake::OapiTasks do
end
end
describe '#urls_for' do
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