Skip to content

Commit eca3327

Browse files
committed
Merge pull request ruby-grape#238 from tim-vandecasteele/master
Also parse params when no description is given
2 parents 7e375f0 + 5b7e021 commit eca3327

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/grape/validations.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,12 @@ def params(&block)
172172
end
173173

174174
def document_attribute(names, opts)
175-
if @last_description
176-
@last_description[:params] ||= {}
175+
@last_description ||= {}
176+
@last_description[:params] ||= {}
177177

178-
Array(names).each do |name|
179-
@last_description[:params][name[:name].to_s] ||= {}
180-
@last_description[:params][name[:name].to_s].merge!(opts).merge!({:full_name => name[:full_name]})
181-
end
178+
Array(names).each do |name|
179+
@last_description[:params][name[:name].to_s] ||= {}
180+
@last_description[:params][name[:name].to_s].merge!(opts).merge!({:full_name => name[:full_name]})
182181
end
183182
end
184183

spec/grape/api_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,17 @@ class CommunicationError < RuntimeError; end
10731073
{ :description => "nesting", :params => { "root_param" => { :required => true, :desc => "root param", :full_name=>"root_param" }, "nested_param" => { :required => true, :desc => "nested param", :full_name=>"nested[nested_param]" } } }
10741074
]
10751075
end
1076+
it "should parse parameters when no description is given" do
1077+
subject.params do
1078+
requires :one_param, :desc => "one param"
1079+
end
1080+
subject.get "method" do ; end
1081+
subject.routes.map { |route|
1082+
{ :description => route.route_description, :params => route.route_params }
1083+
}.should eq [
1084+
{ :description => nil, :params => { "one_param" => { :required => true, :desc => "one param", :full_name=>"one_param" } } }
1085+
]
1086+
end
10761087
it "should not symbolize params" do
10771088
subject.desc "Reverses a string.", { :params =>
10781089
{ "s" => { :desc => "string to reverse", :type => "string" }}

0 commit comments

Comments
 (0)