ruby-grape/grape

Broken Params Type Check in Grape v2.1.x

ninoseki opened this issue · 1 comments

I think Grape's params type check has been broken since v2.1.0.

require "grape"

module Test
  class API < Grape::API
    format :json

    params do
      requires :id, type: Integer
    end
    get "/:id" do
      params[:id]
    end
  end
end

run Test::API

Grape v2.0.0

$ curl localhost:9292/foo --verbose
* Host localhost:9292 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:9292...
* Connected to localhost (::1) port 9292
> GET /foo HTTP/1.1
> Host: localhost:9292
> User-Agent: curl/8.6.0
> Accept: */*
> 
< HTTP/1.1 400 Bad Request
< content-type: application/json
< Content-Length: 25
< 
* Connection #0 to host localhost left intact
{"error":"id is invalid"}

Grape v2.1.2

$ curl localhost:9292/foo --verbose
* Host localhost:9292 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:9292...
* Connected to localhost (::1) port 9292
> GET /foo HTTP/1.1
> Host: localhost:9292
> User-Agent: curl/8.6.0
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< x-cascade: pass
< Content-Length: 13
< 
* Connection #0 to host localhost left intact
404 Not Found

As you can see, v2.1.2 (v2.1+) does not handle the type checking the way it used to.

Sorry I overlooked this.