@kubb/plugin-ts 5.0.0-alpha.3 → 5.0.0-alpha.31
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.cjs +1806 -3
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +590 -4
- package/dist/index.js +1776 -2
- package/dist/index.js.map +1 -0
- package/package.json +7 -27
- package/src/components/Enum.tsx +82 -0
- package/src/components/Type.tsx +29 -162
- package/src/constants.ts +39 -0
- package/src/factory.ts +134 -49
- package/src/generators/typeGenerator.tsx +165 -428
- package/src/generators/typeGeneratorLegacy.tsx +349 -0
- package/src/index.ts +9 -1
- package/src/plugin.ts +98 -176
- package/src/presets.ts +28 -0
- package/src/printers/functionPrinter.ts +196 -0
- package/src/printers/printerTs.ts +310 -0
- package/src/resolvers/resolverTs.ts +66 -0
- package/src/resolvers/resolverTsLegacy.ts +60 -0
- package/src/types.ts +258 -98
- package/src/utils.ts +131 -0
- package/dist/components-CRjwjdyE.js +0 -725
- package/dist/components-CRjwjdyE.js.map +0 -1
- package/dist/components-DI0aTIBg.cjs +0 -978
- package/dist/components-DI0aTIBg.cjs.map +0 -1
- package/dist/components.cjs +0 -3
- package/dist/components.d.ts +0 -38
- package/dist/components.js +0 -2
- package/dist/generators.cjs +0 -4
- package/dist/generators.d.ts +0 -503
- package/dist/generators.js +0 -2
- package/dist/plugin-D5rCK1zO.cjs +0 -992
- package/dist/plugin-D5rCK1zO.cjs.map +0 -1
- package/dist/plugin-DmwgRHK8.js +0 -944
- package/dist/plugin-DmwgRHK8.js.map +0 -1
- package/dist/types-BpeKGgCn.d.ts +0 -170
- package/src/components/index.ts +0 -1
- package/src/components/v2/Type.tsx +0 -165
- package/src/generators/index.ts +0 -2
- package/src/generators/v2/typeGenerator.tsx +0 -196
- package/src/parser.ts +0 -396
- package/src/printer.ts +0 -244
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,596 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import * as _$_kubb_ast0 from "@kubb/ast";
|
|
3
|
+
import { OperationParamsResolver, Printer } from "@kubb/ast";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import * as _$_kubb_core0 from "@kubb/core";
|
|
6
|
+
import { CompatibilityPreset, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, PrinterFactoryOptions, PrinterPartial, ResolvePathOptions, Resolver, UserGroup } from "@kubb/core";
|
|
7
|
+
import { EnumSchemaNode, FunctionNode, OperationNode, ParameterNode, SchemaNode, StatusCode, Visitor } from "@kubb/ast/types";
|
|
8
|
+
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
4
9
|
|
|
10
|
+
//#region src/printers/printerTs.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Partial map of node-type overrides for the TypeScript printer.
|
|
13
|
+
*
|
|
14
|
+
* Each key is a `SchemaType` string (e.g. `'date'`, `'string'`). The function
|
|
15
|
+
* replaces the built-in handler for that node type. Use `this.transform` to
|
|
16
|
+
* recurse into nested schema nodes, and `this.options` to read printer options.
|
|
17
|
+
*
|
|
18
|
+
* @example Override the `date` handler
|
|
19
|
+
* ```ts
|
|
20
|
+
* pluginTs({
|
|
21
|
+
* printer: {
|
|
22
|
+
* nodes: {
|
|
23
|
+
* date(node) {
|
|
24
|
+
* return ts.factory.createTypeReferenceNode('Date', [])
|
|
25
|
+
* },
|
|
26
|
+
* },
|
|
27
|
+
* },
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
type PrinterTsNodes = PrinterPartial<ts.TypeNode, PrinterTsOptions>;
|
|
32
|
+
type PrinterTsOptions = {
|
|
33
|
+
/**
|
|
34
|
+
* @default `'questionToken'`
|
|
35
|
+
*/
|
|
36
|
+
optionalType: PluginTs['resolvedOptions']['optionalType'];
|
|
37
|
+
/**
|
|
38
|
+
* @default `'array'`
|
|
39
|
+
*/
|
|
40
|
+
arrayType: PluginTs['resolvedOptions']['arrayType'];
|
|
41
|
+
/**
|
|
42
|
+
* @default `'inlineLiteral'`
|
|
43
|
+
*/
|
|
44
|
+
enumType: PluginTs['resolvedOptions']['enumType'];
|
|
45
|
+
/**
|
|
46
|
+
* Suffix appended to the generated type alias name when `enumType` is `asConst` or `asPascalConst`.
|
|
47
|
+
*
|
|
48
|
+
* @default `'Key'`
|
|
49
|
+
*/
|
|
50
|
+
enumTypeSuffix?: PluginTs['resolvedOptions']['enumTypeSuffix'];
|
|
51
|
+
/**
|
|
52
|
+
* Controls whether a `type` alias or `interface` declaration is emitted.
|
|
53
|
+
* @default `'type'`
|
|
54
|
+
*/
|
|
55
|
+
syntaxType?: PluginTs['resolvedOptions']['syntaxType'];
|
|
56
|
+
/**
|
|
57
|
+
* When set, `printer.print(node)` produces a full `type Name = …` declaration.
|
|
58
|
+
* When omitted, `printer.print(node)` returns the raw type node.
|
|
59
|
+
*/
|
|
60
|
+
name?: string;
|
|
61
|
+
/**
|
|
62
|
+
* JSDoc `@description` comment added to the generated type or interface declaration.
|
|
63
|
+
*/
|
|
64
|
+
description?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Property keys to exclude from the generated type via `Omit<Type, Keys>`.
|
|
67
|
+
* Forces type-alias syntax even when `syntaxType` is `'interface'`.
|
|
68
|
+
*/
|
|
69
|
+
keysToOmit?: Array<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Resolver used to transform raw schema names into valid TypeScript identifiers.
|
|
72
|
+
*/
|
|
73
|
+
resolver: ResolverTs;
|
|
74
|
+
/**
|
|
75
|
+
* Names of top-level schemas that are enums.
|
|
76
|
+
* When set, the `ref` handler uses the suffixed type name (e.g. `StatusKey`) for enum refs
|
|
77
|
+
* instead of the plain PascalCase name, so imports align with what the enum file actually exports.
|
|
78
|
+
*/
|
|
79
|
+
enumSchemaNames?: Set<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Partial map of node-type overrides. Each entry replaces the built-in handler for that node type.
|
|
82
|
+
*/
|
|
83
|
+
nodes?: PrinterTsNodes;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* TypeScript printer factory options: maps `SchemaNode` → `ts.TypeNode` (raw) or `ts.Node` (full declaration).
|
|
87
|
+
*/
|
|
88
|
+
type PrinterTsFactory = PrinterFactoryOptions<'typescript', PrinterTsOptions, ts.TypeNode, string>;
|
|
89
|
+
/**
|
|
90
|
+
* TypeScript type printer built with `definePrinter`.
|
|
91
|
+
*
|
|
92
|
+
* Converts a `SchemaNode` AST node into a TypeScript AST node:
|
|
93
|
+
* - **`printer.print(node)`** — when `options.typeName` is set, returns a full
|
|
94
|
+
* `type Name = …` or `interface Name { … }` declaration (`ts.Node`).
|
|
95
|
+
* Without `typeName`, returns the raw `ts.TypeNode` for the schema.
|
|
96
|
+
*
|
|
97
|
+
* Dispatches on `node.type` to the appropriate handler in `nodes`. Options are closed
|
|
98
|
+
* over per printer instance, so each call to `printerTs(options)` produces an independent printer.
|
|
99
|
+
*
|
|
100
|
+
* @example Raw type node (no `typeName`)
|
|
101
|
+
* ```ts
|
|
102
|
+
* const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral' })
|
|
103
|
+
* const typeNode = printer.print(schemaNode) // ts.TypeNode
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @example Full declaration (with `typeName`)
|
|
107
|
+
* ```ts
|
|
108
|
+
* const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral', typeName: 'MyType' })
|
|
109
|
+
* const declaration = printer.print(schemaNode) // ts.TypeAliasDeclaration | ts.InterfaceDeclaration
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare const printerTs: (options?: PrinterTsOptions | undefined) => _$_kubb_ast0.Printer<PrinterTsFactory>;
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/types.d.ts
|
|
115
|
+
/**
|
|
116
|
+
* The concrete resolver type for `@kubb/plugin-ts`.
|
|
117
|
+
* Extends the base `Resolver` (which provides `default` and `resolveOptions`) with
|
|
118
|
+
* plugin-specific naming helpers for operations, parameters, responses, and schemas.
|
|
119
|
+
*/
|
|
120
|
+
type ResolverTs = Resolver & OperationParamsResolver & {
|
|
121
|
+
/**
|
|
122
|
+
* Resolves the name for a given raw name (equivalent to `default(name, 'function')`).
|
|
123
|
+
* Since TypeScript only emits types, this is the canonical naming method.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* resolver.resolveName('list pets status 200') // → 'ListPetsStatus200'
|
|
127
|
+
*/
|
|
128
|
+
resolveTypeName(name: string): string;
|
|
129
|
+
/**
|
|
130
|
+
* Resolves the file/path name for a given identifier using PascalCase.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* resolver.resolvePathName('list pets', 'file') // → 'ListPets'
|
|
134
|
+
*/
|
|
135
|
+
resolvePathName(name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
136
|
+
/**
|
|
137
|
+
* Resolves the request body type name for an operation (required on ResolverTs).
|
|
138
|
+
*/
|
|
139
|
+
resolveDataName(node: OperationNode): string;
|
|
140
|
+
/**
|
|
141
|
+
* Resolves the name for an operation response by status code.
|
|
142
|
+
* Encapsulates the `<operationId> Status <statusCode>` template with PascalCase applied to the result.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* resolver.resolveResponseStatusName(node, 200) // → 'ListPetsStatus200'
|
|
146
|
+
*/
|
|
147
|
+
resolveResponseStatusName(node: OperationNode, statusCode: StatusCode): string;
|
|
148
|
+
/**
|
|
149
|
+
* Resolves the name for an operation's request config (`RequestConfig`).
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* resolver.resolveRequestConfigName(node) // → 'ListPetsRequestConfig'
|
|
153
|
+
*/
|
|
154
|
+
resolveRequestConfigName(node: OperationNode): string;
|
|
155
|
+
/**
|
|
156
|
+
* Resolves the name for the collection of all operation responses (`Responses`).
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* resolver.resolveResponsesName(node) // → 'ListPetsResponses'
|
|
160
|
+
*/
|
|
161
|
+
resolveResponsesName(node: OperationNode): string;
|
|
162
|
+
/**
|
|
163
|
+
* Resolves the name for the union of all operation responses (`Response`).
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* resolver.resolveResponseName(node) // → 'ListPetsResponse'
|
|
167
|
+
*/
|
|
168
|
+
resolveResponseName(node: OperationNode): string;
|
|
169
|
+
/**
|
|
170
|
+
* Resolves the TypeScript type alias name for an enum schema's key variant.
|
|
171
|
+
* Appends `enumTypeSuffix` (default `'Key'`) after applying the default naming convention.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* resolver.resolveEnumKeyName(node, 'Key') // → 'PetStatusKey'
|
|
175
|
+
* resolver.resolveEnumKeyName(node, 'Value') // → 'PetStatusValue'
|
|
176
|
+
* resolver.resolveEnumKeyName(node, '') // → 'PetStatus'
|
|
177
|
+
*/
|
|
178
|
+
resolveEnumKeyName(node: {
|
|
179
|
+
name?: string | null;
|
|
180
|
+
}, enumTypeSuffix: string): string;
|
|
181
|
+
/**
|
|
182
|
+
* Resolves the name for an operation's grouped path parameters type.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* resolver.resolvePathParamsName(node, param) // → 'GetPetByIdPathParams'
|
|
186
|
+
*/
|
|
187
|
+
resolvePathParamsName(node: OperationNode, param: ParameterNode): string;
|
|
188
|
+
/**
|
|
189
|
+
* Resolves the name for an operation's grouped query parameters type.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'
|
|
193
|
+
*/
|
|
194
|
+
resolveQueryParamsName(node: OperationNode, param: ParameterNode): string;
|
|
195
|
+
/**
|
|
196
|
+
* Resolves the name for an operation's grouped header parameters type.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'
|
|
200
|
+
*/
|
|
201
|
+
resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string;
|
|
202
|
+
};
|
|
203
|
+
type EnumKeyCasing = 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none';
|
|
204
|
+
/**
|
|
205
|
+
* Discriminated union that ties `enumTypeSuffix` and `enumKeyCasing` to the enum types that actually use them.
|
|
206
|
+
*
|
|
207
|
+
* - `'asConst'` / `'asPascalConst'` — emit a `const` object; both `enumTypeSuffix` (type-alias suffix) and
|
|
208
|
+
* `enumKeyCasing` (key formatting) are meaningful.
|
|
209
|
+
* - `'enum'` / `'constEnum'` — emit a TypeScript enum; `enumKeyCasing` applies to member names,
|
|
210
|
+
* but there is no separate type alias so `enumTypeSuffix` is not used.
|
|
211
|
+
* - `'literal'` / `'inlineLiteral'` — emit only union literals; keys are discarded entirely,
|
|
212
|
+
* so neither `enumTypeSuffix` nor `enumKeyCasing` have any effect.
|
|
213
|
+
*/
|
|
214
|
+
type EnumTypeOptions = {
|
|
215
|
+
/**
|
|
216
|
+
* Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
|
|
217
|
+
* - 'asConst' generates const objects with camelCase names and as const assertion.
|
|
218
|
+
* - 'asPascalConst' generates const objects with PascalCase names and as const assertion.
|
|
219
|
+
* @default 'asConst'
|
|
220
|
+
*/
|
|
221
|
+
enumType?: 'asConst' | 'asPascalConst';
|
|
222
|
+
/**
|
|
223
|
+
* Suffix appended to the generated type alias name.
|
|
224
|
+
*
|
|
225
|
+
* Only affects the type alias — the const object name is unchanged.
|
|
226
|
+
*
|
|
227
|
+
* @default 'Key'
|
|
228
|
+
* @example enumTypeSuffix: 'Value' → `export type PetStatusValue = …`
|
|
229
|
+
*/
|
|
230
|
+
enumTypeSuffix?: string;
|
|
231
|
+
/**
|
|
232
|
+
* Choose the casing for enum key names.
|
|
233
|
+
* - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
|
|
234
|
+
* - 'snakeCase' generates keys in snake_case format.
|
|
235
|
+
* - 'pascalCase' generates keys in PascalCase format.
|
|
236
|
+
* - 'camelCase' generates keys in camelCase format.
|
|
237
|
+
* - 'none' uses the enum value as-is without transformation.
|
|
238
|
+
* @default 'none'
|
|
239
|
+
*/
|
|
240
|
+
enumKeyCasing?: EnumKeyCasing;
|
|
241
|
+
} | {
|
|
242
|
+
/**
|
|
243
|
+
* Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
|
|
244
|
+
* - 'enum' generates TypeScript enum declarations.
|
|
245
|
+
* - 'constEnum' generates TypeScript const enum declarations.
|
|
246
|
+
* @default 'asConst'
|
|
247
|
+
*/
|
|
248
|
+
enumType?: 'enum' | 'constEnum';
|
|
249
|
+
/**
|
|
250
|
+
* `enumTypeSuffix` has no effect for this `enumType`.
|
|
251
|
+
* It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
|
|
252
|
+
*/
|
|
253
|
+
enumTypeSuffix?: never;
|
|
254
|
+
/**
|
|
255
|
+
* Choose the casing for enum key names.
|
|
256
|
+
* - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
|
|
257
|
+
* - 'snakeCase' generates keys in snake_case format.
|
|
258
|
+
* - 'pascalCase' generates keys in PascalCase format.
|
|
259
|
+
* - 'camelCase' generates keys in camelCase format.
|
|
260
|
+
* - 'none' uses the enum value as-is without transformation.
|
|
261
|
+
* @default 'none'
|
|
262
|
+
*/
|
|
263
|
+
enumKeyCasing?: EnumKeyCasing;
|
|
264
|
+
} | {
|
|
265
|
+
/**
|
|
266
|
+
* Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
|
|
267
|
+
* - 'literal' generates literal union types.
|
|
268
|
+
* - 'inlineLiteral' will inline enum values directly into the type (default in v5).
|
|
269
|
+
* @default 'asConst'
|
|
270
|
+
* @note In Kubb v5, 'inlineLiteral' becomes the default.
|
|
271
|
+
*/
|
|
272
|
+
enumType?: 'literal' | 'inlineLiteral';
|
|
273
|
+
/**
|
|
274
|
+
* `enumTypeSuffix` has no effect for this `enumType`.
|
|
275
|
+
* It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
|
|
276
|
+
*/
|
|
277
|
+
enumTypeSuffix?: never;
|
|
278
|
+
/**
|
|
279
|
+
* `enumKeyCasing` has no effect for this `enumType`.
|
|
280
|
+
* Literal and inlineLiteral modes emit only values — keys are discarded entirely.
|
|
281
|
+
*/
|
|
282
|
+
enumKeyCasing?: never;
|
|
283
|
+
};
|
|
284
|
+
type Options = {
|
|
285
|
+
/**
|
|
286
|
+
* Specify the export location for the files and define the behavior of the output
|
|
287
|
+
* @default { path: 'types', barrelType: 'named' }
|
|
288
|
+
*/
|
|
289
|
+
output?: Output;
|
|
290
|
+
/**
|
|
291
|
+
* Define which contentType should be used.
|
|
292
|
+
* By default, uses the first valid JSON media type.
|
|
293
|
+
*/
|
|
294
|
+
contentType?: 'application/json' | (string & {});
|
|
295
|
+
/**
|
|
296
|
+
* Group the clients based on the provided name.
|
|
297
|
+
*/
|
|
298
|
+
group?: UserGroup;
|
|
299
|
+
/**
|
|
300
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
301
|
+
*/
|
|
302
|
+
exclude?: Array<Exclude>;
|
|
303
|
+
/**
|
|
304
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
305
|
+
*/
|
|
306
|
+
include?: Array<Include>;
|
|
307
|
+
/**
|
|
308
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
309
|
+
*/
|
|
310
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
311
|
+
/**
|
|
312
|
+
* Switch between type or interface for creating TypeScript types.
|
|
313
|
+
* - 'type' generates type alias declarations.
|
|
314
|
+
* - 'interface' generates interface declarations.
|
|
315
|
+
* @default 'type'
|
|
316
|
+
*/
|
|
317
|
+
syntaxType?: 'type' | 'interface';
|
|
318
|
+
/**
|
|
319
|
+
* Choose what to use as mode for an optional value.
|
|
320
|
+
* - 'questionToken' marks the property as optional with ? (e.g., type?: string).
|
|
321
|
+
* - 'undefined' adds undefined to the type union (e.g., type: string | undefined).
|
|
322
|
+
* - 'questionTokenAndUndefined' combines both approaches (e.g., type?: string | undefined).
|
|
323
|
+
* @default 'questionToken'
|
|
324
|
+
*/
|
|
325
|
+
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
|
326
|
+
/**
|
|
327
|
+
* Choose between Array<string> or string[] for array types.
|
|
328
|
+
* - 'generic' generates Array<Type> syntax.
|
|
329
|
+
* - 'array' generates Type[] syntax.
|
|
330
|
+
* @default 'array'
|
|
331
|
+
*/
|
|
332
|
+
arrayType?: 'generic' | 'array';
|
|
333
|
+
/**
|
|
334
|
+
* How to style your params, by default no casing is applied
|
|
335
|
+
* - 'camelcase' uses camelCase for pathParams, queryParams and headerParams property names
|
|
336
|
+
* @default undefined
|
|
337
|
+
* @note response types (data/body) are NOT affected by this option
|
|
338
|
+
*/
|
|
339
|
+
paramsCasing?: 'camelcase';
|
|
340
|
+
/**
|
|
341
|
+
* Define some generators next to the ts generators
|
|
342
|
+
*/
|
|
343
|
+
generators?: Array<Generator<PluginTs>>;
|
|
344
|
+
/**
|
|
345
|
+
* Apply a compatibility naming preset.
|
|
346
|
+
* Use `kubbV4` for strict v4 type-generation compatibility.
|
|
347
|
+
* You can further customize naming with `resolvers`.
|
|
348
|
+
* @default 'default'
|
|
349
|
+
*/
|
|
350
|
+
compatibilityPreset?: CompatibilityPreset;
|
|
351
|
+
/**
|
|
352
|
+
* Override naming conventions. When a method returns `null` or `undefined`, the preset
|
|
353
|
+
* resolver (`resolverTs` / `resolverTsLegacy`) is used as fallback.
|
|
354
|
+
*/
|
|
355
|
+
resolver?: Partial<ResolverTs> & ThisType<ResolverTs>;
|
|
356
|
+
/**
|
|
357
|
+
* AST visitor applied to each schema/operation node before printing.
|
|
358
|
+
* Returning `null` or `undefined` from a visitor method falls back to the preset transformer.
|
|
359
|
+
*
|
|
360
|
+
* @example Remove writeOnly properties from response types
|
|
361
|
+
* ```ts
|
|
362
|
+
* transformer: {
|
|
363
|
+
* property(node) {
|
|
364
|
+
* if (node.schema.writeOnly) return undefined
|
|
365
|
+
* }
|
|
366
|
+
* }
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
transformer?: Visitor;
|
|
370
|
+
/**
|
|
371
|
+
* Override individual printer node handlers to customize rendering of specific schema types.
|
|
372
|
+
*
|
|
373
|
+
* Each key is a `SchemaType` (e.g. `'date'`, `'string'`). The function replaces the
|
|
374
|
+
* built-in handler for that type. Use `this.transform` to recurse into nested schema nodes.
|
|
375
|
+
*
|
|
376
|
+
* @example Override the `date` node to use the `Date` object type
|
|
377
|
+
* ```ts
|
|
378
|
+
* import ts from 'typescript'
|
|
379
|
+
* pluginTs({
|
|
380
|
+
* printer: {
|
|
381
|
+
* nodes: {
|
|
382
|
+
* date(node) {
|
|
383
|
+
* return ts.factory.createTypeReferenceNode('Date', [])
|
|
384
|
+
* },
|
|
385
|
+
* },
|
|
386
|
+
* },
|
|
387
|
+
* })
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
printer?: {
|
|
391
|
+
nodes?: PrinterTsNodes;
|
|
392
|
+
};
|
|
393
|
+
} & EnumTypeOptions;
|
|
394
|
+
type ResolvedOptions = {
|
|
395
|
+
output: Output;
|
|
396
|
+
exclude: Array<Exclude>;
|
|
397
|
+
include: Array<Include> | undefined;
|
|
398
|
+
override: Array<Override<ResolvedOptions>>;
|
|
399
|
+
group: Group | undefined;
|
|
400
|
+
enumType: NonNullable<Options['enumType']>;
|
|
401
|
+
enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>;
|
|
402
|
+
enumKeyCasing: EnumKeyCasing;
|
|
403
|
+
optionalType: NonNullable<Options['optionalType']>;
|
|
404
|
+
arrayType: NonNullable<Options['arrayType']>;
|
|
405
|
+
syntaxType: NonNullable<Options['syntaxType']>;
|
|
406
|
+
paramsCasing: Options['paramsCasing'];
|
|
407
|
+
printer: Options['printer'];
|
|
408
|
+
};
|
|
409
|
+
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs>;
|
|
410
|
+
declare global {
|
|
411
|
+
namespace Kubb {
|
|
412
|
+
interface PluginRegistry {
|
|
413
|
+
'plugin-ts': PluginTs;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/components/Enum.d.ts
|
|
419
|
+
type Props$1 = {
|
|
420
|
+
node: EnumSchemaNode;
|
|
421
|
+
enumType: PluginTs['resolvedOptions']['enumType'];
|
|
422
|
+
enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix'];
|
|
423
|
+
enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing'];
|
|
424
|
+
resolver: ResolverTs;
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
|
|
428
|
+
*
|
|
429
|
+
* The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
|
|
430
|
+
* valid TypeScript identifier. The resolver normalizes it; for inline enum
|
|
431
|
+
* properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.
|
|
432
|
+
*/
|
|
433
|
+
/**
|
|
434
|
+
* Renders the enum declaration(s) for a single named `EnumSchemaNode`.
|
|
435
|
+
*
|
|
436
|
+
* Depending on `enumType` this may emit:
|
|
437
|
+
* - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias
|
|
438
|
+
* - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
|
|
439
|
+
* - A union literal type alias (`literal`)
|
|
440
|
+
*
|
|
441
|
+
* The emitted `File.Source` nodes carry the resolved names so that the barrel
|
|
442
|
+
* index picks up the correct export identifiers.
|
|
443
|
+
*/
|
|
444
|
+
declare function Enum({
|
|
445
|
+
node,
|
|
446
|
+
enumType,
|
|
447
|
+
enumTypeSuffix,
|
|
448
|
+
enumKeyCasing,
|
|
449
|
+
resolver
|
|
450
|
+
}: Props$1): FabricReactNode;
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/components/Type.d.ts
|
|
453
|
+
type Props = {
|
|
454
|
+
name: string;
|
|
455
|
+
node: SchemaNode;
|
|
456
|
+
/**
|
|
457
|
+
* Pre-configured printer instance created by the generator.
|
|
458
|
+
* Created with `printerTs({ ..., nodes: options.printer?.nodes })`.
|
|
459
|
+
*/
|
|
460
|
+
printer: Printer<PrinterTsFactory>;
|
|
461
|
+
enumType: PluginTs['resolvedOptions']['enumType'];
|
|
462
|
+
enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix'];
|
|
463
|
+
enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing'];
|
|
464
|
+
resolver: PluginTs['resolver'];
|
|
465
|
+
};
|
|
466
|
+
declare function Type({
|
|
467
|
+
name,
|
|
468
|
+
node,
|
|
469
|
+
printer,
|
|
470
|
+
enumType,
|
|
471
|
+
enumTypeSuffix,
|
|
472
|
+
enumKeyCasing,
|
|
473
|
+
resolver
|
|
474
|
+
}: Props): FabricReactNode;
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/generators/typeGenerator.d.ts
|
|
477
|
+
declare const typeGenerator: _$_kubb_core0.Generator<PluginTs>;
|
|
478
|
+
//#endregion
|
|
5
479
|
//#region src/plugin.d.ts
|
|
480
|
+
/**
|
|
481
|
+
* Canonical plugin name for `@kubb/plugin-ts`, used to identify the plugin in driver lookups and warnings.
|
|
482
|
+
*/
|
|
6
483
|
declare const pluginTsName = "plugin-ts";
|
|
7
|
-
|
|
484
|
+
/**
|
|
485
|
+
* The `@kubb/plugin-ts` plugin factory.
|
|
486
|
+
*
|
|
487
|
+
* Generates TypeScript type declarations from an OpenAPI/AST `RootNode`.
|
|
488
|
+
* Walks schemas and operations, delegates rendering to the active generators,
|
|
489
|
+
* and writes barrel files based on `output.barrelType`.
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* ```ts
|
|
493
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
494
|
+
*
|
|
495
|
+
* export default defineConfig({
|
|
496
|
+
* plugins: [pluginTs({ output: { path: 'types' }, enumType: 'asConst' })],
|
|
497
|
+
* })
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
declare const pluginTs: (options?: Options | undefined) => _$_kubb_core0.UserPluginWithLifeCycle<PluginTs>;
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/printers/functionPrinter.d.ts
|
|
503
|
+
type FunctionPrinterOptions = {
|
|
504
|
+
/**
|
|
505
|
+
* Rendering modes supported by `functionPrinter`.
|
|
506
|
+
*
|
|
507
|
+
* | Mode | Output example | Use case |
|
|
508
|
+
* |---------------|---------------------------------------------|---------------------------------|
|
|
509
|
+
* | `declaration` | `id: string, config: Config = {}` | Function parameter declaration |
|
|
510
|
+
* | `call` | `id, { method, url }` | Function call arguments |
|
|
511
|
+
* | `keys` | `{ id, config }` | Key names only (destructuring) |
|
|
512
|
+
* | `values` | `{ id: id, config: config }` | Key/value object entries |
|
|
513
|
+
*/
|
|
514
|
+
mode: 'declaration' | 'call' | 'keys' | 'values';
|
|
515
|
+
/**
|
|
516
|
+
* Optional transformation applied to every parameter name before printing.
|
|
517
|
+
*/
|
|
518
|
+
transformName?: (name: string) => string;
|
|
519
|
+
/**
|
|
520
|
+
* Optional transformation applied to every type string before printing.
|
|
521
|
+
*/
|
|
522
|
+
transformType?: (type: string) => string;
|
|
523
|
+
};
|
|
524
|
+
/**
|
|
525
|
+
* Default function-signature printer.
|
|
526
|
+
* Covers the four standard output modes used across Kubb plugins.
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```ts
|
|
530
|
+
* const printer = functionPrinter({ mode: 'declaration' })
|
|
531
|
+
*
|
|
532
|
+
* const sig = createFunctionParameters({
|
|
533
|
+
* params: [
|
|
534
|
+
* createFunctionParameter({ name: 'petId', type: 'string', optional: false }),
|
|
535
|
+
* createFunctionParameter({ name: 'config', type: 'Config', optional: false, default: '{}' }),
|
|
536
|
+
* ],
|
|
537
|
+
* })
|
|
538
|
+
*
|
|
539
|
+
* printer.print(sig) // → "petId: string, config: Config = {}"
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) => {
|
|
543
|
+
name: "functionParameters";
|
|
544
|
+
options: FunctionPrinterOptions;
|
|
545
|
+
transform: (node: FunctionNode) => string | null | undefined;
|
|
546
|
+
print: (node: FunctionNode) => string | null | undefined;
|
|
547
|
+
};
|
|
548
|
+
//#endregion
|
|
549
|
+
//#region src/resolvers/resolverTs.d.ts
|
|
550
|
+
/**
|
|
551
|
+
* Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
|
|
552
|
+
* helpers used by the plugin. Import this in other plugins to resolve the exact names and
|
|
553
|
+
* paths that `plugin-ts` generates without hardcoding the conventions.
|
|
554
|
+
*
|
|
555
|
+
* The `default` method is automatically injected by `defineResolver` — it uses `camelCase`
|
|
556
|
+
* for identifiers/files and `pascalCase` for type names.
|
|
557
|
+
*
|
|
558
|
+
* @example
|
|
559
|
+
* ```ts
|
|
560
|
+
* import { resolver } from '@kubb/plugin-ts'
|
|
561
|
+
*
|
|
562
|
+
* resolver.default('list pets', 'type') // → 'ListPets'
|
|
563
|
+
* resolver.resolveName('list pets status 200') // → 'ListPetsStatus200'
|
|
564
|
+
* resolver.resolvePathName('list pets', 'file') // → 'listPets'
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
declare const resolverTs: ResolverTs;
|
|
568
|
+
//#endregion
|
|
569
|
+
//#region src/resolvers/resolverTsLegacy.d.ts
|
|
570
|
+
/**
|
|
571
|
+
* Legacy resolver for `@kubb/plugin-ts` that reproduces the naming conventions
|
|
572
|
+
* used before the v2 resolver refactor. Enable via `compatibilityPreset: 'kubbV4'`
|
|
573
|
+
* (or by composing this resolver manually).
|
|
574
|
+
*
|
|
575
|
+
* Key differences from the default resolver:
|
|
576
|
+
* - Response status types: `<OperationId><StatusCode>` (e.g. `CreatePets201`) instead of `<OperationId>Status201`
|
|
577
|
+
* - Default/error responses: `<OperationId>Error` instead of `<OperationId>StatusDefault`
|
|
578
|
+
* - Request body: `<OperationId>MutationRequest` (non-GET) / `<OperationId>QueryRequest` (GET)
|
|
579
|
+
* - Combined responses type: `<OperationId>Mutation` / `<OperationId>Query`
|
|
580
|
+
* - Response union: `<OperationId>MutationResponse` / `<OperationId>QueryResponse`
|
|
581
|
+
*
|
|
582
|
+
* @example
|
|
583
|
+
* ```ts
|
|
584
|
+
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
585
|
+
*
|
|
586
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 201) // → 'CreatePets201'
|
|
587
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 'default') // → 'CreatePetsError'
|
|
588
|
+
* resolverTsLegacy.resolveDataTypedName(node) // → 'CreatePetsMutationRequest' (POST)
|
|
589
|
+
* resolverTsLegacy.resolveResponsesTypedName(node) // → 'CreatePetsMutation' (POST)
|
|
590
|
+
* resolverTsLegacy.resolveResponseTypedName(node) // → 'CreatePetsMutationResponse' (POST)
|
|
591
|
+
* ```
|
|
592
|
+
*/
|
|
593
|
+
declare const resolverTsLegacy: ResolverTs;
|
|
8
594
|
//#endregion
|
|
9
|
-
export { type PluginTs, pluginTs, pluginTsName };
|
|
595
|
+
export { Enum, type PluginTs, type PrinterTsFactory, type PrinterTsNodes, type PrinterTsOptions, type ResolverTs, Type, functionPrinter, pluginTs, pluginTsName, printerTs, resolverTs, resolverTsLegacy, typeGenerator };
|
|
10
596
|
//# sourceMappingURL=index.d.ts.map
|