These are chat archives for dry-rb/chat

2nd
Nov 2018
Chris Richards
@cmrichards
Nov 02 2018 12:04

Hi, is it possible to validate the keys and values of a hash like this? These are the posted params.

{
 "sample_tests"=>{
   "1"=>{"sample_id"=>149, "lod"=>"200.0", "lod_top_unit_id"=>2, "lod_bottom_unit_id"=>1, "top_unit_id"=>2}, 
   "2"=>{"sample_id"=>149, "lod"=>"101.0", "lod_top_unit_id"=>2, "lod_bottom_unit_id"=>1, "top_unit_id"=>2}, 
   "3"=>{"sample_id"=>149, "lod"=>"101.0", "lod_top_unit_id"=>2, "lod_bottom_unit_id"=>1, "top_unit_id"=>2},
   ..... repeated
  }
}

This is all I have right now. :

      Schema = Dry::Validation.Params do
        required(:sample_tests).filled
      end

I need to validate the part that goes {"sample_id"=>149, "lod"=>"200.0", "lod_top_unit_id"=>2.....

There is no mention of a repeated key like this in the dry-types docs. Maybe I need to convert the hash into a simple array before validating?
Piotr Solnica
@solnic
Nov 02 2018 16:30
@cmrichards not possible yet, it'll be supported in dry-schema