@kubb/plugin-ts 3.0.0-alpha.2 → 3.0.0-alpha.21

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.
Files changed (94) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-3IKQZT26.cjs +2541 -0
  3. package/dist/chunk-3IKQZT26.cjs.map +1 -0
  4. package/dist/chunk-CAATRNVS.js +2514 -0
  5. package/dist/chunk-CAATRNVS.js.map +1 -0
  6. package/dist/chunk-CPJWNK44.js +307 -0
  7. package/dist/chunk-CPJWNK44.js.map +1 -0
  8. package/dist/chunk-YLKAQOZ5.cjs +336 -0
  9. package/dist/chunk-YLKAQOZ5.cjs.map +1 -0
  10. package/dist/components.cjs +11 -6
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +14 -44
  13. package/dist/components.d.ts +14 -44
  14. package/dist/components.js +2 -10
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +17 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +10 -0
  19. package/dist/generators.d.ts +10 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +12 -4
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +4 -122
  25. package/dist/index.d.ts +4 -122
  26. package/dist/index.js +3 -8
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-W01J9acJ.d.cts +106 -0
  29. package/dist/types-W01J9acJ.d.ts +106 -0
  30. package/package.json +21 -15
  31. package/src/components/OasType.tsx +11 -58
  32. package/src/components/Type.tsx +133 -0
  33. package/src/components/index.ts +1 -2
  34. package/src/generators/__snapshots__/bodyUploadFileApiAssetsPost.ts +6 -0
  35. package/src/generators/__snapshots__/catTypeAsConst.ts +11 -0
  36. package/src/generators/__snapshots__/createPet.ts +34 -0
  37. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +34 -0
  38. package/src/generators/__snapshots__/deletePet.ts +5 -0
  39. package/src/generators/__snapshots__/dogTypeAsConst.ts +11 -0
  40. package/src/generators/__snapshots__/enumAllOf.ts +10 -0
  41. package/src/generators/__snapshots__/enumArray.ts +19 -0
  42. package/src/generators/__snapshots__/enumInObject.ts +13 -0
  43. package/src/generators/__snapshots__/enumItems.ts +8 -0
  44. package/src/generators/__snapshots__/enumNames.ts +6 -0
  45. package/src/generators/__snapshots__/enumNamesConst.ts +6 -0
  46. package/src/generators/__snapshots__/enumNamesLiteral.ts +3 -0
  47. package/src/generators/__snapshots__/enumNamesPascalConst.ts +8 -0
  48. package/src/generators/__snapshots__/enumNamesType.ts +8 -0
  49. package/src/generators/__snapshots__/enumNullableMember.ts +8 -0
  50. package/src/generators/__snapshots__/enumNullableType.ts +8 -0
  51. package/src/generators/__snapshots__/enumString.ts +10 -0
  52. package/src/generators/__snapshots__/enumVarNamesType.ts +8 -0
  53. package/src/generators/__snapshots__/getPets.ts +27 -0
  54. package/src/generators/__snapshots__/mixedValueTypeConst.ts +9 -0
  55. package/src/generators/__snapshots__/nullConstNull.ts +6 -0
  56. package/src/generators/__snapshots__/numberValueConst.ts +9 -0
  57. package/src/generators/__snapshots__/petMapper.ts +15 -0
  58. package/src/generators/__snapshots__/petQuestionToken.ts +15 -0
  59. package/src/generators/__snapshots__/petQuestionTokenAndUndefined.ts +15 -0
  60. package/src/generators/__snapshots__/petUndefined.ts +15 -0
  61. package/src/generators/__snapshots__/pets.ts +14 -0
  62. package/src/generators/__snapshots__/petsStoreDiscriminator.ts +13 -0
  63. package/src/generators/__snapshots__/petsStoreRef.ts +1 -0
  64. package/src/generators/__snapshots__/plainDateDate.ts +1 -0
  65. package/src/generators/__snapshots__/plainDateString.ts +1 -0
  66. package/src/generators/__snapshots__/plainEmail.ts +1 -0
  67. package/src/generators/__snapshots__/plainFile.ts +1 -0
  68. package/src/generators/__snapshots__/plainTimeDate.ts +1 -0
  69. package/src/generators/__snapshots__/plainUuid.ts +1 -0
  70. package/src/generators/__snapshots__/showPetById.ts +32 -0
  71. package/src/generators/__snapshots__/stringValueConst.ts +9 -0
  72. package/src/generators/index.ts +2 -0
  73. package/src/generators/oasGenerator.tsx +29 -0
  74. package/src/generators/typeGenerator.tsx +200 -0
  75. package/src/parser/index.ts +2 -1
  76. package/src/plugin.ts +21 -20
  77. package/src/types.ts +9 -35
  78. package/dist/chunk-JF3PKBEA.cjs +0 -608
  79. package/dist/chunk-JF3PKBEA.cjs.map +0 -1
  80. package/dist/chunk-PU22CLWV.js +0 -608
  81. package/dist/chunk-PU22CLWV.js.map +0 -1
  82. package/dist/oas.cjs +0 -1
  83. package/dist/oas.cjs.map +0 -1
  84. package/dist/oas.d.cts +0 -1
  85. package/dist/oas.d.ts +0 -1
  86. package/dist/oas.js +0 -1
  87. package/dist/oas.js.map +0 -1
  88. package/src/OperationGenerator.tsx +0 -49
  89. package/src/SchemaGenerator.tsx +0 -31
  90. package/src/components/OperationSchema.tsx +0 -161
  91. package/src/components/Schema.tsx +0 -135
  92. package/src/components/__snapshots__/Schema/pets.ts +0 -23
  93. package/src/components/__snapshots__/Schema/showPetById.ts +0 -28
  94. package/src/oas/index.ts +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-ts/dist/index.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,qGAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-ts/dist/index.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
package/dist/index.d.cts CHANGED
@@ -1,127 +1,9 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
3
- import * as KubbFile from '@kubb/fs/types';
4
- import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
5
- import { ts } from '@kubb/parser-ts';
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
- */
62
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
63
- /**
64
- * Set a suffix for the generated enums.
65
- * @default ''
66
- * Default will be `'enum'` in version 3 of Kubb
67
- */
68
- enumSuffix?: string;
69
- /**
70
- * Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
71
- * @default 'string'
72
- */
73
- dateType?: 'string' | 'date';
74
- /**
75
- * Which type to use when the Swagger/OpenAPI file is not providing more information.
76
- * @default 'any'
77
- */
78
- unknownType?: 'any' | 'unknown';
79
- /**
80
- * Choose what to use as mode for an optional value.
81
- * @examples 'questionToken': type?: string
82
- * @examples 'undefined': type: string | undefined
83
- * @examples 'questionTokenAndUndefined': type?: string | undefined
84
- * @default 'questionToken'
85
- */
86
- optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
87
- transformers?: {
88
- /**
89
- * Customize the names based on the type that is provided by the plugin.
90
- */
91
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
92
- };
93
- /**
94
- * Export an Oas object as Oas type with `import type { Infer } from '@kubb/oas'`
95
- */
96
- oasType?: 'infer' | false;
97
- /**
98
- * @example
99
- * Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
100
- * category: factory.createPropertySignature(
101
- * undefined,
102
- * factory.createIdentifier("category"),
103
- * factory.createToken(ts.SyntaxKind.QuestionToken),
104
- * factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
105
- * )
106
- */
107
- mapper?: Record<string, ts.PropertySignature>;
108
- };
109
- type ResolvedOptions = {
110
- extName: KubbFile.Extname | undefined;
111
- enumType: NonNullable<Options['enumType']>;
112
- enumSuffix: NonNullable<Options['enumSuffix']>;
113
- dateType: NonNullable<Options['dateType']>;
114
- unknownType: NonNullable<Options['unknownType']>;
115
- optionalType: NonNullable<Options['optionalType']>;
116
- override: NonNullable<Options['override']>;
117
- transformers: NonNullable<Options['transformers']>;
118
- oasType: NonNullable<Options['oasType']>;
119
- usedEnumNames: Record<string, number>;
120
- mapper: Record<string, any>;
121
- };
122
- type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
2
+ import { O as Options, P as PluginTs } from './types-W01J9acJ.cjs';
3
+ import '@kubb/plugin-oas';
4
+ import 'typescript';
123
5
 
124
6
  declare const pluginTsName = "plugin-ts";
125
7
  declare const pluginTs: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginTs>;
126
8
 
127
- export { type PluginTs, pluginTs, pluginTsName };
9
+ export { PluginTs, pluginTs, pluginTsName };
package/dist/index.d.ts CHANGED
@@ -1,127 +1,9 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
3
- import * as KubbFile from '@kubb/fs/types';
4
- import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
5
- import { ts } from '@kubb/parser-ts';
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
- */
62
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
63
- /**
64
- * Set a suffix for the generated enums.
65
- * @default ''
66
- * Default will be `'enum'` in version 3 of Kubb
67
- */
68
- enumSuffix?: string;
69
- /**
70
- * Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
71
- * @default 'string'
72
- */
73
- dateType?: 'string' | 'date';
74
- /**
75
- * Which type to use when the Swagger/OpenAPI file is not providing more information.
76
- * @default 'any'
77
- */
78
- unknownType?: 'any' | 'unknown';
79
- /**
80
- * Choose what to use as mode for an optional value.
81
- * @examples 'questionToken': type?: string
82
- * @examples 'undefined': type: string | undefined
83
- * @examples 'questionTokenAndUndefined': type?: string | undefined
84
- * @default 'questionToken'
85
- */
86
- optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
87
- transformers?: {
88
- /**
89
- * Customize the names based on the type that is provided by the plugin.
90
- */
91
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
92
- };
93
- /**
94
- * Export an Oas object as Oas type with `import type { Infer } from '@kubb/oas'`
95
- */
96
- oasType?: 'infer' | false;
97
- /**
98
- * @example
99
- * Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
100
- * category: factory.createPropertySignature(
101
- * undefined,
102
- * factory.createIdentifier("category"),
103
- * factory.createToken(ts.SyntaxKind.QuestionToken),
104
- * factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
105
- * )
106
- */
107
- mapper?: Record<string, ts.PropertySignature>;
108
- };
109
- type ResolvedOptions = {
110
- extName: KubbFile.Extname | undefined;
111
- enumType: NonNullable<Options['enumType']>;
112
- enumSuffix: NonNullable<Options['enumSuffix']>;
113
- dateType: NonNullable<Options['dateType']>;
114
- unknownType: NonNullable<Options['unknownType']>;
115
- optionalType: NonNullable<Options['optionalType']>;
116
- override: NonNullable<Options['override']>;
117
- transformers: NonNullable<Options['transformers']>;
118
- oasType: NonNullable<Options['oasType']>;
119
- usedEnumNames: Record<string, number>;
120
- mapper: Record<string, any>;
121
- };
122
- type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
2
+ import { O as Options, P as PluginTs } from './types-W01J9acJ.js';
3
+ import '@kubb/plugin-oas';
4
+ import 'typescript';
123
5
 
124
6
  declare const pluginTsName = "plugin-ts";
125
7
  declare const pluginTs: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginTs>;
126
8
 
127
- export { type PluginTs, pluginTs, pluginTsName };
9
+ export { PluginTs, pluginTs, pluginTsName };
package/dist/index.js CHANGED
@@ -1,9 +1,4 @@
1
- import {
2
- pluginTs,
3
- pluginTsName
4
- } from "./chunk-PU22CLWV.js";
5
- export {
6
- pluginTs,
7
- pluginTsName
8
- };
1
+ export { pluginTs, pluginTsName } from './chunk-CPJWNK44.js';
2
+ import './chunk-CAATRNVS.js';
3
+ //# sourceMappingURL=index.js.map
9
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,106 @@
1
+ import { PluginFactoryOptions, Output, ResolveNameParams } from '@kubb/core';
2
+ import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
3
+ import ts from 'typescript';
4
+
5
+ type Options = {
6
+ /**
7
+ * @default 'types'
8
+ */
9
+ output?: Output;
10
+ /**
11
+ * Group the TypeScript types based on the provided name.
12
+ */
13
+ group?: {
14
+ /**
15
+ * Tag will group based on the operation tag inside the Swagger file.
16
+ */
17
+ type: 'tag';
18
+ /**
19
+ * Relative path to save the grouped TypeScript Types.
20
+ *
21
+ * `{{tag}}` will be replaced by the current tagName.
22
+ * @example `${output}/{{tag}}Controller` => `models/PetController`
23
+ * @default `${output}/{{tag}}Controller`
24
+ */
25
+ output?: string;
26
+ };
27
+ /**
28
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
29
+ */
30
+ exclude?: Array<Exclude>;
31
+ /**
32
+ * Array containing include parameters to include tags/operations/methods/paths.
33
+ */
34
+ include?: Array<Include>;
35
+ /**
36
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
37
+ */
38
+ override?: Array<Override<ResolvedOptions>>;
39
+ /**
40
+ * Choose to use `enum` or `as const` for enums
41
+ * @default 'asConst'
42
+ * asPascalConst is deprecated
43
+ */
44
+ enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
45
+ /**
46
+ * Set a suffix for the generated enums.
47
+ * @default ''
48
+ * Default will be `'enum'` in version 3 of Kubb
49
+ */
50
+ enumSuffix?: string;
51
+ /**
52
+ * Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
53
+ * @default 'string'
54
+ */
55
+ dateType?: 'string' | 'date';
56
+ /**
57
+ * Which type to use when the Swagger/OpenAPI file is not providing more information.
58
+ * @default 'any'
59
+ */
60
+ unknownType?: 'any' | 'unknown';
61
+ /**
62
+ * Choose what to use as mode for an optional value.
63
+ * @examples 'questionToken': type?: string
64
+ * @examples 'undefined': type: string | undefined
65
+ * @examples 'questionTokenAndUndefined': type?: string | undefined
66
+ * @default 'questionToken'
67
+ */
68
+ optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
69
+ transformers?: {
70
+ /**
71
+ * Customize the names based on the type that is provided by the plugin.
72
+ */
73
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
74
+ };
75
+ /**
76
+ * Export an Oas object as Oas type with `import type { Infer } from '@kubb/oas'`
77
+ */
78
+ oasType?: 'infer' | false;
79
+ /**
80
+ * @example
81
+ * Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
82
+ * category: factory.createPropertySignature(
83
+ * undefined,
84
+ * factory.createIdentifier("category"),
85
+ * factory.createToken(ts.SyntaxKind.QuestionToken),
86
+ * factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
87
+ * )
88
+ */
89
+ mapper?: Record<string, ts.PropertySignature>;
90
+ };
91
+ type ResolvedOptions = {
92
+ output: Output;
93
+ override: NonNullable<Options['override']>;
94
+ enumType: NonNullable<Options['enumType']>;
95
+ enumSuffix: NonNullable<Options['enumSuffix']>;
96
+ dateType: NonNullable<Options['dateType']>;
97
+ unknownType: NonNullable<Options['unknownType']>;
98
+ optionalType: NonNullable<Options['optionalType']>;
99
+ transformers: NonNullable<Options['transformers']>;
100
+ oasType: NonNullable<Options['oasType']>;
101
+ usedEnumNames: Record<string, number>;
102
+ mapper: Record<string, any>;
103
+ };
104
+ type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
105
+
106
+ export type { Options as O, PluginTs as P };
@@ -0,0 +1,106 @@
1
+ import { PluginFactoryOptions, Output, ResolveNameParams } from '@kubb/core';
2
+ import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
3
+ import ts from 'typescript';
4
+
5
+ type Options = {
6
+ /**
7
+ * @default 'types'
8
+ */
9
+ output?: Output;
10
+ /**
11
+ * Group the TypeScript types based on the provided name.
12
+ */
13
+ group?: {
14
+ /**
15
+ * Tag will group based on the operation tag inside the Swagger file.
16
+ */
17
+ type: 'tag';
18
+ /**
19
+ * Relative path to save the grouped TypeScript Types.
20
+ *
21
+ * `{{tag}}` will be replaced by the current tagName.
22
+ * @example `${output}/{{tag}}Controller` => `models/PetController`
23
+ * @default `${output}/{{tag}}Controller`
24
+ */
25
+ output?: string;
26
+ };
27
+ /**
28
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
29
+ */
30
+ exclude?: Array<Exclude>;
31
+ /**
32
+ * Array containing include parameters to include tags/operations/methods/paths.
33
+ */
34
+ include?: Array<Include>;
35
+ /**
36
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
37
+ */
38
+ override?: Array<Override<ResolvedOptions>>;
39
+ /**
40
+ * Choose to use `enum` or `as const` for enums
41
+ * @default 'asConst'
42
+ * asPascalConst is deprecated
43
+ */
44
+ enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
45
+ /**
46
+ * Set a suffix for the generated enums.
47
+ * @default ''
48
+ * Default will be `'enum'` in version 3 of Kubb
49
+ */
50
+ enumSuffix?: string;
51
+ /**
52
+ * Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
53
+ * @default 'string'
54
+ */
55
+ dateType?: 'string' | 'date';
56
+ /**
57
+ * Which type to use when the Swagger/OpenAPI file is not providing more information.
58
+ * @default 'any'
59
+ */
60
+ unknownType?: 'any' | 'unknown';
61
+ /**
62
+ * Choose what to use as mode for an optional value.
63
+ * @examples 'questionToken': type?: string
64
+ * @examples 'undefined': type: string | undefined
65
+ * @examples 'questionTokenAndUndefined': type?: string | undefined
66
+ * @default 'questionToken'
67
+ */
68
+ optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
69
+ transformers?: {
70
+ /**
71
+ * Customize the names based on the type that is provided by the plugin.
72
+ */
73
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
74
+ };
75
+ /**
76
+ * Export an Oas object as Oas type with `import type { Infer } from '@kubb/oas'`
77
+ */
78
+ oasType?: 'infer' | false;
79
+ /**
80
+ * @example
81
+ * Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
82
+ * category: factory.createPropertySignature(
83
+ * undefined,
84
+ * factory.createIdentifier("category"),
85
+ * factory.createToken(ts.SyntaxKind.QuestionToken),
86
+ * factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
87
+ * )
88
+ */
89
+ mapper?: Record<string, ts.PropertySignature>;
90
+ };
91
+ type ResolvedOptions = {
92
+ output: Output;
93
+ override: NonNullable<Options['override']>;
94
+ enumType: NonNullable<Options['enumType']>;
95
+ enumSuffix: NonNullable<Options['enumSuffix']>;
96
+ dateType: NonNullable<Options['dateType']>;
97
+ unknownType: NonNullable<Options['unknownType']>;
98
+ optionalType: NonNullable<Options['optionalType']>;
99
+ transformers: NonNullable<Options['transformers']>;
100
+ oasType: NonNullable<Options['oasType']>;
101
+ usedEnumNames: Record<string, number>;
102
+ mapper: Record<string, any>;
103
+ };
104
+ type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
105
+
106
+ 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-alpha.2",
3
+ "version": "3.0.0-alpha.21",
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-alpha.2",
54
- "@kubb/fs": "3.0.0-alpha.2",
55
- "@kubb/oas": "3.0.0-alpha.2",
56
- "@kubb/parser-ts": "3.0.0-alpha.2",
57
- "@kubb/plugin-oas": "3.0.0-alpha.2",
58
- "@kubb/react": "3.0.0-alpha.2"
61
+ "@kubb/core": "3.0.0-alpha.21",
62
+ "@kubb/fs": "3.0.0-alpha.21",
63
+ "@kubb/oas": "3.0.0-alpha.21",
64
+ "@kubb/parser-ts": "3.0.0-alpha.21",
65
+ "@kubb/plugin-oas": "3.0.0-alpha.21",
66
+ "@kubb/react": "3.0.0-alpha.21"
59
67
  },
60
68
  "devDependencies": {
61
- "@types/react": "^18.3.4",
62
- "prettier": "^3.3.3",
69
+ "@types/react": "^18.3.8",
63
70
  "react": "^18.3.1",
64
- "tsup": "^8.2.4",
65
- "typescript": "^5.5.4",
66
- "@kubb/config-biome": "3.0.0-alpha.2",
67
- "@kubb/config-ts": "3.0.0-alpha.2",
68
- "@kubb/config-tsup": "3.0.0-alpha.2"
71
+ "tsup": "^8.3.0",
72
+ "typescript": "^5.6.2",
73
+ "@kubb/config-ts": "3.0.0-alpha.21",
74
+ "@kubb/config-tsup": "3.0.0-alpha.21"
69
75
  },
70
76
  "peerDependencies": {
71
- "@kubb/react": "3.0.0-alpha.2"
77
+ "@kubb/react": "3.0.0-alpha.21"
72
78
  },
73
79
  "engines": {
74
80
  "node": ">=20"
@@ -1,11 +1,9 @@
1
- import { Parser, File, Type, useApp } from '@kubb/react'
2
- import { useOas } from '@kubb/plugin-oas/hooks'
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 TemplateProps = {
6
+ type Props = {
9
7
  /**
10
8
  * Name of the function
11
9
  */
@@ -14,63 +12,18 @@ type TemplateProps = {
14
12
  api: OasTypes.OASDocument
15
13
  }
16
14
 
17
- function Template({ name, typeName, api }: TemplateProps): ReactNode {
15
+ export function OasType({ name, typeName, api }: Props): ReactNode {
18
16
  return (
19
17
  <>
20
- {`export const ${name} = ${JSON.stringify(api, undefined, 2)} as const`}
18
+ <File.Source name={name} isExportable isIndexable>
19
+ {`export const ${name} = ${JSON.stringify(api, undefined, 2)} as const`}
20
+ </File.Source>
21
21
  <br />
22
- <Type name={typeName} export>
23
- {`Infer<typeof ${name}>`}
24
- </Type>
22
+ <File.Source name={typeName} isExportable isIndexable isTypeOnly>
23
+ <Type name={typeName} export>
24
+ {`Infer<typeof ${name}>`}
25
+ </Type>
26
+ </File.Source>
25
27
  </>
26
28
  )
27
29
  }
28
-
29
- const defaultTemplates = { default: Template } as const
30
-
31
- type Props = {
32
- name: string
33
- typeName: string
34
- /**
35
- * This will make it possible to override the default behaviour.
36
- */
37
- Template?: React.ComponentType<React.ComponentProps<typeof Template>>
38
- }
39
-
40
- export function OasType({ name, typeName, Template = defaultTemplates.default }: Props): ReactNode {
41
- const oas = useOas()
42
-
43
- return <Template name={name} typeName={typeName} api={oas.api} />
44
- }
45
-
46
- type FileProps = {
47
- name: string
48
- typeName: string
49
- /**
50
- * This will make it possible to override the default behaviour.
51
- */
52
- templates?: typeof defaultTemplates
53
- }
54
-
55
- OasType.File = function ({ name, typeName, templates = defaultTemplates }: FileProps): ReactNode {
56
- const {
57
- pluginManager,
58
- plugin: { key: pluginKey },
59
- } = useApp<PluginTs>()
60
- const file = pluginManager.getFile({ name, extName: '.ts', pluginKey })
61
-
62
- const Template = templates.default
63
-
64
- return (
65
- <Parser language="typescript">
66
- <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
67
- <File.Import name={['Infer']} path="@kubb/oas" isTypeOnly />
68
- <File.Source>
69
- <OasType Template={Template} name={name} typeName={typeName} />
70
- </File.Source>
71
- </File>
72
- </Parser>
73
- )
74
- }
75
-
76
- OasType.templates = defaultTemplates