grape
grape copied to clipboard
Required params at the top level namespace, is this possible?
My code is currently like this:
namespace :top_level do
namespace :child_one do
params do
requires :token, :type => String
requires :id, :type => String
end
mount V1::Controllers::ChildOneController
end
namespace :child_two do
params do
requires :token, :type => String
requires :id, :type => String
requires :name, :type => String
requires :description, :type => String
end
mount V1::Controllers::ChildTwoController
end
As both child_one
and child_two
routes require token
and id
, is it possible to move them up to the top_level
namespace? I tried the following but it doesn't seem to work:
namespace :top_level do
params do
requires :token, :type => String
requires :id, :type => String
end
namespace :child_one do
mount V1::Controllers::ChildOneController
end
namespace :child_two do
params do
requires :name, :type => String
requires :description, :type => String
end
mount V1::Controllers::ChildTwoController
end
The params don't carry over mount
. I think it should be possible, labelling as a feature request.
Would implementing this not cause some potential breaking changes?
Generally I would have thought to use the SharedParams
helper approach for these cases.
It would, so we would need to do this carefully. Note that params
without a method following it right now is not useful at all, maybe we could be producing a warning in that case to start?