-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add length validator #2437
Add length validator #2437
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, some nits below, plus:
- Add README documentation.
- Add tests for zero.
- Handle/add tests for min = max, min > max and min > max. Probably needs to error on some.
This validator validates that the length of the parameter (if the parameter supports `#length` is within the specified limits).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs a bit more work around types.
- Length is not supported on types such as Integer, and should fail accordingly. Needs tests.
- Semantically,
length
andsize
aren't the same thing, even though hashes for example support both length and size. Should we have interchangeablelength
andsize
validators? - What happens with comparable types, e.g. when I say
min: 'xyz'
? - Should this be a more generic validator that works on anything
Comparable
?
makes sense should an argument error be raised in this case 🤔
While I agree, I see that in ruby both are interchangable so maybe an alias for length validator 🤔
IMO that won't make sense. I can restrict the |
Yes, I think that would be the correct behavior. |
Yes, I think anything being sent that doesn't have
I think I'd like to write |
I have restricted the validator to only validate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can leave the size/length for a future PR. But I am not sure restricting to Array and String is correct.
I noticed the |
the problem is when an empty array is passed as the parameter the validator receives |
Why? I think |
could you maybe elaborate on your concern 🤔 . My line of thinking is that a type with a variable "length" (number of contained elements) like |
Either way, if a client sends an empty array, the server is expected to receive an empty array ( |
Take a typical rollup API that receives some stats for a given, say SKU.
I choose a hash because I don't want sku's to repeat themselves, and with the length validator I'd be able to limit how many The other concern is that if we restruct WDYT? |
Btw, thank you for hanging in here with me! Really appreciate your time and work on this. |
Ah makes sense ✅
😅 wasn't sure if this is the library stance or not 🙈 |
|
Merged, thank you! Want to try to implement |
😅 For now no. I'll try the next time I have some time to spare. |
@dblock will you be releasing 2.1.0 soon ? |
@dhruvCW I'll take are of it this week |
This validator validates that the length of the parameter (if the parameter supports
#length
is within the specified limits).I've also added the
min_length
andmax_length
limits to the attribute documentation so that they can be used to specify the limits for an array type in swagger.