How to use Entity for describing params when the entity has validations.

17 kali dilihat
Langsung ke pesan pertama yang belum dibaca

Дмитрий Луцко

belum dibaca,
11 Jan 2020, 08.10.1211/01/20
kepadaGrape Framework Discussion
Hi,
Maybe I'm using these tools in the wrong way. But I want to specify a model (Entity) with a set of fields, types, validations and use it for formatting output and for describing inputs. And when I reusing Entity for describing inputs I got an error.

I'm trying to use Grape with Rails 6:
* grape (1.3.0)
* grape-entity (0.7.1)
* grape-swagger (0.33.0)
* grape-swagger-entity (0.3.3)
* grape-swagger-rails (0.3.1)

I use Entity.documentation to specify params:
module Map
 
module Locations
   
class Create < Grape::API
      resources
:locations do
        desc
'Create a location.'


       
params do
          requires
:all, using: Entities::Loc.documentation
       
end


        post
do
          locations
= ::Location.create!(declared(params))
          present locations
, with: Map::Entities::Loc, root: :location
       
end
     
end
   
end
 
end
end

When I have a simple entity, it works fine. Here is a simple entity:
module Map
 
module Entities
   
class Loc < Grape::Entity
      expose
:name, documentation: { type: 'String' }
   
end
 
end
end

But when I add validation
expose :status, documentation: { type: 'String', values: ['new', 'deleted'] }

I'm starting to get error 
Uncaught exception: class or module required

gems
/grape-1.3.0/lib/grape/validations/params_scope.rb:435:in `is_a?'

Help me please to find a solution, how to reuse Entity in the right way.
Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru