grape
grape copied to clipboard
Dependent Params (given) with different value matching
It seems I'm running into an issue where if I have multiple given
blocks testing the same parameter, the value validation for those dependent parameters is conflicting. Here's my example:
params do
requires :type, type: String, desc: 'Type', values: ['FRONT_CAMERA', 'REAR_CAMERA']
given type: ->(val) { val == 'FRONT_CAMERA' } do
requires :resolution, type: String, desc: 'Resolution', values: ['20x20']
end
given type: ->(val) { val == 'REAR_CAMERA' } do
requires :resolution, type: String, desc: 'Resolution', values: ['1080x1080']
end
end
(Pardon the falsified info)
Can you explain what error you're seeing? This test looks to me to be doing what you describe.
@rnubel in my case the same scenario if I pass FRONT_CAMERA
on the type, validates both, the FRONT_CAMERA
and REAR_CAMERA
and has to be only FRONT_CAMERA
I am having same issue. i am using grape grape-1.2.5.
params do
optional :shelf_id, type: Integer
given :shelf_id do
requires :bin_id, type: Integer
end
optional :category, as: :type
given type: -> (val) { val == 'foo' } do
requires :description
end
optional :Authorization, type: String, documentation: { param_type: 'header' }, default: "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMTdmMGY1YjUtZWNmYS00MTJjLWJlODktYWIyYmE2NTU3YjhlIiwidHlwZSI6InVzZXIiLCJleHAiOjE1ODU4Nzg2Nzh9.L2HGJoYq2-wwKDwZqTmNXj5M-gt24j0DsP1NsfEJV28"
end
get '/testing', http_codes: [
[200, 'Ok'],
[400, 'Bad Request'],
[401, 'Unauthorized'],
[404, 'Not Found'],
[500, 'Internal Server Error']
] do
present :status, 200
end
Same as https://github.com/ruby-grape/grape/issues/1885