grape icon indicating copy to clipboard operation
grape copied to clipboard

Validations not working for parameters 3 level deep

Open tabz24 opened this issue 9 years ago • 5 comments

Any type of validations are not working for the third_level, the parameters under the third level (id, quantity and groupid) can be null or can have any data types. And the parameters under the second_level works totally fine with all the validations.

  requires :first_level, type: Hash do
    optional :second_level, type: Array do
      requires :id, type: Integer, desc: "id"
      requries :value, type: Float, desc: "value"
      optional :third_level, type: Array do
        requires :id, type: Integer, desc: "timeslot id"
        requires :quantity, type: Float, desc: "quantity"
        optional :groupid, type: Integer, desc: "diethabit id"
      end
    end
  end
end

In the above example, if send the below parameters they are getting accepted.

  "first_level": {
    "second_level": [
      {
        "id": 1,
        "value": 0.5,
        "third_level": [
          {
            "quantity": "some string value",
            "groupid": false
          }
        ]
      }
    ]
  }
}

Required id is missing, quantity have some string value and groupid is a boolean value. This is happening only on 3 levels deep and working fine on above levels. Let me know if you need any more details. Grape Version 0.19.2 Ruby Version 2.4.1

tabz24 avatar Nov 24 '17 07:11 tabz24

You should turn this into a spec, please. We have a lot of tests with many levels, I am pretty sure.

dblock avatar Nov 26 '17 02:11 dblock

I added a spec for this case (https://github.com/ruby-grape/grape/pull/1793) and it seems that it's validating just fine in deeper levels of nested params.

Morred avatar Sep 23 '18 05:09 Morred

@tabz24 Care to compare to what you have?

dblock avatar Sep 23 '18 13:09 dblock

Thanks @Morred !

dblock avatar Sep 23 '18 13:09 dblock

I'm closing this. Spec looks good for this exact scenario. @tabz24 Please make sure you're trying against the latest grape and reopen if this is an issue with a better repro.

dblock avatar Dec 22 '19 16:12 dblock