@kubb/adapter-oas 5.5.3 → 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.d.ts CHANGED
@@ -1203,9 +1203,9 @@ type ServerOptions = {
1203
1203
  */
1204
1204
  type AdapterOasOptions = {
1205
1205
  /**
1206
- * Validate the OpenAPI spec with `@readme/openapi-parser` before parsing.
1207
- * Set to `false` only when you have a known-invalid spec you still want to
1208
- * generate from.
1206
+ * Validate the OpenAPI spec with `@readme/openapi-parser` before parsing. Each problem is
1207
+ * reported as a `KUBB_INVALID_SPEC` warning and generation continues. Set to `false` to skip the
1208
+ * check, which also makes generation faster on a large spec.
1209
1209
  *
1210
1210
  * @default true
1211
1211
  */
package/dist/index.js CHANGED
@@ -541,8 +541,17 @@ function assertDocument(document) {
541
541
  location: { kind: "config" }
542
542
  });
543
543
  }
544
+ /** Reports a validation problem as a `KUBB_INVALID_SPEC` warning, a no-op outside a build. */
545
+ function reportInvalidSpec(message) {
546
+ Diagnostics.report({
547
+ code: Diagnostics.code.invalidSpec,
548
+ severity: "warning",
549
+ message,
550
+ help: "Fix the spec, or run `kubb validate` to list every error. Set `validate: false` on the adapter to skip this check."
551
+ });
552
+ }
544
553
  /**
545
- * Validates an OpenAPI document using `@readme/openapi-parser` with colorized error output.
554
+ * Validates an OpenAPI document using `@readme/openapi-parser`. Throws with `throwOnError`, otherwise warns.
546
555
  *
547
556
  * @example
548
557
  * ```ts
@@ -551,12 +560,18 @@ function assertDocument(document) {
551
560
  */
552
561
  async function validateDocument(document, { throwOnError = false } = {}) {
553
562
  const { compileErrors, validate } = await import("@readme/openapi-parser");
563
+ let result;
554
564
  try {
555
- const result = await validate(structuredClone(document), { validate: { errors: { colorize: true } } });
556
- if (!result.valid) throw new Error(compileErrors(result));
565
+ result = await validate(structuredClone(document), { validate: { errors: { colorize: throwOnError } } });
557
566
  } catch (error) {
558
567
  if (throwOnError) throw error;
568
+ reportInvalidSpec(getErrorMessage(error));
569
+ return;
559
570
  }
571
+ if (result.valid) return;
572
+ if (throwOnError) throw new Error(compileErrors(result));
573
+ for (const { message } of result.errors) reportInvalidSpec(message.replace(/\n.*/s, ""));
574
+ if (result.additionalErrors > 0) reportInvalidSpec(`${result.additionalErrors} more validation errors are not listed.`);
560
575
  }
561
576
  //#endregion
562
577
  //#region src/oas.ts