code: public function validate($entity)
      {
          if (!$this->container->has('validator')) {
              throw new \LogicException('The validator service is not available.');
          }
  
          $errors = $this->container->get('validator')->validate($entity);
  
          if (count($errors) === 0) {
              return false;
          }
  
          // TODO Use Hydra Error instead
          return new JsonLdResponse('{ "error": "Validation error" }', 400);
      }
docs: Shortcut to validate an entity
  
  This method uses the Validator service. It throws an Exception with
  a status code of "400 Bad Request" in case of validation errors.
  
  @param object $entity The entity to validate.
  
  @return false|Error If false is returned, no validation errors have
  been found, otherwise an Error response is
  returned.
  
  @throws \LogicException If the validator service is not available