async validate(request, verbose = false) {
    const { _id, index, collection } = request.input.resource,
      collectionSpec =
        (isPlainObject(this.specification) &&
          has(this.specification, index) &&
          get(this.specification[index], collection)) ||
        {};

    let isUpdate = false,
      body = request.input.body;

    if (
      request.input.controller === "document" &&
      request.input.action === "update"
    ) {
      isUpdate = true;

      const document = await global.kuzzle.ask(
        "core:storage:public:document:get",
        index,
        collection,
        _id,
      );

      // Avoid side effects on the request during the update validation
      body = _.cloneDeep(request.input.body);
      _.defaultsDeep(body, document._source);
    }

    const errorMessages = verbose ? {} : [];
    let isValid = true;

    if (collectionSpec) {
      if (collectionSpec.fields && collectionSpec.fields.children) {
        try {
          isValid = this.recurseFieldValidation(
            body,
            collectionSpec.fields.children,
            collectionSpec.strict,
            errorMessages,
            verbose,
          );
        } catch (error) {
          // The strictness message can be received here only if it happens at
          // the validation of the document's root
          if (error.message !== "strictness") {
            throw error;
          }

          isValid = false;
          manageErrorMessage(
            "document",
            errorMessages,
            `The document validation is strict. Cannot add unspecified sub-field "${error.details.field}"`,
            verbose,
          );
        }
      }

      if (collectionSpec.validators) {
        const filters = koncordeTest(
          this.koncorde,
          index,
          collection,
          body,
          _id,
        );

        if (filters.length === 0 || filters[0] !== collectionSpec.validators) {
          isValid = false;
          manageErrorMessage(
            "document",
            errorMessages,
            "The document does not match validation filters.",
            verbose,
          );
        }
      }
    }

    if (!verbose) {
      // We only modify the request if the validation succeeds
      if (collectionSpec.fields && collectionSpec.fields.children) {
        request.input.body = this.recurseApplyDefault(
          isUpdate,
          request.input.body,
          collectionSpec.fields.children,
        );
      }

      return request;
    }

    return { errorMessages, valid: isValid };
  }
Validates a document against its collection specifications

@param {Request} request
@param {boolean} [verbose]
@returns {Promise.<{documentBody: *, errorMessages:string[], valid: boolean}|KuzzleRequest>}