@kubb/plugin-ts 5.0.0-alpha.2 → 5.0.0-alpha.20
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/Type-B70QnSzH.cjs +688 -0
- package/dist/Type-B70QnSzH.cjs.map +1 -0
- package/dist/Type-CMC7L-38.js +671 -0
- package/dist/Type-CMC7L-38.js.map +1 -0
- package/dist/casing-Cp-jbC_k.js +84 -0
- package/dist/casing-Cp-jbC_k.js.map +1 -0
- package/dist/casing-D2uQKLWS.cjs +144 -0
- package/dist/casing-D2uQKLWS.cjs.map +1 -0
- package/dist/components.cjs +3 -2
- package/dist/components.d.ts +41 -11
- package/dist/components.js +2 -2
- package/dist/generators-BFkr7ecU.js +556 -0
- package/dist/generators-BFkr7ecU.js.map +1 -0
- package/dist/generators-xHWQCNd9.cjs +560 -0
- package/dist/generators-xHWQCNd9.cjs.map +1 -0
- package/dist/generators.cjs +2 -2
- package/dist/generators.d.ts +3 -491
- package/dist/generators.js +1 -1
- package/dist/index.cjs +146 -3
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +145 -1
- package/dist/index.js.map +1 -0
- package/dist/resolvers-DsKabI0F.js +184 -0
- package/dist/resolvers-DsKabI0F.js.map +1 -0
- package/dist/resolvers-YIpeP5YD.cjs +194 -0
- package/dist/resolvers-YIpeP5YD.cjs.map +1 -0
- package/dist/resolvers.cjs +4 -0
- package/dist/resolvers.d.ts +52 -0
- package/dist/resolvers.js +2 -0
- package/dist/types-zqLMbIqZ.d.ts +340 -0
- package/package.json +15 -8
- package/src/components/Enum.tsx +83 -0
- package/src/components/Type.tsx +25 -144
- package/src/components/index.ts +1 -0
- package/src/constants.ts +29 -0
- package/src/factory.ts +14 -16
- package/src/generators/typeGenerator.tsx +221 -414
- package/src/generators/utils.ts +308 -0
- package/src/index.ts +1 -1
- package/src/plugin.ts +74 -87
- package/src/presets.ts +23 -0
- package/src/printer.ts +256 -92
- package/src/resolvers/index.ts +2 -0
- package/src/resolvers/resolverTs.ts +104 -0
- package/src/resolvers/resolverTsLegacy.ts +87 -0
- package/src/types.ts +234 -63
- package/dist/components-9wydyqUx.cjs +0 -848
- package/dist/components-9wydyqUx.cjs.map +0 -1
- package/dist/components-LmqJfxMv.js +0 -721
- package/dist/components-LmqJfxMv.js.map +0 -1
- package/dist/plugin-CNkzbtpl.cjs +0 -508
- package/dist/plugin-CNkzbtpl.cjs.map +0 -1
- package/dist/plugin-DoLrDl9P.js +0 -476
- package/dist/plugin-DoLrDl9P.js.map +0 -1
- package/dist/types-BpeKGgCn.d.ts +0 -170
- package/src/parser.ts +0 -396
package/src/types.ts
CHANGED
|
@@ -1,8 +1,193 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OperationNode, ParameterNode, SchemaNode, StatusCode, Visitor } from '@kubb/ast/types'
|
|
2
|
+
import type { CompatibilityPreset, Group, Output, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
2
3
|
import type { contentType, Oas } from '@kubb/oas'
|
|
3
4
|
import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
4
5
|
import type { Generator } from '@kubb/plugin-oas/generators'
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The concrete resolver type for `@kubb/plugin-ts`.
|
|
9
|
+
* Extends the base `Resolver` (which provides `default` and `resolveOptions`) with
|
|
10
|
+
* plugin-specific naming helpers for operations, parameters, responses, and schemas.
|
|
11
|
+
*/
|
|
12
|
+
export type ResolverTs = Resolver & {
|
|
13
|
+
/**
|
|
14
|
+
* Resolves the variable/function name for a given raw name (equivalent to `default(name, 'function')`).
|
|
15
|
+
* Use this shorthand when matching the `name` field produced by the v2 TypeGenerator,
|
|
16
|
+
* so call-sites don't need to repeat the `'function'` type literal.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* resolver.resolveName('list pets status 200') // → 'listPetsStatus200'
|
|
20
|
+
*/
|
|
21
|
+
resolveName(name: string): string
|
|
22
|
+
/**
|
|
23
|
+
* Resolves the TypeScript type name for a given raw name (equivalent to `default(name, 'type')`).
|
|
24
|
+
* Use this shorthand when matching the `typedName` field produced by the v2 TypeGenerator,
|
|
25
|
+
* so call-sites don't need to repeat the `'type'` type literal.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* resolver.resolveTypedName('list pets status 200') // → 'ListPetsStatus200'
|
|
29
|
+
*/
|
|
30
|
+
resolveTypedName(name: string): string
|
|
31
|
+
/**
|
|
32
|
+
* Resolves the file/path name for a given identifier using PascalCase.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* resolver.resolvePathName('list pets', 'file') // → 'ListPets'
|
|
36
|
+
*/
|
|
37
|
+
resolvePathName(name: string, type?: 'file' | 'function' | 'type' | 'const'): string
|
|
38
|
+
/**
|
|
39
|
+
* Resolves the variable/function name for an operation parameter.
|
|
40
|
+
* Encapsulates the `<operationId> <PascalCase(paramIn)> <paramName>` naming convention.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* resolver.resolveParamName(node, param) // → 'ListPetsQueryLimit'
|
|
44
|
+
*/
|
|
45
|
+
resolveParamName(node: OperationNode, param: ParameterNode): string
|
|
46
|
+
/**
|
|
47
|
+
* Resolves the TypeScript type alias name for an operation parameter
|
|
48
|
+
* (equivalent to `resolveParamName` with `type: 'type'`).
|
|
49
|
+
* In the default implementation both return the same PascalCase string;
|
|
50
|
+
* the distinction is preserved so overrides can diverge the two forms.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* resolver.resolveParamTypedName(node, param) // → 'ListPetsQueryLimit'
|
|
54
|
+
*/
|
|
55
|
+
resolveParamTypedName(node: OperationNode, param: ParameterNode): string
|
|
56
|
+
/**
|
|
57
|
+
* Resolves the variable/function name for an operation response by status code.
|
|
58
|
+
* Encapsulates the `<operationId> Status <statusCode>` template with PascalCase applied to the result.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* resolver.resolveResponseStatusName(node, 200) // → 'ListPetsStatus200'
|
|
62
|
+
*/
|
|
63
|
+
resolveResponseStatusName(node: OperationNode, statusCode: StatusCode): string
|
|
64
|
+
/**
|
|
65
|
+
* Resolves the TypeScript type alias name for an operation response by status code.
|
|
66
|
+
* Encapsulates the `<operationId> Status <statusCode>` template with PascalCase applied to the result.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* resolver.resolveResponseStatusTypedName(node, 200) // → 'ListPetsStatus200'
|
|
70
|
+
*/
|
|
71
|
+
resolveResponseStatusTypedName(node: OperationNode, statusCode: StatusCode): string
|
|
72
|
+
/**
|
|
73
|
+
* Resolves the variable/function name for an operation's request body (`Data`).
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* resolver.resolveDataName(node) // → 'ListPetsData'
|
|
77
|
+
*/
|
|
78
|
+
resolveDataName(node: OperationNode): string
|
|
79
|
+
/**
|
|
80
|
+
* Resolves the TypeScript type alias name for an operation's request body (`Data`).
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* resolver.resolveDataTypedName(node) // → 'ListPetsData'
|
|
84
|
+
*/
|
|
85
|
+
resolveDataTypedName(node: OperationNode): string
|
|
86
|
+
/**
|
|
87
|
+
* Resolves the variable/function name for an operation's request config (`RequestConfig`).
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* resolver.resolveRequestConfigName(node) // → 'ListPetsRequestConfig'
|
|
91
|
+
*/
|
|
92
|
+
resolveRequestConfigName(node: OperationNode): string
|
|
93
|
+
/**
|
|
94
|
+
* Resolves the TypeScript type alias name for an operation's request config (`RequestConfig`).
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* resolver.resolveRequestConfigTypedName(node) // → 'ListPetsRequestConfig'
|
|
98
|
+
*/
|
|
99
|
+
resolveRequestConfigTypedName(node: OperationNode): string
|
|
100
|
+
/**
|
|
101
|
+
* Resolves the variable/function name for the collection of all operation responses (`Responses`).
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* resolver.resolveResponsesName(node) // → 'ListPetsResponses'
|
|
105
|
+
*/
|
|
106
|
+
resolveResponsesName(node: OperationNode): string
|
|
107
|
+
/**
|
|
108
|
+
* Resolves the TypeScript type alias name for the collection of all operation responses.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* resolver.resolveResponsesTypedName(node) // → 'ListPetsResponses'
|
|
112
|
+
*/
|
|
113
|
+
resolveResponsesTypedName(node: OperationNode): string
|
|
114
|
+
/**
|
|
115
|
+
* Resolves the variable/function name for the union of all operation responses (`Response`).
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* resolver.resolveResponseName(node) // → 'ListPetsResponse'
|
|
119
|
+
*/
|
|
120
|
+
resolveResponseName(node: OperationNode): string
|
|
121
|
+
/**
|
|
122
|
+
* Resolves the TypeScript type alias name for the union of all operation responses.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* resolver.resolveResponseTypedName(node) // → 'ListPetsResponse'
|
|
126
|
+
*/
|
|
127
|
+
resolveResponseTypedName(node: OperationNode): string
|
|
128
|
+
/**
|
|
129
|
+
* Resolves the TypeScript type alias name for an enum schema's key variant.
|
|
130
|
+
* Appends the `Key` suffix after applying the default naming convention.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* resolver.resolveEnumKeyTypedName(node) // → 'PetStatusKey'
|
|
134
|
+
*/
|
|
135
|
+
resolveEnumKeyTypedName(node: SchemaNode): string
|
|
136
|
+
/**
|
|
137
|
+
* Resolves the variable/function name for an operation's grouped path parameters type.
|
|
138
|
+
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
139
|
+
*
|
|
140
|
+
* @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
|
|
141
|
+
* @example
|
|
142
|
+
* resolver.resolvePathParamsName(node) // → 'GetPetByIdPathParams'
|
|
143
|
+
*/
|
|
144
|
+
resolvePathParamsName?(node: OperationNode): string
|
|
145
|
+
/**
|
|
146
|
+
* Resolves the TypeScript type alias name for an operation's grouped path parameters type.
|
|
147
|
+
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
148
|
+
*
|
|
149
|
+
* @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
|
|
150
|
+
* @example
|
|
151
|
+
* resolver.resolvePathParamsTypedName(node) // → 'GetPetByIdPathParams'
|
|
152
|
+
*/
|
|
153
|
+
resolvePathParamsTypedName?(node: OperationNode): string
|
|
154
|
+
/**
|
|
155
|
+
* Resolves the variable/function name for an operation's grouped query parameters type.
|
|
156
|
+
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
157
|
+
*
|
|
158
|
+
* @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
|
|
159
|
+
* @example
|
|
160
|
+
* resolver.resolveQueryParamsName(node) // → 'FindPetsByStatusQueryParams'
|
|
161
|
+
*/
|
|
162
|
+
resolveQueryParamsName?(node: OperationNode): string
|
|
163
|
+
/**
|
|
164
|
+
* Resolves the TypeScript type alias name for an operation's grouped query parameters type.
|
|
165
|
+
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
166
|
+
*
|
|
167
|
+
* @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
|
|
168
|
+
* @example
|
|
169
|
+
* resolver.resolveQueryParamsTypedName(node) // → 'FindPetsByStatusQueryParams'
|
|
170
|
+
*/
|
|
171
|
+
resolveQueryParamsTypedName?(node: OperationNode): string
|
|
172
|
+
/**
|
|
173
|
+
* Resolves the variable/function name for an operation's grouped header parameters type.
|
|
174
|
+
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
175
|
+
*
|
|
176
|
+
* @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
|
|
177
|
+
* @example
|
|
178
|
+
* resolver.resolveHeaderParamsName(node) // → 'DeletePetHeaderParams'
|
|
179
|
+
*/
|
|
180
|
+
resolveHeaderParamsName?(node: OperationNode): string
|
|
181
|
+
/**
|
|
182
|
+
* Resolves the TypeScript type alias name for an operation's grouped header parameters type.
|
|
183
|
+
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
184
|
+
*
|
|
185
|
+
* @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
|
|
186
|
+
* @example
|
|
187
|
+
* resolver.resolveHeaderParamsTypedName(node) // → 'DeletePetHeaderParams'
|
|
188
|
+
*/
|
|
189
|
+
resolveHeaderParamsTypedName?(node: OperationNode): string
|
|
190
|
+
}
|
|
6
191
|
|
|
7
192
|
export type Options = {
|
|
8
193
|
/**
|
|
@@ -60,42 +245,6 @@ export type Options = {
|
|
|
60
245
|
* @default 'type'
|
|
61
246
|
*/
|
|
62
247
|
syntaxType?: 'type' | 'interface'
|
|
63
|
-
/**
|
|
64
|
-
* Set a suffix for the generated enums.
|
|
65
|
-
* @default 'enum'
|
|
66
|
-
*/
|
|
67
|
-
enumSuffix?: string
|
|
68
|
-
/**
|
|
69
|
-
* Choose to use date or datetime as JavaScript Date instead of string.
|
|
70
|
-
* - 'string' represents dates as string values.
|
|
71
|
-
* - 'date' represents dates as JavaScript Date objects.
|
|
72
|
-
* @default 'string'
|
|
73
|
-
*/
|
|
74
|
-
dateType?: 'string' | 'date'
|
|
75
|
-
/**
|
|
76
|
-
* Choose to use `number` or `bigint` for integer fields with `int64` format.
|
|
77
|
-
* - 'number' uses the TypeScript `number` type (matches JSON.parse() runtime behavior).
|
|
78
|
-
* - 'bigint' uses the TypeScript `bigint` type (accurate for values exceeding Number.MAX_SAFE_INTEGER).
|
|
79
|
-
* @note in v5 of Kubb 'bigint' will become the default to better align with OpenAPI's int64 specification.
|
|
80
|
-
* @default 'number'
|
|
81
|
-
*/
|
|
82
|
-
integerType?: 'number' | 'bigint'
|
|
83
|
-
/**
|
|
84
|
-
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
|
85
|
-
* - 'any' allows any value.
|
|
86
|
-
* - 'unknown' requires type narrowing before use.
|
|
87
|
-
* - 'void' represents no value.
|
|
88
|
-
* @default 'any'
|
|
89
|
-
*/
|
|
90
|
-
unknownType?: 'any' | 'unknown' | 'void'
|
|
91
|
-
/**
|
|
92
|
-
* Which type to use for empty schema values.
|
|
93
|
-
* - 'any' allows any value.
|
|
94
|
-
* - 'unknown' requires type narrowing before use.
|
|
95
|
-
* - 'void' represents no value.
|
|
96
|
-
* @default `unknownType`
|
|
97
|
-
*/
|
|
98
|
-
emptySchemaType?: 'any' | 'unknown' | 'void'
|
|
99
248
|
/**
|
|
100
249
|
* Choose what to use as mode for an optional value.
|
|
101
250
|
* - 'questionToken' marks the property as optional with ? (e.g., type?: string).
|
|
@@ -111,23 +260,6 @@ export type Options = {
|
|
|
111
260
|
* @default 'array'
|
|
112
261
|
*/
|
|
113
262
|
arrayType?: 'generic' | 'array'
|
|
114
|
-
transformers?: {
|
|
115
|
-
/**
|
|
116
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
117
|
-
*/
|
|
118
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* @example
|
|
122
|
-
* Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
|
|
123
|
-
* category: factory.createPropertySignature(
|
|
124
|
-
* undefined,
|
|
125
|
-
* factory.createIdentifier("category"),
|
|
126
|
-
* factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
127
|
-
* factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
128
|
-
* )
|
|
129
|
-
*/
|
|
130
|
-
mapper?: Record<string, ts.PropertySignature>
|
|
131
263
|
/**
|
|
132
264
|
* How to style your params, by default no casing is applied
|
|
133
265
|
* - 'camelcase' uses camelCase for pathParams, queryParams and headerParams property names
|
|
@@ -143,6 +275,43 @@ export type Options = {
|
|
|
143
275
|
* Unstable naming for v5
|
|
144
276
|
*/
|
|
145
277
|
UNSTABLE_NAMING?: true
|
|
278
|
+
/**
|
|
279
|
+
* Apply a compatibility naming preset.
|
|
280
|
+
* Use `kubbV4` for strict v4 type-generation compatibility.
|
|
281
|
+
* You can further customize naming with `resolvers`.
|
|
282
|
+
* @default 'default'
|
|
283
|
+
*/
|
|
284
|
+
compatibilityPreset?: CompatibilityPreset
|
|
285
|
+
/**
|
|
286
|
+
* Array of named resolvers that control naming conventions.
|
|
287
|
+
* Later entries override earlier ones (last wins).
|
|
288
|
+
* Built-in: `resolverTs` (default), `resolverTsLegacy`.
|
|
289
|
+
* @default [resolverTs]
|
|
290
|
+
*/
|
|
291
|
+
resolvers?: Array<ResolverTs>
|
|
292
|
+
/**
|
|
293
|
+
* Array of AST visitors applied to each SchemaNode/OperationNode before printing.
|
|
294
|
+
* Uses `transform()` from `@kubb/ast` — visitors can modify, replace, or annotate nodes.
|
|
295
|
+
*
|
|
296
|
+
* @example Remove writeOnly properties from response types
|
|
297
|
+
* ```ts
|
|
298
|
+
* transformers: [{
|
|
299
|
+
* property(node) {
|
|
300
|
+
* if (node.schema.writeOnly) return undefined
|
|
301
|
+
* }
|
|
302
|
+
* }]
|
|
303
|
+
* ```
|
|
304
|
+
*
|
|
305
|
+
* @example Force all dates to plain strings
|
|
306
|
+
* ```ts
|
|
307
|
+
* transformers: [{
|
|
308
|
+
* schema(node) {
|
|
309
|
+
* if (node.type === 'date') return { ...node, type: 'string' }
|
|
310
|
+
* }
|
|
311
|
+
* }]
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
transformers?: Array<Visitor>
|
|
146
315
|
}
|
|
147
316
|
|
|
148
317
|
type ResolvedOptions = {
|
|
@@ -151,17 +320,19 @@ type ResolvedOptions = {
|
|
|
151
320
|
override: NonNullable<Options['override']>
|
|
152
321
|
enumType: NonNullable<Options['enumType']>
|
|
153
322
|
enumKeyCasing: NonNullable<Options['enumKeyCasing']>
|
|
154
|
-
enumSuffix: NonNullable<Options['enumSuffix']>
|
|
155
|
-
dateType: NonNullable<Options['dateType']>
|
|
156
|
-
integerType: NonNullable<Options['integerType']>
|
|
157
|
-
unknownType: NonNullable<Options['unknownType']>
|
|
158
|
-
emptySchemaType: NonNullable<Options['emptySchemaType']>
|
|
159
323
|
optionalType: NonNullable<Options['optionalType']>
|
|
160
324
|
arrayType: NonNullable<Options['arrayType']>
|
|
161
|
-
transformers: NonNullable<Options['transformers']>
|
|
162
325
|
syntaxType: NonNullable<Options['syntaxType']>
|
|
163
|
-
mapper: Record<string, any>
|
|
164
326
|
paramsCasing: Options['paramsCasing']
|
|
327
|
+
compatibilityPreset: NonNullable<CompatibilityPreset>
|
|
328
|
+
resolver: ResolverTs
|
|
329
|
+
/**
|
|
330
|
+
* The resolver without user naming overrides applied.
|
|
331
|
+
* Used internally to derive stable names for unnamed enums and grouped params
|
|
332
|
+
* so that the schema tree stays consistent regardless of `transformers.name` / custom resolvers.
|
|
333
|
+
*/
|
|
334
|
+
baseResolver: ResolverTs
|
|
335
|
+
transformers: Array<Visitor>
|
|
165
336
|
}
|
|
166
337
|
|
|
167
|
-
export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>
|
|
338
|
+
export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs>
|