@kubb/adapter-oas 5.14.5 → 5.15.0

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,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
2
+ // \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -20,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
23
- //#endregion
24
23
  let _kubb_core = require("@kubb/core");
25
24
  let _kubb_kit = require("@kubb/kit");
26
25
  let node_path = require("node:path");
@@ -30,16 +29,14 @@ let api_ref_bundler = require("api-ref-bundler");
30
29
  let js_yaml = require("js-yaml");
31
30
  let yaml = require("yaml");
32
31
  yaml = __toESM(yaml, 1);
33
- //#region kubb-extension.json
32
+ // kubb-extension.json
34
33
  var compatibility = {
35
34
  "kubb": ">=5.8.3",
36
35
  "node": ">=22.22"
37
36
  };
38
- //#endregion
39
- //#region package.json
40
- var version = "5.14.5";
41
- //#endregion
42
- //#region src/constants.ts
37
+ // package.json
38
+ var version = "5.15.0";
39
+ // src/constants.ts
43
40
  /**
44
41
  * Default parser options applied when no explicit options are provided.
45
42
  */
@@ -163,8 +160,7 @@ const enumExtensionKeys = ["x-enumNames", "x-enum-varnames"];
163
160
  * Vendor extension keys that attach human-readable descriptions to enum values, checked in priority order.
164
161
  */
165
162
  const enumDescriptionKeys = ["x-enumDescriptions", "x-enum-descriptions"];
166
- //#endregion
167
- //#region src/emit/discriminator/propagate.ts
163
+ // src/emit/discriminator/propagate.ts
168
164
  /**
169
165
  * Maps each child schema name to its discriminator patch data by scanning the given
170
166
  * top-level AST schema nodes for union schemas that carry a `discriminatorPropertyName`.
@@ -247,8 +243,7 @@ function patchDiscriminatorNode(node, entry) {
247
243
  members: newMembers
248
244
  };
249
245
  }
250
- //#endregion
251
- //#region ../../internals/utils/src/casing.ts
246
+ // ../../internals/utils/src/casing.ts
252
247
  /**
253
248
  * Shared implementation for camelCase and PascalCase conversion.
254
249
  * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
@@ -263,7 +258,7 @@ function convert(text, pascal) {
263
258
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
264
259
  }
265
260
  const cache = /* @__PURE__ */ new Map();
266
- const cacheLimit = 1e4;
261
+ const cacheLimit = 1e5;
267
262
  function toCamelOrPascal(text, pascal) {
268
263
  const key = `${pascal ? "P" : "c"}${text}`;
269
264
  const cached = cache.get(key);
@@ -285,8 +280,7 @@ function toCamelOrPascal(text, pascal) {
285
280
  function pascalCase(text, { prefix = "", suffix = "" } = {}) {
286
281
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
287
282
  }
288
- //#endregion
289
- //#region ../../internals/utils/src/errors.ts
283
+ // ../../internals/utils/src/errors.ts
290
284
  /**
291
285
  * Coerces an unknown thrown value to an `Error` instance.
292
286
  * Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
@@ -313,8 +307,7 @@ function toError(value) {
313
307
  function getErrorMessage(value) {
314
308
  return value instanceof Error ? value.message : String(value);
315
309
  }
316
- //#endregion
317
- //#region ../../internals/utils/src/jsonPointer.ts
310
+ // ../../internals/utils/src/jsonPointer.ts
318
311
  /**
319
312
  * Escapes a single JSON pointer reference token per RFC 6901 (`~` → `~0`, `/` → `~1`), so a
320
313
  * name holding those characters maps to a distinct pointer.
@@ -327,8 +320,7 @@ function getErrorMessage(value) {
327
320
  function escapePointerToken(token) {
328
321
  return token.replaceAll("~", "~0").replaceAll("/", "~1");
329
322
  }
330
- //#endregion
331
- //#region ../../internals/utils/src/runtime.ts
323
+ // ../../internals/utils/src/runtime.ts
332
324
  const isBun = typeof Bun !== "undefined";
333
325
  const isDeno = "Deno" in globalThis;
334
326
  /**
@@ -357,8 +349,7 @@ function detect() {
357
349
  version: process.versions?.node ?? ""
358
350
  };
359
351
  }
360
- //#endregion
361
- //#region ../../internals/utils/src/fs.ts
352
+ // ../../internals/utils/src/fs.ts
362
353
  /**
363
354
  * Resolves to `true` when the file or directory at `path` exists.
364
355
  * Uses `Bun.file().exists()` when running under Bun, `fs.access` otherwise.
@@ -387,8 +378,7 @@ async function read(path) {
387
378
  if (runtime.isBun) return Bun.file(path).text();
388
379
  return (0, node_fs_promises.readFile)(path, { encoding: "utf8" });
389
380
  }
390
- //#endregion
391
- //#region src/oas.ts
381
+ // src/oas.ts
392
382
  /**
393
383
  * Returns `true` when a schema should be treated as nullable.
394
384
  *
@@ -471,8 +461,7 @@ const jsonMimeFragments = [
471
461
  function isJsonMimeType(mimeType) {
472
462
  return jsonMimeFragments.some((fragment) => mimeType.includes(fragment));
473
463
  }
474
- //#endregion
475
- //#region src/refs.ts
464
+ // src/refs.ts
476
465
  /**
477
466
  * Creates the `$ref` resolution service for one document. One pointer walk backs every method.
478
467
  *
@@ -579,8 +568,7 @@ function createRefs(document) {
579
568
  derefKeepingRef
580
569
  };
581
570
  }
582
- //#endregion
583
- //#region src/load/source.ts
571
+ // src/load/source.ts
584
572
  const urlRegExp = /^https?:\/+/i;
585
573
  /**
586
574
  * Node reports every connection failure as `TypeError: fetch failed` and keeps the useful part
@@ -684,8 +672,7 @@ async function assertInputExists(input) {
684
672
  location: { kind: "config" }
685
673
  });
686
674
  }
687
- //#endregion
688
- //#region src/load/normalize.ts
675
+ // src/load/normalize.ts
689
676
  /**
690
677
  * True when `node` contains a `$ref` pointing outside the current document (a relative path,
691
678
  * absolute path, or URL). An internal `#/...` fragment does not count.
@@ -715,6 +702,30 @@ function inlinePathRefs(node, resolve, visiting = []) {
715
702
  for (const [key, value] of Object.entries(node)) node[key] = inlinePathRefs(value, resolve, visiting);
716
703
  return node;
717
704
  }
705
+ const namedEntryKeys = /* @__PURE__ */ new Set([
706
+ "properties",
707
+ "patternProperties",
708
+ "headers",
709
+ "schemas",
710
+ "responses",
711
+ "parameters",
712
+ "requestBodies",
713
+ "examples",
714
+ "links",
715
+ "callbacks",
716
+ "securitySchemes",
717
+ "securityDefinitions",
718
+ "pathItems",
719
+ "definitions",
720
+ "$defs"
721
+ ]);
722
+ /**
723
+ * True when `path` runs through an `x-` vendor extension. Kubb never reads an extension, so a `$ref`
724
+ * Kubb cannot read inside one cannot change the output.
725
+ */
726
+ function isExtensionPath(path) {
727
+ return path.some((token, index) => String(token).startsWith("x-") && !namedEntryKeys.has(String(path[index - 1])));
728
+ }
718
729
  /**
719
730
  * Bundles a multi-file OpenAPI document into a single document via `api-ref-bundler`.
720
731
  *
@@ -730,7 +741,7 @@ function inlinePathRefs(node, resolve, visiting = []) {
730
741
  *
731
742
  * `document` stands in for the file at `pathOrUrl`, such as inline input. Every other file or URL
732
743
  * read, including one that fails, lands in `sources`. A `$ref` that cannot be read reports
733
- * `KUBB_REF_NOT_FOUND` at the key that holds it.
744
+ * `KUBB_REF_NOT_FOUND` at the key that holds it, as a warning when it sits inside an `x-` extension.
734
745
  *
735
746
  * @example Local file
736
747
  * `const document = await bundleDocument('./openapi.yaml')`
@@ -757,7 +768,7 @@ async function bundleDocument(pathOrUrl, { document, sources = [] } = {}) {
757
768
  const pointer = toKey(state.baseFile) === toKey(pathOrUrl) ? `#/${path.map((token) => escapePointerToken(String(token))).join("/")}` : void 0;
758
769
  const diagnostic = {
759
770
  code: _kubb_kit.Diagnostics.code.refNotFound,
760
- severity: "error",
771
+ severity: isExtensionPath(path) ? "warning" : "error",
761
772
  message: `Could not bundle an external \`$ref\`. ${message}.`,
762
773
  help: "Check that the file or URL the `$ref` points at exists and is readable, or fix the `$ref`.",
763
774
  ...pointer && { location: {
@@ -765,7 +776,7 @@ async function bundleDocument(pathOrUrl, { document, sources = [] } = {}) {
765
776
  pointer
766
777
  } }
767
778
  };
768
- if (!_kubb_kit.Diagnostics.report(diagnostic)) throw new _kubb_kit.Diagnostics.Error(diagnostic);
779
+ if (!_kubb_kit.Diagnostics.report(diagnostic) && diagnostic.severity === "error") throw new _kubb_kit.Diagnostics.Error(diagnostic);
769
780
  } } });
770
781
  }
771
782
  const inlineInputName = "<inline input>";
@@ -907,8 +918,7 @@ async function validateDocumentInWorker(document) {
907
918
  if ("thrown" in message) return reportInvalidSpec(message.thrown);
908
919
  if (!message.valid) reportValidationErrors(message);
909
920
  }
910
- //#endregion
911
- //#region src/model/components.ts
921
+ // src/model/components.ts
912
922
  /**
913
923
  * Extracts the inline schema from a media-type `content` map, with the media type it sits under.
914
924
  *
@@ -1110,8 +1120,7 @@ function getSchemas(document, { contentType }, refs) {
1110
1120
  pointers
1111
1121
  };
1112
1122
  }
1113
- //#endregion
1114
- //#region src/model/server.ts
1123
+ // src/model/server.ts
1115
1124
  /**
1116
1125
  * Reads the server URL from the document's `servers` array at `server.index`,
1117
1126
  * interpolating any `server.variables` into the URL template.
@@ -1163,8 +1172,7 @@ function resolveServerUrl(server, overrides) {
1163
1172
  }
1164
1173
  return url;
1165
1174
  }
1166
- //#endregion
1167
- //#region src/emit/schemaShape.ts
1175
+ // src/emit/schemaShape.ts
1168
1176
  /**
1169
1177
  * Whether `format` maps to a dedicated type; `false` is what `KUBB_UNSUPPORTED_FORMAT` flags.
1170
1178
  */
@@ -1217,8 +1225,7 @@ function flattenSchema(schema) {
1217
1225
  for (const fragment of allOfFragments) for (const [key, value] of Object.entries(fragment)) merged[key] ??= value;
1218
1226
  return merged;
1219
1227
  }
1220
- //#endregion
1221
- //#region src/schemaDiagnostics.ts
1228
+ // src/schemaDiagnostics.ts
1222
1229
  /**
1223
1230
  * Links one freshly converted schema and its nested schemas to their RFC 6901 pointers
1224
1231
  * (`#/components/schemas/Pet/properties/owner/properties/name`), and reports the advisory
@@ -1272,8 +1279,7 @@ function visit(node, pointer) {
1272
1279
  for (const [index, member] of (node.members ?? []).entries()) visit(member, `${pointer}/${keyword}/${index}`);
1273
1280
  }
1274
1281
  }
1275
- //#endregion
1276
- //#region src/operation.ts
1282
+ // src/operation.ts
1277
1283
  function slugify(value) {
1278
1284
  return value.replace(/[^a-zA-Z0-9]/g, "-").replace(/-{2,}/g, "-").replace(/^-|-$/g, "");
1279
1285
  }
@@ -1542,8 +1548,7 @@ function parseOperation({ operation, ...ctx }) {
1542
1548
  extensions: pickExtensions(operation.schema)
1543
1549
  });
1544
1550
  }
1545
- //#endregion
1546
- //#region src/emit/createNode.ts
1551
+ // src/emit/createNode.ts
1547
1552
  /**
1548
1553
  * Builds a schema node from a converter's base context plus its type-specific fields. Every
1549
1554
  * converter needs the same metadata fields (`title`, `description`, `examples`, ...) alongside
@@ -1564,8 +1569,7 @@ function createNode({ schema, name, nullable, defaultValue }, extras) {
1564
1569
  ...extras
1565
1570
  });
1566
1571
  }
1567
- //#endregion
1568
- //#region src/emit/discriminator/preserve.ts
1572
+ // src/emit/discriminator/preserve.ts
1569
1573
  /**
1570
1574
  * Turns string mapping keys into the discriminator property's type when they parse cleanly.
1571
1575
  */
@@ -1801,8 +1805,7 @@ function extractDiscriminatedAllOfMembers({ allOfMembers, name, refs }) {
1801
1805
  discriminantValues
1802
1806
  };
1803
1807
  }
1804
- //#endregion
1805
- //#region src/emit/converters/annotatedEnum.ts
1808
+ // src/emit/converters/annotatedEnum.ts
1806
1809
  const ANNOTATIONS = /* @__PURE__ */ new Set([
1807
1810
  "title",
1808
1811
  "description",
@@ -1868,8 +1871,7 @@ function convertAnnotatedEnum(context) {
1868
1871
  namedEnumValues
1869
1872
  });
1870
1873
  }
1871
- //#endregion
1872
- //#region src/emit/converters/composition.ts
1874
+ // src/emit/converters/composition.ts
1873
1875
  /**
1874
1876
  * Collects property schemas from all `allOf` members and outer schema properties,
1875
1877
  * recursively resolving `$ref` pointers.
@@ -2205,8 +2207,7 @@ function convertMultiType({ schema, name, nullable, defaultValue, parse }) {
2205
2207
  })
2206
2208
  });
2207
2209
  }
2208
- //#endregion
2209
- //#region src/emit/converters/scalar.ts
2210
+ // src/emit/converters/scalar.ts
2210
2211
  /**
2211
2212
  * Normalizes malformed `{ type: 'array', enum: [...] }` schemas by moving enum values into items.
2212
2213
  *
@@ -2382,8 +2383,7 @@ function convertNumeric(context, type) {
2382
2383
  ...getNumericConstraints(context.schema)
2383
2384
  });
2384
2385
  }
2385
- //#endregion
2386
- //#region src/emit/converters/structural.ts
2386
+ // src/emit/converters/structural.ts
2387
2387
  /**
2388
2388
  * Resolves a `true` or empty-object map schema (`additionalProperties`/`patternProperties`) to
2389
2389
  * `options.unknownType`, otherwise parses it as a regular schema.
@@ -2414,8 +2414,9 @@ function nameEnums(node, options) {
2414
2414
  * Converts an object-like schema into an `ObjectSchemaNode`.
2415
2415
  */
2416
2416
  function convertObject({ schema, name, nullable, defaultValue, options, parse, refs }) {
2417
+ const requiredNames = Array.isArray(schema.required) ? new Set(schema.required) : void 0;
2417
2418
  const properties = schema.properties ? Object.entries(schema.properties).map(([propName, propSchema]) => {
2418
- const required = Array.isArray(schema.required) ? schema.required.includes(propName) : !!schema.required;
2419
+ const required = requiredNames ? requiredNames.has(propName) : !!schema.required;
2419
2420
  const resolvedPropSchema = propSchema;
2420
2421
  const propNullable = isNullable(resolvedPropSchema);
2421
2422
  const schemaNode = nameEnums(parse({
@@ -2534,8 +2535,7 @@ function convertArray({ schema, name, nullable, defaultValue, options, parse })
2534
2535
  unique: schema.uniqueItems ?? void 0
2535
2536
  });
2536
2537
  }
2537
- //#endregion
2538
- //#region src/emit/parseSchema.ts
2538
+ // src/emit/parseSchema.ts
2539
2539
  /**
2540
2540
  * Ordered schema rule table. Order is significant: composition keywords (`not`, `$ref`, `allOf`,
2541
2541
  * `oneOf`/`anyOf`) take precedence over `const` (except a `$ref` with a sibling `const`, where the
@@ -2636,8 +2636,7 @@ const schemaRules = [
2636
2636
  convert: ({ schema, name, nullable }) => createNullNode(schema, name, nullable)
2637
2637
  }
2638
2638
  ];
2639
- //#endregion
2640
- //#region src/parser.ts
2639
+ // src/parser.ts
2641
2640
  /**
2642
2641
  * Creates the schema converter bound to one OpenAPI document: `parseSchema` dispatches each
2643
2642
  * schema through the ordered `schemaRules` table, with the parser options merged once.
@@ -2674,8 +2673,7 @@ function createSchemaParser(ctx) {
2674
2673
  }
2675
2674
  return parseSchema;
2676
2675
  }
2677
- //#endregion
2678
- //#region src/promoteEnums.ts
2676
+ // src/promoteEnums.ts
2679
2677
  /**
2680
2678
  * Collects inline enums to lift to the top level, keyed by the name the parser derived for them
2681
2679
  * (e.g. `PetStatusEnum`). An enum already defined as a top-level component is left as-is, and a
@@ -2721,8 +2719,7 @@ function refPromotedEnums(node, promoted) {
2721
2719
  });
2722
2720
  } });
2723
2721
  }
2724
- //#endregion
2725
- //#region src/sourceLocator.ts
2722
+ // src/sourceLocator.ts
2726
2723
  let cached;
2727
2724
  const toRange = ([start, end]) => ({
2728
2725
  start,
@@ -2879,8 +2876,7 @@ const locate = (source, location) => {
2879
2876
  const { document } = cached;
2880
2877
  return findPointer(document, location.pointer) ?? (ref ? findRefUsage(document, ref) : void 0);
2881
2878
  };
2882
- //#endregion
2883
- //#region src/adapter.ts
2879
+ // src/adapter.ts
2884
2880
  /**
2885
2881
  * The `name` of `@kubb/adapter-oas`, used to identify this adapter in a Kubb config.
2886
2882
  */
@@ -3125,7 +3121,6 @@ const adapterOas = (0, _kubb_core.defineExtension)({
3125
3121
  };
3126
3122
  }
3127
3123
  });
3128
- //#endregion
3129
3124
  exports.adapterOas = adapterOas;
3130
3125
  exports.adapterOasName = adapterOasName;
3131
3126