@kubb/adapter-oas 5.23.2 → 5.23.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.cjs CHANGED
@@ -16,7 +16,7 @@ var compatibility = {
16
16
  "node": ">=22.22"
17
17
  };
18
18
  // package.json
19
- var version = "5.23.2";
19
+ var version = "5.23.4";
20
20
  // src/constants.ts
21
21
  /**
22
22
  * Default parser options applied when no explicit options are provided.
@@ -265,37 +265,6 @@ function createStore({ weak, max } = {}) {
265
265
  };
266
266
  }
267
267
  memo.create = createStore;
268
- // ../../internals/utils/src/casing.ts
269
- /**
270
- * Shared implementation for camelCase and PascalCase conversion.
271
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
272
- * and capitalizes each word according to `pascal`.
273
- *
274
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
275
- */
276
- function convert(text, pascal) {
277
- return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)(?!xx(?![a-z]))([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
278
- if (word.length > 1 && word === word.toUpperCase()) return word;
279
- return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
280
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
281
- }
282
- const cache = memo.create({ max: 1e5 });
283
- function toCamelOrPascal(text, pascal) {
284
- const key = `${pascal ? "P" : "c"}${text}`;
285
- return memo(cache, key, () => convert(text, pascal));
286
- }
287
- /**
288
- * Converts `text` to PascalCase.
289
- *
290
- * @example Word boundaries
291
- * `pascalCase('hello-world') // 'HelloWorld'`
292
- *
293
- * @example With a suffix
294
- * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
295
- */
296
- function pascalCase(text, { prefix = "", suffix = "" } = {}) {
297
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
298
- }
299
268
  // ../../internals/utils/src/errors.ts
300
269
  /**
301
270
  * Coerces an unknown thrown value to an `Error` instance.
@@ -462,6 +431,7 @@ function getExternalDocs(source) {
462
431
  * Returns the `x-*` keys of `source` as-is, or `undefined` when there are none.
463
432
  */
464
433
  function pickExtensions(source) {
434
+ if (!source) return void 0;
465
435
  const entries = Object.entries(source).filter(([key]) => key.startsWith("x-"));
466
436
  return entries.length > 0 ? Object.fromEntries(entries) : void 0;
467
437
  }
@@ -1308,7 +1278,7 @@ async function validateDocument(document, { throwOnError = false } = {}) {
1308
1278
  return;
1309
1279
  }
1310
1280
  if (!throwOnError) {
1311
- const { validateSpec } = await Promise.resolve().then(() => require("./validateSpec-DCiUXkMn.cjs"));
1281
+ const { validateSpec } = await Promise.resolve().then(() => require("./validateSpec-Bxf2WZ1Y.cjs"));
1312
1282
  return reportResult(await validateSpec(structuredClone(document)));
1313
1283
  }
1314
1284
  const { compileErrors, validate } = await import("@readme/openapi-parser");
@@ -1549,7 +1519,7 @@ function getSchemas(document, { contentType }, refs) {
1549
1519
  }];
1550
1520
  }))];
1551
1521
  const normalizedNames = memo.create();
1552
- for (const item of candidates) memo(normalizedNames, pascalCase(item.originalName), () => []).push(item);
1522
+ for (const item of candidates) memo(normalizedNames, (0, _kubb_core.pascalCase)(item.originalName), () => []).push(item);
1553
1523
  const schemas = {};
1554
1524
  const renames = /* @__PURE__ */ new Map();
1555
1525
  const pointers = /* @__PURE__ */ new Map();
@@ -2286,7 +2256,7 @@ function collectPropertyKeysByFlag(schema, flag) {
2286
2256
  }
2287
2257
  /** Converts one parameter into a `ParameterNode`, naming an inline schema after the operation and the parameter. */
2288
2258
  function parseParameter({ param, pointer, parentName, options, parseSchema, refs }) {
2289
- const schemaName = parentName && param.name ? pascalCase(`${parentName} ${param.name}`) : void 0;
2259
+ const schemaName = parentName && param.name ? (0, _kubb_core.pascalCase)(`${parentName} ${param.name}`) : void 0;
2290
2260
  const contentType = param.schema ? void 0 : Object.keys(param.content ?? {})[0];
2291
2261
  const mediaType = getMediaType({
2292
2262
  content: param.content,
@@ -2313,7 +2283,8 @@ function parseParameter({ param, pointer, parentName, options, parseSchema, refs
2313
2283
  ...mediaType?.encoding && { encoding: getEncodingFields({ encoding: mediaType.encoding }).encoding },
2314
2284
  ...getExamples(mediaType ?? param, refs),
2315
2285
  ...param.deprecated && { deprecated: true },
2316
- ...param.allowEmptyValue && { allowEmptyValue: true }
2286
+ ...param.allowEmptyValue && { allowEmptyValue: true },
2287
+ extensions: pickExtensions(param)
2317
2288
  });
2318
2289
  }
2319
2290
  function spreadQuerystring(param) {
@@ -2331,7 +2302,8 @@ function spreadQuerystring(param) {
2331
2302
  required: param.required && property.required,
2332
2303
  ...style !== void 0 && { style },
2333
2304
  ...explode !== void 0 && { explode },
2334
- ...allowReserved !== void 0 && { allowReserved }
2305
+ ...allowReserved !== void 0 && { allowReserved },
2306
+ ...param.extensions && { extensions: param.extensions }
2335
2307
  });
2336
2308
  });
2337
2309
  }
@@ -2341,7 +2313,7 @@ function spreadQuerystring(param) {
2341
2313
  function parseOperation({ operation, ...ctx }) {
2342
2314
  const { document, refs, contentType, options, parseSchema } = ctx;
2343
2315
  const operationId = getOperationId(operation);
2344
- const operationName = operationId ? pascalCase(operationId) : void 0;
2316
+ const operationName = operationId ? (0, _kubb_core.pascalCase)(operationId) : void 0;
2345
2317
  const pointer = getOperationPointer(operation);
2346
2318
  const parameters = getParameters({
2347
2319
  operation,
@@ -2389,14 +2361,16 @@ function parseOperation({ operation, ...ctx }) {
2389
2361
  refs,
2390
2362
  document,
2391
2363
  node
2392
- })
2364
+ }),
2365
+ extensions: pickExtensions(mediaType)
2393
2366
  })];
2394
2367
  });
2395
2368
  const requestBody = content.length > 0 || body?.description ? {
2396
2369
  pointer: `${pointer}/requestBody`,
2397
2370
  description: body?.description,
2398
2371
  required: bodyRequired || void 0,
2399
- content: content.length > 0 ? content : void 0
2372
+ content: content.length > 0 ? content : void 0,
2373
+ extensions: pickExtensions(body)
2400
2374
  } : void 0;
2401
2375
  const responses = getResponseStatusCodes(operation).map((key) => {
2402
2376
  const response = getResponseByStatusCode({
@@ -2434,7 +2408,8 @@ function parseOperation({ operation, ...ctx }) {
2434
2408
  refs,
2435
2409
  document,
2436
2410
  node
2437
- }) : {}
2411
+ }) : {},
2412
+ extensions: pickExtensions(mediaType)
2438
2413
  };
2439
2414
  };
2440
2415
  const declaredContentTypes = Object.keys(response?.content ?? {});
@@ -2471,7 +2446,8 @@ function parseOperation({ operation, ...ctx }) {
2471
2446
  description: response?.description,
2472
2447
  content: responseContent,
2473
2448
  ...headers.length && { headers },
2474
- ...links && { links }
2449
+ ...links && { links },
2450
+ extensions: pickExtensions(response)
2475
2451
  });
2476
2452
  });
2477
2453
  const pickDoc = (key) => {
@@ -2533,6 +2509,7 @@ function createNode({ schema, name, nullable, defaultValue }, extras) {
2533
2509
  examples: extractExamples(schema),
2534
2510
  format: schema.format,
2535
2511
  externalDocs: getExternalDocs(schema.externalDocs),
2512
+ extensions: pickExtensions(schema),
2536
2513
  ...extras
2537
2514
  });
2538
2515
  }
@@ -2950,7 +2927,11 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
2950
2927
  writeOnly: schema.writeOnly ?? resolvedSchema.writeOnly,
2951
2928
  default: defaultValue ?? resolvedSchema.default,
2952
2929
  name: name ?? resolvedSchema.name,
2953
- nullable: nullable ?? resolvedSchema.nullable
2930
+ nullable: nullable ?? resolvedSchema.nullable,
2931
+ extensions: pickExtensions({
2932
+ ...resolvedSchema.extensions,
2933
+ ...schema
2934
+ })
2954
2935
  });
2955
2936
  const targetName = renames?.get(schema.$ref);
2956
2937
  return createNode(ctx, {
@@ -3042,6 +3023,10 @@ function convertAllOf({ schema: original, name, nullable, defaultValue, parse, r
3042
3023
  examples: extractExamples(schema) ?? memberNode.examples,
3043
3024
  pattern: schema.pattern ?? ("pattern" in memberNode ? memberNode.pattern : void 0),
3044
3025
  format: schema.format ?? memberNode.format,
3026
+ extensions: pickExtensions({
3027
+ ...memberNode.extensions,
3028
+ ...schema
3029
+ }),
3045
3030
  externalDocs: getExternalDocs(schema.externalDocs) ?? memberNode.externalDocs
3046
3031
  });
3047
3032
  }
@@ -3199,7 +3184,7 @@ function convertMultiType({ schema, name, nullable, defaultValue, parse }) {
3199
3184
  members: nonNullTypes.map((t) => {
3200
3185
  return parse({
3201
3186
  schema: {
3202
- ...schema,
3187
+ ...Object.fromEntries(Object.entries(schema).filter(([key]) => !key.startsWith("x-"))),
3203
3188
  type: t
3204
3189
  },
3205
3190
  name
@@ -3290,7 +3275,8 @@ function createNullNode(schema, name, nullable) {
3290
3275
  description: schema.description,
3291
3276
  deprecated: schema.deprecated,
3292
3277
  nullable,
3293
- format: schema.format
3278
+ format: schema.format,
3279
+ extensions: pickExtensions(schema)
3294
3280
  });
3295
3281
  }
3296
3282
  /**
@@ -3334,6 +3320,7 @@ function convertFormat(context) {
3334
3320
  });
3335
3321
  }
3336
3322
  const specialType = formatMap[schema.format];
3323
+ if (specialType === "blob") return convertBlob(context);
3337
3324
  if (specialType === "string") {
3338
3325
  if (type === "integer" || type === "number") return convertNumeric(context, type);
3339
3326
  return convertString(context);
@@ -3439,6 +3426,14 @@ function convertString(context) {
3439
3426
  ...getStringContent(context)
3440
3427
  });
3441
3428
  }
3429
+ /** Converts a binary schema into a `BlobSchemaNode`, keeping `contentMediaType` and `contentEncoding`. */
3430
+ function convertBlob(context) {
3431
+ return createNode(context, {
3432
+ type: "blob",
3433
+ primitive: "string",
3434
+ ...getStringContent(context)
3435
+ });
3436
+ }
3442
3437
  /**
3443
3438
  * Converts a `type: 'number'` or `type: 'integer'` schema.
3444
3439
  */
@@ -3681,10 +3676,7 @@ const schemaRules = [
3681
3676
  },
3682
3677
  {
3683
3678
  match: ({ schema }) => isBinary(schema),
3684
- convert: (ctx) => createNode(ctx, {
3685
- type: "blob",
3686
- primitive: "string"
3687
- })
3679
+ convert: convertBlob
3688
3680
  },
3689
3681
  {
3690
3682
  match: ({ schema, type }) => !type && !schema.enum?.length && (schema.contentMediaType !== void 0 || schema.contentSchema !== void 0),