@kubb/plugin-ts 3.0.0-alpha.9 → 3.0.0-beta.10
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/README.md +14 -5
- package/dist/{chunk-UVAKTXUA.js → chunk-CO6LGOXH.js} +109 -412
- package/dist/chunk-CO6LGOXH.js.map +1 -0
- package/dist/{chunk-PV5Q7I5O.cjs → chunk-FAYAKEVU.cjs} +208 -484
- package/dist/{chunk-UVAKTXUA.js.map → chunk-FAYAKEVU.cjs.map} +1 -1
- package/dist/chunk-I2Y2NUZG.cjs +335 -0
- package/dist/chunk-I2Y2NUZG.cjs.map +1 -0
- package/dist/chunk-KMHP3TKI.js +306 -0
- package/dist/chunk-KMHP3TKI.js.map +1 -0
- package/dist/components.cjs +11 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +14 -44
- package/dist/components.d.ts +14 -44
- package/dist/components.js +2 -16
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +10 -0
- package/dist/generators.d.ts +10 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +12 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -123
- package/dist/index.d.ts +4 -123
- package/dist/index.js +3 -9
- package/dist/index.js.map +1 -1
- package/dist/types-zQCmVvxv.d.cts +97 -0
- package/dist/types-zQCmVvxv.d.ts +97 -0
- package/package.json +21 -15
- package/src/components/OasType.tsx +3 -50
- package/src/components/{Schema.tsx → Type.tsx} +30 -62
- package/src/components/index.ts +1 -2
- package/src/generators/__snapshots__/bodyUploadFileApiAssetsPost.ts +6 -0
- package/src/generators/__snapshots__/catTypeAsConst.ts +11 -0
- package/src/generators/__snapshots__/createPet.ts +34 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +34 -0
- package/src/generators/__snapshots__/deletePet.ts +7 -0
- package/src/generators/__snapshots__/dogTypeAsConst.ts +11 -0
- package/src/generators/__snapshots__/enumAllOf.ts +10 -0
- package/src/generators/__snapshots__/enumArray.ts +19 -0
- package/src/generators/__snapshots__/enumInObject.ts +13 -0
- package/src/generators/__snapshots__/enumItems.ts +8 -0
- package/src/generators/__snapshots__/enumNames.ts +6 -0
- package/src/generators/__snapshots__/enumNamesConst.ts +6 -0
- package/src/generators/__snapshots__/enumNamesLiteral.ts +3 -0
- package/src/generators/__snapshots__/enumNamesPascalConst.ts +8 -0
- package/src/generators/__snapshots__/enumNamesType.ts +8 -0
- package/src/generators/__snapshots__/enumNullableMember.ts +8 -0
- package/src/generators/__snapshots__/enumNullableType.ts +8 -0
- package/src/generators/__snapshots__/enumString.ts +10 -0
- package/src/generators/__snapshots__/enumVarNamesType.ts +8 -0
- package/src/generators/__snapshots__/getPets.ts +26 -0
- package/src/generators/__snapshots__/mixedValueTypeConst.ts +9 -0
- package/src/generators/__snapshots__/nullConstNull.ts +7 -0
- package/src/generators/__snapshots__/numberValueConst.ts +9 -0
- package/src/generators/__snapshots__/petMapper.ts +15 -0
- package/src/generators/__snapshots__/petQuestionToken.ts +19 -0
- package/src/generators/__snapshots__/petQuestionTokenAndUndefined.ts +19 -0
- package/src/generators/__snapshots__/petUndefined.ts +19 -0
- package/src/generators/__snapshots__/pets.ts +14 -0
- package/src/generators/__snapshots__/petsStoreAdvancedDiscriminator.ts +31 -0
- package/src/generators/__snapshots__/petsStoreDiscriminator.ts +13 -0
- package/src/generators/__snapshots__/petsStoreRef.ts +1 -0
- package/src/generators/__snapshots__/plainDateDate.ts +1 -0
- package/src/generators/__snapshots__/plainDateString.ts +1 -0
- package/src/generators/__snapshots__/plainEmail.ts +1 -0
- package/src/generators/__snapshots__/plainFile.ts +1 -0
- package/src/generators/__snapshots__/plainTimeDate.ts +1 -0
- package/src/generators/__snapshots__/plainUuid.ts +1 -0
- package/src/generators/__snapshots__/readOnly.ts +20 -0
- package/src/{components/__snapshots__/Schema → generators/__snapshots__}/showPetById.ts +11 -12
- package/src/generators/__snapshots__/stringValueConst.ts +9 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/oasGenerator.tsx +29 -0
- package/src/generators/typeGenerator.tsx +205 -0
- package/src/parser/index.ts +26 -11
- package/src/plugin.ts +27 -35
- package/src/types.ts +17 -54
- package/dist/chunk-PV5Q7I5O.cjs.map +0 -1
- package/dist/chunk-SEH6NUCX.cjs +0 -42
- package/dist/chunk-SEH6NUCX.cjs.map +0 -1
- package/dist/chunk-TTGZBH7H.js +0 -42
- package/dist/chunk-TTGZBH7H.js.map +0 -1
- package/dist/oas.cjs +0 -7
- package/dist/oas.cjs.map +0 -1
- package/dist/oas.d.cts +0 -1
- package/dist/oas.d.ts +0 -1
- package/dist/oas.js +0 -7
- package/dist/oas.js.map +0 -1
- package/src/OperationGenerator.tsx +0 -49
- package/src/SchemaGenerator.tsx +0 -31
- package/src/components/OperationSchema.tsx +0 -161
- package/src/components/__snapshots__/Schema/pets.ts +0 -27
- package/src/oas/index.ts +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,128 +1,9 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
6
|
-
|
|
7
|
-
type Options = {
|
|
8
|
-
output?: {
|
|
9
|
-
/**
|
|
10
|
-
* Relative path to save the TypeScript types.
|
|
11
|
-
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
12
|
-
* @default 'types'
|
|
13
|
-
*/
|
|
14
|
-
path: string;
|
|
15
|
-
/**
|
|
16
|
-
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
17
|
-
*/
|
|
18
|
-
exportAs?: string;
|
|
19
|
-
/**
|
|
20
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
21
|
-
*/
|
|
22
|
-
extName?: KubbFile.Extname;
|
|
23
|
-
/**
|
|
24
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
25
|
-
* @default `'barrel'`
|
|
26
|
-
*/
|
|
27
|
-
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Group the TypeScript types based on the provided name.
|
|
31
|
-
*/
|
|
32
|
-
group?: {
|
|
33
|
-
/**
|
|
34
|
-
* Tag will group based on the operation tag inside the Swagger file.
|
|
35
|
-
*/
|
|
36
|
-
type: 'tag';
|
|
37
|
-
/**
|
|
38
|
-
* Relative path to save the grouped TypeScript Types.
|
|
39
|
-
*
|
|
40
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
41
|
-
* @example `${output}/{{tag}}Controller` => `models/PetController`
|
|
42
|
-
* @default `${output}/{{tag}}Controller`
|
|
43
|
-
*/
|
|
44
|
-
output?: string;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
48
|
-
*/
|
|
49
|
-
exclude?: Array<Exclude>;
|
|
50
|
-
/**
|
|
51
|
-
* Array containing include parameters to include tags/operations/methods/paths.
|
|
52
|
-
*/
|
|
53
|
-
include?: Array<Include>;
|
|
54
|
-
/**
|
|
55
|
-
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
56
|
-
*/
|
|
57
|
-
override?: Array<Override<ResolvedOptions>>;
|
|
58
|
-
/**
|
|
59
|
-
* Choose to use `enum` or `as const` for enums
|
|
60
|
-
* @default 'asConst'
|
|
61
|
-
* asPascalConst is deprecated
|
|
62
|
-
*/
|
|
63
|
-
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
64
|
-
/**
|
|
65
|
-
* Set a suffix for the generated enums.
|
|
66
|
-
* @default ''
|
|
67
|
-
* Default will be `'enum'` in version 3 of Kubb
|
|
68
|
-
*/
|
|
69
|
-
enumSuffix?: string;
|
|
70
|
-
/**
|
|
71
|
-
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
|
72
|
-
* @default 'string'
|
|
73
|
-
*/
|
|
74
|
-
dateType?: 'string' | 'date';
|
|
75
|
-
/**
|
|
76
|
-
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
|
77
|
-
* @default 'any'
|
|
78
|
-
*/
|
|
79
|
-
unknownType?: 'any' | 'unknown';
|
|
80
|
-
/**
|
|
81
|
-
* Choose what to use as mode for an optional value.
|
|
82
|
-
* @examples 'questionToken': type?: string
|
|
83
|
-
* @examples 'undefined': type: string | undefined
|
|
84
|
-
* @examples 'questionTokenAndUndefined': type?: string | undefined
|
|
85
|
-
* @default 'questionToken'
|
|
86
|
-
*/
|
|
87
|
-
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
|
88
|
-
transformers?: {
|
|
89
|
-
/**
|
|
90
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
91
|
-
*/
|
|
92
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Export an Oas object as Oas type with `import type { Infer } from '@kubb/oas'`
|
|
96
|
-
*/
|
|
97
|
-
oasType?: 'infer' | false;
|
|
98
|
-
/**
|
|
99
|
-
* @example
|
|
100
|
-
* Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
|
|
101
|
-
* category: factory.createPropertySignature(
|
|
102
|
-
* undefined,
|
|
103
|
-
* factory.createIdentifier("category"),
|
|
104
|
-
* factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
105
|
-
* factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
106
|
-
* )
|
|
107
|
-
*/
|
|
108
|
-
mapper?: Record<string, ts.PropertySignature>;
|
|
109
|
-
};
|
|
110
|
-
type ResolvedOptions = {
|
|
111
|
-
extName: KubbFile.Extname | undefined;
|
|
112
|
-
enumType: NonNullable<Options['enumType']>;
|
|
113
|
-
enumSuffix: NonNullable<Options['enumSuffix']>;
|
|
114
|
-
dateType: NonNullable<Options['dateType']>;
|
|
115
|
-
unknownType: NonNullable<Options['unknownType']>;
|
|
116
|
-
optionalType: NonNullable<Options['optionalType']>;
|
|
117
|
-
override: NonNullable<Options['override']>;
|
|
118
|
-
transformers: NonNullable<Options['transformers']>;
|
|
119
|
-
oasType: NonNullable<Options['oasType']>;
|
|
120
|
-
usedEnumNames: Record<string, number>;
|
|
121
|
-
mapper: Record<string, any>;
|
|
122
|
-
};
|
|
123
|
-
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
2
|
+
import { O as Options, P as PluginTs } from './types-zQCmVvxv.cjs';
|
|
3
|
+
import '@kubb/plugin-oas';
|
|
4
|
+
import 'typescript';
|
|
124
5
|
|
|
125
6
|
declare const pluginTsName = "plugin-ts";
|
|
126
7
|
declare const pluginTs: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginTs>;
|
|
127
8
|
|
|
128
|
-
export {
|
|
9
|
+
export { PluginTs, pluginTs, pluginTsName };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,128 +1,9 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
6
|
-
|
|
7
|
-
type Options = {
|
|
8
|
-
output?: {
|
|
9
|
-
/**
|
|
10
|
-
* Relative path to save the TypeScript types.
|
|
11
|
-
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
12
|
-
* @default 'types'
|
|
13
|
-
*/
|
|
14
|
-
path: string;
|
|
15
|
-
/**
|
|
16
|
-
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
17
|
-
*/
|
|
18
|
-
exportAs?: string;
|
|
19
|
-
/**
|
|
20
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
21
|
-
*/
|
|
22
|
-
extName?: KubbFile.Extname;
|
|
23
|
-
/**
|
|
24
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
25
|
-
* @default `'barrel'`
|
|
26
|
-
*/
|
|
27
|
-
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Group the TypeScript types based on the provided name.
|
|
31
|
-
*/
|
|
32
|
-
group?: {
|
|
33
|
-
/**
|
|
34
|
-
* Tag will group based on the operation tag inside the Swagger file.
|
|
35
|
-
*/
|
|
36
|
-
type: 'tag';
|
|
37
|
-
/**
|
|
38
|
-
* Relative path to save the grouped TypeScript Types.
|
|
39
|
-
*
|
|
40
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
41
|
-
* @example `${output}/{{tag}}Controller` => `models/PetController`
|
|
42
|
-
* @default `${output}/{{tag}}Controller`
|
|
43
|
-
*/
|
|
44
|
-
output?: string;
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
48
|
-
*/
|
|
49
|
-
exclude?: Array<Exclude>;
|
|
50
|
-
/**
|
|
51
|
-
* Array containing include parameters to include tags/operations/methods/paths.
|
|
52
|
-
*/
|
|
53
|
-
include?: Array<Include>;
|
|
54
|
-
/**
|
|
55
|
-
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
56
|
-
*/
|
|
57
|
-
override?: Array<Override<ResolvedOptions>>;
|
|
58
|
-
/**
|
|
59
|
-
* Choose to use `enum` or `as const` for enums
|
|
60
|
-
* @default 'asConst'
|
|
61
|
-
* asPascalConst is deprecated
|
|
62
|
-
*/
|
|
63
|
-
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
64
|
-
/**
|
|
65
|
-
* Set a suffix for the generated enums.
|
|
66
|
-
* @default ''
|
|
67
|
-
* Default will be `'enum'` in version 3 of Kubb
|
|
68
|
-
*/
|
|
69
|
-
enumSuffix?: string;
|
|
70
|
-
/**
|
|
71
|
-
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
|
72
|
-
* @default 'string'
|
|
73
|
-
*/
|
|
74
|
-
dateType?: 'string' | 'date';
|
|
75
|
-
/**
|
|
76
|
-
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
|
77
|
-
* @default 'any'
|
|
78
|
-
*/
|
|
79
|
-
unknownType?: 'any' | 'unknown';
|
|
80
|
-
/**
|
|
81
|
-
* Choose what to use as mode for an optional value.
|
|
82
|
-
* @examples 'questionToken': type?: string
|
|
83
|
-
* @examples 'undefined': type: string | undefined
|
|
84
|
-
* @examples 'questionTokenAndUndefined': type?: string | undefined
|
|
85
|
-
* @default 'questionToken'
|
|
86
|
-
*/
|
|
87
|
-
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
|
88
|
-
transformers?: {
|
|
89
|
-
/**
|
|
90
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
91
|
-
*/
|
|
92
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Export an Oas object as Oas type with `import type { Infer } from '@kubb/oas'`
|
|
96
|
-
*/
|
|
97
|
-
oasType?: 'infer' | false;
|
|
98
|
-
/**
|
|
99
|
-
* @example
|
|
100
|
-
* Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
|
|
101
|
-
* category: factory.createPropertySignature(
|
|
102
|
-
* undefined,
|
|
103
|
-
* factory.createIdentifier("category"),
|
|
104
|
-
* factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
105
|
-
* factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
106
|
-
* )
|
|
107
|
-
*/
|
|
108
|
-
mapper?: Record<string, ts.PropertySignature>;
|
|
109
|
-
};
|
|
110
|
-
type ResolvedOptions = {
|
|
111
|
-
extName: KubbFile.Extname | undefined;
|
|
112
|
-
enumType: NonNullable<Options['enumType']>;
|
|
113
|
-
enumSuffix: NonNullable<Options['enumSuffix']>;
|
|
114
|
-
dateType: NonNullable<Options['dateType']>;
|
|
115
|
-
unknownType: NonNullable<Options['unknownType']>;
|
|
116
|
-
optionalType: NonNullable<Options['optionalType']>;
|
|
117
|
-
override: NonNullable<Options['override']>;
|
|
118
|
-
transformers: NonNullable<Options['transformers']>;
|
|
119
|
-
oasType: NonNullable<Options['oasType']>;
|
|
120
|
-
usedEnumNames: Record<string, number>;
|
|
121
|
-
mapper: Record<string, any>;
|
|
122
|
-
};
|
|
123
|
-
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
2
|
+
import { O as Options, P as PluginTs } from './types-zQCmVvxv.js';
|
|
3
|
+
import '@kubb/plugin-oas';
|
|
4
|
+
import 'typescript';
|
|
124
5
|
|
|
125
6
|
declare const pluginTsName = "plugin-ts";
|
|
126
7
|
declare const pluginTs: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginTs>;
|
|
127
8
|
|
|
128
|
-
export {
|
|
9
|
+
export { PluginTs, pluginTs, pluginTsName };
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-UVAKTXUA.js";
|
|
5
|
-
import "./chunk-TTGZBH7H.js";
|
|
6
|
-
export {
|
|
7
|
-
pluginTs,
|
|
8
|
-
pluginTsName
|
|
9
|
-
};
|
|
1
|
+
export { pluginTs, pluginTsName } from './chunk-KMHP3TKI.js';
|
|
2
|
+
import './chunk-CO6LGOXH.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
10
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
+
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
|
|
5
|
+
type Options = {
|
|
6
|
+
/**
|
|
7
|
+
* Specify the export location for the files and define the behavior of the output
|
|
8
|
+
* @default { path: 'types', barrelType: 'named' }
|
|
9
|
+
*/
|
|
10
|
+
output?: Output;
|
|
11
|
+
/**
|
|
12
|
+
* Group the clients based on the provided name.
|
|
13
|
+
*/
|
|
14
|
+
group?: Group;
|
|
15
|
+
/**
|
|
16
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
17
|
+
*/
|
|
18
|
+
exclude?: Array<Exclude>;
|
|
19
|
+
/**
|
|
20
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
21
|
+
*/
|
|
22
|
+
include?: Array<Include>;
|
|
23
|
+
/**
|
|
24
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
25
|
+
*/
|
|
26
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
27
|
+
/**
|
|
28
|
+
* Choose to use `enum` or `as const` for enums
|
|
29
|
+
* @default 'asConst'
|
|
30
|
+
* asPascalConst is deprecated
|
|
31
|
+
*/
|
|
32
|
+
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
33
|
+
/**
|
|
34
|
+
* Set a suffix for the generated enums.
|
|
35
|
+
* @default 'enum'
|
|
36
|
+
*/
|
|
37
|
+
enumSuffix?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
|
40
|
+
* @default 'string'
|
|
41
|
+
*/
|
|
42
|
+
dateType?: 'string' | 'date';
|
|
43
|
+
/**
|
|
44
|
+
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
|
45
|
+
* @default 'any'
|
|
46
|
+
*/
|
|
47
|
+
unknownType?: 'any' | 'unknown';
|
|
48
|
+
/**
|
|
49
|
+
* Choose what to use as mode for an optional value.
|
|
50
|
+
* @examples 'questionToken': type?: string
|
|
51
|
+
* @examples 'undefined': type: string | undefined
|
|
52
|
+
* @examples 'questionTokenAndUndefined': type?: string | undefined
|
|
53
|
+
* @default 'questionToken'
|
|
54
|
+
*/
|
|
55
|
+
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
|
56
|
+
transformers?: {
|
|
57
|
+
/**
|
|
58
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
59
|
+
*/
|
|
60
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Export an Oas object as Oas type with `import type { Infer } from '@kubb/oas'`
|
|
64
|
+
*/
|
|
65
|
+
oasType?: 'infer' | false;
|
|
66
|
+
/**
|
|
67
|
+
* @example
|
|
68
|
+
* Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
|
|
69
|
+
* category: factory.createPropertySignature(
|
|
70
|
+
* undefined,
|
|
71
|
+
* factory.createIdentifier("category"),
|
|
72
|
+
* factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
73
|
+
* factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
74
|
+
* )
|
|
75
|
+
*/
|
|
76
|
+
mapper?: Record<string, ts.PropertySignature>;
|
|
77
|
+
/**
|
|
78
|
+
* Define some generators next to the ts generators
|
|
79
|
+
*/
|
|
80
|
+
generators?: Array<Generator<PluginTs>>;
|
|
81
|
+
};
|
|
82
|
+
type ResolvedOptions = {
|
|
83
|
+
output: Output;
|
|
84
|
+
override: NonNullable<Options['override']>;
|
|
85
|
+
enumType: NonNullable<Options['enumType']>;
|
|
86
|
+
enumSuffix: NonNullable<Options['enumSuffix']>;
|
|
87
|
+
dateType: NonNullable<Options['dateType']>;
|
|
88
|
+
unknownType: NonNullable<Options['unknownType']>;
|
|
89
|
+
optionalType: NonNullable<Options['optionalType']>;
|
|
90
|
+
transformers: NonNullable<Options['transformers']>;
|
|
91
|
+
oasType: NonNullable<Options['oasType']>;
|
|
92
|
+
usedEnumNames: Record<string, number>;
|
|
93
|
+
mapper: Record<string, any>;
|
|
94
|
+
};
|
|
95
|
+
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
96
|
+
|
|
97
|
+
export type { Options as O, PluginTs as P };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
+
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
|
|
5
|
+
type Options = {
|
|
6
|
+
/**
|
|
7
|
+
* Specify the export location for the files and define the behavior of the output
|
|
8
|
+
* @default { path: 'types', barrelType: 'named' }
|
|
9
|
+
*/
|
|
10
|
+
output?: Output;
|
|
11
|
+
/**
|
|
12
|
+
* Group the clients based on the provided name.
|
|
13
|
+
*/
|
|
14
|
+
group?: Group;
|
|
15
|
+
/**
|
|
16
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
17
|
+
*/
|
|
18
|
+
exclude?: Array<Exclude>;
|
|
19
|
+
/**
|
|
20
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
21
|
+
*/
|
|
22
|
+
include?: Array<Include>;
|
|
23
|
+
/**
|
|
24
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
25
|
+
*/
|
|
26
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
27
|
+
/**
|
|
28
|
+
* Choose to use `enum` or `as const` for enums
|
|
29
|
+
* @default 'asConst'
|
|
30
|
+
* asPascalConst is deprecated
|
|
31
|
+
*/
|
|
32
|
+
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
33
|
+
/**
|
|
34
|
+
* Set a suffix for the generated enums.
|
|
35
|
+
* @default 'enum'
|
|
36
|
+
*/
|
|
37
|
+
enumSuffix?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
|
40
|
+
* @default 'string'
|
|
41
|
+
*/
|
|
42
|
+
dateType?: 'string' | 'date';
|
|
43
|
+
/**
|
|
44
|
+
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
|
45
|
+
* @default 'any'
|
|
46
|
+
*/
|
|
47
|
+
unknownType?: 'any' | 'unknown';
|
|
48
|
+
/**
|
|
49
|
+
* Choose what to use as mode for an optional value.
|
|
50
|
+
* @examples 'questionToken': type?: string
|
|
51
|
+
* @examples 'undefined': type: string | undefined
|
|
52
|
+
* @examples 'questionTokenAndUndefined': type?: string | undefined
|
|
53
|
+
* @default 'questionToken'
|
|
54
|
+
*/
|
|
55
|
+
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
|
56
|
+
transformers?: {
|
|
57
|
+
/**
|
|
58
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
59
|
+
*/
|
|
60
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Export an Oas object as Oas type with `import type { Infer } from '@kubb/oas'`
|
|
64
|
+
*/
|
|
65
|
+
oasType?: 'infer' | false;
|
|
66
|
+
/**
|
|
67
|
+
* @example
|
|
68
|
+
* Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
|
|
69
|
+
* category: factory.createPropertySignature(
|
|
70
|
+
* undefined,
|
|
71
|
+
* factory.createIdentifier("category"),
|
|
72
|
+
* factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
73
|
+
* factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
74
|
+
* )
|
|
75
|
+
*/
|
|
76
|
+
mapper?: Record<string, ts.PropertySignature>;
|
|
77
|
+
/**
|
|
78
|
+
* Define some generators next to the ts generators
|
|
79
|
+
*/
|
|
80
|
+
generators?: Array<Generator<PluginTs>>;
|
|
81
|
+
};
|
|
82
|
+
type ResolvedOptions = {
|
|
83
|
+
output: Output;
|
|
84
|
+
override: NonNullable<Options['override']>;
|
|
85
|
+
enumType: NonNullable<Options['enumType']>;
|
|
86
|
+
enumSuffix: NonNullable<Options['enumSuffix']>;
|
|
87
|
+
dateType: NonNullable<Options['dateType']>;
|
|
88
|
+
unknownType: NonNullable<Options['unknownType']>;
|
|
89
|
+
optionalType: NonNullable<Options['optionalType']>;
|
|
90
|
+
transformers: NonNullable<Options['transformers']>;
|
|
91
|
+
oasType: NonNullable<Options['oasType']>;
|
|
92
|
+
usedEnumNames: Record<string, number>;
|
|
93
|
+
mapper: Record<string, any>;
|
|
94
|
+
};
|
|
95
|
+
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
96
|
+
|
|
97
|
+
export type { Options as O, PluginTs as P };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-ts",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.10",
|
|
4
4
|
"description": "Generator plugin-ts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -25,6 +25,11 @@
|
|
|
25
25
|
"require": "./dist/index.cjs",
|
|
26
26
|
"default": "./dist/index.cjs"
|
|
27
27
|
},
|
|
28
|
+
"./generators": {
|
|
29
|
+
"import": "./dist/generators.js",
|
|
30
|
+
"require": "./dist/generators.cjs",
|
|
31
|
+
"default": "./dist/generators.cjs"
|
|
32
|
+
},
|
|
28
33
|
"./components": {
|
|
29
34
|
"import": "./dist/components.js",
|
|
30
35
|
"require": "./dist/components.cjs",
|
|
@@ -40,6 +45,9 @@
|
|
|
40
45
|
"*": {
|
|
41
46
|
"components": [
|
|
42
47
|
"./dist/components.d.ts"
|
|
48
|
+
],
|
|
49
|
+
"generators": [
|
|
50
|
+
"./dist/generators.d.ts"
|
|
43
51
|
]
|
|
44
52
|
}
|
|
45
53
|
},
|
|
@@ -50,25 +58,23 @@
|
|
|
50
58
|
"!/**/__tests__/**"
|
|
51
59
|
],
|
|
52
60
|
"dependencies": {
|
|
53
|
-
"@kubb/core": "3.0.0-
|
|
54
|
-
"@kubb/fs": "3.0.0-
|
|
55
|
-
"@kubb/oas": "3.0.0-
|
|
56
|
-
"@kubb/parser-ts": "3.0.0-
|
|
57
|
-
"@kubb/plugin-oas": "3.0.0-
|
|
58
|
-
"@kubb/react": "3.0.0-
|
|
61
|
+
"@kubb/core": "3.0.0-beta.10",
|
|
62
|
+
"@kubb/fs": "3.0.0-beta.10",
|
|
63
|
+
"@kubb/oas": "3.0.0-beta.10",
|
|
64
|
+
"@kubb/parser-ts": "3.0.0-beta.10",
|
|
65
|
+
"@kubb/plugin-oas": "3.0.0-beta.10",
|
|
66
|
+
"@kubb/react": "3.0.0-beta.10"
|
|
59
67
|
},
|
|
60
68
|
"devDependencies": {
|
|
61
|
-
"@types/react": "^18.3.
|
|
62
|
-
"prettier": "^3.3.3",
|
|
69
|
+
"@types/react": "^18.3.12",
|
|
63
70
|
"react": "^18.3.1",
|
|
64
|
-
"tsup": "^8.
|
|
65
|
-
"typescript": "^5.
|
|
66
|
-
"@kubb/config-
|
|
67
|
-
"@kubb/config-
|
|
68
|
-
"@kubb/config-tsup": "3.0.0-alpha.9"
|
|
71
|
+
"tsup": "^8.3.5",
|
|
72
|
+
"typescript": "^5.6.3",
|
|
73
|
+
"@kubb/config-ts": "3.0.0-beta.10",
|
|
74
|
+
"@kubb/config-tsup": "3.0.0-beta.10"
|
|
69
75
|
},
|
|
70
76
|
"peerDependencies": {
|
|
71
|
-
"@kubb/react": "3.0.0-
|
|
77
|
+
"@kubb/react": "3.0.0-beta.10"
|
|
72
78
|
},
|
|
73
79
|
"engines": {
|
|
74
80
|
"node": ">=20"
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { File, Type, useApp } from '@kubb/react'
|
|
1
|
+
import { File, Type } from '@kubb/react'
|
|
3
2
|
|
|
4
3
|
import type { OasTypes } from '@kubb/oas'
|
|
5
4
|
import type { ReactNode } from 'react'
|
|
6
|
-
import type { FileMeta, PluginTs } from '../types.ts'
|
|
7
5
|
|
|
8
|
-
type
|
|
6
|
+
type Props = {
|
|
9
7
|
/**
|
|
10
8
|
* Name of the function
|
|
11
9
|
*/
|
|
@@ -14,7 +12,7 @@ type TemplateProps = {
|
|
|
14
12
|
api: OasTypes.OASDocument
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
function
|
|
15
|
+
export function OasType({ name, typeName, api }: Props): ReactNode {
|
|
18
16
|
return (
|
|
19
17
|
<>
|
|
20
18
|
<File.Source name={name} isExportable isIndexable>
|
|
@@ -29,48 +27,3 @@ function Template({ name, typeName, api }: TemplateProps): ReactNode {
|
|
|
29
27
|
</>
|
|
30
28
|
)
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
const defaultTemplates = { default: Template } as const
|
|
34
|
-
|
|
35
|
-
type Props = {
|
|
36
|
-
name: string
|
|
37
|
-
typeName: string
|
|
38
|
-
/**
|
|
39
|
-
* This will make it possible to override the default behaviour.
|
|
40
|
-
*/
|
|
41
|
-
Template?: React.ComponentType<React.ComponentProps<typeof Template>>
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function OasType({ name, typeName, Template = defaultTemplates.default }: Props): ReactNode {
|
|
45
|
-
const oas = useOas()
|
|
46
|
-
|
|
47
|
-
return <Template name={name} typeName={typeName} api={oas.api} />
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
type FileProps = {
|
|
51
|
-
name: string
|
|
52
|
-
typeName: string
|
|
53
|
-
/**
|
|
54
|
-
* This will make it possible to override the default behaviour.
|
|
55
|
-
*/
|
|
56
|
-
templates?: typeof defaultTemplates
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
OasType.File = function ({ name, typeName, templates = defaultTemplates }: FileProps): ReactNode {
|
|
60
|
-
const {
|
|
61
|
-
pluginManager,
|
|
62
|
-
plugin: { key: pluginKey },
|
|
63
|
-
} = useApp<PluginTs>()
|
|
64
|
-
const file = pluginManager.getFile({ name, extName: '.ts', pluginKey })
|
|
65
|
-
|
|
66
|
-
const Template = templates.default
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
70
|
-
<File.Import name={['Infer']} path="@kubb/oas" isTypeOnly />
|
|
71
|
-
<OasType Template={Template} name={name} typeName={typeName} />
|
|
72
|
-
</File>
|
|
73
|
-
)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
OasType.templates = defaultTemplates
|