Grape Entity expose to delegate/forward to other object

When using Grape Entity, sometimes we want to expose a few fields from an inner/related object. We can simply do this by:expose(:bar) { |entity| entity.foo.bar }However if many fields needs this treatment, this can get very repetitive. Is there a way to define delegation / forward so a bunch of expose all are associated with another object?...Read more

grape-api - Force empty string to set values to null

I am creating an API endpoint which contains a file upload field and a few string fields. My goal is to allow clients to clear values on those string fields, i.e. the DB should persist these values as null.However, due to the fact that the request may contain files, the client should be setting the Content-type header to multipart/form-data. This implies that client cannot send a representation of "null", but can only send an empty string to indicate the intent of clearing the value for a given string field.Is there a way for grape-api library ...Read more

grape - Uploading multiple files in the same request

I need to create a POST where I can upload multiple files in the same request, but I don't know how to write this with grape. Right now to upload just one file this is what I'm doing and It's working fine:desc 'Creates a new attachment.'params do requires :file, :type => Rack::Multipart::UploadedFile, :desc => "Attachment File."endpost do attachment = Attachment.new attachment.file = ActionDispatch::Http::UploadedFile.new(params[:file]) attachment.save! attachmentendSwagger shows me this:I was thinking of doing something like this:de...Read more

grape - How do I map the JSON body of a GET request to a parameter?

I have the following definition in my endpoint:params do requires :entities do requires :id, type: String optional :email, type: String optional :phone, type: String end end post "test" do endNote this only works as a POST request and the following CURL will work:curl -XPOST localhost/test -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{ "entities": [{ "id": 3, "email": "test@abc.com" }] }'However, the moment I change the declaration to get "test" instead of post, the corresponding c...Read more