Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional Array validate #928

Closed
u2 opened this issue Feb 15, 2015 · 2 comments
Closed

optional Array validate #928

u2 opened this issue Feb 15, 2015 · 2 comments

Comments

@u2
Copy link
Contributor

u2 commented Feb 15, 2015

The params validation like this.

            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 keep like before:

{"videos"=>[{"description"=>"", "height"=>"111", "id"=>"22", "video_path"=>"path", "width"=>"1111"}]}

it passed.
It seems that if there is a default value in Array, this array must be passed.It's a bug or feature?

@dm1try
Copy link
Member

dm1try commented Feb 15, 2015

It's definitely a bug. Seems related to #615.
It's kinda tricky to fix without refactoring "params_scope/validation" sources.

@dblock
Copy link
Member

dblock commented Feb 26, 2015

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants