Hi,
I've recently started work on updating our codebase to the current versions of grape
, grape-entity
and grape_logging
.
Whereas one of our APIs works with grape
1.2.4, grape-entity
0.7.1 and grape_logging
1.8.1, it doesn't with the latest versions.
The API in question defines some params
that are entities as required. No matter what params are passed to the call, a 400 response code is returned with an error indicating that each required entity param is invalid.
I have been assured that grape 1.3.1 is compatible with grape-entity 0.8.0.
Here is the abbreviated code:
class RegistrationAPI < Grape::API
resource :registration do
desc 'Register a new user',
entity: Entities::User,
http_codes: [[400, 'Bad Request', Entities::Error],
[405, 'Method not allowed', Entities::Error],
[422, 'Unprocessable Entity', Entities::Error]]
params do
requires :user, type: Entities::UserRegistration
requires :questions, type: Entities::Risk::Questions
end
post '/' do
# Never gets this far
end
end
end
module Entities
class UserRegistration < Grape::Entity
expose :name, documentation: { required: true, type: 'String', desc: 'The name of the user' }
# and so on
end
end
module Entities
module Risk
class Questions < Grape::Entity
root 'questions'
expose :order, documentation: { required: true, type: 'Integer', desc: 'The order' }
expose :text, documentation: { required: true, type: 'String', desc: 'The question' }
expose answers, using: Risk::Answers, documentation: { required: true, type: 'Entities::Risk::Answers', desc: 'The available answers to the question' }
def order
object.order.to_i
end
end
end
end
{"error"=>"user is invalid, questions is invalid"}
Whilst I've started to attempt to debug this problem, I would be grateful if anyone could offer me some suggestions as to what could be causing these errors.
Keith
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-grape/75632cbe-3e8c-46f8-83e1-4b7c78d96dc8%40googlegroups.com.