grape
grape copied to clipboard
given arg_one require arg_two of array -> auto passes empty string to array when empty array is given
desc 'Breaking Grape', security: [jwt: []], success: { code: 201, model: SomeRepresenter }
params do
with documentation: { param_type: 'body' } do
requires :arg_one, type: String, values: %w[one two three]
given arg_one: ->(type) { type == 'two' } do
requires :arg_two, type: Array[String], allow_blank: false
end
end
end
end
POST to that endpoint with { "arg_one": "two", "arg_two": [] }
and somehow the array will contain an empty string. Fails both with allow_blank false and allow_blank.
How does the empty string end up there? How does it not fail when allow_blank false?
- Does it work if
typeis not an array (e.g.String)? - Does it work without
given? - Confirm the version of Grape and Rack, could be related to https://github.com/ruby-grape/grape/issues/2298.
Probably a bug in some combination. Would appreciate a unit test that reproduces the problem in a pull request.