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
I'm trying to write a set of classes to validate the json payload of some restful APIs.
So far I'm able to validate against rules for any of the data values, but I'm becoming crazy when trying to validate optional fields that are in fact required to be of a specified type if they are present. In addition if what I'm checking is an optional array, every child attribute has to be required whenever the parent array is included in the payload.
In the above example I want sender to be an optional array, required to be an array when it is filled. If sender is null, sender.name and sender.address would not be required, otherwise they need to be validated.
Every rule is a keyNested check chained to the object $validator in the master class and virtually becomes something like
I'm trying to write a set of classes to validate the json payload of some restful APIs.
So far I'm able to validate against rules for any of the data values, but I'm becoming crazy when trying to validate optional fields that are in fact required to be of a specified type if they are present. In addition if what I'm checking is an optional array, every child attribute has to be required whenever the parent array is included in the payload.
What I have done so far:
Master validator class
Example of rules sub-class
In the above example I want
sender
to be an optional array, required to be an array when it is filled. Ifsender
isnull
,sender.name
andsender.address
would not be required, otherwise they need to be validated.Every rule is a
keyNested
check chained to the object$validator
in the master class and virtually becomes something likeThe text was updated successfully, but these errors were encountered: