@kubb/plugin-ts 5.0.0-alpha.11 → 5.0.0-alpha.13
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-C8EHVKjc.js +663 -0
- package/dist/Type-C8EHVKjc.js.map +1 -0
- package/dist/Type-DrOq6-nh.cjs +680 -0
- package/dist/Type-DrOq6-nh.cjs.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 -9
- package/dist/components.js +2 -2
- package/dist/generators-CX3cSSdF.cjs +551 -0
- package/dist/generators-CX3cSSdF.cjs.map +1 -0
- package/dist/generators-dCqW0ECC.js +547 -0
- package/dist/generators-dCqW0ECC.js.map +1 -0
- package/dist/generators.cjs +2 -3
- package/dist/generators.d.ts +3 -503
- package/dist/generators.js +2 -2
- package/dist/index.cjs +135 -4
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -41
- package/dist/index.js +134 -2
- package/dist/index.js.map +1 -0
- package/dist/resolvers-CH7hINyz.js +181 -0
- package/dist/resolvers-CH7hINyz.js.map +1 -0
- package/dist/resolvers-ebHaaCyw.cjs +191 -0
- package/dist/resolvers-ebHaaCyw.cjs.map +1 -0
- package/dist/resolvers.cjs +4 -0
- package/dist/resolvers.d.ts +51 -0
- package/dist/resolvers.js +2 -0
- package/dist/{types-mSXmB8WU.d.ts → types-BSRhtbGl.d.ts} +80 -57
- package/package.json +12 -5
- package/src/components/{v2/Enum.tsx → Enum.tsx} +27 -11
- package/src/components/Type.tsx +24 -141
- package/src/components/index.ts +1 -0
- package/src/generators/index.ts +0 -1
- package/src/generators/typeGenerator.tsx +204 -413
- package/src/generators/utils.ts +300 -0
- package/src/index.ts +0 -1
- package/src/plugin.ts +81 -126
- package/src/printer.ts +20 -6
- package/src/resolvers/index.ts +2 -0
- package/src/{resolverTs.ts → resolvers/resolverTs.ts} +26 -2
- package/src/resolvers/resolverTsLegacy.ts +85 -0
- package/src/types.ts +75 -52
- package/dist/components-CRu8IKY3.js +0 -729
- package/dist/components-CRu8IKY3.js.map +0 -1
- package/dist/components-DeNDKlzf.cjs +0 -982
- package/dist/components-DeNDKlzf.cjs.map +0 -1
- package/dist/plugin-CJ29AwE2.cjs +0 -1320
- package/dist/plugin-CJ29AwE2.cjs.map +0 -1
- package/dist/plugin-D60XNJSD.js +0 -1267
- package/dist/plugin-D60XNJSD.js.map +0 -1
- package/src/components/v2/Type.tsx +0 -59
- package/src/generators/v2/typeGenerator.tsx +0 -167
- package/src/generators/v2/utils.ts +0 -140
- package/src/parser.ts +0 -389
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { pascalCase } from '@internals/utils'
|
|
2
2
|
import { defineResolver } from '@kubb/core'
|
|
3
|
-
import type { PluginTs } from '
|
|
3
|
+
import type { PluginTs } from '../types.ts'
|
|
4
|
+
|
|
5
|
+
function resolveName(name: string, type?: 'file' | 'function' | 'type' | 'const'): string {
|
|
6
|
+
return pascalCase(name, { isFile: type === 'file' })
|
|
7
|
+
}
|
|
4
8
|
|
|
5
9
|
/**
|
|
6
10
|
* Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
|
|
@@ -23,7 +27,7 @@ import type { PluginTs } from './types.ts'
|
|
|
23
27
|
export const resolverTs = defineResolver<PluginTs>(() => {
|
|
24
28
|
return {
|
|
25
29
|
default(name, type) {
|
|
26
|
-
return
|
|
30
|
+
return resolveName(name, type)
|
|
27
31
|
},
|
|
28
32
|
resolveName(name) {
|
|
29
33
|
return this.default(name, 'function')
|
|
@@ -73,5 +77,25 @@ export const resolverTs = defineResolver<PluginTs>(() => {
|
|
|
73
77
|
resolveEnumKeyTypedName(node) {
|
|
74
78
|
return `${this.resolveTypedName(node.name ?? '')}Key`
|
|
75
79
|
},
|
|
80
|
+
resolvePathParamsName(_node) {
|
|
81
|
+
throw new Error('resolvePathParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.')
|
|
82
|
+
},
|
|
83
|
+
resolvePathParamsTypedName(_node) {
|
|
84
|
+
throw new Error('resolvePathParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.')
|
|
85
|
+
},
|
|
86
|
+
resolveQueryParamsName(node) {
|
|
87
|
+
return this.resolveName(`${node.operationId} QueryParams`)
|
|
88
|
+
},
|
|
89
|
+
resolveQueryParamsTypedName(node) {
|
|
90
|
+
return this.resolveTypedName(`${node.operationId} QueryParams`)
|
|
91
|
+
},
|
|
92
|
+
resolveHeaderParamsName(_node) {
|
|
93
|
+
throw new Error('resolveHeaderParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.')
|
|
94
|
+
},
|
|
95
|
+
resolveHeaderParamsTypedName(_node) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
'resolveHeaderParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.',
|
|
98
|
+
)
|
|
99
|
+
},
|
|
76
100
|
}
|
|
77
101
|
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { defineResolver } from '@kubb/core'
|
|
2
|
+
import type { PluginTs } from '../types.ts'
|
|
3
|
+
import { resolverTs } from './resolverTs.ts'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Legacy resolver for `@kubb/plugin-ts` that reproduces the naming conventions
|
|
7
|
+
* used before the v2 resolver refactor. Enable via `legacy: true` in plugin options.
|
|
8
|
+
*
|
|
9
|
+
* Key differences from the default resolver:
|
|
10
|
+
* - Response status types: `<OperationId><StatusCode>` (e.g. `CreatePets201`) instead of `<OperationId>Status201`
|
|
11
|
+
* - Default/error responses: `<OperationId>Error` instead of `<OperationId>StatusDefault`
|
|
12
|
+
* - Request body: `<OperationId>MutationRequest` (non-GET) / `<OperationId>QueryRequest` (GET)
|
|
13
|
+
* - Combined responses type: `<OperationId>Mutation` / `<OperationId>Query`
|
|
14
|
+
* - Response union: `<OperationId>MutationResponse` / `<OperationId>QueryResponse`
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
19
|
+
*
|
|
20
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 201) // → 'CreatePets201'
|
|
21
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 'default') // → 'CreatePetsError'
|
|
22
|
+
* resolverTsLegacy.resolveDataTypedName(node) // → 'CreatePetsMutationRequest' (POST)
|
|
23
|
+
* resolverTsLegacy.resolveResponsesTypedName(node) // → 'CreatePetsMutation' (POST)
|
|
24
|
+
* resolverTsLegacy.resolveResponseTypedName(node) // → 'CreatePetsMutationResponse' (POST)
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const resolverTsLegacy = defineResolver<PluginTs>(() => {
|
|
28
|
+
return {
|
|
29
|
+
...resolverTs,
|
|
30
|
+
resolveResponseStatusName(node, statusCode) {
|
|
31
|
+
if (statusCode === 'default') {
|
|
32
|
+
return this.resolveName(`${node.operationId} Error`)
|
|
33
|
+
}
|
|
34
|
+
return this.resolveName(`${node.operationId} ${statusCode}`)
|
|
35
|
+
},
|
|
36
|
+
resolveResponseStatusTypedName(node, statusCode) {
|
|
37
|
+
if (statusCode === 'default') {
|
|
38
|
+
return this.resolveTypedName(`${node.operationId} Error`)
|
|
39
|
+
}
|
|
40
|
+
return this.resolveTypedName(`${node.operationId} ${statusCode}`)
|
|
41
|
+
},
|
|
42
|
+
resolveDataName(node) {
|
|
43
|
+
const suffix = node.method === 'GET' ? 'QueryRequest' : 'MutationRequest'
|
|
44
|
+
return this.resolveName(`${node.operationId} ${suffix}`)
|
|
45
|
+
},
|
|
46
|
+
resolveDataTypedName(node) {
|
|
47
|
+
const suffix = node.method === 'GET' ? 'QueryRequest' : 'MutationRequest'
|
|
48
|
+
return this.resolveTypedName(`${node.operationId} ${suffix}`)
|
|
49
|
+
},
|
|
50
|
+
resolveResponsesName(node) {
|
|
51
|
+
const suffix = node.method === 'GET' ? 'Query' : 'Mutation'
|
|
52
|
+
return `${this.default(node.operationId, 'function')}${suffix}`
|
|
53
|
+
},
|
|
54
|
+
resolveResponsesTypedName(node) {
|
|
55
|
+
const suffix = node.method === 'GET' ? 'Query' : 'Mutation'
|
|
56
|
+
return `${this.default(node.operationId, 'type')}${suffix}`
|
|
57
|
+
},
|
|
58
|
+
resolveResponseName(node) {
|
|
59
|
+
const suffix = node.method === 'GET' ? 'QueryResponse' : 'MutationResponse'
|
|
60
|
+
return this.resolveName(`${node.operationId} ${suffix}`)
|
|
61
|
+
},
|
|
62
|
+
resolveResponseTypedName(node) {
|
|
63
|
+
const suffix = node.method === 'GET' ? 'QueryResponse' : 'MutationResponse'
|
|
64
|
+
return this.resolveTypedName(`${node.operationId} ${suffix}`)
|
|
65
|
+
},
|
|
66
|
+
resolvePathParamsName(node) {
|
|
67
|
+
return this.resolveName(`${node.operationId} PathParams`)
|
|
68
|
+
},
|
|
69
|
+
resolvePathParamsTypedName(node) {
|
|
70
|
+
return this.resolveTypedName(`${node.operationId} PathParams`)
|
|
71
|
+
},
|
|
72
|
+
resolveQueryParamsName(node) {
|
|
73
|
+
return this.resolveName(`${node.operationId} QueryParams`)
|
|
74
|
+
},
|
|
75
|
+
resolveQueryParamsTypedName(node) {
|
|
76
|
+
return this.resolveTypedName(`${node.operationId} QueryParams`)
|
|
77
|
+
},
|
|
78
|
+
resolveHeaderParamsName(node) {
|
|
79
|
+
return this.resolveName(`${node.operationId} HeaderParams`)
|
|
80
|
+
},
|
|
81
|
+
resolveHeaderParamsTypedName(node) {
|
|
82
|
+
return this.resolveTypedName(`${node.operationId} HeaderParams`)
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
})
|
package/src/types.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { Generator } from '@kubb/plugin-oas/generators'
|
|
|
9
9
|
* Extends the base `Resolver` (which provides `default` and `resolveOptions`) with
|
|
10
10
|
* plugin-specific naming helpers for operations, parameters, responses, and schemas.
|
|
11
11
|
*/
|
|
12
|
-
type ResolverTs = Resolver & {
|
|
12
|
+
export type ResolverTs = Resolver & {
|
|
13
13
|
/**
|
|
14
14
|
* Resolves the variable/function name for a given raw name (equivalent to `default(name, 'function')`).
|
|
15
15
|
* Use this shorthand when matching the `name` field produced by the v2 TypeGenerator,
|
|
@@ -133,6 +133,60 @@ type ResolverTs = Resolver & {
|
|
|
133
133
|
* resolver.resolveEnumKeyTypedName(node) // → 'PetStatusKey'
|
|
134
134
|
*/
|
|
135
135
|
resolveEnumKeyTypedName(node: SchemaNode): string
|
|
136
|
+
/**
|
|
137
|
+
* Resolves the variable/function name for an operation's grouped path parameters type.
|
|
138
|
+
* Only available in legacy mode (`legacy: true`).
|
|
139
|
+
*
|
|
140
|
+
* @deprecated Legacy only — will be removed in v6. 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 in legacy mode (`legacy: true`).
|
|
148
|
+
*
|
|
149
|
+
* @deprecated Legacy only — will be removed in v6. 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 in legacy mode (`legacy: true`).
|
|
157
|
+
*
|
|
158
|
+
* @deprecated Legacy only — will be removed in v6. 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 in legacy mode (`legacy: true`).
|
|
166
|
+
*
|
|
167
|
+
* @deprecated Legacy only — will be removed in v6. 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 in legacy mode (`legacy: true`).
|
|
175
|
+
*
|
|
176
|
+
* @deprecated Legacy only — will be removed in v6. 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 in legacy mode (`legacy: true`).
|
|
184
|
+
*
|
|
185
|
+
* @deprecated Legacy only — will be removed in v6. Use `resolveParamTypedName` per individual parameter instead.
|
|
186
|
+
* @example
|
|
187
|
+
* resolver.resolveHeaderParamsTypedName(node) // → 'DeletePetHeaderParams'
|
|
188
|
+
*/
|
|
189
|
+
resolveHeaderParamsTypedName?(node: OperationNode): string
|
|
136
190
|
}
|
|
137
191
|
|
|
138
192
|
export type Options = {
|
|
@@ -191,52 +245,6 @@ export type Options = {
|
|
|
191
245
|
* @default 'type'
|
|
192
246
|
*/
|
|
193
247
|
syntaxType?: 'type' | 'interface'
|
|
194
|
-
/**
|
|
195
|
-
* Set a suffix for the generated enums.
|
|
196
|
-
* @default 'enum'
|
|
197
|
-
* @deprecated Set `enumSuffix` on the adapter (`adapterOas({ enumSuffix })`) instead.
|
|
198
|
-
* In v5, the adapter owns this decision at parse time; the plugin option is ignored.
|
|
199
|
-
*/
|
|
200
|
-
enumSuffix?: string
|
|
201
|
-
/**
|
|
202
|
-
* Choose to use date or datetime as JavaScript Date instead of string.
|
|
203
|
-
* - 'string' represents dates as string values.
|
|
204
|
-
* - 'date' represents dates as JavaScript Date objects.
|
|
205
|
-
* @default 'string'
|
|
206
|
-
* @deprecated Set `dateType` on the adapter (`adapterOas({ dateType })`) instead.
|
|
207
|
-
* In v5, the adapter owns this decision at parse time; the plugin option is ignored.
|
|
208
|
-
*/
|
|
209
|
-
dateType?: 'string' | 'date'
|
|
210
|
-
/**
|
|
211
|
-
* Choose to use `number` or `bigint` for integer fields with `int64` format.
|
|
212
|
-
* - 'number' uses the TypeScript `number` type (matches JSON.parse() runtime behavior).
|
|
213
|
-
* - 'bigint' uses the TypeScript `bigint` type (accurate for values exceeding Number.MAX_SAFE_INTEGER).
|
|
214
|
-
* @note in v5 of Kubb 'bigint' will become the default to better align with OpenAPI's int64 specification.
|
|
215
|
-
* @default 'number'
|
|
216
|
-
* @deprecated Set `integerType` on the adapter (`adapterOas({ integerType })`) instead.
|
|
217
|
-
* In v5, the adapter owns this decision at parse time; the plugin option is ignored.
|
|
218
|
-
*/
|
|
219
|
-
integerType?: 'number' | 'bigint'
|
|
220
|
-
/**
|
|
221
|
-
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
|
222
|
-
* - 'any' allows any value.
|
|
223
|
-
* - 'unknown' requires type narrowing before use.
|
|
224
|
-
* - 'void' represents no value.
|
|
225
|
-
* @default 'any'
|
|
226
|
-
* @deprecated Set `unknownType` on the adapter (`adapterOas({ unknownType })`) instead.
|
|
227
|
-
* In v5, the adapter owns this decision at parse time; the plugin option is ignored.
|
|
228
|
-
*/
|
|
229
|
-
unknownType?: 'any' | 'unknown' | 'void'
|
|
230
|
-
/**
|
|
231
|
-
* Which type to use for empty schema values.
|
|
232
|
-
* - 'any' allows any value.
|
|
233
|
-
* - 'unknown' requires type narrowing before use.
|
|
234
|
-
* - 'void' represents no value.
|
|
235
|
-
* @default `unknownType`
|
|
236
|
-
* @deprecated Set `emptySchemaType` on the adapter (`adapterOas({ emptySchemaType })`) instead.
|
|
237
|
-
* In v5, the adapter owns this decision at parse time; the plugin option is ignored.
|
|
238
|
-
*/
|
|
239
|
-
emptySchemaType?: 'any' | 'unknown' | 'void'
|
|
240
248
|
/**
|
|
241
249
|
* Choose what to use as mode for an optional value.
|
|
242
250
|
* - 'questionToken' marks the property as optional with ? (e.g., type?: string).
|
|
@@ -273,6 +281,17 @@ export type Options = {
|
|
|
273
281
|
* Unstable naming for v5
|
|
274
282
|
*/
|
|
275
283
|
UNSTABLE_NAMING?: true
|
|
284
|
+
/**
|
|
285
|
+
* Enable legacy naming conventions for backwards compatibility.
|
|
286
|
+
* When enabled, operation-level types use the old naming scheme:
|
|
287
|
+
* - GET responses → `<OperationId>QueryResponse`, `<OperationId>Query`
|
|
288
|
+
* - Non-GET responses → `<OperationId>MutationResponse`, `<OperationId>Mutation`
|
|
289
|
+
* - Request body → `<OperationId>QueryRequest` / `<OperationId>MutationRequest`
|
|
290
|
+
* - Response status codes → `<OperationId><StatusCode>` (e.g. `CreatePets201`)
|
|
291
|
+
* - Default/error response → `<OperationId>Error`
|
|
292
|
+
* @default false
|
|
293
|
+
*/
|
|
294
|
+
legacy?: boolean
|
|
276
295
|
}
|
|
277
296
|
|
|
278
297
|
type ResolvedOptions = {
|
|
@@ -281,16 +300,20 @@ type ResolvedOptions = {
|
|
|
281
300
|
override: NonNullable<Options['override']>
|
|
282
301
|
enumType: NonNullable<Options['enumType']>
|
|
283
302
|
enumKeyCasing: NonNullable<Options['enumKeyCasing']>
|
|
284
|
-
enumSuffix: NonNullable<Options['enumSuffix']>
|
|
285
|
-
dateType: NonNullable<Options['dateType']>
|
|
286
|
-
integerType: NonNullable<Options['integerType']>
|
|
287
|
-
unknownType: NonNullable<Options['unknownType']>
|
|
288
|
-
emptySchemaType: NonNullable<Options['emptySchemaType']>
|
|
289
303
|
optionalType: NonNullable<Options['optionalType']>
|
|
290
304
|
arrayType: NonNullable<Options['arrayType']>
|
|
291
305
|
transformers: NonNullable<Options['transformers']>
|
|
292
306
|
syntaxType: NonNullable<Options['syntaxType']>
|
|
293
307
|
paramsCasing: Options['paramsCasing']
|
|
308
|
+
legacy: NonNullable<Options['legacy']>
|
|
309
|
+
resolver: ResolverTs
|
|
310
|
+
/**
|
|
311
|
+
* The base resolver without any `transformers.name` wrapping.
|
|
312
|
+
* Used internally to derive enum prefix names so that user-defined
|
|
313
|
+
* name transformations (e.g. appending `Type`) are not embedded in
|
|
314
|
+
* the middle of inline-enum identifiers.
|
|
315
|
+
*/
|
|
316
|
+
baseResolver?: ResolverTs
|
|
294
317
|
}
|
|
295
318
|
|
|
296
319
|
export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs>
|