ruby-grape / grape

An opinionated framework for creating REST-like APIs in Ruby.
http://www.ruby-grape.org
MIT License
9.89k stars 1.22k forks source link

Nested Param Helpers - using *:use* inside a Grape::API::Helper #1391

Open eidge opened 8 years ago

eidge commented 8 years ago

Hello guys,

I'm trying to reuse param definition in my helpers but the use :param method doesn't seem to work inside Grape::API::Helpers.

The use case is I have two different models that include a third model like this:

module Animal
  extend Grape::API::Helpers

  params :animal do
    requires :mammal, Boolean
    requires :other_fields, String
  end
end

module Dog
  extend Grape::API::Helpers

  params :dog do
    requires :breed, String
    requires :animal do
      use :animal
    end
  end
end

Unfortunately inside Dog grape complains that it cannot find params for :animal. I've tried extending and including the Animal module with no success.

Also the helpers method is not included by Grape::API::Helpers.

Is there any way I can do this?

dblock commented 8 years ago

I will leave this open as a feature request. It's possible that the only thing missing is that helpers method, but generally the documentation tells you to declare reusable parameters inside a helpers block. I would go from there.

eidge commented 8 years ago

That makes sense. Our API is big enough to have the same params repeated in more than one endpoint though (think filters, embeddable models, etc..)

tanduong commented 7 years ago

Hi guys, do we have progress on this one?

dblock commented 7 years ago

Maybe you can help @tanduong?