Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use mount_path to narrow down urls_for #924

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
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') }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the specs generation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmh, it is gone … what do you mean?

.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('/') }
Expand Down
14 changes: 13 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
LeFnord marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
Expand All @@ -132,6 +136,14 @@ class Base < Grape::API
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
Expand Down