You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
params do
optional :photos, type: Array do
optional :id, type: Integer
optional :photo_path, type: String
optional :width, type: Integer
optional :height, type: Integer
optional :description, type: String, default: ""
end
optional :videos, type: Array do
optional :id, type: Integer
optional :video_path, type: String
optional :width, type: Integer
optional :height, type: Integer
optional :description, type: String
optional :persistent_id, type: String
end
end
post '/array' do
end
When the params like below: {"videos"=>[{"description"=>"", "height"=>"111", "id"=>"22", "video_path"=>"path", "width"=>"1111"}], "photos"=>[{"id"=>"2222", "photo_path"=>"path", "width"=>"222"}]}
it pass.
But, if the params like below: {"videos"=>[{"description"=>"", "height"=>"111", "id"=>"22", "video_path"=>"path", "width"=>"1111"}]}
it returned the error: no implicit conversion of String into Integer.
Then I comment the default value.
params do
optional :photos, type: Array do
optional :id, type: Integer
optional :photo_path, type: String
optional :width, type: Integer
optional :height, type: Integer
optional :description, type: String#, default: ''
end
optional :videos, type: Array do
optional :id, type: Integer
optional :video_path, type: String
optional :width, type: Integer
optional :height, type: Integer
optional :description, type: String
optional :persistent_id, type: String
end
end
post '/array' do
end
The params validation like this.
When the params like below:
{"videos"=>[{"description"=>"", "height"=>"111", "id"=>"22", "video_path"=>"path", "width"=>"1111"}], "photos"=>[{"id"=>"2222", "photo_path"=>"path", "width"=>"222"}]}
it pass.
But, if the params like below:
{"videos"=>[{"description"=>"", "height"=>"111", "id"=>"22", "video_path"=>"path", "width"=>"1111"}]}
it returned the error:
no implicit conversion of String into Integer.
Then I comment the default value.
The params keep like before:
it passed.
It seems that if there is a default value in
Array
, this array must be passed.It's a bug or feature?The text was updated successfully, but these errors were encountered: