@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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime-BowF1xt-.js";
2
- import { defineExtension } from "@kubb/core";
2
+ import { defineExtension, pascalCase } from "@kubb/core";
3
3
  import { Diagnostics, Url, ast, childName, enumPrimitive, enumPropName, macroDedupeUnion, macroDiscriminatorEnum, macroEnumName, mergeAdjacentObjectsLazy } from "@kubb/kit";
4
4
  import { access, realpath } from "node:fs/promises";
5
5
  import { dirname, isAbsolute, join, relative, resolve } from "node:path";
@@ -15,7 +15,7 @@ var compatibility = {
15
15
  "node": ">=22.22"
16
16
  };
17
17
  // package.json
18
- var version = "5.23.2";
18
+ var version = "5.23.4";
19
19
  // src/constants.ts
20
20
  /**
21
21
  * Default parser options applied when no explicit options are provided.
@@ -264,37 +264,6 @@ function createStore({ weak, max } = {}) {
264
264
  };
265
265
  }
266
266
  memo.create = createStore;
267
- // ../../internals/utils/src/casing.ts
268
- /**
269
- * Shared implementation for camelCase and PascalCase conversion.
270
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
271
- * and capitalizes each word according to `pascal`.
272
- *
273
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
274
- */
275
- function convert(text, pascal) {
276
- 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) => {
277
- if (word.length > 1 && word === word.toUpperCase()) return word;
278
- return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
279
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
280
- }
281
- const cache = memo.create({ max: 1e5 });
282
- function toCamelOrPascal(text, pascal) {
283
- const key = `${pascal ? "P" : "c"}${text}`;
284
- return memo(cache, key, () => convert(text, pascal));
285
- }
286
- /**
287
- * Converts `text` to PascalCase.
288
- *
289
- * @example Word boundaries
290
- * `pascalCase('hello-world') // 'HelloWorld'`
291
- *
292
- * @example With a suffix
293
- * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
294
- */
295
- function pascalCase(text, { prefix = "", suffix = "" } = {}) {
296
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
297
- }
298
267
  // ../../internals/utils/src/errors.ts
299
268
  /**
300
269
  * Coerces an unknown thrown value to an `Error` instance.
@@ -461,6 +430,7 @@ function getExternalDocs(source) {
461
430
  * Returns the `x-*` keys of `source` as-is, or `undefined` when there are none.
462
431
  */
463
432
  function pickExtensions(source) {
433
+ if (!source) return void 0;
464
434
  const entries = Object.entries(source).filter(([key]) => key.startsWith("x-"));
465
435
  return entries.length > 0 ? Object.fromEntries(entries) : void 0;
466
436
  }
@@ -1306,7 +1276,7 @@ async function validateDocument(document, { throwOnError = false } = {}) {
1306
1276
  return;
1307
1277
  }
1308
1278
  if (!throwOnError) {
1309
- const { validateSpec } = await import("./validateSpec-9zbtcjcA.js");
1279
+ const { validateSpec } = await import("./validateSpec-DL7ObLHI.js");
1310
1280
  return reportResult(await validateSpec(structuredClone(document)));
1311
1281
  }
1312
1282
  const { compileErrors, validate } = await import("@readme/openapi-parser");
@@ -2311,7 +2281,8 @@ function parseParameter({ param, pointer, parentName, options, parseSchema, refs
2311
2281
  ...mediaType?.encoding && { encoding: getEncodingFields({ encoding: mediaType.encoding }).encoding },
2312
2282
  ...getExamples(mediaType ?? param, refs),
2313
2283
  ...param.deprecated && { deprecated: true },
2314
- ...param.allowEmptyValue && { allowEmptyValue: true }
2284
+ ...param.allowEmptyValue && { allowEmptyValue: true },
2285
+ extensions: pickExtensions(param)
2315
2286
  });
2316
2287
  }
2317
2288
  function spreadQuerystring(param) {
@@ -2329,7 +2300,8 @@ function spreadQuerystring(param) {
2329
2300
  required: param.required && property.required,
2330
2301
  ...style !== void 0 && { style },
2331
2302
  ...explode !== void 0 && { explode },
2332
- ...allowReserved !== void 0 && { allowReserved }
2303
+ ...allowReserved !== void 0 && { allowReserved },
2304
+ ...param.extensions && { extensions: param.extensions }
2333
2305
  });
2334
2306
  });
2335
2307
  }
@@ -2387,14 +2359,16 @@ function parseOperation({ operation, ...ctx }) {
2387
2359
  refs,
2388
2360
  document,
2389
2361
  node
2390
- })
2362
+ }),
2363
+ extensions: pickExtensions(mediaType)
2391
2364
  })];
2392
2365
  });
2393
2366
  const requestBody = content.length > 0 || body?.description ? {
2394
2367
  pointer: `${pointer}/requestBody`,
2395
2368
  description: body?.description,
2396
2369
  required: bodyRequired || void 0,
2397
- content: content.length > 0 ? content : void 0
2370
+ content: content.length > 0 ? content : void 0,
2371
+ extensions: pickExtensions(body)
2398
2372
  } : void 0;
2399
2373
  const responses = getResponseStatusCodes(operation).map((key) => {
2400
2374
  const response = getResponseByStatusCode({
@@ -2432,7 +2406,8 @@ function parseOperation({ operation, ...ctx }) {
2432
2406
  refs,
2433
2407
  document,
2434
2408
  node
2435
- }) : {}
2409
+ }) : {},
2410
+ extensions: pickExtensions(mediaType)
2436
2411
  };
2437
2412
  };
2438
2413
  const declaredContentTypes = Object.keys(response?.content ?? {});
@@ -2469,7 +2444,8 @@ function parseOperation({ operation, ...ctx }) {
2469
2444
  description: response?.description,
2470
2445
  content: responseContent,
2471
2446
  ...headers.length && { headers },
2472
- ...links && { links }
2447
+ ...links && { links },
2448
+ extensions: pickExtensions(response)
2473
2449
  });
2474
2450
  });
2475
2451
  const pickDoc = (key) => {
@@ -2531,6 +2507,7 @@ function createNode({ schema, name, nullable, defaultValue }, extras) {
2531
2507
  examples: extractExamples(schema),
2532
2508
  format: schema.format,
2533
2509
  externalDocs: getExternalDocs(schema.externalDocs),
2510
+ extensions: pickExtensions(schema),
2534
2511
  ...extras
2535
2512
  });
2536
2513
  }
@@ -2948,7 +2925,11 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
2948
2925
  writeOnly: schema.writeOnly ?? resolvedSchema.writeOnly,
2949
2926
  default: defaultValue ?? resolvedSchema.default,
2950
2927
  name: name ?? resolvedSchema.name,
2951
- nullable: nullable ?? resolvedSchema.nullable
2928
+ nullable: nullable ?? resolvedSchema.nullable,
2929
+ extensions: pickExtensions({
2930
+ ...resolvedSchema.extensions,
2931
+ ...schema
2932
+ })
2952
2933
  });
2953
2934
  const targetName = renames?.get(schema.$ref);
2954
2935
  return createNode(ctx, {
@@ -3040,6 +3021,10 @@ function convertAllOf({ schema: original, name, nullable, defaultValue, parse, r
3040
3021
  examples: extractExamples(schema) ?? memberNode.examples,
3041
3022
  pattern: schema.pattern ?? ("pattern" in memberNode ? memberNode.pattern : void 0),
3042
3023
  format: schema.format ?? memberNode.format,
3024
+ extensions: pickExtensions({
3025
+ ...memberNode.extensions,
3026
+ ...schema
3027
+ }),
3043
3028
  externalDocs: getExternalDocs(schema.externalDocs) ?? memberNode.externalDocs
3044
3029
  });
3045
3030
  }
@@ -3197,7 +3182,7 @@ function convertMultiType({ schema, name, nullable, defaultValue, parse }) {
3197
3182
  members: nonNullTypes.map((t) => {
3198
3183
  return parse({
3199
3184
  schema: {
3200
- ...schema,
3185
+ ...Object.fromEntries(Object.entries(schema).filter(([key]) => !key.startsWith("x-"))),
3201
3186
  type: t
3202
3187
  },
3203
3188
  name
@@ -3288,7 +3273,8 @@ function createNullNode(schema, name, nullable) {
3288
3273
  description: schema.description,
3289
3274
  deprecated: schema.deprecated,
3290
3275
  nullable,
3291
- format: schema.format
3276
+ format: schema.format,
3277
+ extensions: pickExtensions(schema)
3292
3278
  });
3293
3279
  }
3294
3280
  /**
@@ -3332,6 +3318,7 @@ function convertFormat(context) {
3332
3318
  });
3333
3319
  }
3334
3320
  const specialType = formatMap[schema.format];
3321
+ if (specialType === "blob") return convertBlob(context);
3335
3322
  if (specialType === "string") {
3336
3323
  if (type === "integer" || type === "number") return convertNumeric(context, type);
3337
3324
  return convertString(context);
@@ -3437,6 +3424,14 @@ function convertString(context) {
3437
3424
  ...getStringContent(context)
3438
3425
  });
3439
3426
  }
3427
+ /** Converts a binary schema into a `BlobSchemaNode`, keeping `contentMediaType` and `contentEncoding`. */
3428
+ function convertBlob(context) {
3429
+ return createNode(context, {
3430
+ type: "blob",
3431
+ primitive: "string",
3432
+ ...getStringContent(context)
3433
+ });
3434
+ }
3440
3435
  /**
3441
3436
  * Converts a `type: 'number'` or `type: 'integer'` schema.
3442
3437
  */
@@ -3679,10 +3674,7 @@ const schemaRules = [
3679
3674
  },
3680
3675
  {
3681
3676
  match: ({ schema }) => isBinary(schema),
3682
- convert: (ctx) => createNode(ctx, {
3683
- type: "blob",
3684
- primitive: "string"
3685
- })
3677
+ convert: convertBlob
3686
3678
  },
3687
3679
  {
3688
3680
  match: ({ schema, type }) => !type && !schema.enum?.length && (schema.contentMediaType !== void 0 || schema.contentSchema !== void 0),