Skip to content

Commit b291b20

Browse files
Adriano DadarioTim Vandecasteele
authored andcommitted
Include in regex to capture URL with '-' in name
Some URL with names that contains the character '-' were not captured by the regex. Example name /simple-test(:format) Adriano Dadario Vagas Tecnologia
1 parent 0834096 commit b291b20

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
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.match('\/([\w|-]*?)[\.\/\(]').captures.first
1717
next if resource.empty?
1818
resource.downcase!
1919
@combined_routes[resource] ||= []

spec/simple_mounted_api_spec.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ class SimpleMountedApi < Grape::API
1717
{ bla: 'something' }
1818
end
1919

20+
desc 'This gets something for URL using - separator.', {
21+
:notes => '_test_'
22+
}
23+
24+
get '/simple-test' do
25+
{ bla: 'something' }
26+
end
27+
2028
desc 'this gets something else', {
2129
:headers => {
2230
"XAuthToken" => { description: "A required header.", required: true },
@@ -67,6 +75,7 @@ def app; SimpleApi end
6775
"operations" => [],
6876
"apis" => [
6977
{ "path" => "/swagger_doc/simple.{format}" },
78+
{ "path" => "/swagger_doc/simple-test.{format}" },
7079
{ "path" => "/swagger_doc/simple_with_headers.{format}" },
7180
{ "path" => "/swagger_doc/items.{format}" },
7281
{ "path" => "/swagger_doc/custom.{format}" },
@@ -94,6 +103,24 @@ def app; SimpleApi end
94103
end
95104

96105
context "retrieves the documentation for mounted-api that" do
106+
it "contains '-' in URL" do
107+
get '/swagger_doc/simple-test.json'
108+
JSON.parse(last_response.body).should == {
109+
"apiVersion" => "0.1",
110+
"swaggerVersion" => "1.1",
111+
"basePath" => "http://example.org",
112+
"resourcePath" => "",
113+
"apis" => [
114+
{
115+
"path" => "/simple-test.{format}",
116+
"operations" => [
117+
{ "notes" => "_test_", "summary" => "This gets something for URL using - separator.", "nickname" => "GET-simple-test---format-", "httpMethod" => "GET", "parameters" => [] }
118+
]
119+
}
120+
]
121+
}
122+
end
123+
97124
it "includes headers" do
98125
get '/swagger_doc/simple_with_headers.json'
99126
JSON.parse(last_response.body)["apis"].should == [{
@@ -117,7 +144,7 @@ def app; SimpleApi end
117144
}]
118145
end
119146

120-
it "retrieves the documentation for mounted-api that supports multiple parameters" do
147+
it "supports multiple parameters" do
121148
get '/swagger_doc/items.json'
122149
JSON.parse(last_response.body)["apis"].should == [{
123150
"path" => "/items.{format}",

0 commit comments

Comments
 (0)