Open raderio opened 5 years ago
I'd see the dsl as this:
oneOf("only one of arrayOne or arrayTwo can be present!",{
MyData::arrayOne{
minItems(1)
}
MyData::arrayTwo{
maxItems(0)
}
},{
MyData::arrayOne{
maxItems(0)
}
MyData::arrayTwo{
minItems(1)
}
})
This creates a validation error, if not only one of the rules passed. This specific validation ensures that only one of the specified arrays have any items. I'd set both of the default values to an empty array, and after I parsed it from say json only the array that was present in the input will contain any items.
anyOf("custom message",{
//first validation
},{
//second validation
})
This throws if none of the validations passed.
This may also be just enough for:
oneOf
,anyOf
as you can use validation results to check which type it matches. (allOf
is supported by the class structure). You do need to use nullable fields, but it is a small price for this feature.
For example a login field can be a phone or and email.