grape icon indicating copy to clipboard operation
grape copied to clipboard

Required params at the top level namespace, is this possible?

Open ggwc82 opened this issue 6 years ago • 3 comments

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

ggwc82 avatar Dec 12 '18 12:12 ggwc82

The params don't carry over mount. I think it should be possible, labelling as a feature request.

dblock avatar Dec 13 '18 03:12 dblock

Would implementing this not cause some potential breaking changes? Generally I would have thought to use the SharedParams helper approach for these cases.

myxoh avatar Dec 13 '18 10:12 myxoh

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?

dblock avatar Dec 14 '18 00:12 dblock