@kubb/plugin-ts 5.0.0-alpha.22 → 5.0.0-alpha.24

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 (66) hide show
  1. package/dist/index.cjs +1680 -49
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +529 -4
  4. package/dist/index.js +1653 -52
  5. package/dist/index.js.map +1 -1
  6. package/package.json +3 -42
  7. package/src/components/Enum.tsx +2 -7
  8. package/src/components/Type.tsx +11 -5
  9. package/src/generators/typeGenerator.tsx +36 -24
  10. package/src/generators/typeGeneratorLegacy.tsx +28 -38
  11. package/src/index.ts +13 -1
  12. package/src/plugin.ts +42 -23
  13. package/src/presets.ts +16 -34
  14. package/src/printers/functionPrinter.ts +194 -0
  15. package/src/printers/printerTs.ts +23 -7
  16. package/src/resolvers/resolverTs.ts +10 -47
  17. package/src/resolvers/resolverTsLegacy.ts +4 -31
  18. package/src/types.ts +169 -254
  19. package/src/utils.ts +103 -0
  20. package/dist/Type-Bf8raoQX.cjs +0 -124
  21. package/dist/Type-Bf8raoQX.cjs.map +0 -1
  22. package/dist/Type-BpXxT4l_.js +0 -113
  23. package/dist/Type-BpXxT4l_.js.map +0 -1
  24. package/dist/builderTs-COUg3xtQ.cjs +0 -135
  25. package/dist/builderTs-COUg3xtQ.cjs.map +0 -1
  26. package/dist/builderTs-DPpkJKd1.js +0 -131
  27. package/dist/builderTs-DPpkJKd1.js.map +0 -1
  28. package/dist/builders.cjs +0 -3
  29. package/dist/builders.d.ts +0 -23
  30. package/dist/builders.js +0 -2
  31. package/dist/casing-BJHFg-zZ.js +0 -84
  32. package/dist/casing-BJHFg-zZ.js.map +0 -1
  33. package/dist/casing-DHfdqpLi.cjs +0 -107
  34. package/dist/casing-DHfdqpLi.cjs.map +0 -1
  35. package/dist/chunk-ByKO4r7w.cjs +0 -38
  36. package/dist/components.cjs +0 -4
  37. package/dist/components.d.ts +0 -71
  38. package/dist/components.js +0 -2
  39. package/dist/generators-DFDut8o-.js +0 -555
  40. package/dist/generators-DFDut8o-.js.map +0 -1
  41. package/dist/generators-DKd7MYbx.cjs +0 -567
  42. package/dist/generators-DKd7MYbx.cjs.map +0 -1
  43. package/dist/generators.cjs +0 -4
  44. package/dist/generators.d.ts +0 -12
  45. package/dist/generators.js +0 -2
  46. package/dist/printerTs-BcHudagv.cjs +0 -594
  47. package/dist/printerTs-BcHudagv.cjs.map +0 -1
  48. package/dist/printerTs-CMBCOuqd.js +0 -558
  49. package/dist/printerTs-CMBCOuqd.js.map +0 -1
  50. package/dist/printers.cjs +0 -3
  51. package/dist/printers.d.ts +0 -81
  52. package/dist/printers.js +0 -2
  53. package/dist/resolverTsLegacy-CPiqqsO6.js +0 -185
  54. package/dist/resolverTsLegacy-CPiqqsO6.js.map +0 -1
  55. package/dist/resolverTsLegacy-CuR9XbKk.cjs +0 -196
  56. package/dist/resolverTsLegacy-CuR9XbKk.cjs.map +0 -1
  57. package/dist/resolvers.cjs +0 -4
  58. package/dist/resolvers.d.ts +0 -52
  59. package/dist/resolvers.js +0 -2
  60. package/dist/types-CRtcZOCz.d.ts +0 -374
  61. package/src/builders/builderTs.ts +0 -107
  62. package/src/builders/index.ts +0 -1
  63. package/src/components/index.ts +0 -2
  64. package/src/generators/index.ts +0 -2
  65. package/src/printers/index.ts +0 -1
  66. package/src/resolvers/index.ts +0 -2
package/src/types.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import type { OperationParamsResolver } from '@kubb/ast'
1
2
  import type { OperationNode, ParameterNode, SchemaNode, StatusCode, Visitor } from '@kubb/ast/types'
2
3
  import type {
3
- Builder,
4
4
  CompatibilityPreset,
5
5
  Exclude,
6
6
  Generator,
@@ -11,233 +11,180 @@ import type {
11
11
  PluginFactoryOptions,
12
12
  ResolvePathOptions,
13
13
  Resolver,
14
+ UserGroup,
14
15
  } from '@kubb/core'
15
16
  /**
16
17
  * The concrete resolver type for `@kubb/plugin-ts`.
17
18
  * Extends the base `Resolver` (which provides `default` and `resolveOptions`) with
18
19
  * plugin-specific naming helpers for operations, parameters, responses, and schemas.
19
20
  */
20
- export type ResolverTs = Resolver & {
21
- /**
22
- * Resolves the variable/function name for a given raw name (equivalent to `default(name, 'function')`).
23
- * Use this shorthand when matching the `name` field produced by the v2 TypeGenerator,
24
- * so call-sites don't need to repeat the `'function'` type literal.
25
- *
26
- * @example
27
- * resolver.resolveName('list pets status 200') // → 'listPetsStatus200'
28
- */
29
- resolveName(name: string): string
30
- /**
31
- * Resolves the TypeScript type name for a given raw name (equivalent to `default(name, 'type')`).
32
- * Use this shorthand when matching the `typedName` field produced by the v2 TypeGenerator,
33
- * so call-sites don't need to repeat the `'type'` type literal.
34
- *
35
- * @example
36
- * resolver.resolveTypedName('list pets status 200') // 'ListPetsStatus200'
37
- */
38
- resolveTypedName(name: string): string
39
- /**
40
- * Resolves the file/path name for a given identifier using PascalCase.
41
- *
42
- * @example
43
- * resolver.resolvePathName('list pets', 'file') // → 'ListPets'
44
- */
45
- resolvePathName(name: string, type?: 'file' | 'function' | 'type' | 'const'): string
46
- /**
47
- * Resolves the variable/function name for an operation parameter.
48
- * Encapsulates the `<operationId> <PascalCase(paramIn)> <paramName>` naming convention.
49
- *
50
- * @example
51
- * resolver.resolveParamName(node, param) // → 'ListPetsQueryLimit'
52
- */
53
- resolveParamName(node: OperationNode, param: ParameterNode): string
54
- /**
55
- * Resolves the TypeScript type alias name for an operation parameter
56
- * (equivalent to `resolveParamName` with `type: 'type'`).
57
- * In the default implementation both return the same PascalCase string;
58
- * the distinction is preserved so overrides can diverge the two forms.
59
- *
60
- * @example
61
- * resolver.resolveParamTypedName(node, param) // → 'ListPetsQueryLimit'
62
- */
63
- resolveParamTypedName(node: OperationNode, param: ParameterNode): string
64
- /**
65
- * Resolves the variable/function name for an operation response by status code.
66
- * Encapsulates the `<operationId> Status <statusCode>` template with PascalCase applied to the result.
67
- *
68
- * @example
69
- * resolver.resolveResponseStatusName(node, 200) // → 'ListPetsStatus200'
70
- */
71
- resolveResponseStatusName(node: OperationNode, statusCode: StatusCode): string
72
- /**
73
- * Resolves the TypeScript type alias name for an operation response by status code.
74
- * Encapsulates the `<operationId> Status <statusCode>` template with PascalCase applied to the result.
75
- *
76
- * @example
77
- * resolver.resolveResponseStatusTypedName(node, 200) // → 'ListPetsStatus200'
78
- */
79
- resolveResponseStatusTypedName(node: OperationNode, statusCode: StatusCode): string
80
- /**
81
- * Resolves the variable/function name for an operation's request body (`Data`).
82
- *
83
- * @example
84
- * resolver.resolveDataName(node) // → 'ListPetsData'
85
- */
86
- resolveDataName(node: OperationNode): string
87
- /**
88
- * Resolves the TypeScript type alias name for an operation's request body (`Data`).
89
- *
90
- * @example
91
- * resolver.resolveDataTypedName(node) // → 'ListPetsData'
92
- */
93
- resolveDataTypedName(node: OperationNode): string
94
- /**
95
- * Resolves the variable/function name for an operation's request config (`RequestConfig`).
96
- *
97
- * @example
98
- * resolver.resolveRequestConfigName(node) // → 'ListPetsRequestConfig'
99
- */
100
- resolveRequestConfigName(node: OperationNode): string
101
- /**
102
- * Resolves the TypeScript type alias name for an operation's request config (`RequestConfig`).
103
- *
104
- * @example
105
- * resolver.resolveRequestConfigTypedName(node) // → 'ListPetsRequestConfig'
106
- */
107
- resolveRequestConfigTypedName(node: OperationNode): string
108
- /**
109
- * Resolves the variable/function name for the collection of all operation responses (`Responses`).
110
- *
111
- * @example
112
- * resolver.resolveResponsesName(node) // → 'ListPetsResponses'
113
- */
114
- resolveResponsesName(node: OperationNode): string
115
- /**
116
- * Resolves the TypeScript type alias name for the collection of all operation responses.
117
- *
118
- * @example
119
- * resolver.resolveResponsesTypedName(node) // → 'ListPetsResponses'
120
- */
121
- resolveResponsesTypedName(node: OperationNode): string
122
- /**
123
- * Resolves the variable/function name for the union of all operation responses (`Response`).
124
- *
125
- * @example
126
- * resolver.resolveResponseName(node) // → 'ListPetsResponse'
127
- */
128
- resolveResponseName(node: OperationNode): string
129
- /**
130
- * Resolves the TypeScript type alias name for the union of all operation responses.
131
- *
132
- * @example
133
- * resolver.resolveResponseTypedName(node) // → 'ListPetsResponse'
134
- */
135
- resolveResponseTypedName(node: OperationNode): string
136
- /**
137
- * Resolves the TypeScript type alias name for an enum schema's key variant.
138
- * Appends `enumTypeSuffix` (default `'Key'`) after applying the default naming convention.
139
- *
140
- * @example
141
- * resolver.resolveEnumKeyTypedName(node, 'Key') // → 'PetStatusKey'
142
- * resolver.resolveEnumKeyTypedName(node, 'Value') // → 'PetStatusValue'
143
- * resolver.resolveEnumKeyTypedName(node, '') // → 'PetStatus'
144
- */
145
- resolveEnumKeyTypedName(node: SchemaNode, enumTypeSuffix: string): string
146
- /**
147
- * Resolves the variable/function name for an operation's grouped path parameters type.
148
- * Only available with `compatibilityPreset: 'kubbV4'`.
149
- *
150
- * @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
151
- * @example
152
- * resolver.resolvePathParamsName(node) // → 'GetPetByIdPathParams'
153
- */
154
- resolvePathParamsName?(node: OperationNode): string
155
- /**
156
- * Resolves the TypeScript type alias name for an operation's grouped path parameters type.
157
- * Only available with `compatibilityPreset: 'kubbV4'`.
158
- *
159
- * @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
160
- * @example
161
- * resolver.resolvePathParamsTypedName(node) // → 'GetPetByIdPathParams'
162
- */
163
- resolvePathParamsTypedName?(node: OperationNode): string
164
- /**
165
- * Resolves the variable/function name for an operation's grouped query parameters type.
166
- * Only available with `compatibilityPreset: 'kubbV4'`.
167
- *
168
- * @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
169
- * @example
170
- * resolver.resolveQueryParamsName(node) // → 'FindPetsByStatusQueryParams'
171
- */
172
- resolveQueryParamsName?(node: OperationNode): string
173
- /**
174
- * Resolves the TypeScript type alias name for an operation's grouped query parameters type.
175
- * Only available with `compatibilityPreset: 'kubbV4'`.
176
- *
177
- * @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
178
- * @example
179
- * resolver.resolveQueryParamsTypedName(node) // → 'FindPetsByStatusQueryParams'
180
- */
181
- resolveQueryParamsTypedName?(node: OperationNode): string
182
- /**
183
- * Resolves the variable/function name for an operation's grouped header parameters type.
184
- * Only available with `compatibilityPreset: 'kubbV4'`.
185
- *
186
- * @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
187
- * @example
188
- * resolver.resolveHeaderParamsName(node) // → 'DeletePetHeaderParams'
189
- */
190
- resolveHeaderParamsName?(node: OperationNode): string
191
- /**
192
- * Resolves the TypeScript type alias name for an operation's grouped header parameters type.
193
- * Only available with `compatibilityPreset: 'kubbV4'`.
194
- *
195
- * @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
196
- * @example
197
- * resolver.resolveHeaderParamsTypedName(node) // → 'DeletePetHeaderParams'
198
- */
199
- resolveHeaderParamsTypedName?(node: OperationNode): string
200
- }
21
+ export type ResolverTs = Resolver &
22
+ OperationParamsResolver & {
23
+ /**
24
+ * Resolves the name for a given raw name (equivalent to `default(name, 'function')`).
25
+ * Since TypeScript only emits types, this is the canonical naming method.
26
+ *
27
+ * @example
28
+ * resolver.resolveName('list pets status 200') // → 'ListPetsStatus200'
29
+ */
30
+ resolveName(name: string): string
31
+ /**
32
+ * Resolves the file/path name for a given identifier using PascalCase.
33
+ *
34
+ * @example
35
+ * resolver.resolvePathName('list pets', 'file') // → 'ListPets'
36
+ */
37
+ resolvePathName(name: string, type?: 'file' | 'function' | 'type' | 'const'): string
38
+ /** Resolves the request body type name (required on ResolverTs). */
39
+ resolveDataName(node: OperationNode): string
201
40
 
202
- /**
203
- * Options for building a grouped parameter schema (`pathParams`, `queryParams`, `headerParams`).
204
- */
205
- type BuildParamsSchemaOptions = {
206
- params: Array<ParameterNode>
207
- node: OperationNode
208
- resolver: ResolverTs
209
- }
41
+ /**
42
+ * Resolves the name for an operation response by status code.
43
+ * Encapsulates the `<operationId> Status <statusCode>` template with PascalCase applied to the result.
44
+ *
45
+ * @example
46
+ * resolver.resolveResponseStatusName(node, 200) // → 'ListPetsStatus200'
47
+ */
48
+ resolveResponseStatusName(node: OperationNode, statusCode: StatusCode): string
49
+ /**
50
+ * Resolves the name for an operation's request config (`RequestConfig`).
51
+ *
52
+ * @example
53
+ * resolver.resolveRequestConfigName(node) // → 'ListPetsRequestConfig'
54
+ */
55
+ resolveRequestConfigName(node: OperationNode): string
56
+ /**
57
+ * Resolves the name for the collection of all operation responses (`Responses`).
58
+ *
59
+ * @example
60
+ * resolver.resolveResponsesName(node) // → 'ListPetsResponses'
61
+ */
62
+ resolveResponsesName(node: OperationNode): string
63
+ /**
64
+ * Resolves the name for the union of all operation responses (`Response`).
65
+ *
66
+ * @example
67
+ * resolver.resolveResponseName(node) // → 'ListPetsResponse'
68
+ */
69
+ resolveResponseName(node: OperationNode): string
70
+ /**
71
+ * Resolves the TypeScript type alias name for an enum schema's key variant.
72
+ * Appends `enumTypeSuffix` (default `'Key'`) after applying the default naming convention.
73
+ *
74
+ * @example
75
+ * resolver.resolveEnumKeyName(node, 'Key') // → 'PetStatusKey'
76
+ * resolver.resolveEnumKeyName(node, 'Value') // → 'PetStatusValue'
77
+ * resolver.resolveEnumKeyName(node, '') // → 'PetStatus'
78
+ */
79
+ resolveEnumKeyName(node: SchemaNode, enumTypeSuffix: string): string
80
+ /**
81
+ * Resolves the name for an operation's grouped path parameters type.
82
+ *
83
+ * @example
84
+ * resolver.resolvePathParamsName(node, param) // → 'GetPetByIdPathParams'
85
+ */
86
+ resolvePathParamsName(node: OperationNode, param: ParameterNode): string
87
+ /**
88
+ * Resolves the name for an operation's grouped query parameters type.
89
+ *
90
+ * @example
91
+ * resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'
92
+ */
93
+ resolveQueryParamsName(node: OperationNode, param: ParameterNode): string
94
+ /**
95
+ * Resolves the name for an operation's grouped header parameters type.
96
+ *
97
+ * @example
98
+ * resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'
99
+ */
100
+ resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string
101
+ }
210
102
 
211
- /**
212
- * Options for building an operation-level schema (`data`, `responses`, `responseUnion`).
213
- */
214
- type BuildOperationSchemaOptions = {
215
- node: OperationNode
216
- resolver: ResolverTs
217
- }
103
+ type EnumKeyCasing = 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none'
218
104
 
219
105
  /**
220
- * The concrete builder type for `@kubb/plugin-ts`.
221
- * Extends the base `Builder` with schema-building helpers used by the v5 type generator.
106
+ * Discriminated union that ties `enumTypeSuffix` and `enumKeyCasing` to the enum types that actually use them.
107
+ *
108
+ * - `'asConst'` / `'asPascalConst'` — emit a `const` object; both `enumTypeSuffix` (type-alias suffix) and
109
+ * `enumKeyCasing` (key formatting) are meaningful.
110
+ * - `'enum'` / `'constEnum'` — emit a TypeScript enum; `enumKeyCasing` applies to member names,
111
+ * but there is no separate type alias so `enumTypeSuffix` is not used.
112
+ * - `'literal'` / `'inlineLiteral'` — emit only union literals; keys are discarded entirely,
113
+ * so neither `enumTypeSuffix` nor `enumKeyCasing` have any effect.
222
114
  */
223
- export type BuilderTs = Builder & {
224
- /**
225
- * Builds an object schema that groups the given parameters by name.
226
- */
227
- buildParams(options: BuildParamsSchemaOptions): SchemaNode
228
- /**
229
- * Builds the combined data schema containing `pathParams`, `queryParams`, `headerParams`, `data`, and `url`.
230
- */
231
- buildData(options: BuildOperationSchemaOptions): SchemaNode
232
- /**
233
- * Builds an object schema that maps each response status code to its type reference, or `null` when there are no responses.
234
- */
235
- buildResponses(options: BuildOperationSchemaOptions): SchemaNode | null
236
- /**
237
- * Builds a union schema of all response status types, or `null` when no responses have a schema.
238
- */
239
- buildResponseUnion(options: BuildOperationSchemaOptions): SchemaNode | null
240
- }
115
+ type EnumTypeOptions =
116
+ | {
117
+ /**
118
+ * Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
119
+ * - 'asConst' generates const objects with camelCase names and as const assertion.
120
+ * - 'asPascalConst' generates const objects with PascalCase names and as const assertion.
121
+ * @default 'asConst'
122
+ */
123
+ enumType?: 'asConst' | 'asPascalConst'
124
+ /**
125
+ * Suffix appended to the generated type alias name.
126
+ *
127
+ * Only affects the type alias — the const object name is unchanged.
128
+ *
129
+ * @default 'Key'
130
+ * @example enumTypeSuffix: 'Value' → `export type PetStatusValue = …`
131
+ */
132
+ enumTypeSuffix?: string
133
+ /**
134
+ * Choose the casing for enum key names.
135
+ * - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
136
+ * - 'snakeCase' generates keys in snake_case format.
137
+ * - 'pascalCase' generates keys in PascalCase format.
138
+ * - 'camelCase' generates keys in camelCase format.
139
+ * - 'none' uses the enum value as-is without transformation.
140
+ * @default 'none'
141
+ */
142
+ enumKeyCasing?: EnumKeyCasing
143
+ }
144
+ | {
145
+ /**
146
+ * Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
147
+ * - 'enum' generates TypeScript enum declarations.
148
+ * - 'constEnum' generates TypeScript const enum declarations.
149
+ * @default 'asConst'
150
+ */
151
+ enumType?: 'enum' | 'constEnum'
152
+ /**
153
+ * `enumTypeSuffix` has no effect for this `enumType`.
154
+ * It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
155
+ */
156
+ enumTypeSuffix?: never
157
+ /**
158
+ * Choose the casing for enum key names.
159
+ * - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
160
+ * - 'snakeCase' generates keys in snake_case format.
161
+ * - 'pascalCase' generates keys in PascalCase format.
162
+ * - 'camelCase' generates keys in camelCase format.
163
+ * - 'none' uses the enum value as-is without transformation.
164
+ * @default 'none'
165
+ */
166
+ enumKeyCasing?: EnumKeyCasing
167
+ }
168
+ | {
169
+ /**
170
+ * Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
171
+ * - 'literal' generates literal union types.
172
+ * - 'inlineLiteral' inlines enum values directly into the type (default in v5).
173
+ * @default 'asConst'
174
+ * @note In Kubb v5, 'inlineLiteral' becomes the default.
175
+ */
176
+ enumType?: 'literal' | 'inlineLiteral'
177
+ /**
178
+ * `enumTypeSuffix` has no effect for this `enumType`.
179
+ * It is only used when `enumType` is `'asConst'` or `'asPascalConst'`.
180
+ */
181
+ enumTypeSuffix?: never
182
+ /**
183
+ * `enumKeyCasing` has no effect for this `enumType`.
184
+ * Literal and inlineLiteral modes emit only values — keys are discarded entirely.
185
+ */
186
+ enumKeyCasing?: never
187
+ }
241
188
 
242
189
  export type Options = {
243
190
  /**
@@ -253,7 +200,7 @@ export type Options = {
253
200
  /**
254
201
  * Group the clients based on the provided name.
255
202
  */
256
- group?: Group
203
+ group?: UserGroup
257
204
  /**
258
205
  * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
259
206
  */
@@ -266,37 +213,6 @@ export type Options = {
266
213
  * Array containing override parameters to override `options` based on tags/operations/methods/paths.
267
214
  */
268
215
  override?: Array<Override<ResolvedOptions>>
269
- /**
270
- * Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
271
- * - 'enum' generates TypeScript enum declarations.
272
- * - 'asConst' generates const objects with camelCase names and as const assertion.
273
- * - 'asPascalConst' generates const objects with PascalCase names and as const assertion.
274
- * - 'constEnum' generates TypeScript const enum declarations.
275
- * - 'literal' generates literal union types.
276
- * - 'inlineLiteral' inline enum values directly into the type (default in v5).
277
- * @default 'asConst'
278
- * @note In Kubb v5, 'inlineLiteral' becomes the default.
279
- */
280
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral'
281
- /**
282
- * Suffix appended to the generated type alias name when `enumType` is `asConst` or `asPascalConst`.
283
- *
284
- * Only affects the type alias — the const object name is unchanged.
285
- *
286
- * @default 'Key'
287
- * @example enumTypeSuffix: 'Value' → `export type PetStatusValue = …`
288
- */
289
- enumTypeSuffix?: string
290
- /**
291
- * Choose the casing for enum key names.
292
- * - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
293
- * - 'snakeCase' generates keys in snake_case format.
294
- * - 'pascalCase' generates keys in PascalCase format.
295
- * - 'camelCase' generates keys in camelCase format.
296
- * - 'none' uses the enum value as-is without transformation.
297
- * @default 'none'
298
- */
299
- enumKeyCasing?: 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none'
300
216
  /**
301
217
  * Switch between type or interface for creating TypeScript types.
302
218
  * - 'type' generates type alias declarations.
@@ -367,20 +283,19 @@ export type Options = {
367
283
  * ```
368
284
  */
369
285
  transformers?: Array<Visitor>
370
- }
286
+ } & EnumTypeOptions
371
287
 
372
288
  type ResolvedOptions = {
373
289
  output: Output
374
- group: Options['group']
290
+ group: Group | undefined
375
291
  enumType: NonNullable<Options['enumType']>
376
292
  enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>
377
- enumKeyCasing: NonNullable<Options['enumKeyCasing']>
293
+ enumKeyCasing: EnumKeyCasing
378
294
  optionalType: NonNullable<Options['optionalType']>
379
295
  arrayType: NonNullable<Options['arrayType']>
380
296
  syntaxType: NonNullable<Options['syntaxType']>
381
297
  paramsCasing: Options['paramsCasing']
382
- resolver: ResolverTs
383
298
  transformers: Array<Visitor>
384
299
  }
385
300
 
386
- export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs, BuilderTs>
301
+ export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs>
package/src/utils.ts ADDED
@@ -0,0 +1,103 @@
1
+ import { createProperty, createSchema } from '@kubb/ast'
2
+ import type { OperationNode, ParameterNode, SchemaNode } from '@kubb/ast/types'
3
+ import type { ResolverTs } from './types.ts'
4
+
5
+ type BuildParamsSchemaOptions = {
6
+ params: Array<ParameterNode>
7
+ node: OperationNode
8
+ resolver: ResolverTs
9
+ }
10
+
11
+ type BuildOperationSchemaOptions = {
12
+ node: OperationNode
13
+ resolver: ResolverTs
14
+ }
15
+
16
+ export function buildParams({ params, node, resolver }: BuildParamsSchemaOptions): SchemaNode {
17
+ return createSchema({
18
+ type: 'object',
19
+ properties: params.map((param) =>
20
+ createProperty({
21
+ name: param.name,
22
+ required: param.required,
23
+ schema: createSchema({
24
+ type: 'ref',
25
+ name: resolver.resolveParamName(node, param),
26
+ }),
27
+ }),
28
+ ),
29
+ })
30
+ }
31
+
32
+ export function buildData({ node, resolver }: BuildOperationSchemaOptions): SchemaNode {
33
+ const pathParams = node.parameters.filter((p) => p.in === 'path')
34
+ const queryParams = node.parameters.filter((p) => p.in === 'query')
35
+ const headerParams = node.parameters.filter((p) => p.in === 'header')
36
+
37
+ return createSchema({
38
+ type: 'object',
39
+ deprecated: node.deprecated,
40
+ properties: [
41
+ createProperty({
42
+ name: 'data',
43
+ schema: node.requestBody?.schema
44
+ ? createSchema({ type: 'ref', name: resolver.resolveDataName(node), optional: true })
45
+ : createSchema({ type: 'never', optional: true }),
46
+ }),
47
+ createProperty({
48
+ name: 'pathParams',
49
+ required: pathParams.length > 0,
50
+ schema: pathParams.length > 0 ? buildParams({ params: pathParams, node, resolver }) : createSchema({ type: 'never' }),
51
+ }),
52
+ createProperty({
53
+ name: 'queryParams',
54
+ schema:
55
+ queryParams.length > 0
56
+ ? createSchema({ ...buildParams({ params: queryParams, node, resolver }), optional: true })
57
+ : createSchema({ type: 'never', optional: true }),
58
+ }),
59
+ createProperty({
60
+ name: 'headerParams',
61
+ schema:
62
+ headerParams.length > 0
63
+ ? createSchema({ ...buildParams({ params: headerParams, node, resolver }), optional: true })
64
+ : createSchema({ type: 'never', optional: true }),
65
+ }),
66
+ createProperty({
67
+ name: 'url',
68
+ required: true,
69
+ schema: createSchema({ type: 'url', path: node.path }),
70
+ }),
71
+ ],
72
+ })
73
+ }
74
+
75
+ export function buildResponses({ node, resolver }: BuildOperationSchemaOptions): SchemaNode | null {
76
+ if (node.responses.length === 0) {
77
+ return null
78
+ }
79
+
80
+ return createSchema({
81
+ type: 'object',
82
+ properties: node.responses.map((res) =>
83
+ createProperty({
84
+ name: String(res.statusCode),
85
+ required: true,
86
+ schema: createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, res.statusCode) }),
87
+ }),
88
+ ),
89
+ })
90
+ }
91
+
92
+ export function buildResponseUnion({ node, resolver }: BuildOperationSchemaOptions): SchemaNode | null {
93
+ const responsesWithSchema = node.responses.filter((res) => res.schema)
94
+
95
+ if (responsesWithSchema.length === 0) {
96
+ return null
97
+ }
98
+
99
+ return createSchema({
100
+ type: 'union',
101
+ members: responsesWithSchema.map((res) => createSchema({ type: 'ref', name: resolver.resolveResponseStatusName(node, res.statusCode) })),
102
+ })
103
+ }