@kubb/ast 5.0.0-beta.62 → 5.0.0-beta.64

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.
Files changed (92) hide show
  1. package/dist/{defineMacro-CNkUpxia.js → defineMacro-B76LsJwO.js} +4 -4
  2. package/dist/defineMacro-B76LsJwO.js.map +1 -0
  3. package/dist/{defineMacro-Vw-xQvq7.d.ts → defineMacro-B7qm3zTd.d.ts} +5 -6
  4. package/dist/{defineMacro-BryDiuQl.cjs → defineMacro-CEZHaCXE.cjs} +5 -5
  5. package/dist/defineMacro-CEZHaCXE.cjs.map +1 -0
  6. package/dist/factory-wJLzHeXT.d.ts +27 -0
  7. package/dist/factory.cjs +56 -56
  8. package/dist/factory.cjs.map +1 -1
  9. package/dist/factory.d.ts +3 -27
  10. package/dist/factory.js +6 -6
  11. package/dist/factory.js.map +1 -1
  12. package/dist/{index-CTaN_ee_.d.ts → index-BKD4drsX.d.ts} +47 -114
  13. package/dist/index.cjs +193 -270
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.ts +31 -21
  16. package/dist/index.js +154 -236
  17. package/dist/index.js.map +1 -1
  18. package/dist/macros.cjs +12 -12
  19. package/dist/macros.cjs.map +1 -1
  20. package/dist/macros.d.ts +3 -3
  21. package/dist/macros.js +5 -5
  22. package/dist/macros.js.map +1 -1
  23. package/dist/{operationParams-B44p6EQy.d.ts → operationParams-ByVfpYr7.d.ts} +10 -3
  24. package/dist/{visitor-DepQEKyp.js → refs-Dx6U5LoE.js} +116 -121
  25. package/dist/refs-Dx6U5LoE.js.map +1 -0
  26. package/dist/{visitor-B7Zlnp4c.cjs → refs-u5SDdyV7.cjs} +139 -144
  27. package/dist/refs-u5SDdyV7.cjs.map +1 -0
  28. package/dist/{response-BeG6hq2D.cjs → schema-BkvrrOAr.cjs} +171 -153
  29. package/dist/schema-BkvrrOAr.cjs.map +1 -0
  30. package/dist/{response-Rd1uisM1.js → schema-YNbOtTCM.js} +167 -155
  31. package/dist/schema-YNbOtTCM.js.map +1 -0
  32. package/dist/{types-DQTgVSwE.d.ts → types-BP9BZoq-.d.ts} +56 -80
  33. package/dist/types.d.ts +5 -5
  34. package/dist/{utils-DW9rnfsD.js → utils-BJi0y-xg.js} +57 -50
  35. package/dist/utils-BJi0y-xg.js.map +1 -0
  36. package/dist/{utils-BDI3kXlb.cjs → utils-CEepwqmb.cjs} +74 -67
  37. package/dist/utils-CEepwqmb.cjs.map +1 -0
  38. package/dist/utils.cjs +11 -11
  39. package/dist/utils.d.ts +45 -30
  40. package/dist/utils.js +3 -3
  41. package/package.json +1 -2
  42. package/dist/defineMacro-BryDiuQl.cjs.map +0 -1
  43. package/dist/defineMacro-CNkUpxia.js.map +0 -1
  44. package/dist/response-BeG6hq2D.cjs.map +0 -1
  45. package/dist/response-Rd1uisM1.js.map +0 -1
  46. package/dist/utils-BDI3kXlb.cjs.map +0 -1
  47. package/dist/utils-DW9rnfsD.js.map +0 -1
  48. package/dist/visitor-B7Zlnp4c.cjs.map +0 -1
  49. package/dist/visitor-DepQEKyp.js.map +0 -1
  50. package/src/constants.ts +0 -153
  51. package/src/dedupe.ts +0 -231
  52. package/src/defineMacro.ts +0 -139
  53. package/src/defineNode.ts +0 -105
  54. package/src/definePrinter.ts +0 -256
  55. package/src/dialect.ts +0 -76
  56. package/src/factory.ts +0 -44
  57. package/src/guards.ts +0 -28
  58. package/src/index.ts +0 -13
  59. package/src/infer.ts +0 -132
  60. package/src/macros/index.ts +0 -3
  61. package/src/macros/macroDiscriminatorEnum.ts +0 -50
  62. package/src/macros/macroEnumName.ts +0 -33
  63. package/src/macros/macroSimplifyUnion.ts +0 -60
  64. package/src/nodes/base.ts +0 -49
  65. package/src/nodes/code.ts +0 -352
  66. package/src/nodes/content.ts +0 -51
  67. package/src/nodes/file.ts +0 -379
  68. package/src/nodes/function.ts +0 -283
  69. package/src/nodes/index.ts +0 -93
  70. package/src/nodes/input.ts +0 -144
  71. package/src/nodes/operation.ts +0 -165
  72. package/src/nodes/output.ts +0 -49
  73. package/src/nodes/parameter.ts +0 -71
  74. package/src/nodes/property.ts +0 -67
  75. package/src/nodes/requestBody.ts +0 -54
  76. package/src/nodes/response.ts +0 -173
  77. package/src/nodes/schema.ts +0 -732
  78. package/src/registry.ts +0 -75
  79. package/src/signature.ts +0 -207
  80. package/src/types.ts +0 -9
  81. package/src/utils/codegen.ts +0 -104
  82. package/src/utils/extractStringsFromNodes.ts +0 -35
  83. package/src/utils/fileMerge.ts +0 -184
  84. package/src/utils/index.ts +0 -11
  85. package/src/utils/operationParams.ts +0 -353
  86. package/src/utils/refs.ts +0 -138
  87. package/src/utils/schemaGraph.ts +0 -169
  88. package/src/utils/schemaMerge.ts +0 -34
  89. package/src/utils/schemaTraversal.ts +0 -86
  90. package/src/utils/strings.ts +0 -139
  91. package/src/visitor.ts +0 -519
  92. /package/dist/{chunk-CNktS9qV.js → rolldown-runtime-CNktS9qV.js} +0 -0
@@ -1,6 +1,6 @@
1
- import "./chunk-CNktS9qV.js";
2
- import { d as resolveRefName, h as INDENT, m as narrowSchema, n as collectLazy, t as collect, u as resolveGroupType } from "./visitor-DepQEKyp.js";
3
- import { Q as createSchema, X as camelCase, _ as createIndexedAccessType, g as createFunctionParameters, h as createFunctionParameter, y as createTypeLiteral } from "./response-Rd1uisM1.js";
1
+ import "./rolldown-runtime-CNktS9qV.js";
2
+ import { a as resolveGroupType, c as collect, h as INDENT, l as collectLazy, m as narrowSchema, o as resolveRefName } from "./refs-Dx6U5LoE.js";
3
+ import { L as camelCase, S as createTypeLiteral, b as createIndexedAccessType, t as createSchema, v as createFunctionParameter, y as createFunctionParameters } from "./schema-YNbOtTCM.js";
4
4
  //#region ../../internals/utils/src/promise.ts
5
5
  /**
6
6
  * Wraps `factory` with a keyed cache backed by the provided store.
@@ -178,8 +178,8 @@ function singleQuote(value) {
178
178
  //#endregion
179
179
  //#region src/utils/codegen.ts
180
180
  /**
181
- * Builds a JSDoc comment block from an array of lines, returning `fallback` when there are no
182
- * comments so callers always get a usable string.
181
+ * Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no
182
+ * comments.
183
183
  *
184
184
  * @example
185
185
  * ```ts
@@ -214,9 +214,8 @@ function objectKey(name) {
214
214
  }
215
215
  /**
216
216
  * Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
217
- * level and closing the brace at column zero. Nested objects built the same way indent cumulatively,
218
- * so callers never re-parse the generated code. A trailing comma is added per entry to match the
219
- * formatter's multi-line style.
217
+ * level and closing the brace at column zero. Entries that are themselves multi-line objects indent
218
+ * cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.
220
219
  *
221
220
  * @example
222
221
  * ```ts
@@ -231,8 +230,8 @@ function buildObject(entries) {
231
230
  /**
232
231
  * Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
233
232
  * one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
234
- * one level with a trailing comma and the closing bracket at column zero. Use it for `z.union([…])`,
235
- * `z.array([…])`, and similar member lists so objects inside them nest correctly.
233
+ * one level with a trailing comma and the closing bracket at column zero. Used for member lists such
234
+ * as `z.union([…])` and `z.array([…])`.
236
235
  *
237
236
  * @example
238
237
  * ```ts
@@ -250,8 +249,8 @@ function buildList(items, brackets = ["[", "]"]) {
250
249
  //#region src/utils/schemaMerge.ts
251
250
  /**
252
251
  * Merges a run of adjacent anonymous object members into one. Named or non-object members break the
253
- * run and pass through. Stays a construction-time helper, not a macro, so callers keep control of the
254
- * member boundaries (such as keeping synthetic discriminant objects out of a run).
252
+ * run and pass through unchanged. The merge follows member order, so callers control which members
253
+ * combine by where they place them in the sequence.
255
254
  *
256
255
  * @example
257
256
  * ```ts
@@ -394,14 +393,28 @@ function getNestedAccessor(param, accessor) {
394
393
  //#endregion
395
394
  //#region src/utils/schemaGraph.ts
396
395
  /**
397
- * Collects every named schema referenced transitively from a node through its ref edges.
396
+ * Memoized inner pass that walks a single node and returns the names of every schema it references.
397
+ */
398
+ const collectSchemaRefs = memoize(/* @__PURE__ */ new WeakMap(), (node) => {
399
+ const refs = /* @__PURE__ */ new Set();
400
+ collect(node, { schema(child) {
401
+ if (child.type === "ref") {
402
+ const name = resolveRefName(child);
403
+ if (name) refs.add(name);
404
+ }
405
+ } });
406
+ return refs;
407
+ });
408
+ /**
409
+ * Collects the names of every ref found anywhere inside a node's own subtree.
398
410
  *
399
- * Refs are followed by name only, so the resolved `node.schema` is never traversed inline.
411
+ * Each ref contributes its name only, so the schema it points to is never traversed here. Pass `out`
412
+ * to accumulate names from several nodes into one set.
400
413
  *
401
414
  * @example Collect refs from a single schema
402
415
  * ```ts
403
416
  * const names = collectReferencedSchemaNames(petSchema)
404
- * // Set { 'Category', 'Tag' }
417
+ * // Set { 'Category', 'Tag' }
405
418
  * ```
406
419
  *
407
420
  * @example Accumulate refs from multiple schemas into one set
@@ -412,39 +425,13 @@ function getNestedAccessor(param, accessor) {
412
425
  * }
413
426
  * ```
414
427
  */
415
- const collectSchemaRefs = memoize(/* @__PURE__ */ new WeakMap(), (node) => {
416
- const refs = /* @__PURE__ */ new Set();
417
- collect(node, { schema(child) {
418
- if (child.type === "ref") {
419
- const name = resolveRefName(child);
420
- if (name) refs.add(name);
421
- }
422
- } });
423
- return refs;
424
- });
425
428
  function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
426
429
  if (!node) return out;
427
430
  for (const name of collectSchemaRefs(node)) out.add(name);
428
431
  return out;
429
432
  }
430
433
  /**
431
- * Collects the names of all top-level schemas transitively used by a set of operations.
432
- *
433
- * An operation uses a schema when its parameters, request body, or responses reference it, directly
434
- * or through other named schemas. The walk is iterative, so reference cycles are safe.
435
- *
436
- * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.
437
- *
438
- * @example Only generate schemas referenced by included operations
439
- * ```ts
440
- * const includedOps = operations.filter((op) => resolver.resolveOptions(op, { options, include }) !== null)
441
- * const allowed = collectUsedSchemaNames(includedOps, schemas)
442
- *
443
- * for (const schema of schemas) {
444
- * if (schema.name && !allowed.has(schema.name)) continue
445
- * // … generate schema
446
- * }
447
- * ```
434
+ * Memoized two-level cache keyed first on the operations array, then on the schemas array.
448
435
  */
449
436
  const collectUsedSchemaNamesMemo = memoize(/* @__PURE__ */ new WeakMap(), (ops) => memoize(/* @__PURE__ */ new WeakMap(), (schemas) => computeUsedSchemaNames(ops, schemas)));
450
437
  function computeUsedSchemaNames(operations, schemas) {
@@ -465,6 +452,26 @@ function computeUsedSchemaNames(operations, schemas) {
465
452
  })) visitSchema(schema);
466
453
  return result;
467
454
  }
455
+ /**
456
+ * Collects the names of all top-level schemas transitively used by a set of operations.
457
+ *
458
+ * An operation uses a schema when its parameters, request body, or responses reference it, directly
459
+ * or through other named schemas. Once a name is added to the result it is not revisited, so
460
+ * reference cycles terminate.
461
+ *
462
+ * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.
463
+ *
464
+ * @example Only generate schemas referenced by included operations
465
+ * ```ts
466
+ * const includedOps = operations.filter((op) => resolver.resolveOptions(op, { options, include }) !== null)
467
+ * const allowed = collectUsedSchemaNames(includedOps, schemas)
468
+ *
469
+ * for (const schema of schemas) {
470
+ * if (schema.name && !allowed.has(schema.name)) continue
471
+ * // generate schema
472
+ * }
473
+ * ```
474
+ */
468
475
  function collectUsedSchemaNames(operations, schemas) {
469
476
  return collectUsedSchemaNamesMemo(operations)(schemas);
470
477
  }
@@ -578,13 +585,6 @@ function lazyGetter({ name, body }) {
578
585
  }
579
586
  //#endregion
580
587
  //#region src/utils/operationParams.ts
581
- /**
582
- * Applies casing rules to parameter names and returns a new array without mutating the input.
583
- *
584
- * Run it before handing parameters to schema builders so output property keys get the right casing
585
- * while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the
586
- * original array is returned unchanged.
587
- */
588
588
  const caseParamsMemo = memoize(/* @__PURE__ */ new WeakMap(), (params) => memoize(/* @__PURE__ */ new Map(), (casing) => params.map((param) => {
589
589
  const transformed = casing === "camelcase" || !isValidVarName(param.name) ? camelCase(param.name) : param.name;
590
590
  return {
@@ -592,6 +592,13 @@ const caseParamsMemo = memoize(/* @__PURE__ */ new WeakMap(), (params) => memoiz
592
592
  name: transformed
593
593
  };
594
594
  })));
595
+ /**
596
+ * Applies casing rules to parameter names and returns a new array without mutating the input.
597
+ *
598
+ * Run it before handing parameters to schema builders so output property keys get the right casing
599
+ * while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the
600
+ * original array is returned unchanged.
601
+ */
595
602
  function caseParams(params, casing) {
596
603
  if (!casing) return params;
597
604
  return caseParamsMemo(params)(casing);
@@ -767,4 +774,4 @@ function buildTypeLiteral({ node, params, resolver }) {
767
774
  //#endregion
768
775
  export { objectKey as C, buildObject as S, toRegExpString as _, resolveParamType as a, buildJSDoc as b, mapSchemaMembers as c, containsCircularRef as d, findCircularSchemas as f, stringifyObject as g, stringify as h, createOperationParams as i, mapSchemaProperties as l, jsStringEscape as m, buildTypeLiteral as n, lazyGetter as o, getNestedAccessor as p, caseParams as r, mapSchemaItems as s, buildGroupParam as t, collectUsedSchemaNames as u, trimQuotes as v, isValidVarName as w, buildList as x, mergeAdjacentObjectsLazy as y };
769
776
 
770
- //# sourceMappingURL=utils-DW9rnfsD.js.map
777
+ //# sourceMappingURL=utils-BJi0y-xg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils-BJi0y-xg.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/string.ts","../src/utils/codegen.ts","../src/utils/schemaMerge.ts","../src/utils/strings.ts","../src/utils/schemaGraph.ts","../src/utils/schemaTraversal.ts","../src/utils/operationParams.ts"],"sourcesContent":["function* chunks<T>(arr: ReadonlyArray<T>, size: number): Generator<Array<T>> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: ReadonlyArray<T> | AsyncIterable<T>,\n process: (batch: Array<T>) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: Array<T> = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return isIdentifier(name)\n}\n\n/**\n * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.\n *\n * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys\n * even though they are not valid variable names, so use this (not {@link isValidVarName}) when\n * deciding whether an object key needs quoting.\n *\n * @example\n * ```ts\n * isIdentifier('name') // true\n * isIdentifier('x-total')// false\n * ```\n */\nexport function isIdentifier(name: string): boolean {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n","/**\n * Wraps a value in single quotes for emitting a single-quoted JavaScript string literal, escaping\n * any backslash or single quote in the content.\n *\n * @example\n * ```ts\n * singleQuote('foo') // \"'foo'\"\n * singleQuote(\"o'clock\") // \"'o\\\\'clock'\"\n * ```\n */\nexport function singleQuote(value: string | number | boolean | undefined | null): string {\n if (value === undefined || value === null) return \"''\"\n const escaped = String(value).replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n\n return `'${escaped}'`\n}\n","import { isIdentifier, singleQuote } from '@internals/utils'\nimport { INDENT } from '../constants.ts'\n\n/**\n * Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no\n * comments.\n *\n * @example\n * ```ts\n * buildJSDoc(['@type string', '@example hello'])\n * // '/**\\n * @type string\\n * @example hello\\n *\\/\\n '\n * ```\n */\nexport function buildJSDoc(\n comments: Array<string>,\n options: {\n /**\n * String used to indent each comment line.\n * @default ' * '\n */\n indent?: string\n /**\n * String appended after the closing tag.\n * @default '\\n '\n */\n suffix?: string\n /**\n * Returned as-is when `comments` is empty.\n * @default ' '\n */\n fallback?: string\n } = {},\n): string {\n const { indent = ' * ', suffix = '\\n ', fallback = ' ' } = options\n\n if (comments.length === 0) return fallback\n\n return `/**\\n${comments.map((c) => `${indent}${c}`).join('\\n')}\\n */${suffix}`\n}\n\n/**\n * Indents every non-empty line of `text` by one indent level, leaving blank lines empty.\n */\nfunction indentLines(text: string): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${INDENT}${line}` : ''))\n .join('\\n')\n}\n\n/**\n * Renders an object key, quoting it with single quotes only when it is not a valid identifier.\n * Reserved words and globals (`name`, `class`, …) are valid bare keys and stay unquoted.\n *\n * @example\n * ```ts\n * objectKey('name') // 'name'\n * objectKey('x-total') // \"'x-total'\"\n * ```\n */\nexport function objectKey(name: string): string {\n return isIdentifier(name) ? name : singleQuote(name)\n}\n\n/**\n * Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one\n * level and closing the brace at column zero. Entries that are themselves multi-line objects indent\n * cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.\n *\n * @example\n * ```ts\n * buildObject(['id: z.number()', 'name: z.string()'])\n * // '{\\n id: z.number(),\\n name: z.string(),\\n}'\n * ```\n */\nexport function buildObject(entries: Array<string>): string {\n if (entries.length === 0) return '{}'\n const body = entries.map((entry) => `${indentLines(entry)},`).join('\\n')\n\n return `{\\n${body}\\n}`\n}\n\n/**\n * Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on\n * one line when no item spans multiple lines, and otherwise puts each item on its own line, indented\n * one level with a trailing comma and the closing bracket at column zero. Used for member lists such\n * as `z.union([…])` and `z.array([…])`.\n *\n * @example\n * ```ts\n * buildList(['z.string()', 'z.number()'])\n * // '[z.string(), z.number()]'\n * ```\n */\nexport function buildList(items: Array<string>, brackets: [open: string, close: string] = ['[', ']']): string {\n const [open, close] = brackets\n if (items.length === 0) return `${open}${close}`\n if (!items.some((item) => item.includes('\\n'))) return `${open}${items.join(', ')}${close}`\n const body = items.map((item) => `${indentLines(item)},`).join('\\n')\n\n return `${open}\\n${body}\\n${close}`\n}\n","import { narrowSchema } from '../guards.ts'\nimport { createSchema, type SchemaNode } from '../nodes/schema.ts'\n\n/**\n * Merges a run of adjacent anonymous object members into one. Named or non-object members break the\n * run and pass through unchanged. The merge follows member order, so callers control which members\n * combine by where they place them in the sequence.\n *\n * @example\n * ```ts\n * const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]\n * ```\n */\nexport function* mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined> {\n let acc: SchemaNode | undefined\n\n for (const member of members) {\n const objectMember = narrowSchema(member, 'object')\n if (objectMember && !objectMember.name && acc !== undefined) {\n const accObject = narrowSchema(acc, 'object')\n if (accObject && !accObject.name) {\n acc = createSchema({\n ...accObject,\n properties: [...(accObject.properties ?? []), ...(objectMember.properties ?? [])],\n })\n continue\n }\n }\n if (acc !== undefined) yield acc\n acc = member\n }\n\n if (acc !== undefined) yield acc\n}\n","/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * ```ts\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n * ```\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Serializes a primitive to a single-quoted string literal, stripping any surrounding quotes first.\n *\n * Escaping runs through `JSON.stringify`, then the result switches to single quotes so the generated\n * code matches the repo style without a formatter.\n *\n * @example\n * ```ts\n * stringify('hello') // \"'hello'\"\n * stringify('\"hello\"') // \"'hello'\"\n * ```\n */\nexport function stringify(value: string | number | boolean | undefined): string {\n if (value === undefined || value === null) return \"''\"\n const json = JSON.stringify(trimQuotes(value.toString()))\n const inner = json.slice(1, -1).replace(/\\\\\"/g, '\"').replace(/'/g, \"\\\\'\")\n return `'${inner}'`\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,\n * and the Unicode line terminators U+2028 and U+2029.\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.\n * Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.\n * Pass `null` as the second argument to emit a `/pattern/flags` literal instead.\n *\n * @example\n * ```ts\n * toRegExpString('^(?im)foo') // 'new RegExp(\"^foo\", \"im\")'\n * toRegExpString('^(?im)foo', null) // '/^foo/im'\n * ```\n */\nexport function toRegExpString(text: string, func: string | null = 'RegExp'): string {\n const raw = trimQuotes(text)\n\n const match = raw.match(/^\\^(\\(\\?([igmsuy]+)\\))/i)\n const replacementTarget = match?.[1] ?? ''\n const matchedFlags = match?.[2]\n const cleaned = raw\n .replace(/^\\\\?\\//, '')\n .replace(/\\\\?\\/$/, '')\n .replace(replacementTarget, '')\n\n const { source, flags } = new RegExp(cleaned, matchedFlags)\n\n if (func === null) return `/${source}/${flags}`\n\n return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ''})`\n}\n\n/**\n * Renders a plain object as multi-line `key: value` source for embedding in generated code. Nested\n * objects recurse with fixed indentation, so the result drops straight into an object literal\n * without re-parsing.\n *\n * @example\n * ```ts\n * stringifyObject({ foo: 'bar', nested: { a: 1 } })\n * // 'foo: bar,\\nnested: {\\n a: 1\\n }'\n * ```\n */\nexport function stringifyObject(value: Record<string, unknown>): string {\n const items = Object.entries(value)\n .map(([key, val]) => {\n if (val !== null && typeof val === 'object') {\n return `${key}: {\\n ${stringifyObject(val as Record<string, unknown>)}\\n }`\n }\n return `${key}: ${val}`\n })\n .filter(Boolean)\n return items.join(',\\n')\n}\n\n/**\n * Renders a dotted path or string array as an optional-chaining accessor expression rooted at\n * `accessor`. Returns `null` for an empty path.\n *\n * @example\n * ```ts\n * getNestedAccessor('pagination.next.id', 'lastPage')\n * // \"lastPage?.['pagination']?.['next']?.['id']\"\n * ```\n */\nexport function getNestedAccessor(param: string | Array<string>, accessor: string): string | null {\n const parts = Array.isArray(param) ? param : param.split('.')\n if (parts.length === 0 || (parts.length === 1 && parts[0] === '')) return null\n return `${accessor}?.['${`${parts.join(\"']?.['\")}']`}`\n}\n","import { memoize } from '@internals/utils'\nimport type { OperationNode, SchemaNode } from '../nodes/index.ts'\nimport { collect, collectLazy } from '../visitor.ts'\nimport { resolveRefName } from './refs.ts'\n\n/**\n * Memoized inner pass that walks a single node and returns the names of every schema it references.\n */\nconst collectSchemaRefs = memoize(new WeakMap<SchemaNode, ReadonlySet<string>>(), (node: SchemaNode): ReadonlySet<string> => {\n const refs = new Set<string>()\n collect<void>(node, {\n schema(child) {\n if (child.type === 'ref') {\n const name = resolveRefName(child)\n if (name) refs.add(name)\n }\n },\n })\n return refs\n})\n\n/**\n * Collects the names of every ref found anywhere inside a node's own subtree.\n *\n * Each ref contributes its name only, so the schema it points to is never traversed here. Pass `out`\n * to accumulate names from several nodes into one set.\n *\n * @example Collect refs from a single schema\n * ```ts\n * const names = collectReferencedSchemaNames(petSchema)\n * // Set { 'Category', 'Tag' }\n * ```\n *\n * @example Accumulate refs from multiple schemas into one set\n * ```ts\n * const out = new Set<string>()\n * for (const schema of schemas) {\n * collectReferencedSchemaNames(schema, out)\n * }\n * ```\n */\nexport function collectReferencedSchemaNames(node: SchemaNode | undefined, out: Set<string> = new Set()): Set<string> {\n if (!node) return out\n for (const name of collectSchemaRefs(node)) out.add(name)\n return out\n}\n\n/**\n * Memoized two-level cache keyed first on the operations array, then on the schemas array.\n */\nconst collectUsedSchemaNamesMemo = memoize(new WeakMap<ReadonlyArray<OperationNode>, (schemas: ReadonlyArray<SchemaNode>) => Set<string>>(), (ops) =>\n memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas) => computeUsedSchemaNames(ops, schemas)),\n)\n\nfunction computeUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n const schemaMap = new Map<string, SchemaNode>()\n for (const schema of schemas) {\n if (schema.name) schemaMap.set(schema.name, schema)\n }\n\n const result = new Set<string>()\n\n function visitSchema(schema: SchemaNode): void {\n const directRefs = collectReferencedSchemaNames(schema)\n for (const name of directRefs) {\n if (!result.has(name)) {\n result.add(name)\n const namedSchema = schemaMap.get(name)\n if (namedSchema) visitSchema(namedSchema)\n }\n }\n }\n\n for (const op of operations) {\n for (const schema of collectLazy<SchemaNode>(op, { depth: 'shallow', schema: (node) => node })) {\n visitSchema(schema)\n }\n }\n\n return result\n}\n\n/**\n * Collects the names of all top-level schemas transitively used by a set of operations.\n *\n * An operation uses a schema when its parameters, request body, or responses reference it, directly\n * or through other named schemas. Once a name is added to the result it is not revisited, so\n * reference cycles terminate.\n *\n * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.\n *\n * @example Only generate schemas referenced by included operations\n * ```ts\n * const includedOps = operations.filter((op) => resolver.resolveOptions(op, { options, include }) !== null)\n * const allowed = collectUsedSchemaNames(includedOps, schemas)\n *\n * for (const schema of schemas) {\n * if (schema.name && !allowed.has(schema.name)) continue\n * // generate schema\n * }\n * ```\n */\nexport function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string> {\n return collectUsedSchemaNamesMemo(operations)(schemas)\n}\n\nconst EMPTY_CIRCULAR_SET = new Set<string>()\n\nconst findCircularSchemasMemo = memoize(new WeakMap<ReadonlyArray<SchemaNode>, Set<string>>(), (schemas: ReadonlyArray<SchemaNode>): Set<string> => {\n const graph = new Map<string, Set<string>>()\n\n for (const schema of schemas) {\n if (!schema.name) continue\n graph.set(schema.name, collectReferencedSchemaNames(schema))\n }\n\n const circular = new Set<string>()\n for (const start of graph.keys()) {\n const visited = new Set<string>()\n const stack: Array<string> = [...(graph.get(start) ?? [])]\n while (stack.length > 0) {\n const node = stack.pop()!\n if (node === start) {\n circular.add(start)\n break\n }\n if (visited.has(node)) continue\n visited.add(node)\n\n const next = graph.get(node)\n if (next) for (const r of next) stack.push(r)\n }\n }\n\n return circular\n})\n\n/**\n * Finds every schema that takes part in a circular dependency chain, including direct self-loops.\n *\n * Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so\n * the generated code does not recurse forever. Refs are followed by name only, so the walk stays\n * linear in the size of the schema graph.\n *\n * @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.\n */\nexport function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<string> {\n if (schemas.length === 0) return EMPTY_CIRCULAR_SET\n return findCircularSchemasMemo(schemas)\n}\n\n/**\n * Returns `true` when a schema, or anything nested inside it, references a circular schema.\n *\n * Pass `excludeName` to skip refs to a specific schema, which helps when self-references are handled\n * on their own. Pair it with `findCircularSchemas()` to decide where lazy wrappers go.\n *\n * @note Stops at the first matching circular ref.\n */\nexport function containsCircularRef(\n node: SchemaNode | undefined,\n { circularSchemas, excludeName }: { circularSchemas: ReadonlySet<string>; excludeName?: string },\n): boolean {\n if (!node || circularSchemas.size === 0) return false\n\n for (const _ of collectLazy<true>(node, {\n schema(child) {\n if (child.type !== 'ref') return null\n const name = resolveRefName(child)\n return name && name !== excludeName && circularSchemas.has(name) ? true : null\n },\n })) {\n return true\n }\n\n return false\n}\n","import type { ArraySchemaNode, IntersectionSchemaNode, ObjectSchemaNode, PropertyNode, SchemaNode, UnionSchemaNode } from '../nodes/index.ts'\nimport { objectKey } from './codegen.ts'\n\n/**\n * Converts a child schema to printer output. Plugins instantiate it with their own output type:\n * `string` for the zod and faker printers, `ts.TypeNode` for the TypeScript printer. A printer's\n * `this.transform` fits directly, so its `null` for an empty result carries through to `output`.\n */\nexport type SchemaTransform<TOutput> = (schema: SchemaNode) => TOutput\n\n/**\n * A union or intersection member, or an array or tuple item, paired with its transformed output.\n */\nexport type MappedSchema<TOutput> = {\n /**\n * The original child schema, kept so the printer can read its metadata for leaf formatting.\n */\n schema: SchemaNode\n /**\n * The child schema after being run through the transform.\n */\n output: TOutput\n}\n\n/**\n * An object property paired with its transformed output.\n */\nexport type MappedProperty<TOutput> = {\n /**\n * The property name as written on the schema, before any identifier quoting.\n */\n name: string\n /**\n * The original property node, kept so the printer can read `required`, `schema`, and metadata.\n */\n property: PropertyNode\n /**\n * The property schema after being run through the transform.\n */\n output: TOutput\n}\n\n/**\n * Maps each property of an object schema to its transformed output. Pairs every result with the\n * original property so the printer keeps full control over modifiers, getters, and key syntax.\n *\n * @example\n * ```ts\n * const entries = mapSchemaProperties(node, (schema) => this.transform(schema))\n * // entries: [{ name: 'id', property, output: 'z.number()' }, ...]\n * ```\n */\nexport function mapSchemaProperties<TOutput>(node: ObjectSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedProperty<TOutput>> {\n return node.properties.map((property) => ({ name: property.name, property, output: transform(property.schema) }))\n}\n\n/**\n * Maps each member of a union or intersection schema to its transformed output, pairing every\n * result with the original member.\n */\nexport function mapSchemaMembers<TOutput>(node: UnionSchemaNode | IntersectionSchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>> {\n return (node.members ?? []).map((schema) => ({ schema, output: transform(schema) }))\n}\n\n/**\n * Maps each item of an array or tuple schema to its transformed output, pairing every result with\n * the original item.\n */\nexport function mapSchemaItems<TOutput>(node: ArraySchemaNode, transform: SchemaTransform<TOutput>): Array<MappedSchema<TOutput>> {\n return (node.items ?? []).map((schema) => ({ schema, output: transform(schema) }))\n}\n\n/**\n * Emits a lazy getter for a circular-ref property position, `get name() { return body }`. The key\n * is quoted only when it is not a valid identifier. Used by the string printers to defer evaluation\n * of a recursive schema until first access.\n *\n * @example\n * ```ts\n * lazyGetter({ name: 'parent', body: 'z.lazy(() => Pet)' })\n * // \"get parent() { return z.lazy(() => Pet) }\"\n * ```\n */\nexport function lazyGetter({ name, body }: { name: string; body: string }): string {\n return `get ${objectKey(name)}() { return ${body} }`\n}\n","import { camelCase, isValidVarName, memoize } from '@internals/utils'\nimport { createFunctionParameter, createFunctionParameters, createIndexedAccessType, createTypeLiteral } from '../nodes/function.ts'\nimport type { FunctionParameterNode, FunctionParametersNode, OperationNode, ParameterNode, TypeExpression, TypeLiteralNode } from '../nodes/index.ts'\nimport { resolveGroupType } from './refs.ts'\n\nconst caseParamsMemo = memoize(new WeakMap<Array<ParameterNode>, (casing: string) => Array<ParameterNode>>(), (params) =>\n memoize(new Map<string, Array<ParameterNode>>(), (casing: string) =>\n params.map((param) => {\n const transformed = casing === 'camelcase' || !isValidVarName(param.name) ? camelCase(param.name) : param.name\n return { ...param, name: transformed }\n }),\n ),\n)\n\n/**\n * Applies casing rules to parameter names and returns a new array without mutating the input.\n *\n * Run it before handing parameters to schema builders so output property keys get the right casing\n * while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the\n * original array is returned unchanged.\n */\nexport function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode> {\n if (!casing) return params\n return caseParamsMemo(params)(casing)\n}\n\n/**\n * Named type for a group of parameters (query or header) emitted as a single typed parameter.\n */\nexport type ParamGroupType = {\n /**\n * Type expression for the group, a plain group-name reference.\n */\n type: TypeExpression\n /**\n * Whether the parameter group is optional.\n */\n optional: boolean\n}\n\n/**\n * A single member of a destructured parameter group, fed to `createFunctionParameter({ properties })`.\n */\ntype GroupProperty = {\n name: string\n type: TypeExpression\n optional?: boolean\n}\n\n/**\n * Resolver interface for {@link createOperationParams}.\n *\n * `ResolverTs` from `@kubb/plugin-ts` satisfies this interface and can be passed directly.\n */\nexport type OperationParamsResolver = {\n /**\n * Resolves the type name for an individual parameter.\n *\n * @example Individual path parameter name\n * `resolver.resolveParamName(node, param) // → 'DeletePetPathPetId'`\n */\n resolveParamName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the request body type name.\n *\n * @example Request body type name\n * `resolver.resolveDataName(node) // → 'CreatePetData'`\n */\n resolveDataName(node: OperationNode): string\n /**\n * Resolves the grouped path parameters type name.\n * When the return value equals `resolveParamName`, no indexed access is emitted.\n *\n * @example Grouped path params type name\n * `resolver.resolvePathParamsName(node, param) // → 'DeletePetPathParams'`\n */\n resolvePathParamsName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the grouped query parameters type name.\n * When the return value equals `resolveParamName`, an inline struct type is emitted instead.\n *\n * @example Grouped query params type name\n * `resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'`\n */\n resolveQueryParamsName(node: OperationNode, param: ParameterNode): string\n /**\n * Resolves the grouped header parameters type name.\n * When the return value equals `resolveParamName`, an inline struct type is emitted instead.\n *\n * @example Grouped header params type name\n * `resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'`\n */\n resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string\n}\n\n/**\n * Options for {@link createOperationParams}.\n */\nexport type CreateOperationParamsOptions = {\n /**\n * How all operation parameters are grouped in the function signature.\n * - `'object'` wraps all params into a single destructured object `{ petId, data, params }`\n * - `'inline'` emits each param category as a separate top-level parameter\n */\n paramsType: 'object' | 'inline'\n /**\n * How path parameters are emitted when `paramsType` is `'inline'`.\n * - `'object'` groups them as `{ petId, storeId }: PathParams`\n * - `'inline'` spreads them as individual parameters `petId: string, storeId: string`\n * - `'inlineSpread'` emits a single rest parameter `...pathParams: PathParams`\n */\n pathParamsType: 'object' | 'inline' | 'inlineSpread'\n /**\n * Converts parameter names to camelCase before output.\n */\n paramsCasing?: 'camelcase'\n /**\n * Resolver for parameter and request body type names.\n * Pass `ResolverTs` from `@kubb/plugin-ts` directly.\n * When omitted, falls back to the schema primitive or `'unknown'`.\n */\n resolver?: OperationParamsResolver\n /**\n * Default value for the path parameters binding when `pathParamsType` is `'object'`.\n * Falls back to `'{}'` when all path params are optional.\n */\n pathParamsDefault?: string\n /**\n * Extra parameters appended after the standard operation parameters.\n *\n * @example Plugin-specific trailing parameter\n * ```ts\n * extraParams: [createFunctionParameter({ name: 'options', type: 'Partial<RequestOptions>', default: '{}' })]\n * ```\n */\n extraParams?: Array<FunctionParameterNode>\n /**\n * Override the default parameter names used for body, query, header, and rest-path groups.\n *\n * Useful when targeting languages or frameworks with different naming conventions.\n *\n * @default { data: 'data', params: 'params', headers: 'headers', path: 'pathParams' }\n */\n paramNames?: {\n /**\n * Name for the request body parameter.\n * @default 'data'\n */\n data?: string\n /**\n * Name for the query parameters group parameter.\n * @default 'params'\n */\n params?: string\n /**\n * Name for the header parameters group parameter.\n * @default 'headers'\n */\n headers?: string\n /**\n * Name for the rest path-parameters parameter when `pathParamsType` is `'inlineSpread'`.\n * @default 'pathParams'\n */\n path?: string\n }\n /**\n * Transforms every resolved type name before it lands in a parameter node, for framework-level\n * type wrappers.\n *\n * @example Vue Query, wrap every parameter type with `MaybeRefOrGetter`\n * `typeWrapper: (t) => \\`MaybeRefOrGetter<${t}>\\``\n */\n typeWrapper?: (type: string) => string\n}\n\n/**\n * Resolves the {@link TypeExpression} for an individual parameter.\n *\n * Without a resolver, it falls back to the schema primitive (a plain type-name string). When the\n * parameter belongs to a named group, it emits an {@link IndexedAccessTypeNode} like\n * `GroupParams['petId']`, otherwise the resolved individual name.\n */\nexport function resolveParamType({\n node,\n param,\n resolver,\n}: {\n node: OperationNode\n param: ParameterNode\n resolver: OperationParamsResolver | undefined\n}): TypeExpression {\n if (!resolver) {\n return param.schema.primitive ?? 'unknown'\n }\n\n const individualName = resolver.resolveParamName(node, param)\n\n const groupLocation = param.in === 'path' || param.in === 'query' || param.in === 'header' ? param.in : undefined\n\n const groupResolvers = {\n path: resolver.resolvePathParamsName,\n query: resolver.resolveQueryParamsName,\n header: resolver.resolveHeaderParamsName,\n } as const\n\n const groupName = groupLocation ? groupResolvers[groupLocation].call(resolver, node, param) : undefined\n\n if (groupName && groupName !== individualName) {\n return createIndexedAccessType({ target: groupName, key: param.name })\n }\n\n return individualName\n}\n\n/**\n * Converts an `OperationNode` into function parameters for code generation.\n *\n * Centralizes parameter grouping logic for all plugins. `paramsType` chooses between one\n * destructured object parameter (`object`) and separate top-level parameters (`inline`), while\n * `pathParamsType` controls how path params render in inline mode. Provide a `resolver` for type\n * name resolution and `extraParams` for plugin-specific trailing parameters such as an `options` object.\n */\nexport function createOperationParams(node: OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode {\n const { paramsType, pathParamsType, paramsCasing, resolver, pathParamsDefault, extraParams = [], paramNames, typeWrapper } = options\n\n const dataName = paramNames?.data ?? 'data'\n const paramsName = paramNames?.params ?? 'params'\n const headersName = paramNames?.headers ?? 'headers'\n const pathName = paramNames?.path ?? 'pathParams'\n\n const wrapType = (type: string): string => (typeWrapper ? typeWrapper(type) : type)\n // typeWrapper takes a type-name string, so only plain references are wrapped.\n // TypeLiteral and IndexedAccessType expressions are pre-resolved and pass through unchanged.\n const wrapTypeExpression = (type: TypeExpression): TypeExpression => (typeof type === 'string' ? wrapType(type) : type)\n\n const casedParams = caseParams(node.parameters, paramsCasing)\n const pathParams = casedParams.filter((p) => p.in === 'path')\n const queryParams = casedParams.filter((p) => p.in === 'query')\n const headerParams = casedParams.filter((p) => p.in === 'header')\n\n const toProperty = (param: ParameterNode): GroupProperty => ({\n name: param.name,\n type: wrapTypeExpression(resolveParamType({ node, param, resolver })),\n optional: !param.required,\n })\n const emptyObjectDefault = (props: Array<GroupProperty>): string | undefined => (props.every((p) => p.optional) ? '{}' : undefined)\n\n const bodyType = node.requestBody?.content?.[0]?.schema ? wrapType(resolver?.resolveDataName(node) ?? 'unknown') : undefined\n const bodyProperty: Array<GroupProperty> = bodyType ? [{ name: dataName, type: bodyType, optional: !(node.requestBody?.required ?? false) }] : []\n\n const trailingGroups: Array<BuildGroupArgs> = [\n { name: paramsName, node, params: queryParams, groupType: resolveGroupType({ node, params: queryParams, group: 'query', resolver }), resolver, wrapType },\n {\n name: headersName,\n node,\n params: headerParams,\n groupType: resolveGroupType({ node, params: headerParams, group: 'header', resolver }),\n resolver,\n wrapType,\n },\n ]\n\n const params: Array<FunctionParameterNode> = []\n\n if (paramsType === 'object') {\n const children = [...pathParams.map(toProperty), ...bodyProperty, ...trailingGroups.flatMap(buildGroupProperty)]\n if (children.length) {\n params.push(createFunctionParameter({ properties: children, default: emptyObjectDefault(children) }))\n }\n } else {\n if (pathParamsType === 'inlineSpread' && pathParams.length) {\n const spreadType = resolver?.resolvePathParamsName(node, pathParams[0]!)\n params.push(createFunctionParameter({ name: pathName, type: spreadType ? wrapType(spreadType) : undefined, rest: true }))\n } else if (pathParamsType === 'inline') {\n params.push(...pathParams.map((p) => createFunctionParameter(toProperty(p))))\n } else if (pathParams.length) {\n const pathChildren = pathParams.map(toProperty)\n params.push(createFunctionParameter({ properties: pathChildren, default: pathParamsDefault ?? emptyObjectDefault(pathChildren) }))\n }\n\n params.push(...bodyProperty.map((p) => createFunctionParameter(p)))\n params.push(...trailingGroups.flatMap(buildGroupParam))\n }\n\n params.push(...extraParams)\n\n return createFunctionParameters({ params })\n}\n\n/**\n * Shared arguments for building a query or header parameter group.\n */\nexport type BuildGroupArgs = {\n name: string\n node: OperationNode\n params: Array<ParameterNode>\n groupType: ParamGroupType | null\n resolver: OperationParamsResolver | undefined\n wrapType: (type: string) => string\n}\n\n/**\n * Builds the property descriptor for a query or header group.\n * Returns an empty array when there are no params to emit.\n *\n * A pre-resolved `groupType` emits `name: GroupType`. Otherwise it builds an inline\n * {@link TypeLiteralNode} from the individual params.\n */\nfunction buildGroupProperty({ name, node, params, groupType, resolver, wrapType }: BuildGroupArgs): Array<GroupProperty> {\n if (groupType) {\n const type = typeof groupType.type === 'string' ? wrapType(groupType.type) : groupType.type\n return [{ name, type, optional: groupType.optional }]\n }\n if (params.length) {\n return [{ name, type: buildTypeLiteral({ node, params, resolver }), optional: params.every((p) => !p.required) }]\n }\n return []\n}\n\n/**\n * Builds a single {@link FunctionParameterNode} for a query or header group.\n * Returns an empty array when there are no params to emit.\n *\n * A pre-resolved `groupType` emits `name: GroupType`. Otherwise it builds an inline\n * {@link TypeLiteralNode} from the individual params.\n */\nexport function buildGroupParam(args: BuildGroupArgs): Array<FunctionParameterNode> {\n return buildGroupProperty(args).map((p) => createFunctionParameter(p))\n}\n\n/**\n * Builds a {@link TypeLiteralNode} for an inline anonymous type grouping named fields.\n *\n * Used when query or header parameters have no dedicated group type name.\n * Each language printer renders this appropriately (TypeScript: `{ petId: string; name?: string }`).\n */\nexport function buildTypeLiteral({\n node,\n params,\n resolver,\n}: {\n node: OperationNode\n params: Array<ParameterNode>\n resolver: OperationParamsResolver | undefined\n}): TypeLiteralNode {\n return createTypeLiteral({\n members: params.map((p) => ({\n name: p.name,\n type: resolveParamType({ node, param: p, resolver }),\n optional: !p.required,\n })),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6IA,SAAgB,QAAsB,OAA4B,SAAuD;CACvH,QAAQ,QAAsB;EAC5B,IAAI,MAAM,IAAI,GAAG,GAAG,OAAO,MAAM,IAAI,GAAG;EACxC,MAAM,QAAQ,QAAQ,GAAG;EACzB,MAAM,IAAI,KAAK,KAAK;EACpB,OAAO;CACT;AACF;;;;;;;AChJA,MAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;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./response-BeG6hq2D.cjs");
2
- const require_visitor = require("./visitor-B7Zlnp4c.cjs");
1
+ const require_schema = require("./schema-BkvrrOAr.cjs");
2
+ const require_refs = require("./refs-u5SDdyV7.cjs");
3
3
  //#region ../../internals/utils/src/promise.ts
4
4
  /**
5
5
  * Wraps `factory` with a keyed cache backed by the provided store.
@@ -177,8 +177,8 @@ function singleQuote(value) {
177
177
  //#endregion
178
178
  //#region src/utils/codegen.ts
179
179
  /**
180
- * Builds a JSDoc comment block from an array of lines, returning `fallback` when there are no
181
- * comments so callers always get a usable string.
180
+ * Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no
181
+ * comments.
182
182
  *
183
183
  * @example
184
184
  * ```ts
@@ -196,7 +196,7 @@ function buildJSDoc(comments, options = {}) {
196
196
  */
197
197
  function indentLines(text) {
198
198
  if (!text) return "";
199
- return text.split("\n").map((line) => line.trim() ? `${require_visitor.INDENT}${line}` : "").join("\n");
199
+ return text.split("\n").map((line) => line.trim() ? `${require_refs.INDENT}${line}` : "").join("\n");
200
200
  }
201
201
  /**
202
202
  * Renders an object key, quoting it with single quotes only when it is not a valid identifier.
@@ -213,9 +213,8 @@ function objectKey(name) {
213
213
  }
214
214
  /**
215
215
  * Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
216
- * level and closing the brace at column zero. Nested objects built the same way indent cumulatively,
217
- * so callers never re-parse the generated code. A trailing comma is added per entry to match the
218
- * formatter's multi-line style.
216
+ * level and closing the brace at column zero. Entries that are themselves multi-line objects indent
217
+ * cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.
219
218
  *
220
219
  * @example
221
220
  * ```ts
@@ -230,8 +229,8 @@ function buildObject(entries) {
230
229
  /**
231
230
  * Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
232
231
  * one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
233
- * one level with a trailing comma and the closing bracket at column zero. Use it for `z.union([…])`,
234
- * `z.array([…])`, and similar member lists so objects inside them nest correctly.
232
+ * one level with a trailing comma and the closing bracket at column zero. Used for member lists such
233
+ * as `z.union([…])` and `z.array([…])`.
235
234
  *
236
235
  * @example
237
236
  * ```ts
@@ -249,8 +248,8 @@ function buildList(items, brackets = ["[", "]"]) {
249
248
  //#region src/utils/schemaMerge.ts
250
249
  /**
251
250
  * Merges a run of adjacent anonymous object members into one. Named or non-object members break the
252
- * run and pass through. Stays a construction-time helper, not a macro, so callers keep control of the
253
- * member boundaries (such as keeping synthetic discriminant objects out of a run).
251
+ * run and pass through unchanged. The merge follows member order, so callers control which members
252
+ * combine by where they place them in the sequence.
254
253
  *
255
254
  * @example
256
255
  * ```ts
@@ -260,11 +259,11 @@ function buildList(items, brackets = ["[", "]"]) {
260
259
  function* mergeAdjacentObjectsLazy(members) {
261
260
  let acc;
262
261
  for (const member of members) {
263
- const objectMember = require_visitor.narrowSchema(member, "object");
262
+ const objectMember = require_refs.narrowSchema(member, "object");
264
263
  if (objectMember && !objectMember.name && acc !== void 0) {
265
- const accObject = require_visitor.narrowSchema(acc, "object");
264
+ const accObject = require_refs.narrowSchema(acc, "object");
266
265
  if (accObject && !accObject.name) {
267
- acc = require_response.createSchema({
266
+ acc = require_schema.createSchema({
268
267
  ...accObject,
269
268
  properties: [...accObject.properties ?? [], ...objectMember.properties ?? []]
270
269
  });
@@ -393,14 +392,28 @@ function getNestedAccessor(param, accessor) {
393
392
  //#endregion
394
393
  //#region src/utils/schemaGraph.ts
395
394
  /**
396
- * Collects every named schema referenced transitively from a node through its ref edges.
395
+ * Memoized inner pass that walks a single node and returns the names of every schema it references.
396
+ */
397
+ const collectSchemaRefs = memoize(/* @__PURE__ */ new WeakMap(), (node) => {
398
+ const refs = /* @__PURE__ */ new Set();
399
+ require_refs.collect(node, { schema(child) {
400
+ if (child.type === "ref") {
401
+ const name = require_refs.resolveRefName(child);
402
+ if (name) refs.add(name);
403
+ }
404
+ } });
405
+ return refs;
406
+ });
407
+ /**
408
+ * Collects the names of every ref found anywhere inside a node's own subtree.
397
409
  *
398
- * Refs are followed by name only, so the resolved `node.schema` is never traversed inline.
410
+ * Each ref contributes its name only, so the schema it points to is never traversed here. Pass `out`
411
+ * to accumulate names from several nodes into one set.
399
412
  *
400
413
  * @example Collect refs from a single schema
401
414
  * ```ts
402
415
  * const names = collectReferencedSchemaNames(petSchema)
403
- * // Set { 'Category', 'Tag' }
416
+ * // Set { 'Category', 'Tag' }
404
417
  * ```
405
418
  *
406
419
  * @example Accumulate refs from multiple schemas into one set
@@ -411,39 +424,13 @@ function getNestedAccessor(param, accessor) {
411
424
  * }
412
425
  * ```
413
426
  */
414
- const collectSchemaRefs = memoize(/* @__PURE__ */ new WeakMap(), (node) => {
415
- const refs = /* @__PURE__ */ new Set();
416
- require_visitor.collect(node, { schema(child) {
417
- if (child.type === "ref") {
418
- const name = require_visitor.resolveRefName(child);
419
- if (name) refs.add(name);
420
- }
421
- } });
422
- return refs;
423
- });
424
427
  function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
425
428
  if (!node) return out;
426
429
  for (const name of collectSchemaRefs(node)) out.add(name);
427
430
  return out;
428
431
  }
429
432
  /**
430
- * Collects the names of all top-level schemas transitively used by a set of operations.
431
- *
432
- * An operation uses a schema when its parameters, request body, or responses reference it, directly
433
- * or through other named schemas. The walk is iterative, so reference cycles are safe.
434
- *
435
- * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.
436
- *
437
- * @example Only generate schemas referenced by included operations
438
- * ```ts
439
- * const includedOps = operations.filter((op) => resolver.resolveOptions(op, { options, include }) !== null)
440
- * const allowed = collectUsedSchemaNames(includedOps, schemas)
441
- *
442
- * for (const schema of schemas) {
443
- * if (schema.name && !allowed.has(schema.name)) continue
444
- * // … generate schema
445
- * }
446
- * ```
433
+ * Memoized two-level cache keyed first on the operations array, then on the schemas array.
447
434
  */
448
435
  const collectUsedSchemaNamesMemo = memoize(/* @__PURE__ */ new WeakMap(), (ops) => memoize(/* @__PURE__ */ new WeakMap(), (schemas) => computeUsedSchemaNames(ops, schemas)));
449
436
  function computeUsedSchemaNames(operations, schemas) {
@@ -458,12 +445,32 @@ function computeUsedSchemaNames(operations, schemas) {
458
445
  if (namedSchema) visitSchema(namedSchema);
459
446
  }
460
447
  }
461
- for (const op of operations) for (const schema of require_visitor.collectLazy(op, {
448
+ for (const op of operations) for (const schema of require_refs.collectLazy(op, {
462
449
  depth: "shallow",
463
450
  schema: (node) => node
464
451
  })) visitSchema(schema);
465
452
  return result;
466
453
  }
454
+ /**
455
+ * Collects the names of all top-level schemas transitively used by a set of operations.
456
+ *
457
+ * An operation uses a schema when its parameters, request body, or responses reference it, directly
458
+ * or through other named schemas. Once a name is added to the result it is not revisited, so
459
+ * reference cycles terminate.
460
+ *
461
+ * Pair it with `include` filters so schemas reachable only from excluded operations stay ungenerated.
462
+ *
463
+ * @example Only generate schemas referenced by included operations
464
+ * ```ts
465
+ * const includedOps = operations.filter((op) => resolver.resolveOptions(op, { options, include }) !== null)
466
+ * const allowed = collectUsedSchemaNames(includedOps, schemas)
467
+ *
468
+ * for (const schema of schemas) {
469
+ * if (schema.name && !allowed.has(schema.name)) continue
470
+ * // generate schema
471
+ * }
472
+ * ```
473
+ */
467
474
  function collectUsedSchemaNames(operations, schemas) {
468
475
  return collectUsedSchemaNamesMemo(operations)(schemas);
469
476
  }
@@ -515,9 +522,9 @@ function findCircularSchemas(schemas) {
515
522
  */
516
523
  function containsCircularRef(node, { circularSchemas, excludeName }) {
517
524
  if (!node || circularSchemas.size === 0) return false;
518
- for (const _ of require_visitor.collectLazy(node, { schema(child) {
525
+ for (const _ of require_refs.collectLazy(node, { schema(child) {
519
526
  if (child.type !== "ref") return null;
520
- const name = require_visitor.resolveRefName(child);
527
+ const name = require_refs.resolveRefName(child);
521
528
  return name && name !== excludeName && circularSchemas.has(name) ? true : null;
522
529
  } })) return true;
523
530
  return false;
@@ -577,6 +584,13 @@ function lazyGetter({ name, body }) {
577
584
  }
578
585
  //#endregion
579
586
  //#region src/utils/operationParams.ts
587
+ const caseParamsMemo = memoize(/* @__PURE__ */ new WeakMap(), (params) => memoize(/* @__PURE__ */ new Map(), (casing) => params.map((param) => {
588
+ const transformed = casing === "camelcase" || !isValidVarName(param.name) ? require_schema.camelCase(param.name) : param.name;
589
+ return {
590
+ ...param,
591
+ name: transformed
592
+ };
593
+ })));
580
594
  /**
581
595
  * Applies casing rules to parameter names and returns a new array without mutating the input.
582
596
  *
@@ -584,13 +598,6 @@ function lazyGetter({ name, body }) {
584
598
  * while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the
585
599
  * original array is returned unchanged.
586
600
  */
587
- const caseParamsMemo = memoize(/* @__PURE__ */ new WeakMap(), (params) => memoize(/* @__PURE__ */ new Map(), (casing) => params.map((param) => {
588
- const transformed = casing === "camelcase" || !isValidVarName(param.name) ? require_response.camelCase(param.name) : param.name;
589
- return {
590
- ...param,
591
- name: transformed
592
- };
593
- })));
594
601
  function caseParams(params, casing) {
595
602
  if (!casing) return params;
596
603
  return caseParamsMemo(params)(casing);
@@ -612,7 +619,7 @@ function resolveParamType({ node, param, resolver }) {
612
619
  header: resolver.resolveHeaderParamsName
613
620
  };
614
621
  const groupName = groupLocation ? groupResolvers[groupLocation].call(resolver, node, param) : void 0;
615
- if (groupName && groupName !== individualName) return require_response.createIndexedAccessType({
622
+ if (groupName && groupName !== individualName) return require_schema.createIndexedAccessType({
616
623
  target: groupName,
617
624
  key: param.name
618
625
  });
@@ -658,7 +665,7 @@ function createOperationParams(node, options) {
658
665
  name: paramsName,
659
666
  node,
660
667
  params: queryParams,
661
- groupType: require_visitor.resolveGroupType({
668
+ groupType: require_refs.resolveGroupType({
662
669
  node,
663
670
  params: queryParams,
664
671
  group: "query",
@@ -670,7 +677,7 @@ function createOperationParams(node, options) {
670
677
  name: headersName,
671
678
  node,
672
679
  params: headerParams,
673
- groupType: require_visitor.resolveGroupType({
680
+ groupType: require_refs.resolveGroupType({
674
681
  node,
675
682
  params: headerParams,
676
683
  group: "header",
@@ -686,31 +693,31 @@ function createOperationParams(node, options) {
686
693
  ...bodyProperty,
687
694
  ...trailingGroups.flatMap(buildGroupProperty)
688
695
  ];
689
- if (children.length) params.push(require_response.createFunctionParameter({
696
+ if (children.length) params.push(require_schema.createFunctionParameter({
690
697
  properties: children,
691
698
  default: emptyObjectDefault(children)
692
699
  }));
693
700
  } else {
694
701
  if (pathParamsType === "inlineSpread" && pathParams.length) {
695
702
  const spreadType = resolver?.resolvePathParamsName(node, pathParams[0]);
696
- params.push(require_response.createFunctionParameter({
703
+ params.push(require_schema.createFunctionParameter({
697
704
  name: pathName,
698
705
  type: spreadType ? wrapType(spreadType) : void 0,
699
706
  rest: true
700
707
  }));
701
- } else if (pathParamsType === "inline") params.push(...pathParams.map((p) => require_response.createFunctionParameter(toProperty(p))));
708
+ } else if (pathParamsType === "inline") params.push(...pathParams.map((p) => require_schema.createFunctionParameter(toProperty(p))));
702
709
  else if (pathParams.length) {
703
710
  const pathChildren = pathParams.map(toProperty);
704
- params.push(require_response.createFunctionParameter({
711
+ params.push(require_schema.createFunctionParameter({
705
712
  properties: pathChildren,
706
713
  default: pathParamsDefault ?? emptyObjectDefault(pathChildren)
707
714
  }));
708
715
  }
709
- params.push(...bodyProperty.map((p) => require_response.createFunctionParameter(p)));
716
+ params.push(...bodyProperty.map((p) => require_schema.createFunctionParameter(p)));
710
717
  params.push(...trailingGroups.flatMap(buildGroupParam));
711
718
  }
712
719
  params.push(...extraParams);
713
- return require_response.createFunctionParameters({ params });
720
+ return require_schema.createFunctionParameters({ params });
714
721
  }
715
722
  /**
716
723
  * Builds the property descriptor for a query or header group.
@@ -744,7 +751,7 @@ function buildGroupProperty({ name, node, params, groupType, resolver, wrapType
744
751
  * {@link TypeLiteralNode} from the individual params.
745
752
  */
746
753
  function buildGroupParam(args) {
747
- return buildGroupProperty(args).map((p) => require_response.createFunctionParameter(p));
754
+ return buildGroupProperty(args).map((p) => require_schema.createFunctionParameter(p));
748
755
  }
749
756
  /**
750
757
  * Builds a {@link TypeLiteralNode} for an inline anonymous type grouping named fields.
@@ -753,7 +760,7 @@ function buildGroupParam(args) {
753
760
  * Each language printer renders this appropriately (TypeScript: `{ petId: string; name?: string }`).
754
761
  */
755
762
  function buildTypeLiteral({ node, params, resolver }) {
756
- return require_response.createTypeLiteral({ members: params.map((p) => ({
763
+ return require_schema.createTypeLiteral({ members: params.map((p) => ({
757
764
  name: p.name,
758
765
  type: resolveParamType({
759
766
  node,
@@ -909,4 +916,4 @@ Object.defineProperty(exports, "trimQuotes", {
909
916
  }
910
917
  });
911
918
 
912
- //# sourceMappingURL=utils-BDI3kXlb.cjs.map
919
+ //# sourceMappingURL=utils-CEepwqmb.cjs.map