I have definition of api endpoint below:
params do
requires :ids, type: Array, desc: 'Array of group ids'
end
I can't pass an array form the UI generated by Swagger. If I enter [1, 2, 3, 4]
or ids%5b%5d=1&ids%5b%5d=2&ids%5b%5d=3
then both become invalid. If I call the api from spec with an array it works. My client would like to try the whole api from Swagger, so I would like a solution which works with Swagger UI.
my solution for all cases:
params do
requires :ids, type: Array[Integer], desc: 'Array of group ids',
coerce_with: -> { |val| (val.is_a?(Array) ? val : val.to_s.split(',').map(&:strip)).map(&:to_i) }
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With