@kubb/plugin-ts 5.0.0-beta.3 → 5.0.0-beta.30

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
@@ -82,7 +82,7 @@ type PrinterTsOptions = {
82
82
  * Properties to exclude using `Omit<Type, Keys>`.
83
83
  * Forces type alias syntax regardless of `syntaxType` setting.
84
84
  */
85
- keysToOmit?: Array<string>;
85
+ keysToOmit?: Array<string> | null;
86
86
  /**
87
87
  * Transforms raw schema names into valid TypeScript identifiers.
88
88
  */
@@ -238,7 +238,7 @@ type EnumTypeOptions = {
238
238
  /**
239
239
  * Suffix appended to the generated type alias name.
240
240
  *
241
- * Only affects the type alias the const object name is unchanged.
241
+ * Only affects the type alias; the const object name is unchanged.
242
242
  *
243
243
  * @default 'Key'
244
244
  * @example enumTypeSuffix: 'Value' → `export type PetStatusValue = …`
@@ -293,80 +293,88 @@ type EnumTypeOptions = {
293
293
  enumTypeSuffix?: never;
294
294
  /**
295
295
  * `enumKeyCasing` has no effect for this `enumType`.
296
- * Literal and inlineLiteral modes emit only values keys are discarded entirely.
296
+ * Literal and inlineLiteral modes emit only values; keys are discarded entirely.
297
297
  */
298
298
  enumKeyCasing?: never;
299
299
  };
300
300
  type Options = {
301
301
  /**
302
- * Specify the export location for the files and define the behavior of the output
303
- * @default { path: 'types', barrelType: 'named' }
302
+ * Where the generated `.ts` files are written and how they are exported.
303
+ *
304
+ * @default { path: 'types', barrel: { type: 'named' } }
304
305
  */
305
306
  output?: Output;
306
307
  /**
307
- * Define which contentType should be used.
308
- * By default, uses the first valid JSON media type.
308
+ * Media type read from the OpenAPI spec when an operation defines several.
309
+ * Defaults to the first JSON-compatible media type Kubb finds.
309
310
  */
310
311
  contentType?: 'application/json' | (string & {});
311
312
  /**
312
- * Group the clients based on the provided name.
313
+ * Split generated files into subfolders based on the operation's tag.
313
314
  */
314
315
  group?: Group;
315
316
  /**
316
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
317
+ * Skip operations matching at least one entry in the list.
317
318
  */
318
319
  exclude?: Array<Exclude>;
319
320
  /**
320
- * Array containing include parameters to include tags/operations/methods/paths.
321
+ * Restrict generation to operations matching at least one entry in the list.
321
322
  */
322
323
  include?: Array<Include>;
323
324
  /**
324
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
325
+ * Apply a different options object to operations matching a pattern.
325
326
  */
326
327
  override?: Array<Override<ResolvedOptions>>;
327
328
  /**
328
- * Switch between type or interface for creating TypeScript types.
329
- * - 'type' generates type alias declarations.
330
- * - 'interface' generates interface declarations.
329
+ * Whether object schemas are emitted as `type` aliases or `interface` declarations.
330
+ * - `'type'` emits closed type aliases. Safer default for generated code.
331
+ * - `'interface'` emits interfaces. Useful when consumers rely on declaration merging.
332
+ *
331
333
  * @default 'type'
334
+ * @see https://www.totaltypescript.com/type-vs-interface-which-should-you-use
332
335
  */
333
336
  syntaxType?: 'type' | 'interface';
334
337
  /**
335
- * Choose what to use as mode for an optional value.
336
- * - 'questionToken' marks the property as optional with ? (e.g., type?: string).
337
- * - 'undefined' adds undefined to the type union (e.g., type: string | undefined).
338
- * - 'questionTokenAndUndefined' combines both approaches (e.g., type?: string | undefined).
338
+ * How optional properties are written in generated types.
339
+ * - `'questionToken'` `type?: string`. The property may be missing.
340
+ * - `'undefined'` `type: string | undefined`. Required to exist, may be `undefined`.
341
+ * - `'questionTokenAndUndefined'` `type?: string | undefined`. Strictest.
342
+ *
339
343
  * @default 'questionToken'
344
+ * @note Pick `'questionTokenAndUndefined'` when `exactOptionalPropertyTypes` is on in `tsconfig.json`.
340
345
  */
341
346
  optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
342
347
  /**
343
- * Choose between Array<string> or string[] for array types.
344
- * - 'generic' generates Array<Type> syntax.
345
- * - 'array' generates Type[] syntax.
348
+ * Syntax used for array types.
349
+ * - `'array'` `Type[]`. Shorter.
350
+ * - `'generic'` `Array<Type>`. More readable for complex element types.
351
+ *
346
352
  * @default 'array'
347
353
  */
348
354
  arrayType?: 'generic' | 'array';
349
355
  /**
350
- * How to style your params, by default no casing is applied
351
- * - 'camelcase' uses camelCase for pathParams, queryParams and headerParams property names
352
- * @default undefined
353
- * @note response types (data/body) are NOT affected by this option
356
+ * Rename properties inside `PathParams`, `QueryParams`, and `HeaderParams` types.
357
+ * Response and request body types are not affected.
358
+ *
359
+ * @note Every plugin that touches operation parameters must use the same value.
354
360
  */
355
361
  paramsCasing?: 'camelcase';
356
362
  /**
357
- * Define some generators next to the ts generators
363
+ * Custom generators that run alongside the built-in TypeScript generators.
358
364
  */
359
365
  generators?: Array<Generator<PluginTs>>;
360
366
  /**
361
- * Override naming conventions. When a method returns `null` or `undefined`, the preset
362
- * resolver (`resolverTs`) is used as fallback.
367
+ * Override how names and file paths are built for generated symbols.
368
+ * Methods you omit fall back to the default `resolverTs`. `this` is bound to the
369
+ * full resolver, so `this.default(name, 'function')` delegates to the built-in
370
+ * implementation.
363
371
  */
364
372
  resolver?: Partial<ResolverTs> & ThisType<ResolverTs>;
365
373
  /**
366
- * AST visitor applied to each schema/operation node before printing.
367
- * Returning `null` or `undefined` from a visitor method falls back to the preset transformer.
374
+ * AST visitor applied to each schema or operation node before printing.
375
+ * Methods you omit fall back to the preset transformer.
368
376
  *
369
- * @example Remove writeOnly properties from response types
377
+ * @example Drop writeOnly properties from response types
370
378
  * ```ts
371
379
  * transformer: {
372
380
  * property(node) {
@@ -377,18 +385,17 @@ type Options = {
377
385
  */
378
386
  transformer?: ast.Visitor;
379
387
  /**
380
- * Override individual printer node handlers to customize rendering of specific schema types.
381
- *
382
- * Each key is a `SchemaType` (e.g. `'date'`, `'string'`). The function replaces the
383
- * built-in handler for that type. Use `this.transform` to recurse into nested schema nodes.
388
+ * Replace the TypeScript handler for a specific schema type (`'integer'`, `'date'`, ...).
389
+ * Each handler returns a TypeScript AST node for that schema type. Use `this.transform`
390
+ * to recurse into nested schema nodes.
384
391
  *
385
- * @example Override the `date` node to use the `Date` object type
392
+ * @example Use the JavaScript `Date` object for date schemas
386
393
  * ```ts
387
394
  * import ts from 'typescript'
388
395
  * pluginTs({
389
396
  * printer: {
390
397
  * nodes: {
391
- * date(node) {
398
+ * date() {
392
399
  * return ts.factory.createTypeReferenceNode('Date', [])
393
400
  * },
394
401
  * },
@@ -405,7 +412,7 @@ type ResolvedOptions = {
405
412
  exclude: Array<Exclude>;
406
413
  include: Array<Include> | undefined;
407
414
  override: Array<Override<ResolvedOptions>>;
408
- group: Group | undefined;
415
+ group: Group | null;
409
416
  enumType: NonNullable<Options['enumType']>;
410
417
  enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>;
411
418
  enumKeyCasing: EnumKeyCasing;
@@ -484,26 +491,41 @@ declare function Type({
484
491
  }: Props): KubbReactNode;
485
492
  //#endregion
486
493
  //#region src/generators/typeGenerator.d.ts
494
+ /**
495
+ * Built-in generator for `@kubb/plugin-ts`. Emits one TypeScript file per
496
+ * schema in the spec plus per-operation request, response, and parameter
497
+ * types. Drop-replace with a custom `Generator<PluginTs>` to change how
498
+ * TypeScript output is produced.
499
+ */
487
500
  declare const typeGenerator: _$_kubb_core0.Generator<PluginTs, unknown>;
488
501
  //#endregion
489
502
  //#region src/plugin.d.ts
490
503
  /**
491
- * Canonical plugin name for `@kubb/plugin-ts`, used to identify the plugin in driver lookups and warnings.
504
+ * Canonical plugin name for `@kubb/plugin-ts`. Used for driver lookups and
505
+ * cross-plugin dependency references.
492
506
  */
493
507
  declare const pluginTsName = "plugin-ts";
494
508
  /**
495
- * The `@kubb/plugin-ts` plugin factory.
496
- *
497
- * Generates TypeScript type declarations from an OpenAPI/AST `RootNode`.
498
- * Walks schemas and operations, delegates rendering to the active generators,
499
- * and writes barrel files based on `output.barrelType`.
509
+ * Generates TypeScript `type` aliases and `interface` declarations from an
510
+ * OpenAPI spec. The foundation that every other Kubb plugin builds on:
511
+ * clients, query hooks, mocks, and validators all reference the names this
512
+ * plugin produces.
500
513
  *
501
514
  * @example
502
515
  * ```ts
503
- * import pluginTs from '@kubb/plugin-ts'
516
+ * import { defineConfig } from 'kubb'
517
+ * import { pluginTs } from '@kubb/plugin-ts'
504
518
  *
505
519
  * export default defineConfig({
506
- * plugins: [pluginTs({ output: { path: 'types' }, enumType: 'asConst' })],
520
+ * input: { path: './petStore.yaml' },
521
+ * output: { path: './src/gen' },
522
+ * plugins: [
523
+ * pluginTs({
524
+ * output: { path: './types' },
525
+ * enumType: 'asConst',
526
+ * optionalType: 'questionTokenAndUndefined',
527
+ * }),
528
+ * ],
507
529
  * })
508
530
  * ```
509
531
  */
@@ -552,26 +574,27 @@ type FunctionPrinterOptions = {
552
574
  declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) => {
553
575
  name: "functionParameters";
554
576
  options: FunctionPrinterOptions;
555
- transform: (node: ast.FunctionParamNode) => string | null | undefined;
556
- print: (node: ast.FunctionParamNode) => string | null | undefined;
577
+ transform: (node: ast.FunctionParamNode) => string | null;
578
+ print: (node: ast.FunctionParamNode) => string | null;
557
579
  };
558
580
  //#endregion
559
581
  //#region src/resolvers/resolverTs.d.ts
560
582
  /**
561
- * Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
562
- * helpers used by the plugin. Import this in other plugins to resolve the exact names and
563
- * paths that `plugin-ts` generates without hardcoding the conventions.
583
+ * Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
584
+ * for every generated TypeScript type. Import this in other plugins that need
585
+ * to reference the exact names `plugin-ts` produces without duplicating the
586
+ * casing/file-layout rules.
564
587
  *
565
- * The `default` method is automatically injected by `defineResolver` it uses `camelCase`
566
- * for identifiers/files and `pascalCase` for type names.
588
+ * The `default` method is supplied by `defineResolver`. It uses PascalCase for
589
+ * type names and PascalCase-with-isFile for files.
567
590
  *
568
- * @example
591
+ * @example Resolve a type and file name
569
592
  * ```ts
570
- * import { resolver } from '@kubb/plugin-ts'
593
+ * import { resolverTs } from '@kubb/plugin-ts'
571
594
  *
572
- * resolver.default('list pets', 'type') // 'ListPets'
573
- * resolver.resolveName('list pets status 200') // 'ListPetsStatus200'
574
- * resolver.resolvePathName('list pets', 'file') // 'listPets'
595
+ * resolverTs.default('list pets', 'type') // 'ListPets'
596
+ * resolverTs.resolvePathName('list pets', 'file') // 'ListPets'
597
+ * resolverTs.resolveResponseStatusName(node, 200) // 'ListPetsStatus200'
575
598
  * ```
576
599
  */
577
600
  declare const resolverTs: ResolverTs;