Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Also parse params when no description is given #238

Merged
merged 1 commit into from

3 participants

@tim-vandecasteele

Something that was bothering me for a while now: if no description is given, the params would not be evaluated, so

params do
  requires :one_param, :desc => "one param"
end
get "method" do ; end

would do nothing, you would need to do

desc 'some description to make the below work'
params do
  requires :one_param, :desc => "one param"
end
get "method" do ; end
@travisbot

This pull request passes (merged 5b7e021 into 7e375f0).

@dblock
Owner

Thanks, nice.

@dblock dblock merged commit eca3327 into intridea:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 5, 2012
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 6 deletions.
  1. +5 −6 lib/grape/validations.rb
  2. +11 −0 spec/grape/api_spec.rb
View
11 lib/grape/validations.rb
@@ -172,13 +172,12 @@ def params(&block)
end
def document_attribute(names, opts)
- if @last_description
- @last_description[:params] ||= {}
+ @last_description ||= {}
+ @last_description[:params] ||= {}
- Array(names).each do |name|
- @last_description[:params][name[:name].to_s] ||= {}
- @last_description[:params][name[:name].to_s].merge!(opts).merge!({:full_name => name[:full_name]})
- end
+ Array(names).each do |name|
+ @last_description[:params][name[:name].to_s] ||= {}
+ @last_description[:params][name[:name].to_s].merge!(opts).merge!({:full_name => name[:full_name]})
end
end
View
11 spec/grape/api_spec.rb
@@ -1073,6 +1073,17 @@ class CommunicationError < RuntimeError; end
{ :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]" } } }
]
end
+ it "should parse parameters when no description is given" do
+ subject.params do
+ requires :one_param, :desc => "one param"
+ end
+ subject.get "method" do ; end
+ subject.routes.map { |route|
+ { :description => route.route_description, :params => route.route_params }
+ }.should eq [
+ { :description => nil, :params => { "one_param" => { :required => true, :desc => "one param", :full_name=>"one_param" } } }
+ ]
+ end
it "should not symbolize params" do
subject.desc "Reverses a string.", { :params =>
{ "s" => { :desc => "string to reverse", :type => "string" }}
Something went wrong with that request. Please try again.