Skip to content

Commit 712d95c

Browse files
dblockTim Vandecasteele
authored andcommitted
Fix: allow parameters such as name[], support :desc and :description.
1 parent 8a052ed commit 712d95c

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

CHANGELOG.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Added Rails 4 support - [@jrhe](https://github.com/jrhe).
44
* Fix: document APIs at root level - [@dblock](https://github.com/dblock).
55
* Added support for procs in basepath - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
6+
* Support both `:desc` and `:description` when describing parameters - [@dblock](https://github.com/dblock).
7+
* Fix: allow parameters such as `name[]` - [@dblock](https://github.com/dblock).
68

79
### 0.5.0 (March 28, 2013)
810

lib/grape-swagger.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ def parse_params(params, path, method)
120120
value[:type] = 'file' if value.is_a?(Hash) && value[:type] == 'Rack::Multipart::UploadedFile'
121121

122122
dataType = value.is_a?(Hash) ? value[:type]||'String' : 'String'
123-
description = value.is_a?(Hash) ? value[:desc] : ''
123+
description = value.is_a?(Hash) ? value[:desc] || value[:description] : ''
124124
required = value.is_a?(Hash) ? !!value[:required] : false
125-
paramType = path.match(":#{param}") ? 'path' : (method == 'POST') ? 'form' : 'query'
125+
paramType = path.include?(":#{param}") ? 'path' : (method == 'POST') ? 'form' : 'query'
126126
name = (value.is_a?(Hash) && value[:full_name]) || param
127127
{
128128
paramType: paramType,

spec/simple_mounted_api_spec.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@ class SimpleMountedApi < Grape::API
2020
"XAuthToken" => {description: "A required header.", required: true},
2121
"XOtherHeader" => {description: "An optional header.", required: false}
2222
},
23-
:http_codes => {
24-
403 => "invalid pony",
25-
405 => "no ponies left!"
26-
}
23+
:http_codes => {
24+
403 => "invalid pony",
25+
405 => "no ponies left!"
26+
}
2727
}
2828
get '/simple_with_headers' do
2929
{:bla => 'something_else'}
3030
end
31+
32+
desc 'this takes an array of parameters', {
33+
:params => {
34+
"items[]" => { :description => "array of items" }
35+
}
36+
}
37+
post '/items' do
38+
{}
39+
end
3140
end
3241

3342
class SimpleApi < Grape::API
@@ -40,7 +49,7 @@ def app; SimpleApi end
4049

4150
it "retrieves swagger-documentation on /swagger_doc" do
4251
get '/swagger_doc'
43-
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/simple.{format}\"}, {:path=>\"/swagger_doc/simple_with_headers.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
52+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :operations=>[], :apis=>[{:path=>\"/swagger_doc/simple.{format}\"}, {:path=>\"/swagger_doc/simple_with_headers.{format}\"}, {:path=>\"/swagger_doc/items.{format}\"}, {:path=>\"/swagger_doc/swagger_doc.{format}\"}]}"
4453
end
4554

4655
it "retrieves the documentation for mounted-api" do
@@ -52,4 +61,9 @@ def app; SimpleApi end
5261
get '/swagger_doc/simple_with_headers'
5362
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/simple_with_headers.{format}\", :operations=>[{:notes=>nil, :summary=>\"this gets something else\", :nickname=>\"GET-simple_with_headers---format-\", :httpMethod=>\"GET\", :parameters=>[{:paramType=>\"header\", :name=>\"XAuthToken\", :description=>\"A required header.\", :dataType=>\"String\", :required=>true}, {:paramType=>\"header\", :name=>\"XOtherHeader\", :description=>\"An optional header.\", :dataType=>\"String\", :required=>false}], :errorResponses=>[{:code=>403, :reason=>\"invalid pony\"}, {:code=>405, :reason=>\"no ponies left!\"}]}]}]}"
5463
end
64+
65+
it "retrieves the documentation for mounted-api that supports multiple parameters" do
66+
get '/swagger_doc/items'
67+
last_response.body.should == "{:apiVersion=>\"0.1\", :swaggerVersion=>\"1.1\", :basePath=>\"http://example.org\", :resourcePath=>\"\", :apis=>[{:path=>\"/items.{format}\", :operations=>[{:notes=>nil, :summary=>\"this takes an array of parameters\", :nickname=>\"POST-items---format-\", :httpMethod=>\"POST\", :parameters=>[{:paramType=>\"form\", :name=>\"items[]\", :description=>\"array of items\", :dataType=>\"String\", :required=>false}]}]}]}"
68+
end
5569
end

0 commit comments

Comments
 (0)