@kubb/adapter-oas 5.5.3 → 5.5.5

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
@@ -452,7 +452,7 @@ async function resolveSource(sourcePath) {
452
452
  * its parse error instead.
453
453
  */
454
454
  async function assertInputExists(input) {
455
- if (URL.canParse(input)) return;
455
+ if (urlRegExp.test(input)) return;
456
456
  if (!await exists(input)) throw new _kubb_core.Diagnostics.Error({
457
457
  code: _kubb_core.Diagnostics.code.inputNotFound,
458
458
  severity: "error",
@@ -541,7 +541,7 @@ async function parseDocument(pathOrApi) {
541
541
  */
542
542
  async function parseFromConfig(source) {
543
543
  if (source.type === "data") return parseDocument(typeof source.data === "string" ? (0, yaml.parse)(source.data) : structuredClone(source.data));
544
- if (URL.canParse(source.path)) return parseDocument(source.path);
544
+ if (urlRegExp.test(source.path)) return parseDocument(source.path);
545
545
  const resolved = node_path.default.resolve(node_path.default.dirname(source.path), source.path);
546
546
  await assertInputExists(resolved);
547
547
  return parseDocument(resolved);
@@ -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
@@ -2001,7 +2016,7 @@ function walkPointer(document, $ref) {
2001
2016
  applicable: false,
2002
2017
  value: null
2003
2018
  };
2004
- const pointer = globalThis.decodeURIComponent(trimmed.substring(1));
2019
+ const pointer = trimmed.substring(1);
2005
2020
  let docCache = _refCache.get(document);
2006
2021
  if (!docCache) {
2007
2022
  docCache = /* @__PURE__ */ new Map();
@@ -2011,7 +2026,7 @@ function walkPointer(document, $ref) {
2011
2026
  applicable: true,
2012
2027
  value: docCache.get(pointer)
2013
2028
  };
2014
- const current = pointer.split("/").filter(Boolean).reduce((obj, key) => obj?.[key], document);
2029
+ const current = pointer.split("/").filter(Boolean).map((token) => globalThis.decodeURIComponent(token).replaceAll("~1", "/").replaceAll("~0", "~")).reduce((obj, key) => obj?.[key], document);
2015
2030
  if (current) docCache.set(pointer, current);
2016
2031
  return {
2017
2032
  applicable: true,