@kubb/adapter-oas 5.15.0 → 5.15.2

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.js CHANGED
@@ -19,7 +19,7 @@ var compatibility = {
19
19
  "node": ">=22.22"
20
20
  };
21
21
  // package.json
22
- var version = "5.15.0";
22
+ var version = "5.15.2";
23
23
  // src/constants.ts
24
24
  /**
25
25
  * Default parser options applied when no explicit options are provided.
@@ -304,6 +304,12 @@ function getErrorMessage(value) {
304
304
  function escapePointerToken(token) {
305
305
  return token.replaceAll("~", "~0").replaceAll("/", "~1");
306
306
  }
307
+ /**
308
+ * Unescapes one JSON pointer token per RFC 6901 (`~1` → `/`, then `~0` → `~`).
309
+ */
310
+ function unescapePointerToken(token) {
311
+ return token.replaceAll("~1", "/").replaceAll("~0", "~");
312
+ }
307
313
  // ../../internals/utils/src/runtime.ts
308
314
  const isBun = typeof Bun !== "undefined";
309
315
  const isDeno = "Deno" in globalThis;
@@ -474,7 +480,7 @@ function createRefs(document) {
474
480
  applicable: true,
475
481
  value: pointerCache.get(pointer)
476
482
  };
477
- const current = pointer.split("/").filter(Boolean).map((token) => globalThis.decodeURIComponent(token).replaceAll("~1", "/").replaceAll("~0", "~")).reduce((obj, key) => obj?.[key], document);
483
+ const current = pointer.split("/").filter(Boolean).map((token) => unescapePointerToken(globalThis.decodeURIComponent(token))).reduce((obj, key) => obj?.[key], document);
478
484
  if (current) pointerCache.set(pointer, current);
479
485
  return {
480
486
  applicable: true,
@@ -1335,14 +1341,19 @@ const PARAMETER_STYLES = /* @__PURE__ */ new Set([
1335
1341
  "pipeDelimited",
1336
1342
  "deepObject"
1337
1343
  ]);
1344
+ function pickStyleFields({ style, explode, allowReserved }) {
1345
+ return {
1346
+ ...style !== void 0 && PARAMETER_STYLES.has(style) ? { style } : {},
1347
+ ...explode !== void 0 ? { explode } : {},
1348
+ ...allowReserved !== void 0 ? { allowReserved } : {}
1349
+ };
1350
+ }
1338
1351
  /** The `encoding` of a media type, reduced to the entries that set a field Kubb carries. A `style` outside the OpenAPI set is dropped. */
1339
1352
  function getEncoding(encoding) {
1340
- const entries = Object.entries(encoding ?? {}).flatMap(([property, { contentType, style, explode, allowReserved }]) => {
1353
+ const entries = Object.entries(encoding ?? {}).flatMap(([property, { contentType, ...rest }]) => {
1341
1354
  const node = {
1342
1355
  ...contentType !== void 0 ? { contentType } : {},
1343
- ...style !== void 0 && PARAMETER_STYLES.has(style) ? { style } : {},
1344
- ...explode !== void 0 ? { explode } : {},
1345
- ...allowReserved !== void 0 ? { allowReserved } : {}
1356
+ ...pickStyleFields(rest)
1346
1357
  };
1347
1358
  return Object.keys(node).length ? [[property, node]] : [];
1348
1359
  });
@@ -1402,9 +1413,6 @@ function parseParameter({ param, pointer, parentName, options, parseSchema }) {
1402
1413
  name: schemaName
1403
1414
  }) : ast.factory.createSchema({ type: options.unknownType });
1404
1415
  if (rawSchema) scanSchema(schema, contentType ? `${pointer}/content/${escapePointerToken(contentType)}/schema` : `${pointer}/schema`);
1405
- const style = param.style !== void 0 && PARAMETER_STYLES.has(param.style) ? param.style : void 0;
1406
- const explode = param.explode;
1407
- const allowReserved = param.allowReserved;
1408
1416
  return ast.factory.createParameter({
1409
1417
  pointer,
1410
1418
  name: param.name,
@@ -1414,9 +1422,7 @@ function parseParameter({ param, pointer, parentName, options, parseSchema }) {
1414
1422
  description: param.description ?? schema.description
1415
1423
  },
1416
1424
  required: param.required ?? false,
1417
- ...style !== void 0 ? { style } : {},
1418
- ...explode !== void 0 ? { explode } : {},
1419
- ...allowReserved !== void 0 ? { allowReserved } : {},
1425
+ ...pickStyleFields(param),
1420
1426
  ...contentType !== void 0 ? { contentType } : {}
1421
1427
  });
1422
1428
  }
@@ -2709,10 +2715,9 @@ const toRange = ([start, end]) => ({
2709
2715
  start,
2710
2716
  end
2711
2717
  });
2712
- const unescapeToken = (token) => token.replaceAll("~1", "/").replaceAll("~0", "~");
2713
2718
  /** Walks a JSON pointer through maps and sequences; the range is the last key or item it reached. */
2714
2719
  function findPointer(document, pointer) {
2715
- return pointer.replace(/^#/, "").split("/").slice(1).map(unescapeToken).reduce((at, token) => {
2720
+ return pointer.replace(/^#/, "").split("/").slice(1).map(unescapePointerToken).reduce((at, token) => {
2716
2721
  if (yaml.isMap(at?.node)) {
2717
2722
  const pair = at.node.items.find((item) => yaml.isScalar(item.key) && String(item.key.value) === token);
2718
2723
  return pair && yaml.isScalar(pair.key) && pair.key.range ? {
@@ -2924,7 +2929,6 @@ const adapterOas = defineExtension({
2924
2929
  function parseInput({ document, refs, schemas, pointers, parseSchema }) {
2925
2930
  const parsedByName = /* @__PURE__ */ new Map();
2926
2931
  const refAliasMap = /* @__PURE__ */ new Map();
2927
- const enumNames = [];
2928
2932
  const discriminatorParentNodes = [];
2929
2933
  for (const [name, schema] of Object.entries(schemas)) {
2930
2934
  const node = {
@@ -2937,10 +2941,8 @@ const adapterOas = defineExtension({
2937
2941
  parsedByName.set(name, node);
2938
2942
  scanSchema(node);
2939
2943
  if (node.type === "ref" && node.name) refAliasMap.set(name, node);
2940
- if (ast.narrowSchema(node, "enum") && node.name) enumNames.push(node.name);
2941
2944
  if (discriminator === "propagate" && (schema.oneOf ?? schema.anyOf) && schema.discriminator?.propertyName) discriminatorParentNodes.push(node);
2942
2945
  }
2943
- const circularNames = [...ast.findCircularSchemas([...parsedByName.values()])];
2944
2946
  const discriminatorChildMap = discriminatorParentNodes.length > 0 ? buildDiscriminatorChildMap(discriminatorParentNodes) : null;
2945
2947
  const operationNodes = getOperations(document, refs).map((operation) => parseOperation({
2946
2948
  operation,
@@ -2950,7 +2952,6 @@ const adapterOas = defineExtension({
2950
2952
  parseSchema
2951
2953
  }));
2952
2954
  const promotedEnums = enums === "root" ? collectInlineEnums([...parsedByName.values(), ...operationNodes], new Set(Object.keys(schemas))) : null;
2953
- if (promotedEnums) for (const name of promotedEnums.keys()) enumNames.push(name);
2954
2955
  const aliasTargetOf = (name) => {
2955
2956
  const node = refAliasMap.get(name);
2956
2957
  return node?.ref ? ast.refName(node.ref) : node?.name;
@@ -3039,8 +3040,6 @@ const adapterOas = defineExtension({
3039
3040
  parameterName: scheme.name
3040
3041
  }] : [];
3041
3042
  }),
3042
- circularNames,
3043
- enumNames,
3044
3043
  extensions: pickExtensions(document)
3045
3044
  }
3046
3045
  });