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

declared(params) - "no implicit conversion of Symbol into Integer" when receiving blank array #2141

Open
jacek213 opened this issue Dec 17, 2020 · 3 comments
Labels

Comments

@jacek213
Copy link

jacek213 commented Dec 17, 2020

  1. I have an optional array parameter. In some cases I want it to be blank, but if the items are passed, they must match the schema inside.
params do
  optional :outline, type: Array do
    requires :x
    requires :y
  end
end
  1. I do a PATCH request and send {"outline": []} payload.
  2. Received params =>{ "outline"=>[""] } - here is the first question - why an empty string inside an array? I have a feeling that I've struggled with that a few years back, but don't remember what was the cause.
  3. declared(params) raises no implicit conversion of Symbol into Integer
@dblock
Copy link
Member

dblock commented Dec 17, 2020

What content-type are you using? This should work with content-type: JSON, but if you supply things in multipart or query params Rack can't figure it out.

@jacek213
Copy link
Author

@dblock thanks for a quick response.

Content-type is JSON.

module API
  class Base < Grape::API
    prefix :api
    content_type :json, 'application/json; charset=utf-8'
    format :json
    formatter :json, Grape::Formatter::ActiveModelSerializers

    ...
end

@dblock
Copy link
Member

dblock commented Dec 18, 2020

That defines the response, not the request. How do you PATCH/POST data?

@dblock dblock added the bug? label Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants