Skip to content

Handle cases where a route's prefix is a nested URL #758

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

Merged
merged 1 commit into from
Oct 10, 2019
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 @@ -6,6 +6,7 @@

#### Fixes

* [#758](https://github.com/ruby-grape/grape-swagger/pull/758): Handle cases where a route's prefix is a nested URL - [@SimonKaluza](https://github.com/simonkaluza).
* [#757](https://github.com/ruby-grape/grape-swagger/pull/757): Fix `array_use_braces` for nested body params - [@bikolya](https://github.com/bikolya).
* [#756](https://github.com/ruby-grape/grape-swagger/pull/756): Fix reference creation when custom type for documentation is provided - [@bikolya](https://github.com/bikolya).

Expand Down
4 changes: 2 additions & 2 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ def success_codes_from_route(route)
def tag_object(route, path)
version = GrapeSwagger::DocMethods::Version.get(route)
version = [version] unless version.is_a?(Array)

prefix = route.prefix.to_s.split('/').reject(&:empty?)
Array(
path.split('{')[0].split('/').reject(&:empty?).delete_if do |i|
i == route.prefix.to_s || version.map(&:to_s).include?(i)
prefix.include?(i) || version.map(&:to_s).include?(i)
end.first
).presence
end
Expand Down
16 changes: 15 additions & 1 deletion spec/swagger_v2/namespace_tags_prefix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,25 @@ class CascadingVersionApi < Grape::API
end
end
end

class NestedPrefixApi < Grape::API
version :v1
prefix 'nested_prefix/api'

namespace :deep_namespace do
desc 'This gets something within a deeply nested resource'
get '/deep' do
{ bla: 'something' }
end
end
end
end

class TagApi < Grape::API
prefix :api
mount TheApi::CascadingVersionApi
mount TheApi::NamespaceApi
mount TheApi::NestedPrefixApi
add_swagger_documentation
end
end
Expand All @@ -55,7 +68,8 @@ def app
{ 'name' => 'hudson', 'description' => 'Operations about hudsons' },
{ 'name' => 'colorado', 'description' => 'Operations about colorados' },
{ 'name' => 'thames', 'description' => 'Operations about thames' },
{ 'name' => 'niles', 'description' => 'Operations about niles' }
{ 'name' => 'niles', 'description' => 'Operations about niles' },
{ 'name' => 'deep_namespace', 'description' => 'Operations about deep_namespaces' }
]
)

Expand Down