title: How to dynamically validate a form with Yup?
body: <p>I get an object with random properties (keys) and I would like to validate, this is an example of what I can get:</p>
  <pre><code>{
      &quot;underlying_ticker&quot;: &quot;&quot;,
      &quot;barrier&quot;: &quot;&quot;,
      &quot;fixing_date&quot;: &quot;3223&quot;,
      &quot;maturity_date&quot;: &quot;2323&quot;,
      &quot;payment_date&quot;: &quot;2332&quot;,
      &quot;put_barrier&quot;: &quot;2323&quot;,
      &quot;put_strike&quot;: &quot;3232&quot;,
      &quot;quantity&quot;: &quot;2323&quot;,
      &quot;strike&quot;: &quot;32&quot;
  }
  </code></pre>
  <p>I would like to know how I can validate them to know if they are filled and so on.</p>
  <p>I tried the following code below:</p>
  <pre><code>  const validateForm = async (data) =&gt; {
      try {
        parametersFormRef.current.setErrors({});
  
        const shapes = Object.keys(data).map(((parameter) =&gt; {
          return ({ [parameter]: Yup.string().typeError(&quot;Test&quot;).required() });
        }));
  
        const schema = Yup.object().shape({ ...shapes });
  
        await schema.validate(data, { abortEarly: false });
      } catch (err) {
        console.error(err);
        const validationErrors = {};
  
        if (err instanceof Yup.ValidationError) {
          err.inner.forEach((error) =&gt; {
            validationErrors[error.path] = error.message;
          });
        }
      }
    };
  </code></pre>
  <p>However, it is not falling into catch, even with both empty values.</p>