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.
# 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?