Questions tagged [grape-entity]

grape-entity - Entities - a simple Facade to use with your models and API - extracted from Grape.

grape-entity - Entities - a simple Facade to use with your models and API - extracted from Grape.

https://github.com/intridea/grape-entity

51 questions
9
votes
1 answer

Grape error handling strategy?

I am using Grape and Rails to create a REST API. I have the basic architecture in place and I am looking for places to 'clean' things up. One of those places is the error handling/processing. I am currently rescuing errors in the root.rb (GRAPE::API…
mfunaro
  • 574
  • 6
  • 23
7
votes
0 answers

Grape entities and Single table inheritance

Let's say i have Base class "Attachment < ActiveRecord::Base" and 2 child classes "Attachment::Video < Attachment" , "Attachment::Image < Attachment". present Attachment.all, with: API::Entities::AttachmentEntity But i want to use different…
Yegor Razumovsky
  • 902
  • 2
  • 9
  • 26
7
votes
2 answers

Grape: required params with grape-entity

I'm writing an API server with grape and i choose to use grape-entity because it has the capability to auto generate the documentation for swagger. But now i have a problem when i set a param as required. Because grape don't validate that the param…
Spike886
  • 609
  • 8
  • 23
5
votes
1 answer

How to connect Rails Grape API with Ember reflexive model

I'm having a problem with connecting Json payload from Grape (serialized with Grape entity) with Ember reflexive model. Model looks like this: Category = DS.Model.extend { name: DS.attr 'string', children: DS.hasMany 'category', inverse:…
szsoppa
  • 113
  • 5
3
votes
0 answers

API documentation - How to give response schema using rabl with grape-api

We are using grape for APIs and grape-rabl for responses in our Rails application. Now we are in the process of documenting the APIs, and we use grape-swagger for it. But we do not know how to document the response schema for the API endpoints. The…
sureshprasanna70
  • 1,043
  • 1
  • 10
  • 27
3
votes
1 answer

Add constant attribute to Grape entity

I'm trying to build a set of APIs using Rails and Grape. The User model like below: { "email": "foo@bar.com" "name": "Foo Bar" } Now, at the API presentation level, I want a user object be like: { "object": "User" "email":…
fengye87
  • 2,433
  • 4
  • 24
  • 41
3
votes
1 answer

Passing argument to grape-entity modules

The requirements of my project are now forcing me to passing parameters to nested entities. I have an entity A and an entity B that show some information and needs the A identifier on the system to build them. module Services module Trips class…
3
votes
1 answer

Resolve all ActiveRecord Associations using Grape::Entity (SQL Join)

Question I've been messing with ruby, grape, grape-entity, and activerecord. Everything is going swimmingly however I can't see to get the desired result from grape-entity when using the using keyword for a expose item. My goal is to basically…
abc123
  • 17,855
  • 7
  • 52
  • 82
2
votes
1 answer

Share desc and type across Grape and Grape Entity gems

What I'm trying to do is to reuse type and description across grape and grape-entity gems. In the documentation I read the following: You can use entity documentation directly in the params block with using: Entity.documentation. module API …
Francesco Meli
  • 2,484
  • 2
  • 21
  • 52
2
votes
0 answers

How to expose associated record using grape entity

Hi I have a model Event and this event has one Setting. e.g class Event < ActiveRecord::Base has_one :setting end class Setting < ActieRecord::Base belongs_to :event end My event entity looks some thing like module Entities class…
2
votes
2 answers

How to use rails routes in grape entities?

I have an image entity exposes a url to a rails controller. The controller shows the image conforming to some business logic. (ex it deletes the image if everybody in the group viewed it,...) expose :media_url do |message, options| #TODO…
Boti
  • 3,275
  • 1
  • 29
  • 54
1
vote
0 answers

Inheritance does not properly work with grape-entity >= 0.5.0

module API module V1 module Entities class A < Grape::Entity expose :k expose :l expose :status def status 'HI' end end end end end module API module V101 module…
1
vote
1 answer

How to expose Hash in Grape Entity and not use `using`

I have this entity. class EmpEntity < Grape::Entity expose :id expose :age expose :name do expose :firstname expose :lastname expose :nickname end end And I take a result like this. data = { id: 1, age: 18, name: { …
1
vote
1 answer

Grape Entity for a Hash with string keys not working

I am using 'grape-entity', '~> 0.7.1' I have a hash in the format: temp_data = [{sheet_index: 0, other_names: []},{'sheet_index' => 1, 'other_names': ['a']}] And I have the following entities class Sheet < Grape::Entity expose :sheet_index,…
VXCSL
  • 37
  • 8
1
vote
0 answers

How to use nested exposure when referencing the same model twice?

I have a grape entity for a Contact model, which references User model twice: class Contact < ApplicationRecord belongs_to :user, foreign_key: :user_id belongs_to :contact, class_name: 'User', foreign_key: :contact_id def entity …
1
2 3 4