Support custom enumerable types and coercion, or arrays of custom type
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
Imagine I wanted to specify the following parameter:
optional :groups, type: GroupParamList, values: GroupParamList.parse(['variation'])
Where GroupParamList includes Enumerable. This works fine, until we coerce the values as above.
In validate_value_coercion, grape handles Arrays, but not enumerable types:
coerce_type = coerce_type.first if coerce_type.is_a?(Array)
As a result, grape tries to check if the enumerated type inside GroupParamList is the same as GroupParamList, which doesn't work.
Alternately, it would be great if grape could support arrays of custom types, as such:
optional :groups, type: [GroupParam]
But, it doesn't seem coerce/parse the parameters in the array (the groups param ends up as an array of strings in the above case), ignoring the custom class specified. And, if a value coercion is specified, it fails whether or not the values are specified as string (because IncompatibleOptionValues is raised), or as GroupParams, because the raw param strings will be compared to them.
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
Start with validate_value_coercion and reproduce the GroupParamList examples from the issue, including an array of custom types. Trace how enumerable types, array element types, coercion, and values are compared. Done means custom enumerable parameters and arrays of custom types are coerced or parsed consistently without incorrect type comparisons or IncompatibleOptionValues.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100