one
$one
A constraint that checks whether exactly one of the provided processors returns a defined value.
Returns the single defined value, or throws if zero or more than one succeed. Be careful to not use this in a situation where the provided processors may require late-resolved values! This works best in finalizers, validators, or in opaque schema transformers.
See $exclusive if you want to check for truthiness instead of a defined value.
Parameters
processors(Array<ProcessorSpec>, required): Array of processor specifications, exactly one of which must return a defined value.
Example
// Exactly one authentication method must be configured
new Schema('object').validator({
$one: [
{$property: 'apiKey'},
{$property: 'oauth'},
{$property: 'basicAuth'},
]
})