You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The length validator will raise an ArgumentError at runtime if min, max or is conditions aren't met.
For instance
describe'/negative_max'dolet(:app)doClass.new(Grape::API)doparamsdorequires:list,type: [Integer],length: {max: -3}endpost'negative_max'endendcontext'it raises an error'doitdoexpect{post'negative_max',list: [12]}.toraise_error(ArgumentError,'max must be an integer greater than or equal to zero')endendend
This test will succeed but it doesn't seem right since its caused by the way its declared and not by the input. I think this kind of error should occur a loading time like when we're coercing values, except and default values.
For instance, this will raise an error when the api is loaded.
describe'only integers'dosubject{Class.new(Grape::API)}context'values are not integers'doit'raises exception'doexpectdosubject.params{optional:numbers,type: Set[Integer],values: %w[ab]}end.toraise_errorGrape::Exceptions::IncompatibleOptionValuesendendend
IMO this early exception helps the users to fix the issue right away instead of waiting at runtime when its already too late.
I'm working on something to initialize validators at loading time instead of runtime. The validators are saved per API and their state won't change at runtime since its just validating the input.
The text was updated successfully, but these errors were encountered:
ericproulx
changed the title
LengthValidator will raise ArgumentException at runtime if options are not satisfied
LengthValidator will raise ArgumentException at runtime if conditions aren't met
Dec 29, 2024
The length validator will raise an ArgumentError at runtime if
min
,max
oris
conditions aren't met.For instance
This test will succeed but it doesn't seem right since its caused by the way its declared and not by the input. I think this kind of error should occur a loading time like when we're coercing values, except and default values.
For instance, this will raise an error when the api is loaded.
IMO this early exception helps the users to fix the issue right away instead of waiting at runtime when its already too late.
I'm working on something to initialize validators at loading time instead of runtime. The validators are saved per API and their state won't change at runtime since its just validating the input.
The text was updated successfully, but these errors were encountered: