How to define multiple allowed types when one of them is array of hash?
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
Currently I got an endpoint with params like this:
params do
requires :content, types: [String, Hash]
end
When content can be array of hash also ([{"type": "paragraph", "children": [{"text": "test"}]}]), how are we gonna define it?
params do
requires :content, types: [String, Hash, Array[Hash]]
end
with the code above, params[:content] will be
#<Hashie::Mash #<Hashie::Mash children=#<Hashie::Array [#<Hashie::Mash text="test">]>
which I don't think is correct? It looks like a hash of array. My expectation is params[:content] will be this:
[#<Hashie::Mash children=[#<Hashie::Mash text="test">] type="paragraph">]
because with that I can store params[:content] directly to a JSON column in the DB.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files, tests, or entry points; start by locating Grape's parameter handling for the types: option and its conversion of array-of-hash values. Done means determining whether the requested declaration preserves the expected array of Hashie::Mash objects for JSON storage, and documenting or correcting that behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100