schema icon indicating copy to clipboard operation
schema copied to clipboard

min/max/assert not applyed on default value

Open ncou opened this issue 5 years ago • 2 comments

Hi,

It seems the controles like min/max or assert() are not appplyed on the default value. This could be problematic if the default value is dynamic.

In my use case i should controle the application key is a hexa 64 chars, and by default we use the environement variable APP_KEY.

I also tryed to move the min/max/assert function after the chained ->default(), but the result is the same :(

return Expect::structure([ 'key' => Expect::xdigit()->min(64)->max(64)->default(env('APP_KEY')), ]);

Is that a bug or an "expected" behaviour ?

Keep up the good work.

ncou avatar Oct 23 '20 05:10 ncou

Sometimes the default value doesn't really follow the rules, for example Expect::string() has default value null, but it doesn't allow null. So it's more like expected behaviour.

dg avatar Dec 18 '20 11:12 dg

Yes you are right, but it seems more logic to enforce the rules if the default value is explicitely defined. And have an error in the illogical cases like Expect::string()->default(123)

ncou avatar Dec 18 '20 12:12 ncou