Grape-Entity as params type for Grape

1,138 views
Skip to first unread message

Gonzalo Melo

unread,
Dec 16, 2014, 2:33:51 PM12/16/14
to ruby-...@googlegroups.com
Hello,

I am trying to set a Grape-Entity as a type for params on a Grape POST so that it gets sent on the request body.

For example on the example app https://github.com/swagger-api/rails-petstore I have:

    # post /pet
    desc "Add a new pet to the store", {
      nickname: "addPet",
      http_codes: {
        405 => "Invalid input",
      }
    }
    params do
      requires :body, type: Entities::Pet
    end
    post :pet do
      pet = ::Pet.new(params[:body])
      present pet, with: Entities::Pet
    end

module Entities
  class Pet < Grape::Entity
    expose :id, documentation: { type: "integer", required: true, desc: "unique identifier for the pet" }
    expose :category, using: Entities::Category, documentation: { type: "Category" }
    expose :name, documentation: { type: "string", required: true }
    expose :photoUrls, documentation: { type: "string", is_array: true }
    expose :tags, using: Entities::Tag, documentation: { type: "Tag", is_array: true }
    expose :status, documentation: { type: "string", desc: "pet status in the store", enum: [ "available", "pending", "sold" ] }
  end
end

When I test the post method through Swagger I get the response: "{ body is missing }".

On the version 0.9.0 of Grape, is it possible to set a Grape-Entity as type of a param?

Thanks!

Daniel Doubrovkine

unread,
Dec 17, 2014, 8:13:04 AM12/17/14
to ruby-...@googlegroups.com
It's not currently possible. I think what you're asking is exactly https://github.com/intridea/grape/issues/827. Add your comments.

--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Reply all
Reply to author
Forward
0 new messages