title: Node Express joi validation failed when I added .when()
body: <p>I'm setting my schema in Mongoose model using Joi and Joigoose, everything works fine until I add the conditions &quot; .when(...) &quot; like following</p>
  <pre><code>const ClientJoiSchema = Joi.object().keys({
      clientType: Joi.string().valid(&quot;physical&quot;, &quot;moral&quot;).default(&quot;physical&quot;),
      firstName: Joi.when('clientType', { is: &quot;physical&quot;, then: Joi.string().required() }),
      lastName: Joi.when('clientType', { is: &quot;physical&quot;, then: Joi.string().required() }),
      ...
  )}
  </code></pre>
  <p>when I try that on Postman I get this :</p>
  <pre><code>&quot;message&quot;: {
          &quot;errors&quot;: {
              &quot;firstName&quot;: {
                  &quot;properties&quot;: {
                      &quot;message&quot;: &quot;Validator failed for path `firstName` with value `Daniel`&quot;,
                      &quot;type&quot;: &quot;user defined&quot;,
                      &quot;path&quot;: &quot;firstName&quot;,
                      &quot;value&quot;: &quot;Daniel&quot;
                  },
                  &quot;kind&quot;: &quot;user defined&quot;,
                  &quot;path&quot;: &quot;firstName&quot;,
                  &quot;value&quot;: &quot;Daniel&quot;
              },
              &quot;lastName&quot;: {
                  &quot;properties&quot;: {
                      &quot;message&quot;: &quot;Validator failed for path `lastName` with value `Noah`&quot;,
                      &quot;type&quot;: &quot;user defined&quot;,
                      &quot;path&quot;: &quot;lastName&quot;,
                      &quot;value&quot;: &quot;Noah&quot;
                  },
                  &quot;kind&quot;: &quot;user defined&quot;,
                  &quot;path&quot;: &quot;lastName&quot;,
                  &quot;value&quot;: &quot;Noah&quot;
              }
          },
          &quot;_message&quot;: &quot;Clients validation failed&quot;,
          &quot;message&quot;: &quot;Clients validation failed: firstName: Validator failed for path `firstName` with value `Daniel`, lastName: Validator failed for path `lastName` with value `Noah`&quot;
      }
  </code></pre>