title: How to validate an array of objects in a request body using JOI
body: <p>I am trying to validate the request body of an order placed. I recieve an array of json objects on the request body that I am trying to validate. Everytime I get the error " "productId" is required"</p>
  
  <p><strong>Here is my request body:</strong></p>
  
  <pre><code>req.body={
      "productId": [
          { "id": "5dd635c5618d29001747c01e", "quantity": 1 },
          { "id": "5dd63922618d29001747c028", "quantity": 2 },
          { "id": "5dd635c5618d29001747c01e", "quantity": 3 }
      ]
  }
  </code></pre>
  
  <p>Here is the valdateOrder function to validate the request body:</p>
  
  <pre><code>function validateOrder(req.body) {
      const schema = {
  
          productId: joi.array().items(
              joi.object().keys({
                  id: joi.string().required(),
                  quantity: joi.string().required()
              })).required(),
      }
  
      return joi.validate(req.body, schema)
  
  }
  </code></pre>
  
  <p>I would be really thankful if anyone can point out whats wrong with my validateOrder function.</p>