title: Require at least one non-null child in joi object that allows null
body: <p>I am defining a <a href="https://github.com/hapijs/joi/blob/master/API.md#anyvalidatevalue-options-callback" rel="nofollow noreferrer">Joi</a> schema for an object with some fields for social profiles. The goal is to ensure that all of the fields are present and that at least one of them is a non-empty string, but to allow the others to be <code>null</code>.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>const socialUrl = joi.string().min(1).alphanum().allow(null);
  const schema = joi.object({
      facebook : socialUrl.required(),
      twitter  : socialUrl.required(),
      youtube  : socialUrl.required()
  }).required()
  </code></pre>
  
  <p>This works great except that the following object is considered valid:</p>
  
  <pre><code>{
      facebook : null,
      twitter  : null,
      youtube  : null
  }
  </code></pre>
  
  <p>Using <a href="https://github.com/hapijs/joi/blob/master/API.md#objectminlimit" rel="nofollow noreferrer">min()</a> and <a href="https://github.com/hapijs/joi/blob/master/API.md#objectorpeers" rel="nofollow noreferrer">or()</a> on the object doesn't help because the fields exist, they're just the wrong type.</p>
  
  <p>It would be pretty trivial to do an extra loop myself afterwards and check for the specific case of all fields being <code>null</code>, but that is not ideal.</p>
  
  <p>This is being used for <a href="https://hapijs.com/tutorials/validation#input" rel="nofollow noreferrer">payload validation</a> where it would be nice to know that the client understands the full schema, hence the desire that all of the fields be present. Maybe that is not worth it. I do get the sense that I could use some verbose <a href="https://github.com/hapijs/joi/blob/master/API.md#anywhenref-options" rel="nofollow noreferrer">when()</a> code to get the job done, but it seems like at that point I might as well just make my own loop. Hoping to be proven wrong!</p>