@kubb/plugin-ts 5.0.0-beta.42 → 5.0.0-beta.56

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk-C0LytTxp.js";
2
- import { Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
2
+ import { Exclude, Generator, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
3
3
  import ts from "typescript";
4
4
  import { KubbReactNode } from "@kubb/renderer-jsx/types";
5
5
 
@@ -43,23 +43,11 @@ type PrinterTsOptions = {
43
43
  */
44
44
  arrayType: PluginTs['resolvedOptions']['arrayType'];
45
45
  /**
46
- * Enum output format.
47
- * - `'inlineLiteral'` embeds literal unions inline
48
- * - `'asPascalConst'` generates named const unions
49
- * - `'asConst'` generates as const declarations
50
- *
51
- * @default `'inlineLiteral'`
52
- */
53
- enumType: PluginTs['resolvedOptions']['enumType'];
54
- /**
55
- * Suffix appended to enum key reference names.
56
- *
57
- * @example Enum key naming
58
- * `StatusKey` when `enumType` is `'asConst'`
59
- *
60
- * @default `'Key'`
46
+ * Grouped enum settings. The printer emits references to enums, not the enum declarations, so only
47
+ * `type` (the output format) and `typeSuffix` (the enum key reference suffix) matter here.
48
+ * `constCasing` and `keyCasing` are ignored.
61
49
  */
62
- enumTypeSuffix?: PluginTs['resolvedOptions']['enumTypeSuffix'];
50
+ enum: PluginTs['resolvedOptions']['enum'];
63
51
  /**
64
52
  * Syntax for generated declarations.
65
53
  * - `'type'` generates type aliases
@@ -112,13 +100,13 @@ type PrinterTsFactory = ast.PrinterFactoryOptions<'typescript', PrinterTsOptions
112
100
  *
113
101
  * @example Raw type node (no `typeName`)
114
102
  * ```ts
115
- * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral' })
103
+ * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enum: { type: 'inlineLiteral' } })
116
104
  * const typeNode = printer.print(schemaNode) // ts.TypeNode
117
105
  * ```
118
106
  *
119
107
  * @example Full declaration (with `typeName`)
120
108
  * ```ts
121
- * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral', typeName: 'MyType' })
109
+ * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enum: { type: 'inlineLiteral' }, typeName: 'MyType' })
122
110
  * const declaration = printer.print(schemaNode) // ts.TypeAliasDeclaration | ts.InterfaceDeclaration
123
111
  * ```
124
112
  */
@@ -216,33 +204,47 @@ type ResolverTs = Resolver & ast.OperationParamsResolver & {
216
204
  resolveHeaderParamsName(node: ast.OperationNode, param: ast.ParameterNode): string;
217
205
  };
218
206
  type EnumKeyCasing = 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none';
207
+ type EnumConstCasing = 'camelCase' | 'pascalCase';
219
208
  /**
220
- * Discriminated union that ties `enumTypeSuffix` and `enumKeyCasing` to the enum types that actually use them.
209
+ * Grouped enum settings. Each `type` uses only some of the other fields.
210
+ *
211
+ * - `'asConst'` emits a `const` object plus a `typeof` type alias, so `constCasing`, `typeSuffix`, and `keyCasing` all apply.
212
+ * - `'enum'` and `'constEnum'` emit a TypeScript enum, so only `keyCasing` (the member names) applies.
213
+ * - `'literal'` and `'inlineLiteral'` emit union literals and drop the keys, so none of the other fields apply.
221
214
  *
222
- * - `'asConst'` / `'asPascalConst'` emit a `const` object; both `enumTypeSuffix` (type-alias suffix) and
223
- * `enumKeyCasing` (key formatting) are meaningful.
224
- * - `'enum'` / `'constEnum'` emit a TypeScript enum; `enumKeyCasing` applies to member names,
225
- * but there is no separate type alias so `enumTypeSuffix` is not used.
226
- * - `'literal'` / `'inlineLiteral'` emit only union literals; keys are discarded entirely,
227
- * so neither `enumTypeSuffix` nor `enumKeyCasing` have any effect.
215
+ * @example Share one name between the const and the type
216
+ * ```ts
217
+ * enum: { type: 'asConst', constCasing: 'pascalCase', typeSuffix: '' }
218
+ * // export const VehicleType = { } as const
219
+ * // export type VehicleType = (typeof VehicleType)[keyof typeof VehicleType]
220
+ * ```
228
221
  */
229
- type EnumTypeOptions = {
222
+ type EnumOptions$1 = {
230
223
  /**
231
- * Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
232
- * - 'asConst' generates const objects with camelCase names and as const assertion.
233
- * - 'asPascalConst' generates const objects with PascalCase names and as const assertion.
224
+ * Emit a `const` object asserted with `as const`, paired with a `typeof` type alias.
225
+ * This is tree-shakeable and adds no enum runtime.
226
+ *
234
227
  * @default 'asConst'
235
228
  */
236
- enumType?: 'asConst' | 'asPascalConst';
229
+ type?: 'asConst';
237
230
  /**
238
- * Suffix appended to the generated type alias name.
231
+ * Casing of the generated const variable.
232
+ * - 'camelCase' names the const `vehicleType`.
233
+ * - 'pascalCase' names the const `VehicleType`, matching the schema name.
239
234
  *
240
- * Only affects the type alias; the const object name is unchanged.
235
+ * @default 'camelCase'
236
+ */
237
+ constCasing?: EnumConstCasing;
238
+ /**
239
+ * Suffix appended to the generated type alias name. Only the type alias is renamed. The const
240
+ * object name stays the same. Set it to `''` together with `constCasing: 'pascalCase'` to merge
241
+ * the const and type under the schema's exact name.
241
242
  *
242
243
  * @default 'Key'
243
- * @example enumTypeSuffix: 'Value' → `export type PetStatusValue = …`
244
+ * @example A custom suffix
245
+ * `typeSuffix: 'Value'` renames the alias to `PetStatusValue`
244
246
  */
245
- enumTypeSuffix?: string;
247
+ typeSuffix?: string;
246
248
  /**
247
249
  * Choose the casing for enum key names.
248
250
  * - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
@@ -252,22 +254,24 @@ type EnumTypeOptions = {
252
254
  * - 'none' uses the enum value as-is without transformation.
253
255
  * @default 'none'
254
256
  */
255
- enumKeyCasing?: EnumKeyCasing;
257
+ keyCasing?: EnumKeyCasing;
256
258
  } | {
257
259
  /**
258
- * Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
259
- * - 'enum' generates TypeScript enum declarations.
260
- * - 'constEnum' generates TypeScript const enum declarations.
260
+ * Emit a TypeScript `enum` (`'enum'`) or `const enum` (`'constEnum'`) declaration.
261
+ *
261
262
  * @default 'asConst'
262
263
  */
263
- enumType?: 'enum' | 'constEnum';
264
+ type?: 'enum' | 'constEnum';
264
265
  /**
265
- * `enumTypeSuffix` has no effect for this `enumType`.
266
- * It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
266
+ * `constCasing` has no effect for this `type`. Only `'asConst'` emits a const object.
267
267
  */
268
- enumTypeSuffix?: never;
268
+ constCasing?: never;
269
269
  /**
270
- * Choose the casing for enum key names.
270
+ * `typeSuffix` has no effect for this `type`. Only `'asConst'` emits a separate type alias.
271
+ */
272
+ typeSuffix?: never;
273
+ /**
274
+ * Choose the casing for enum member names.
271
275
  * - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
272
276
  * - 'snakeCase' generates keys in snake_case format.
273
277
  * - 'pascalCase' generates keys in PascalCase format.
@@ -275,43 +279,37 @@ type EnumTypeOptions = {
275
279
  * - 'none' uses the enum value as-is without transformation.
276
280
  * @default 'none'
277
281
  */
278
- enumKeyCasing?: EnumKeyCasing;
282
+ keyCasing?: EnumKeyCasing;
279
283
  } | {
280
284
  /**
281
- * Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
282
- * - 'literal' generates literal union types.
283
- * - 'inlineLiteral' will inline enum values directly into the type (default in v5).
285
+ * Emit a union of literals as a named alias (`'literal'`) or inline the union at every usage
286
+ * site (`'inlineLiteral'`).
287
+ *
284
288
  * @default 'asConst'
285
289
  * @note In Kubb v5, 'inlineLiteral' becomes the default.
286
290
  */
287
- enumType?: 'literal' | 'inlineLiteral';
291
+ type?: 'literal' | 'inlineLiteral';
288
292
  /**
289
- * `enumTypeSuffix` has no effect for this `enumType`.
290
- * It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
293
+ * `constCasing` has no effect for this `type`; literal modes emit no const object.
291
294
  */
292
- enumTypeSuffix?: never;
295
+ constCasing?: never;
293
296
  /**
294
- * `enumKeyCasing` has no effect for this `enumType`.
295
- * Literal and inlineLiteral modes emit only values; keys are discarded entirely.
297
+ * `typeSuffix` has no effect for this `type`; literal modes emit no separate type alias.
296
298
  */
297
- enumKeyCasing?: never;
298
- };
299
- type Options = {
300
- /**
301
- * Where the generated `.ts` files are written and how they are exported.
302
- *
303
- * @default { path: 'types', barrel: { type: 'named' } }
304
- */
305
- output?: Output;
299
+ typeSuffix?: never;
306
300
  /**
307
- * Media type read from the OpenAPI spec when an operation defines several.
308
- * Defaults to the first JSON-compatible media type Kubb finds.
301
+ * `keyCasing` has no effect for this `type`. Literal and inlineLiteral modes emit only values,
302
+ * so the keys are discarded.
309
303
  */
310
- contentType?: 'application/json' | (string & {});
311
- /**
312
- * Split generated files into subfolders based on the operation's tag.
313
- */
314
- group?: Group;
304
+ keyCasing?: never;
305
+ };
306
+ /**
307
+ * Where the generated `.ts` files are written and how they are exported, plus the optional
308
+ * `group` strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
309
+ *
310
+ * @default { path: 'types', barrel: { type: 'named' } }
311
+ */
312
+ type Options = OutputOptions & {
315
313
  /**
316
314
  * Skip operations matching at least one entry in the list.
317
315
  */
@@ -405,16 +403,24 @@ type Options = {
405
403
  printer?: {
406
404
  nodes?: PrinterTsNodes;
407
405
  };
408
- } & EnumTypeOptions;
406
+ /**
407
+ * How OpenAPI enums are represented in the generated TypeScript, and how their names are cased.
408
+ */
409
+ enum?: EnumOptions$1;
410
+ };
411
+ type ResolvedEnumOptions = {
412
+ type: NonNullable<EnumOptions$1['type']>;
413
+ constCasing: EnumConstCasing;
414
+ typeSuffix: string;
415
+ keyCasing: EnumKeyCasing;
416
+ };
409
417
  type ResolvedOptions = {
410
418
  output: Output;
411
419
  exclude: Array<Exclude>;
412
420
  include: Array<Include> | undefined;
413
421
  override: Array<Override<ResolvedOptions>>;
414
422
  group: Group | null;
415
- enumType: NonNullable<Options['enumType']>;
416
- enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>;
417
- enumKeyCasing: EnumKeyCasing;
423
+ enum: ResolvedEnumOptions;
418
424
  optionalType: NonNullable<Options['optionalType']>;
419
425
  arrayType: NonNullable<Options['arrayType']>;
420
426
  syntaxType: NonNullable<Options['syntaxType']>;
@@ -431,11 +437,10 @@ declare global {
431
437
  }
432
438
  //#endregion
433
439
  //#region src/components/Enum.d.ts
440
+ type EnumOptions = PluginTs['resolvedOptions']['enum'];
434
441
  type Props$1 = {
435
442
  node: ast.EnumSchemaNode;
436
- enumType: PluginTs['resolvedOptions']['enumType'];
437
- enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix'];
438
- enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing'];
443
+ enum: EnumOptions;
439
444
  resolver: ResolverTs;
440
445
  key?: string | number | null;
441
446
  };
@@ -443,14 +448,17 @@ type Props$1 = {
443
448
  * Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
444
449
  *
445
450
  * The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
446
- * valid TypeScript identifier. The resolver normalizes it; for inline enum
447
- * properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.
451
+ * valid TypeScript identifier. The resolver normalizes it. For inline enum properties the adapter
452
+ * already emits a PascalCase+suffix name, so resolution is typically a no-op.
453
+ *
454
+ * When `constCasing` is `'pascalCase'` and `typeSuffix` is empty, the const and the type
455
+ * resolve to the same name, which TypeScript merges into a single value+type declaration.
448
456
  */
449
457
  /**
450
458
  * Renders the enum declaration(s) for a single named `EnumSchemaNode`.
451
459
  *
452
- * Depending on `enumType` this may emit:
453
- * - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias
460
+ * Depending on `enum.type` this may emit:
461
+ * - A runtime object (`asConst`) plus a `typeof` type alias
454
462
  * - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
455
463
  * - A union literal type alias (`literal`)
456
464
  *
@@ -459,9 +467,7 @@ type Props$1 = {
459
467
  */
460
468
  declare function Enum({
461
469
  node,
462
- enumType,
463
- enumTypeSuffix,
464
- enumKeyCasing,
470
+ enum: enumOptions,
465
471
  resolver
466
472
  }: Props$1): KubbReactNode;
467
473
  //#endregion
@@ -474,18 +480,14 @@ type Props = {
474
480
  * Created with `printerTs({ ..., nodes: options.printer?.nodes })`.
475
481
  */
476
482
  printer: ast.Printer<PrinterTsFactory>;
477
- enumType: PluginTs['resolvedOptions']['enumType'];
478
- enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix'];
479
- enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing'];
483
+ enum: PluginTs['resolvedOptions']['enum'];
480
484
  resolver: ResolverTs;
481
485
  };
482
486
  declare function Type({
483
487
  name,
484
488
  node,
485
489
  printer,
486
- enumType,
487
- enumTypeSuffix,
488
- enumKeyCasing,
490
+ enum: enumOptions,
489
491
  resolver
490
492
  }: Props): KubbReactNode;
491
493
  //#endregion
@@ -521,7 +523,7 @@ declare const pluginTsName = "plugin-ts";
521
523
  * plugins: [
522
524
  * pluginTs({
523
525
  * output: { path: './types' },
524
- * enumType: 'asConst',
526
+ * enum: { type: 'asConst' },
525
527
  * optionalType: 'questionTokenAndUndefined',
526
528
  * }),
527
529
  * ],
@@ -585,7 +587,7 @@ declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) =>
585
587
  * casing/file-layout rules.
586
588
  *
587
589
  * The `default` method is supplied by `defineResolver`. It uses PascalCase for
588
- * type names and PascalCase-with-isFile for files.
590
+ * type names and PascalCase file paths (dotted names become `/`-joined) for files.
589
591
  *
590
592
  * @example Resolve a type and file name
591
593
  * ```ts