@kubb/plugin-ts 5.0.0-beta.4 → 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/README.md +39 -22
- package/dist/index.cjs +513 -266
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +168 -144
- package/dist/index.js +506 -263
- package/dist/index.js.map +1 -1
- package/package.json +13 -22
- package/src/components/Enum.tsx +33 -29
- package/src/components/Type.tsx +6 -11
- package/src/constants.ts +7 -7
- package/src/factory.ts +58 -62
- package/src/generators/typeGenerator.tsx +118 -77
- package/src/plugin.ts +30 -28
- package/src/printers/functionPrinter.ts +2 -2
- package/src/printers/printerTs.ts +44 -54
- package/src/resolvers/resolverTs.ts +28 -25
- package/src/types.ts +113 -86
- package/src/utils.ts +24 -14
- package/extension.yaml +0 -632
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { t as __name } from "./chunk
|
|
2
|
-
import
|
|
3
|
-
import { Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
|
|
1
|
+
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
2
|
+
import { Exclude, Generator, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
|
|
4
3
|
import ts from "typescript";
|
|
5
4
|
import { KubbReactNode } from "@kubb/renderer-jsx/types";
|
|
6
5
|
|
|
@@ -44,23 +43,11 @@ type PrinterTsOptions = {
|
|
|
44
43
|
*/
|
|
45
44
|
arrayType: PluginTs['resolvedOptions']['arrayType'];
|
|
46
45
|
/**
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* - `'asConst'` generates as const declarations
|
|
51
|
-
*
|
|
52
|
-
* @default `'inlineLiteral'`
|
|
53
|
-
*/
|
|
54
|
-
enumType: PluginTs['resolvedOptions']['enumType'];
|
|
55
|
-
/**
|
|
56
|
-
* Suffix appended to enum key reference names.
|
|
57
|
-
*
|
|
58
|
-
* @example Enum key naming
|
|
59
|
-
* `StatusKey` when `enumType` is `'asConst'`
|
|
60
|
-
*
|
|
61
|
-
* @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.
|
|
62
49
|
*/
|
|
63
|
-
|
|
50
|
+
enum: PluginTs['resolvedOptions']['enum'];
|
|
64
51
|
/**
|
|
65
52
|
* Syntax for generated declarations.
|
|
66
53
|
* - `'type'` generates type aliases
|
|
@@ -82,7 +69,7 @@ type PrinterTsOptions = {
|
|
|
82
69
|
* Properties to exclude using `Omit<Type, Keys>`.
|
|
83
70
|
* Forces type alias syntax regardless of `syntaxType` setting.
|
|
84
71
|
*/
|
|
85
|
-
keysToOmit?: Array<string
|
|
72
|
+
keysToOmit?: Array<string> | null;
|
|
86
73
|
/**
|
|
87
74
|
* Transforms raw schema names into valid TypeScript identifiers.
|
|
88
75
|
*/
|
|
@@ -113,13 +100,13 @@ type PrinterTsFactory = ast.PrinterFactoryOptions<'typescript', PrinterTsOptions
|
|
|
113
100
|
*
|
|
114
101
|
* @example Raw type node (no `typeName`)
|
|
115
102
|
* ```ts
|
|
116
|
-
* const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array',
|
|
103
|
+
* const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enum: { type: 'inlineLiteral' } })
|
|
117
104
|
* const typeNode = printer.print(schemaNode) // ts.TypeNode
|
|
118
105
|
* ```
|
|
119
106
|
*
|
|
120
107
|
* @example Full declaration (with `typeName`)
|
|
121
108
|
* ```ts
|
|
122
|
-
* const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array',
|
|
109
|
+
* const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enum: { type: 'inlineLiteral' }, typeName: 'MyType' })
|
|
123
110
|
* const declaration = printer.print(schemaNode) // ts.TypeAliasDeclaration | ts.InterfaceDeclaration
|
|
124
111
|
* ```
|
|
125
112
|
*/
|
|
@@ -217,33 +204,47 @@ type ResolverTs = Resolver & ast.OperationParamsResolver & {
|
|
|
217
204
|
resolveHeaderParamsName(node: ast.OperationNode, param: ast.ParameterNode): string;
|
|
218
205
|
};
|
|
219
206
|
type EnumKeyCasing = 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none';
|
|
207
|
+
type EnumConstCasing = 'camelCase' | 'pascalCase';
|
|
220
208
|
/**
|
|
221
|
-
*
|
|
209
|
+
* Grouped enum settings. Each `type` uses only some of the other fields.
|
|
222
210
|
*
|
|
223
|
-
* - `'asConst'`
|
|
224
|
-
*
|
|
225
|
-
* - `'
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
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.
|
|
214
|
+
*
|
|
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
|
+
* ```
|
|
229
221
|
*/
|
|
230
|
-
type
|
|
222
|
+
type EnumOptions$1 = {
|
|
231
223
|
/**
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
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
|
+
*
|
|
235
227
|
* @default 'asConst'
|
|
236
228
|
*/
|
|
237
|
-
|
|
229
|
+
type?: 'asConst';
|
|
238
230
|
/**
|
|
239
|
-
*
|
|
231
|
+
* Casing of the generated const variable.
|
|
232
|
+
* - 'camelCase' names the const `vehicleType`.
|
|
233
|
+
* - 'pascalCase' names the const `VehicleType`, matching the schema name.
|
|
240
234
|
*
|
|
241
|
-
*
|
|
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.
|
|
242
242
|
*
|
|
243
243
|
* @default 'Key'
|
|
244
|
-
* @example
|
|
244
|
+
* @example A custom suffix
|
|
245
|
+
* `typeSuffix: 'Value'` renames the alias to `PetStatusValue`
|
|
245
246
|
*/
|
|
246
|
-
|
|
247
|
+
typeSuffix?: string;
|
|
247
248
|
/**
|
|
248
249
|
* Choose the casing for enum key names.
|
|
249
250
|
* - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
|
|
@@ -253,22 +254,24 @@ type EnumTypeOptions = {
|
|
|
253
254
|
* - 'none' uses the enum value as-is without transformation.
|
|
254
255
|
* @default 'none'
|
|
255
256
|
*/
|
|
256
|
-
|
|
257
|
+
keyCasing?: EnumKeyCasing;
|
|
257
258
|
} | {
|
|
258
259
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* - 'constEnum' generates TypeScript const enum declarations.
|
|
260
|
+
* Emit a TypeScript `enum` (`'enum'`) or `const enum` (`'constEnum'`) declaration.
|
|
261
|
+
*
|
|
262
262
|
* @default 'asConst'
|
|
263
263
|
*/
|
|
264
|
-
|
|
264
|
+
type?: 'enum' | 'constEnum';
|
|
265
265
|
/**
|
|
266
|
-
* `
|
|
267
|
-
* It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
|
|
266
|
+
* `constCasing` has no effect for this `type`. Only `'asConst'` emits a const object.
|
|
268
267
|
*/
|
|
269
|
-
|
|
268
|
+
constCasing?: never;
|
|
270
269
|
/**
|
|
271
|
-
*
|
|
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.
|
|
272
275
|
* - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
|
|
273
276
|
* - 'snakeCase' generates keys in snake_case format.
|
|
274
277
|
* - 'pascalCase' generates keys in PascalCase format.
|
|
@@ -276,97 +279,99 @@ type EnumTypeOptions = {
|
|
|
276
279
|
* - 'none' uses the enum value as-is without transformation.
|
|
277
280
|
* @default 'none'
|
|
278
281
|
*/
|
|
279
|
-
|
|
282
|
+
keyCasing?: EnumKeyCasing;
|
|
280
283
|
} | {
|
|
281
284
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
+
* Emit a union of literals as a named alias (`'literal'`) or inline the union at every usage
|
|
286
|
+
* site (`'inlineLiteral'`).
|
|
287
|
+
*
|
|
285
288
|
* @default 'asConst'
|
|
286
289
|
* @note In Kubb v5, 'inlineLiteral' becomes the default.
|
|
287
290
|
*/
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* `enumTypeSuffix` has no effect for this `enumType`.
|
|
291
|
-
* It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
|
|
292
|
-
*/
|
|
293
|
-
enumTypeSuffix?: never;
|
|
294
|
-
/**
|
|
295
|
-
* `enumKeyCasing` has no effect for this `enumType`.
|
|
296
|
-
* Literal and inlineLiteral modes emit only values — keys are discarded entirely.
|
|
297
|
-
*/
|
|
298
|
-
enumKeyCasing?: never;
|
|
299
|
-
};
|
|
300
|
-
type Options = {
|
|
291
|
+
type?: 'literal' | 'inlineLiteral';
|
|
301
292
|
/**
|
|
302
|
-
*
|
|
303
|
-
* @default { path: 'types', barrelType: 'named' }
|
|
293
|
+
* `constCasing` has no effect for this `type`; literal modes emit no const object.
|
|
304
294
|
*/
|
|
305
|
-
|
|
295
|
+
constCasing?: never;
|
|
306
296
|
/**
|
|
307
|
-
*
|
|
308
|
-
* By default, uses the first valid JSON media type.
|
|
297
|
+
* `typeSuffix` has no effect for this `type`; literal modes emit no separate type alias.
|
|
309
298
|
*/
|
|
310
|
-
|
|
299
|
+
typeSuffix?: never;
|
|
311
300
|
/**
|
|
312
|
-
*
|
|
301
|
+
* `keyCasing` has no effect for this `type`. Literal and inlineLiteral modes emit only values,
|
|
302
|
+
* so the keys are discarded.
|
|
313
303
|
*/
|
|
314
|
-
|
|
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
|
*/
|
|
318
316
|
exclude?: Array<Exclude>;
|
|
319
317
|
/**
|
|
320
|
-
*
|
|
318
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
321
319
|
*/
|
|
322
320
|
include?: Array<Include>;
|
|
323
321
|
/**
|
|
324
|
-
*
|
|
322
|
+
* Apply a different options object to operations matching a pattern.
|
|
325
323
|
*/
|
|
326
324
|
override?: Array<Override<ResolvedOptions>>;
|
|
327
325
|
/**
|
|
328
|
-
*
|
|
329
|
-
* - 'type'
|
|
330
|
-
* - 'interface'
|
|
326
|
+
* Whether object schemas are emitted as `type` aliases or `interface` declarations.
|
|
327
|
+
* - `'type'` emits closed type aliases. Safer default for generated code.
|
|
328
|
+
* - `'interface'` emits interfaces. Useful when consumers rely on declaration merging.
|
|
329
|
+
*
|
|
331
330
|
* @default 'type'
|
|
331
|
+
* @see https://www.totaltypescript.com/type-vs-interface-which-should-you-use
|
|
332
332
|
*/
|
|
333
333
|
syntaxType?: 'type' | 'interface';
|
|
334
334
|
/**
|
|
335
|
-
*
|
|
336
|
-
* - 'questionToken'
|
|
337
|
-
* - 'undefined'
|
|
338
|
-
* - 'questionTokenAndUndefined'
|
|
335
|
+
* How optional properties are written in generated types.
|
|
336
|
+
* - `'questionToken'` — `type?: string`. The property may be missing.
|
|
337
|
+
* - `'undefined'` — `type: string | undefined`. Required to exist, may be `undefined`.
|
|
338
|
+
* - `'questionTokenAndUndefined'` — `type?: string | undefined`. Strictest.
|
|
339
|
+
*
|
|
339
340
|
* @default 'questionToken'
|
|
341
|
+
* @note Pick `'questionTokenAndUndefined'` when `exactOptionalPropertyTypes` is on in `tsconfig.json`.
|
|
340
342
|
*/
|
|
341
343
|
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
|
342
344
|
/**
|
|
343
|
-
*
|
|
344
|
-
* - '
|
|
345
|
-
* - '
|
|
345
|
+
* Syntax used for array types.
|
|
346
|
+
* - `'array'` — `Type[]`. Shorter.
|
|
347
|
+
* - `'generic'` — `Array<Type>`. More readable for complex element types.
|
|
348
|
+
*
|
|
346
349
|
* @default 'array'
|
|
347
350
|
*/
|
|
348
351
|
arrayType?: 'generic' | 'array';
|
|
349
352
|
/**
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
* @note
|
|
353
|
+
* Rename properties inside `PathParams`, `QueryParams`, and `HeaderParams` types.
|
|
354
|
+
* Response and request body types are not affected.
|
|
355
|
+
*
|
|
356
|
+
* @note Every plugin that touches operation parameters must use the same value.
|
|
354
357
|
*/
|
|
355
358
|
paramsCasing?: 'camelcase';
|
|
356
359
|
/**
|
|
357
|
-
*
|
|
360
|
+
* Custom generators that run alongside the built-in TypeScript generators.
|
|
358
361
|
*/
|
|
359
362
|
generators?: Array<Generator<PluginTs>>;
|
|
360
363
|
/**
|
|
361
|
-
* Override
|
|
362
|
-
*
|
|
364
|
+
* Override how names and file paths are built for generated symbols.
|
|
365
|
+
* Methods you omit fall back to the default `resolverTs`. `this` is bound to the
|
|
366
|
+
* full resolver, so `this.default(name, 'function')` delegates to the built-in
|
|
367
|
+
* implementation.
|
|
363
368
|
*/
|
|
364
369
|
resolver?: Partial<ResolverTs> & ThisType<ResolverTs>;
|
|
365
370
|
/**
|
|
366
|
-
* AST visitor applied to each schema
|
|
367
|
-
*
|
|
371
|
+
* AST visitor applied to each schema or operation node before printing.
|
|
372
|
+
* Methods you omit fall back to the preset transformer.
|
|
368
373
|
*
|
|
369
|
-
* @example
|
|
374
|
+
* @example Drop writeOnly properties from response types
|
|
370
375
|
* ```ts
|
|
371
376
|
* transformer: {
|
|
372
377
|
* property(node) {
|
|
@@ -377,18 +382,17 @@ type Options = {
|
|
|
377
382
|
*/
|
|
378
383
|
transformer?: ast.Visitor;
|
|
379
384
|
/**
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* built-in handler for that type. Use `this.transform` to recurse into nested schema nodes.
|
|
385
|
+
* Replace the TypeScript handler for a specific schema type (`'integer'`, `'date'`, ...).
|
|
386
|
+
* Each handler returns a TypeScript AST node for that schema type. Use `this.transform`
|
|
387
|
+
* to recurse into nested schema nodes.
|
|
384
388
|
*
|
|
385
|
-
* @example
|
|
389
|
+
* @example Use the JavaScript `Date` object for date schemas
|
|
386
390
|
* ```ts
|
|
387
391
|
* import ts from 'typescript'
|
|
388
392
|
* pluginTs({
|
|
389
393
|
* printer: {
|
|
390
394
|
* nodes: {
|
|
391
|
-
* date(
|
|
395
|
+
* date() {
|
|
392
396
|
* return ts.factory.createTypeReferenceNode('Date', [])
|
|
393
397
|
* },
|
|
394
398
|
* },
|
|
@@ -399,16 +403,24 @@ type Options = {
|
|
|
399
403
|
printer?: {
|
|
400
404
|
nodes?: PrinterTsNodes;
|
|
401
405
|
};
|
|
402
|
-
|
|
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
|
+
};
|
|
403
417
|
type ResolvedOptions = {
|
|
404
418
|
output: Output;
|
|
405
419
|
exclude: Array<Exclude>;
|
|
406
420
|
include: Array<Include> | undefined;
|
|
407
421
|
override: Array<Override<ResolvedOptions>>;
|
|
408
|
-
group: Group |
|
|
409
|
-
|
|
410
|
-
enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>;
|
|
411
|
-
enumKeyCasing: EnumKeyCasing;
|
|
422
|
+
group: Group | null;
|
|
423
|
+
enum: ResolvedEnumOptions;
|
|
412
424
|
optionalType: NonNullable<Options['optionalType']>;
|
|
413
425
|
arrayType: NonNullable<Options['arrayType']>;
|
|
414
426
|
syntaxType: NonNullable<Options['syntaxType']>;
|
|
@@ -425,11 +437,10 @@ declare global {
|
|
|
425
437
|
}
|
|
426
438
|
//#endregion
|
|
427
439
|
//#region src/components/Enum.d.ts
|
|
440
|
+
type EnumOptions = PluginTs['resolvedOptions']['enum'];
|
|
428
441
|
type Props$1 = {
|
|
429
442
|
node: ast.EnumSchemaNode;
|
|
430
|
-
|
|
431
|
-
enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix'];
|
|
432
|
-
enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing'];
|
|
443
|
+
enum: EnumOptions;
|
|
433
444
|
resolver: ResolverTs;
|
|
434
445
|
key?: string | number | null;
|
|
435
446
|
};
|
|
@@ -437,14 +448,17 @@ type Props$1 = {
|
|
|
437
448
|
* Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
|
|
438
449
|
*
|
|
439
450
|
* The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
|
|
440
|
-
* valid TypeScript identifier. The resolver normalizes it
|
|
441
|
-
*
|
|
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.
|
|
442
456
|
*/
|
|
443
457
|
/**
|
|
444
458
|
* Renders the enum declaration(s) for a single named `EnumSchemaNode`.
|
|
445
459
|
*
|
|
446
|
-
* Depending on `
|
|
447
|
-
* - A runtime object (`asConst`
|
|
460
|
+
* Depending on `enum.type` this may emit:
|
|
461
|
+
* - A runtime object (`asConst`) plus a `typeof` type alias
|
|
448
462
|
* - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
|
|
449
463
|
* - A union literal type alias (`literal`)
|
|
450
464
|
*
|
|
@@ -453,9 +467,7 @@ type Props$1 = {
|
|
|
453
467
|
*/
|
|
454
468
|
declare function Enum({
|
|
455
469
|
node,
|
|
456
|
-
|
|
457
|
-
enumTypeSuffix,
|
|
458
|
-
enumKeyCasing,
|
|
470
|
+
enum: enumOptions,
|
|
459
471
|
resolver
|
|
460
472
|
}: Props$1): KubbReactNode;
|
|
461
473
|
//#endregion
|
|
@@ -468,46 +480,57 @@ type Props = {
|
|
|
468
480
|
* Created with `printerTs({ ..., nodes: options.printer?.nodes })`.
|
|
469
481
|
*/
|
|
470
482
|
printer: ast.Printer<PrinterTsFactory>;
|
|
471
|
-
|
|
472
|
-
enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix'];
|
|
473
|
-
enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing'];
|
|
483
|
+
enum: PluginTs['resolvedOptions']['enum'];
|
|
474
484
|
resolver: ResolverTs;
|
|
475
485
|
};
|
|
476
486
|
declare function Type({
|
|
477
487
|
name,
|
|
478
488
|
node,
|
|
479
489
|
printer,
|
|
480
|
-
|
|
481
|
-
enumTypeSuffix,
|
|
482
|
-
enumKeyCasing,
|
|
490
|
+
enum: enumOptions,
|
|
483
491
|
resolver
|
|
484
492
|
}: Props): KubbReactNode;
|
|
485
493
|
//#endregion
|
|
486
494
|
//#region src/generators/typeGenerator.d.ts
|
|
487
|
-
|
|
495
|
+
/**
|
|
496
|
+
* Built-in generator for `@kubb/plugin-ts`. Emits one TypeScript file per
|
|
497
|
+
* schema in the spec plus per-operation request, response, and parameter
|
|
498
|
+
* types. Drop-replace with a custom `Generator<PluginTs>` to change how
|
|
499
|
+
* TypeScript output is produced.
|
|
500
|
+
*/
|
|
501
|
+
declare const typeGenerator: import("@kubb/core").Generator<PluginTs, unknown>;
|
|
488
502
|
//#endregion
|
|
489
503
|
//#region src/plugin.d.ts
|
|
490
504
|
/**
|
|
491
|
-
* Canonical plugin name for `@kubb/plugin-ts
|
|
505
|
+
* Canonical plugin name for `@kubb/plugin-ts`. Used for driver lookups and
|
|
506
|
+
* cross-plugin dependency references.
|
|
492
507
|
*/
|
|
493
508
|
declare const pluginTsName = "plugin-ts";
|
|
494
509
|
/**
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
499
|
-
* and writes barrel files based on `output.barrelType`.
|
|
510
|
+
* Generates TypeScript `type` aliases and `interface` declarations from an
|
|
511
|
+
* OpenAPI spec. The foundation that every other Kubb plugin builds on:
|
|
512
|
+
* clients, query hooks, mocks, and validators all reference the names this
|
|
513
|
+
* plugin produces.
|
|
500
514
|
*
|
|
501
515
|
* @example
|
|
502
516
|
* ```ts
|
|
503
|
-
* import
|
|
517
|
+
* import { defineConfig } from 'kubb'
|
|
518
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
504
519
|
*
|
|
505
520
|
* export default defineConfig({
|
|
506
|
-
*
|
|
521
|
+
* input: { path: './petStore.yaml' },
|
|
522
|
+
* output: { path: './src/gen' },
|
|
523
|
+
* plugins: [
|
|
524
|
+
* pluginTs({
|
|
525
|
+
* output: { path: './types' },
|
|
526
|
+
* enum: { type: 'asConst' },
|
|
527
|
+
* optionalType: 'questionTokenAndUndefined',
|
|
528
|
+
* }),
|
|
529
|
+
* ],
|
|
507
530
|
* })
|
|
508
531
|
* ```
|
|
509
532
|
*/
|
|
510
|
-
declare const pluginTs: (options?: Options | undefined) =>
|
|
533
|
+
declare const pluginTs: (options?: Options | undefined) => import("@kubb/core").Plugin<PluginTs>;
|
|
511
534
|
//#endregion
|
|
512
535
|
//#region src/printers/functionPrinter.d.ts
|
|
513
536
|
type FunctionPrinterOptions = {
|
|
@@ -552,26 +575,27 @@ type FunctionPrinterOptions = {
|
|
|
552
575
|
declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) => {
|
|
553
576
|
name: "functionParameters";
|
|
554
577
|
options: FunctionPrinterOptions;
|
|
555
|
-
transform: (node: ast.FunctionParamNode) => string | null
|
|
556
|
-
print: (node: ast.FunctionParamNode) => string | null
|
|
578
|
+
transform: (node: ast.FunctionParamNode) => string | null;
|
|
579
|
+
print: (node: ast.FunctionParamNode) => string | null;
|
|
557
580
|
};
|
|
558
581
|
//#endregion
|
|
559
582
|
//#region src/resolvers/resolverTs.d.ts
|
|
560
583
|
/**
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
584
|
+
* Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
|
|
585
|
+
* for every generated TypeScript type. Import this in other plugins that need
|
|
586
|
+
* to reference the exact names `plugin-ts` produces without duplicating the
|
|
587
|
+
* casing/file-layout rules.
|
|
564
588
|
*
|
|
565
|
-
* The `default` method is
|
|
566
|
-
*
|
|
589
|
+
* The `default` method is supplied by `defineResolver`. It uses PascalCase for
|
|
590
|
+
* type names and PascalCase file paths (dotted names become `/`-joined) for files.
|
|
567
591
|
*
|
|
568
|
-
* @example
|
|
592
|
+
* @example Resolve a type and file name
|
|
569
593
|
* ```ts
|
|
570
|
-
* import {
|
|
594
|
+
* import { resolverTs } from '@kubb/plugin-ts'
|
|
571
595
|
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
596
|
+
* resolverTs.default('list pets', 'type') // 'ListPets'
|
|
597
|
+
* resolverTs.resolvePathName('list pets', 'file') // 'ListPets'
|
|
598
|
+
* resolverTs.resolveResponseStatusName(node, 200) // 'ListPetsStatus200'
|
|
575
599
|
* ```
|
|
576
600
|
*/
|
|
577
601
|
declare const resolverTs: ResolverTs;
|