Fail on (or get list of) unknown parameters
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
Hi,
Prior to https://github.com/ruby-grape/grape/pull/2189 the params object also contained the unknown parameters that weren't described in the route definition.
For instance:
requires :name,
type: String,
as: :company_name,
optional :bar,
type: String,
If then the following params where passed:
{
"name": "Grape",
"baz": "Bar",
}
The params object contained:
{
"company_name": "Grape",
"baz": "Bar",
}
This way our code could fail on the fact that "baz" was passed in but doesn't exist. This is helpful because most probably the consumer of the api wanted to pass in bar which is an optional field (this is a frequent occurring scenario btw in our production systems). I think it is good practice to fail fast in scenarios where parameters are passed in that are "unknown".
After this fix there is no easy way anymore to get these unknown parameters since declared filters them out, declared(params) yields to:
{
"company_name": "Grape",
}
Merging them with the original params is also not an option because then we also get the name parameter back again.
So my question is: Is there a way in grape to get the "unknown parameters" passed in? Or let Grape fail when such a parameter is passed?
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 by reviewing pull request 2189 and the behavior of declared(params), especially how aliases such as name and company_name are handled. The work is done when Grape either exposes unknown parameters separately or rejects them, without reintroducing aliased input names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100