Skip to content

Commit 4b43fd5

Browse files
aewTim Vandecasteele
authored andcommitted
Support resource groupings for prefixed APIs
The fact that an API has a prefix (e.g., /api) should not affect the way resources are grouped for documentation purposes. This patch updates the hardcoded single level of resource grouping to ignore the prefix (which available as part of the route object).
1 parent 1fddab9 commit 4b43fd5

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/grape-swagger.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def add_swagger_documentation(options={})
1313

1414
@combined_routes = {}
1515
routes.each do |route|
16-
resource = route.route_path.match('\/([\w|-]*?)[\.\/\(]').captures.first
16+
resource = route.route_path.split(route.route_prefix).last.match('\/([\w|-]*?)[\.\/\(]').captures.first
1717
next if resource.empty?
1818
resource.downcase!
1919
@combined_routes[resource] ||= []

spec/non_default_api_spec.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def app; SimpleApiWithMarkdown end
257257
end
258258
end
259259

260-
context "versioned API" do
260+
context "prefixed and versioned API" do
261261
before :all do
262262
class VersionedMountedApi < Grape::API
263263
prefix 'api'
@@ -278,7 +278,8 @@ class SimpleApiWithVersion < Grape::API
278278
def app; SimpleApiWithVersion end
279279

280280
it "parses version and places it in the path" do
281-
get '/swagger_doc/api.json'
281+
get '/swagger_doc/something.json'
282+
282283
JSON.parse(last_response.body)["apis"].each do |api|
283284
api["path"].should start_with "/api/v1/"
284285
end

0 commit comments

Comments
 (0)