@kubb/plugin-ts 5.0.0-alpha.23 → 5.0.0-alpha.25
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 +480 -473
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +105 -37
- package/dist/index.js +486 -479
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/Enum.tsx +2 -7
- package/src/components/Type.tsx +8 -0
- package/src/constants.ts +10 -0
- package/src/factory.ts +122 -1
- package/src/generators/typeGenerator.tsx +119 -96
- package/src/generators/typeGeneratorLegacy.tsx +85 -80
- package/src/index.ts +0 -5
- package/src/plugin.ts +19 -49
- package/src/printers/functionPrinter.ts +6 -5
- package/src/printers/printerTs.ts +65 -181
- package/src/resolvers/resolverTs.ts +2 -2
- package/src/types.ts +93 -36
- package/src/utils.ts +41 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import ts from "typescript";
|
|
3
2
|
import { OperationParamsResolver } from "@kubb/ast";
|
|
3
|
+
import ts from "typescript";
|
|
4
4
|
import * as _$_kubb_core0 from "@kubb/core";
|
|
5
5
|
import { CompatibilityPreset, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, PrinterFactoryOptions, ResolvePathOptions, Resolver, UserGroup } from "@kubb/core";
|
|
6
6
|
import { EnumSchemaNode, FunctionNode, OperationNode, ParameterNode, SchemaNode, StatusCode, Visitor } from "@kubb/ast/types";
|
|
@@ -27,7 +27,10 @@ type ResolverTs = Resolver & OperationParamsResolver & {
|
|
|
27
27
|
* @example
|
|
28
28
|
* resolver.resolvePathName('list pets', 'file') // → 'ListPets'
|
|
29
29
|
*/
|
|
30
|
-
resolvePathName(name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
30
|
+
resolvePathName(name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
31
|
+
/**
|
|
32
|
+
* Resolves the request body type name for an operation (required on ResolverTs).
|
|
33
|
+
*/
|
|
31
34
|
resolveDataName(node: OperationNode): string;
|
|
32
35
|
/**
|
|
33
36
|
* Resolves the name for an operation response by status code.
|
|
@@ -67,7 +70,9 @@ type ResolverTs = Resolver & OperationParamsResolver & {
|
|
|
67
70
|
* resolver.resolveEnumKeyName(node, 'Value') // → 'PetStatusValue'
|
|
68
71
|
* resolver.resolveEnumKeyName(node, '') // → 'PetStatus'
|
|
69
72
|
*/
|
|
70
|
-
resolveEnumKeyName(node:
|
|
73
|
+
resolveEnumKeyName(node: {
|
|
74
|
+
name?: string | null;
|
|
75
|
+
}, enumTypeSuffix: string): string;
|
|
71
76
|
/**
|
|
72
77
|
* Resolves the name for an operation's grouped path parameters type.
|
|
73
78
|
*
|
|
@@ -90,6 +95,87 @@ type ResolverTs = Resolver & OperationParamsResolver & {
|
|
|
90
95
|
*/
|
|
91
96
|
resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string;
|
|
92
97
|
};
|
|
98
|
+
type EnumKeyCasing = 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none';
|
|
99
|
+
/**
|
|
100
|
+
* Discriminated union that ties `enumTypeSuffix` and `enumKeyCasing` to the enum types that actually use them.
|
|
101
|
+
*
|
|
102
|
+
* - `'asConst'` / `'asPascalConst'` — emit a `const` object; both `enumTypeSuffix` (type-alias suffix) and
|
|
103
|
+
* `enumKeyCasing` (key formatting) are meaningful.
|
|
104
|
+
* - `'enum'` / `'constEnum'` — emit a TypeScript enum; `enumKeyCasing` applies to member names,
|
|
105
|
+
* but there is no separate type alias so `enumTypeSuffix` is not used.
|
|
106
|
+
* - `'literal'` / `'inlineLiteral'` — emit only union literals; keys are discarded entirely,
|
|
107
|
+
* so neither `enumTypeSuffix` nor `enumKeyCasing` have any effect.
|
|
108
|
+
*/
|
|
109
|
+
type EnumTypeOptions = {
|
|
110
|
+
/**
|
|
111
|
+
* Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
|
|
112
|
+
* - 'asConst' generates const objects with camelCase names and as const assertion.
|
|
113
|
+
* - 'asPascalConst' generates const objects with PascalCase names and as const assertion.
|
|
114
|
+
* @default 'asConst'
|
|
115
|
+
*/
|
|
116
|
+
enumType?: 'asConst' | 'asPascalConst';
|
|
117
|
+
/**
|
|
118
|
+
* Suffix appended to the generated type alias name.
|
|
119
|
+
*
|
|
120
|
+
* Only affects the type alias — the const object name is unchanged.
|
|
121
|
+
*
|
|
122
|
+
* @default 'Key'
|
|
123
|
+
* @example enumTypeSuffix: 'Value' → `export type PetStatusValue = …`
|
|
124
|
+
*/
|
|
125
|
+
enumTypeSuffix?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Choose the casing for enum key names.
|
|
128
|
+
* - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
|
|
129
|
+
* - 'snakeCase' generates keys in snake_case format.
|
|
130
|
+
* - 'pascalCase' generates keys in PascalCase format.
|
|
131
|
+
* - 'camelCase' generates keys in camelCase format.
|
|
132
|
+
* - 'none' uses the enum value as-is without transformation.
|
|
133
|
+
* @default 'none'
|
|
134
|
+
*/
|
|
135
|
+
enumKeyCasing?: EnumKeyCasing;
|
|
136
|
+
} | {
|
|
137
|
+
/**
|
|
138
|
+
* Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
|
|
139
|
+
* - 'enum' generates TypeScript enum declarations.
|
|
140
|
+
* - 'constEnum' generates TypeScript const enum declarations.
|
|
141
|
+
* @default 'asConst'
|
|
142
|
+
*/
|
|
143
|
+
enumType?: 'enum' | 'constEnum';
|
|
144
|
+
/**
|
|
145
|
+
* `enumTypeSuffix` has no effect for this `enumType`.
|
|
146
|
+
* It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
|
|
147
|
+
*/
|
|
148
|
+
enumTypeSuffix?: never;
|
|
149
|
+
/**
|
|
150
|
+
* Choose the casing for enum key names.
|
|
151
|
+
* - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
|
|
152
|
+
* - 'snakeCase' generates keys in snake_case format.
|
|
153
|
+
* - 'pascalCase' generates keys in PascalCase format.
|
|
154
|
+
* - 'camelCase' generates keys in camelCase format.
|
|
155
|
+
* - 'none' uses the enum value as-is without transformation.
|
|
156
|
+
* @default 'none'
|
|
157
|
+
*/
|
|
158
|
+
enumKeyCasing?: EnumKeyCasing;
|
|
159
|
+
} | {
|
|
160
|
+
/**
|
|
161
|
+
* Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
|
|
162
|
+
* - 'literal' generates literal union types.
|
|
163
|
+
* - 'inlineLiteral' will inline enum values directly into the type (default in v5).
|
|
164
|
+
* @default 'asConst'
|
|
165
|
+
* @note In Kubb v5, 'inlineLiteral' becomes the default.
|
|
166
|
+
*/
|
|
167
|
+
enumType?: 'literal' | 'inlineLiteral';
|
|
168
|
+
/**
|
|
169
|
+
* `enumTypeSuffix` has no effect for this `enumType`.
|
|
170
|
+
* It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
|
|
171
|
+
*/
|
|
172
|
+
enumTypeSuffix?: never;
|
|
173
|
+
/**
|
|
174
|
+
* `enumKeyCasing` has no effect for this `enumType`.
|
|
175
|
+
* Literal and inlineLiteral modes emit only values — keys are discarded entirely.
|
|
176
|
+
*/
|
|
177
|
+
enumKeyCasing?: never;
|
|
178
|
+
};
|
|
93
179
|
type Options = {
|
|
94
180
|
/**
|
|
95
181
|
* Specify the export location for the files and define the behavior of the output
|
|
@@ -117,37 +203,6 @@ type Options = {
|
|
|
117
203
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
118
204
|
*/
|
|
119
205
|
override?: Array<Override<ResolvedOptions>>;
|
|
120
|
-
/**
|
|
121
|
-
* Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
|
|
122
|
-
* - 'enum' generates TypeScript enum declarations.
|
|
123
|
-
* - 'asConst' generates const objects with camelCase names and as const assertion.
|
|
124
|
-
* - 'asPascalConst' generates const objects with PascalCase names and as const assertion.
|
|
125
|
-
* - 'constEnum' generates TypeScript const enum declarations.
|
|
126
|
-
* - 'literal' generates literal union types.
|
|
127
|
-
* - 'inlineLiteral' inline enum values directly into the type (default in v5).
|
|
128
|
-
* @default 'asConst'
|
|
129
|
-
* @note In Kubb v5, 'inlineLiteral' becomes the default.
|
|
130
|
-
*/
|
|
131
|
-
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
|
|
132
|
-
/**
|
|
133
|
-
* Suffix appended to the generated type alias name when `enumType` is `asConst` or `asPascalConst`.
|
|
134
|
-
*
|
|
135
|
-
* Only affects the type alias — the const object name is unchanged.
|
|
136
|
-
*
|
|
137
|
-
* @default 'Key'
|
|
138
|
-
* @example enumTypeSuffix: 'Value' → `export type PetStatusValue = …`
|
|
139
|
-
*/
|
|
140
|
-
enumTypeSuffix?: string;
|
|
141
|
-
/**
|
|
142
|
-
* Choose the casing for enum key names.
|
|
143
|
-
* - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
|
|
144
|
-
* - 'snakeCase' generates keys in snake_case format.
|
|
145
|
-
* - 'pascalCase' generates keys in PascalCase format.
|
|
146
|
-
* - 'camelCase' generates keys in camelCase format.
|
|
147
|
-
* - 'none' uses the enum value as-is without transformation.
|
|
148
|
-
* @default 'none'
|
|
149
|
-
*/
|
|
150
|
-
enumKeyCasing?: 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none';
|
|
151
206
|
/**
|
|
152
207
|
* Switch between type or interface for creating TypeScript types.
|
|
153
208
|
* - 'type' generates type alias declarations.
|
|
@@ -218,13 +273,13 @@ type Options = {
|
|
|
218
273
|
* ```
|
|
219
274
|
*/
|
|
220
275
|
transformers?: Array<Visitor>;
|
|
221
|
-
};
|
|
276
|
+
} & EnumTypeOptions;
|
|
222
277
|
type ResolvedOptions = {
|
|
223
278
|
output: Output;
|
|
224
279
|
group: Group | undefined;
|
|
225
280
|
enumType: NonNullable<Options['enumType']>;
|
|
226
281
|
enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>;
|
|
227
|
-
enumKeyCasing:
|
|
282
|
+
enumKeyCasing: EnumKeyCasing;
|
|
228
283
|
optionalType: NonNullable<Options['optionalType']>;
|
|
229
284
|
arrayType: NonNullable<Options['arrayType']>;
|
|
230
285
|
syntaxType: NonNullable<Options['syntaxType']>;
|
|
@@ -280,6 +335,12 @@ type Props = {
|
|
|
280
335
|
resolver: PluginTs['resolver'];
|
|
281
336
|
description?: string;
|
|
282
337
|
keysToOmit?: string[];
|
|
338
|
+
/**
|
|
339
|
+
* Names of top-level schemas that are enums.
|
|
340
|
+
* Used so the printer's `ref` handler can use the suffixed type name (e.g. `StatusKey`)
|
|
341
|
+
* instead of the plain PascalCase name (e.g. `Status`) when resolving `$ref` enum targets.
|
|
342
|
+
*/
|
|
343
|
+
enumSchemaNames?: Set<string>;
|
|
283
344
|
};
|
|
284
345
|
declare function Type({
|
|
285
346
|
name,
|
|
@@ -292,7 +353,8 @@ declare function Type({
|
|
|
292
353
|
enumTypeSuffix,
|
|
293
354
|
enumKeyCasing,
|
|
294
355
|
description,
|
|
295
|
-
resolver
|
|
356
|
+
resolver,
|
|
357
|
+
enumSchemaNames
|
|
296
358
|
}: Props): FabricReactNode;
|
|
297
359
|
//#endregion
|
|
298
360
|
//#region src/generators/typeGenerator.d.ts
|
|
@@ -411,6 +473,12 @@ type TsOptions = {
|
|
|
411
473
|
* Resolver used to transform raw schema names into valid TypeScript identifiers.
|
|
412
474
|
*/
|
|
413
475
|
resolver: ResolverTs;
|
|
476
|
+
/**
|
|
477
|
+
* Names of top-level schemas that are enums.
|
|
478
|
+
* When set, the `ref` handler uses the suffixed type name (e.g. `StatusKey`) for enum refs
|
|
479
|
+
* instead of the plain PascalCase name, so imports align with what the enum file actually exports.
|
|
480
|
+
*/
|
|
481
|
+
enumSchemaNames?: Set<string>;
|
|
414
482
|
};
|
|
415
483
|
/**
|
|
416
484
|
* TypeScript printer factory options: maps `SchemaNode` → `ts.TypeNode` (raw) or `ts.Node` (full declaration).
|