@kubb/plugin-ts 5.0.0-beta.42 → 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/dist/index.cjs +106 -165
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +94 -92
- package/dist/index.js +104 -163
- package/dist/index.js.map +1 -1
- package/package.json +8 -15
- package/src/components/Enum.tsx +30 -26
- package/src/components/Type.tsx +6 -11
- package/src/constants.ts +7 -7
- package/src/factory.ts +5 -38
- package/src/generators/typeGenerator.tsx +22 -42
- package/src/plugin.ts +12 -9
- package/src/printers/printerTs.ts +13 -24
- package/src/resolvers/resolverTs.ts +6 -6
- package/src/types.ts +77 -57
- package/src/utils.ts +1 -1
- package/extension.yaml +0 -1080
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ast, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
1
|
+
import type { ast, Exclude, Generator, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
2
2
|
import type { PrinterTsNodes } from './printers/printerTs.ts'
|
|
3
3
|
/**
|
|
4
4
|
* The concrete resolver type for `@kubb/plugin-ts`.
|
|
@@ -93,34 +93,49 @@ export type ResolverTs = Resolver &
|
|
|
93
93
|
|
|
94
94
|
type EnumKeyCasing = 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none'
|
|
95
95
|
|
|
96
|
+
type EnumConstCasing = 'camelCase' | 'pascalCase'
|
|
97
|
+
|
|
96
98
|
/**
|
|
97
|
-
*
|
|
99
|
+
* Grouped enum settings. Each `type` uses only some of the other fields.
|
|
100
|
+
*
|
|
101
|
+
* - `'asConst'` emits a `const` object plus a `typeof` type alias, so `constCasing`, `typeSuffix`, and `keyCasing` all apply.
|
|
102
|
+
* - `'enum'` and `'constEnum'` emit a TypeScript enum, so only `keyCasing` (the member names) applies.
|
|
103
|
+
* - `'literal'` and `'inlineLiteral'` emit union literals and drop the keys, so none of the other fields apply.
|
|
98
104
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
+
* @example Share one name between the const and the type
|
|
106
|
+
* ```ts
|
|
107
|
+
* enum: { type: 'asConst', constCasing: 'pascalCase', typeSuffix: '' }
|
|
108
|
+
* // export const VehicleType = { … } as const
|
|
109
|
+
* // export type VehicleType = (typeof VehicleType)[keyof typeof VehicleType]
|
|
110
|
+
* ```
|
|
105
111
|
*/
|
|
106
|
-
type
|
|
112
|
+
type EnumOptions =
|
|
107
113
|
| {
|
|
108
114
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
115
|
+
* Emit a `const` object asserted with `as const`, paired with a `typeof` type alias.
|
|
116
|
+
* This is tree-shakeable and adds no enum runtime.
|
|
117
|
+
*
|
|
112
118
|
* @default 'asConst'
|
|
113
119
|
*/
|
|
114
|
-
|
|
120
|
+
type?: 'asConst'
|
|
115
121
|
/**
|
|
116
|
-
*
|
|
122
|
+
* Casing of the generated const variable.
|
|
123
|
+
* - 'camelCase' names the const `vehicleType`.
|
|
124
|
+
* - 'pascalCase' names the const `VehicleType`, matching the schema name.
|
|
117
125
|
*
|
|
118
|
-
*
|
|
126
|
+
* @default 'camelCase'
|
|
127
|
+
*/
|
|
128
|
+
constCasing?: EnumConstCasing
|
|
129
|
+
/**
|
|
130
|
+
* Suffix appended to the generated type alias name. Only the type alias is renamed. The const
|
|
131
|
+
* object name stays the same. Set it to `''` together with `constCasing: 'pascalCase'` to merge
|
|
132
|
+
* the const and type under the schema's exact name.
|
|
119
133
|
*
|
|
120
134
|
* @default 'Key'
|
|
121
|
-
* @example
|
|
135
|
+
* @example A custom suffix
|
|
136
|
+
* `typeSuffix: 'Value'` renames the alias to `PetStatusValue`
|
|
122
137
|
*/
|
|
123
|
-
|
|
138
|
+
typeSuffix?: string
|
|
124
139
|
/**
|
|
125
140
|
* Choose the casing for enum key names.
|
|
126
141
|
* - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
|
|
@@ -130,23 +145,25 @@ type EnumTypeOptions =
|
|
|
130
145
|
* - 'none' uses the enum value as-is without transformation.
|
|
131
146
|
* @default 'none'
|
|
132
147
|
*/
|
|
133
|
-
|
|
148
|
+
keyCasing?: EnumKeyCasing
|
|
134
149
|
}
|
|
135
150
|
| {
|
|
136
151
|
/**
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
* - 'constEnum' generates TypeScript const enum declarations.
|
|
152
|
+
* Emit a TypeScript `enum` (`'enum'`) or `const enum` (`'constEnum'`) declaration.
|
|
153
|
+
*
|
|
140
154
|
* @default 'asConst'
|
|
141
155
|
*/
|
|
142
|
-
|
|
156
|
+
type?: 'enum' | 'constEnum'
|
|
143
157
|
/**
|
|
144
|
-
* `
|
|
145
|
-
* It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
|
|
158
|
+
* `constCasing` has no effect for this `type`. Only `'asConst'` emits a const object.
|
|
146
159
|
*/
|
|
147
|
-
|
|
160
|
+
constCasing?: never
|
|
148
161
|
/**
|
|
149
|
-
*
|
|
162
|
+
* `typeSuffix` has no effect for this `type`. Only `'asConst'` emits a separate type alias.
|
|
163
|
+
*/
|
|
164
|
+
typeSuffix?: never
|
|
165
|
+
/**
|
|
166
|
+
* Choose the casing for enum member names.
|
|
150
167
|
* - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
|
|
151
168
|
* - 'snakeCase' generates keys in snake_case format.
|
|
152
169
|
* - 'pascalCase' generates keys in PascalCase format.
|
|
@@ -154,45 +171,39 @@ type EnumTypeOptions =
|
|
|
154
171
|
* - 'none' uses the enum value as-is without transformation.
|
|
155
172
|
* @default 'none'
|
|
156
173
|
*/
|
|
157
|
-
|
|
174
|
+
keyCasing?: EnumKeyCasing
|
|
158
175
|
}
|
|
159
176
|
| {
|
|
160
177
|
/**
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
178
|
+
* Emit a union of literals as a named alias (`'literal'`) or inline the union at every usage
|
|
179
|
+
* site (`'inlineLiteral'`).
|
|
180
|
+
*
|
|
164
181
|
* @default 'asConst'
|
|
165
182
|
* @note In Kubb v5, 'inlineLiteral' becomes the default.
|
|
166
183
|
*/
|
|
167
|
-
|
|
184
|
+
type?: 'literal' | 'inlineLiteral'
|
|
168
185
|
/**
|
|
169
|
-
* `
|
|
170
|
-
* It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
|
|
186
|
+
* `constCasing` has no effect for this `type`; literal modes emit no const object.
|
|
171
187
|
*/
|
|
172
|
-
|
|
188
|
+
constCasing?: never
|
|
173
189
|
/**
|
|
174
|
-
* `
|
|
175
|
-
* Literal and inlineLiteral modes emit only values; keys are discarded entirely.
|
|
190
|
+
* `typeSuffix` has no effect for this `type`; literal modes emit no separate type alias.
|
|
176
191
|
*/
|
|
177
|
-
|
|
192
|
+
typeSuffix?: never
|
|
193
|
+
/**
|
|
194
|
+
* `keyCasing` has no effect for this `type`. Literal and inlineLiteral modes emit only values,
|
|
195
|
+
* so the keys are discarded.
|
|
196
|
+
*/
|
|
197
|
+
keyCasing?: never
|
|
178
198
|
}
|
|
179
199
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Media type read from the OpenAPI spec when an operation defines several.
|
|
189
|
-
* Defaults to the first JSON-compatible media type Kubb finds.
|
|
190
|
-
*/
|
|
191
|
-
contentType?: 'application/json' | (string & {})
|
|
192
|
-
/**
|
|
193
|
-
* Split generated files into subfolders based on the operation's tag.
|
|
194
|
-
*/
|
|
195
|
-
group?: Group
|
|
200
|
+
/**
|
|
201
|
+
* Where the generated `.ts` files are written and how they are exported, plus the optional
|
|
202
|
+
* `group` strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
|
|
203
|
+
*
|
|
204
|
+
* @default { path: 'types', barrel: { type: 'named' } }
|
|
205
|
+
*/
|
|
206
|
+
export type Options = OutputOptions & {
|
|
196
207
|
/**
|
|
197
208
|
* Skip operations matching at least one entry in the list.
|
|
198
209
|
*/
|
|
@@ -286,7 +297,18 @@ export type Options = {
|
|
|
286
297
|
printer?: {
|
|
287
298
|
nodes?: PrinterTsNodes
|
|
288
299
|
}
|
|
289
|
-
|
|
300
|
+
/**
|
|
301
|
+
* How OpenAPI enums are represented in the generated TypeScript, and how their names are cased.
|
|
302
|
+
*/
|
|
303
|
+
enum?: EnumOptions
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
type ResolvedEnumOptions = {
|
|
307
|
+
type: NonNullable<EnumOptions['type']>
|
|
308
|
+
constCasing: EnumConstCasing
|
|
309
|
+
typeSuffix: string
|
|
310
|
+
keyCasing: EnumKeyCasing
|
|
311
|
+
}
|
|
290
312
|
|
|
291
313
|
type ResolvedOptions = {
|
|
292
314
|
output: Output
|
|
@@ -294,9 +316,7 @@ type ResolvedOptions = {
|
|
|
294
316
|
include: Array<Include> | undefined
|
|
295
317
|
override: Array<Override<ResolvedOptions>>
|
|
296
318
|
group: Group | null
|
|
297
|
-
|
|
298
|
-
enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>
|
|
299
|
-
enumKeyCasing: EnumKeyCasing
|
|
319
|
+
enum: ResolvedEnumOptions
|
|
300
320
|
optionalType: NonNullable<Options['optionalType']>
|
|
301
321
|
arrayType: NonNullable<Options['arrayType']>
|
|
302
322
|
syntaxType: NonNullable<Options['syntaxType']>
|
package/src/utils.ts
CHANGED