grape icon indicating copy to clipboard operation
grape copied to clipboard

Dependent Params (given) with different value matching

Open daniel-archer-hs opened this issue 7 years ago • 4 comments

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)

daniel-archer-hs avatar May 05 '17 23:05 daniel-archer-hs

Can you explain what error you're seeing? This test looks to me to be doing what you describe.

rnubel avatar May 06 '17 05:05 rnubel

@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

murbano83 avatar Apr 19 '18 09:04 murbano83

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

palpandiR avatar Apr 03 '20 01:04 palpandiR

Same as https://github.com/ruby-grape/grape/issues/1885

tyleralves avatar Feb 12 '21 19:02 tyleralves