private async loadAllSpecValidatorInBackground()

in lib/liveValidation/liveValidator.ts [328:403]


  private async loadAllSpecValidatorInBackground(allSpecs: SwaggerSpec[]) {
    const backgroundStartTime = Date.now();
    utils.shuffleArray(allSpecs);
    while (allSpecs.length > 0) {
      let spec;
      try {
        spec = allSpecs.shift()!;
        const startTime = Date.now();
        this.logging(
          `Start building validator for ${spec._filePath} in background`,
          LiveValidatorLoggingLevels.debug,
          LiveValidatorLoggingTypes.trace,
          "Oav.liveValidator.loadAllSpecValidatorInBackground"
        );
        await this.loader!.buildAjvValidator(spec, { inBackground: true });
        const elapsedTime = Date.now() - startTime;
        this.logging(
          `Complete building validator for ${spec._filePath} in background with DurationInMs:${elapsedTime}.`,
          LiveValidatorLoggingLevels.debug,
          LiveValidatorLoggingTypes.trace,
          "Oav.liveValidator.loadAllSpecValidatorInBackground"
        );
        this.logging(
          `Complete building validator for ${spec._filePath} in background`,
          LiveValidatorLoggingLevels.info,
          LiveValidatorLoggingTypes.perfTrace,
          "Oav.liveValidator.loadAllSpecValidatorInBackground",
          elapsedTime
        );
        this.logging(
          `Complete building validator for spec ${spec._filePath}`,
          LiveValidatorLoggingLevels.info,
          LiveValidatorLoggingTypes.specTrace,
          "Oav.liveValidator.loadAllSpecValidatorInBackground",
          elapsedTime,
          {
            providerNamespace: spec._providerNamespace ?? "unknown",
            apiVersion: spec.info.version,
            specName: spec._filePath,
          }
        );
      } catch (e) {
        this.logging(
          `Failed to build validator for spec ${spec?._filePath}.\nErrorMessage:${
            (e as any)?.message
          }.\nErrorStack:${(e as any)?.stack}`,
          LiveValidatorLoggingLevels.error,
          LiveValidatorLoggingTypes.specTrace,
          "Oav.liveValidator.loadAllSpecValidatorInBackground",
          undefined,
          {
            providerNamespace: spec?._providerNamespace ?? "unknown",
            apiVersion: spec?.info.version ?? "unknown",
            specName: spec?._filePath,
          }
        );
      }
    }

    this.loader = undefined;
    this.loadInBackgroundComplete = true;
    const elapsedTimeForBuild = Date.now() - backgroundStartTime;
    this.logging(
      `Completed building validator for all specs in background with DurationInMs:${elapsedTimeForBuild}.`,
      LiveValidatorLoggingLevels.info,
      LiveValidatorLoggingTypes.trace,
      "Oav.liveValidator.loadAllSpecValidatorInBackground"
    );
    this.logging(
      `Completed building validator for all specs in background`,
      LiveValidatorLoggingLevels.info,
      LiveValidatorLoggingTypes.perfTrace,
      "Oav.liveValidator.loadAllSpecValidatorInBackground",
      elapsedTimeForBuild
    );
  }