-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
How to define multiple allowed types when one of them is array of hash? #2150
Comments
This should work. Are you POSTing content-type=JSON? Turn this into a spec otherwise so we can see what's going on. |
Yes I'm posting with content-type = application/json class Testing < Grape::API
namespace :testing do
params do
requires :content, types: [String, Hash, Array]
end
post do
declared(params)[:content]
end
end
end
If I modify params to requires :content, types: [Array, String, Hash] Then with the same above request I get correct result:
But when I request with
|
Sounds like a bug. Turn it into a spec, maybe try fixing it? |
Hi 👋 I've just tested this potential bug with the last Grape version and it's working fine 👍 I'm always obtaining the expected response [{"type"=>"paragraph", "children"=>[{"text"=>"Hahaha"}]}] |
@jcagarcia Thanks. Before we close we should be sure that 1) it was broken when the bug was reported (whichever version shipped last by Jan 14, 2021), 2) that we can bisect it to a specific fix/pull request, 3) that we have a spec for it. |
Currently I got an endpoint with params like this:
When content can be array of hash also (
[{"type": "paragraph", "children": [{"text": "test"}]}]
), how are we gonna define it?with the code above,
params[:content]
will bewhich I don't think is correct? It looks like a hash of array. My expectation is
params[:content]
will be this:because with that I can store
params[:content]
directly to a JSON column in the DB.The text was updated successfully, but these errors were encountered: