intridea/grape — pull request #394 by tmornini (2013-04-27 20:38:58+00:00)
Title: API version overriding version parameter in body

Hello there fine fellows!

Beginning to use and love Grape, but have run into a serious issue which I am unable to resolve myself.

I have an endpoint described as such:

params do
optional :description, :type => String, :desc => 'Book description'
optional :reference, :type => String, :desc => 'Book reference'
requires :version, :type => Integer, :desc => 'Book current version'
end

This works fine with API versioning via headers when I pass in this body:

{"description":"Updated Description","reference":"b:a","version":2}

However, when I use API versioning via path, the version parameter is set to the API version from the path, which results in a 403 with this body:

{"error":"invalid parameter: version"}

I verified this at coerce.rb by adding these lines after line 14:

puts attr_name
puts params[attr_name]

This produces:

version
pacioli

where pacioli is my API version from:

class App < ::Grape::API
version 'pacioli', :using => :path

I believe this to be 100% incorrect. :-)

Let me know if I can help in any way!

P.S. The 403 is weird in itself as line 15 of coerce.rb certainly appears to throw a 400.