-
Notifications
You must be signed in to change notification settings - Fork 468
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
Revamp array validator #259
Conversation
The name ArrayValidator is a bit confusing as the type of the argument value is not an array
Nice PR! |
end | ||
|
||
def self.build(param_description, argument, options={}, block) | ||
if argument == Array && !block.is_a?(Proc) |
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.
should be better to only allow lambda for code safety ?
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.
block is eventually a block of nested param. it is not a lambda.
currently this validator does not support nested object we just skip this param. it will be handle by NestedValidator
@iNecas any thoughts on this PR ? |
Nice one! Could you add some notes to the readme for the documentation purposes? |
Validates that argument value is an array It allow to specify additional validation on array elements via param description options
@iNecas do the readme updates match your expectation? |
They do, thanks for the notification: would be nice if github notified about new commits in the PR,merging now. |
The changes were released as part of the 0.2.3 release. Thanks for your contribution! Let the code be with you! |
Introduce a new ApiPie Array validator for more flexible validations
The following validation are currently supported
Validates all items of an array has the specified type
Validates all items are in a set of values
example 1
Assert
hits
must be an array of integer valueexample 2
Assert each items of
colors
to be in the enumerationexample 3
The load of enum can be deferred until needed. this useful when the enum may changes
example 4
Assert
things
is an array of any typeNotes
This is a first try for a more consistent validator dsl. I want a uniform way to express constraints on parameters. The validators are build around a set of core types
String
,Number
,Boolean
,Array
andHash
it would would simple to extend our validations by adding additional constraints
or by defining custom validators.
The validator class would be found by naming convention