Skip to content

Fail on (or get list of) unknown parameters #2241

Open
@lvonk

Description

@lvonk

Hi,

Prior to #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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions