Action params are not coerced?
wuarmin opened this issue · comments
Armin commented
module API
module Actions
module Customers
class Index < API::Action
include Deps["repositories.customers_repo"]
params do
optional(:first_name).filled(:str?)
optional(:limit).filled(:int?)
end
def handle(req, res)
halt 400, req.params.errors.to_json unless req.params.valid?
# returns {"limit":["must be an integer"]}
# for http://localhost:2300/api/customers?limit=20
end
end
end
end
end
thanks and best regards
Luca Guidi commented
I can reproduce the problem.
Armin commented
Thanks!
I tried to find and fix the problem, but didn't have enough time today. maybe tomorrow.
Tim Riley commented
Can you please try defining your params schema using type specs? These are missing from your schema definition here.
Armin commented
@timriley thanks! Following works:
module API
module Actions
module Customers
class Index < API::Action
include Deps["repositories.customers_repo"]
params do
optional(:first_name).filled(:string)
optional(:limit).filled(:integer)
end
def handle(req, res)
halt 400, req.params.errors.to_json unless req.params.valid?
res.body = "yess"
end
end
end
end
end
Is it intentional that a type predicate alone does not cause a conversion? That's new, isn't it?
Luca Guidi commented
@wuarmin With type specs, the code works as expected.