@kubb/adapter-oas 5.5.2 → 5.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -564,8 +564,17 @@ function assertDocument(document) {
564
564
  location: { kind: "config" }
565
565
  });
566
566
  }
567
+ /** Reports a validation problem as a `KUBB_INVALID_SPEC` warning, a no-op outside a build. */
568
+ function reportInvalidSpec(message) {
569
+ _kubb_core.Diagnostics.report({
570
+ code: _kubb_core.Diagnostics.code.invalidSpec,
571
+ severity: "warning",
572
+ message,
573
+ help: "Fix the spec, or run `kubb validate` to list every error. Set `validate: false` on the adapter to skip this check."
574
+ });
575
+ }
567
576
  /**
568
- * Validates an OpenAPI document using `@readme/openapi-parser` with colorized error output.
577
+ * Validates an OpenAPI document using `@readme/openapi-parser`. Throws with `throwOnError`, otherwise warns.
569
578
  *
570
579
  * @example
571
580
  * ```ts
@@ -574,12 +583,18 @@ function assertDocument(document) {
574
583
  */
575
584
  async function validateDocument(document, { throwOnError = false } = {}) {
576
585
  const { compileErrors, validate } = await import("@readme/openapi-parser");
586
+ let result;
577
587
  try {
578
- const result = await validate(structuredClone(document), { validate: { errors: { colorize: true } } });
579
- if (!result.valid) throw new Error(compileErrors(result));
588
+ result = await validate(structuredClone(document), { validate: { errors: { colorize: throwOnError } } });
580
589
  } catch (error) {
581
590
  if (throwOnError) throw error;
591
+ reportInvalidSpec(getErrorMessage(error));
592
+ return;
582
593
  }
594
+ if (result.valid) return;
595
+ if (throwOnError) throw new Error(compileErrors(result));
596
+ for (const { message } of result.errors) reportInvalidSpec(message.replace(/\n.*/s, ""));
597
+ if (result.additionalErrors > 0) reportInvalidSpec(`${result.additionalErrors} more validation errors are not listed.`);
583
598
  }
584
599
  //#endregion
585
600
  //#region src/oas.ts