khrt / Raisin

Raisin - a REST API micro framework for Perl 🐫 🐪
61 stars 29 forks source link

Optional params that fail type constraints do not return "Invalid Parameters" response. #85

Closed mschout closed 4 years ago

mschout commented 4 years ago

It appears that if you have an optional param that has a type constraint (such as Enum from Types::Standard, or enum() from Moose::Util::TypeConstraints, then you will not get an Invalid Parameters response.

If the param is instead changed to requires, then you get the expected Invalid Parameters response.

For example

params(
  optional('foo', type => Enum[qw(bar baz)])
)
get sub {
...
}

If called with foo=invalid, then a 200 OK response is received.

The problem is in Raisin::Request::prepare_params() I have a patch with a test case that I will submit as a PR shortly.