@kubb/adapter-oas 5.11.3 → 5.11.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
@@ -1,4 +1,25 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
2
23
  //#endregion
3
24
  let _kubb_core = require("@kubb/core");
4
25
  let _kubb_kit = require("@kubb/kit");
@@ -6,6 +27,7 @@ let node_fs_promises = require("node:fs/promises");
6
27
  let _scalar_openapi_upgrader = require("@scalar/openapi-upgrader");
7
28
  let api_ref_bundler = require("api-ref-bundler");
8
29
  let yaml = require("yaml");
30
+ yaml = __toESM(yaml, 1);
9
31
  //#region kubb-extension.json
10
32
  var compatibility = {
11
33
  "kubb": ">=5.8.3",
@@ -13,7 +35,7 @@ var compatibility = {
13
35
  };
14
36
  //#endregion
15
37
  //#region package.json
16
- var version = "5.11.3";
38
+ var version = "5.11.5";
17
39
  //#endregion
18
40
  //#region src/constants.ts
19
41
  /**
@@ -2295,6 +2317,58 @@ function visit(node, pointer) {
2295
2317
  if (node.type === "union" || node.type === "intersection" || node.type === "not") for (const [index, member] of (node.members ?? []).entries()) visit(member, `${pointer}/members/${index}`);
2296
2318
  }
2297
2319
  //#endregion
2320
+ //#region src/sourceLocator.ts
2321
+ const cache = /* @__PURE__ */ new Map();
2322
+ const toRange = ([start, end]) => ({
2323
+ start,
2324
+ end
2325
+ });
2326
+ const unescapeToken = (token) => token.replaceAll("~1", "/").replaceAll("~0", "~");
2327
+ /** Walks a JSON pointer through maps and sequences; the range is the last key or item it reached. */
2328
+ function findPointer(document, pointer) {
2329
+ return pointer.replace(/^#/, "").split("/").slice(1).map(unescapeToken).reduce((at, token) => {
2330
+ if (yaml.isMap(at?.node)) {
2331
+ const pair = at.node.items.find((item) => yaml.isScalar(item.key) && String(item.key.value) === token);
2332
+ return pair && yaml.isScalar(pair.key) && pair.key.range ? {
2333
+ node: pair.value,
2334
+ range: toRange(pair.key.range)
2335
+ } : void 0;
2336
+ }
2337
+ if (yaml.isSeq(at?.node)) {
2338
+ const item = at.node.items[Number(token)];
2339
+ return yaml.isNode(item) && item.range ? {
2340
+ node: item,
2341
+ range: toRange(item.range)
2342
+ } : void 0;
2343
+ }
2344
+ }, {
2345
+ node: document.contents,
2346
+ range: void 0
2347
+ })?.range;
2348
+ }
2349
+ /** The first `$ref` whose value is `ref`. */
2350
+ function findRefUsage(document, ref) {
2351
+ const found = [];
2352
+ yaml.visit(document, { Pair(_, { key, value }) {
2353
+ if (!yaml.isScalar(key) || key.value !== "$ref" || !yaml.isScalar(value) || value.value !== ref || !value.range) return;
2354
+ found.push(toRange(value.range));
2355
+ return yaml.visit.BREAK;
2356
+ } });
2357
+ return found[0];
2358
+ }
2359
+ /**
2360
+ * Maps OpenAPI JSON pointers and unresolved references to ranges in YAML or JSON source.
2361
+ */
2362
+ const locate = (source, location) => {
2363
+ if (!("pointer" in location)) return void 0;
2364
+ if (!cache.has(source)) {
2365
+ cache.clear();
2366
+ cache.set(source, yaml.parseDocument(source));
2367
+ }
2368
+ const document = cache.get(source);
2369
+ return findPointer(document, location.pointer) ?? ("ref" in location && location.ref ? findRefUsage(document, location.ref) : void 0);
2370
+ };
2371
+ //#endregion
2298
2372
  //#region src/adapter.ts
2299
2373
  /**
2300
2374
  * The `name` of `@kubb/adapter-oas`, used to identify this adapter in a Kubb config.
@@ -2449,6 +2523,7 @@ const adapterOas = (0, _kubb_core.defineExtension)({
2449
2523
  get document() {
2450
2524
  return parsedDocument;
2451
2525
  },
2526
+ locate,
2452
2527
  async validate(input, options) {
2453
2528
  const document = await parseFromConfig({
2454
2529
  type: "path",