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

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 +1668 -49
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +466 -4
  4. package/dist/index.js +1641 -52
  5. package/dist/index.js.map +1 -1
  6. package/package.json +3 -42
  7. package/src/components/Enum.tsx +1 -1
  8. package/src/components/Type.tsx +3 -5
  9. package/src/generators/typeGenerator.tsx +10 -22
  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 +6 -6
  16. package/src/resolvers/resolverTs.ts +10 -47
  17. package/src/resolvers/resolverTsLegacy.ts +4 -31
  18. package/src/types.ts +85 -225
  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
@@ -19,8 +19,7 @@ function resolveName(name: string, type?: 'file' | 'function' | 'type' | 'const'
19
19
  * import { resolver } from '@kubb/plugin-ts'
20
20
  *
21
21
  * resolver.default('list pets', 'type') // → 'ListPets'
22
- * resolver.resolveName('list pets status 200') // → 'listPetsStatus200'
23
- * resolver.resolveTypedName('list pets status 200') // → 'ListPetsStatus200'
22
+ * resolver.resolveName('list pets status 200') // → 'ListPetsStatus200'
24
23
  * resolver.resolvePathName('list pets', 'file') // → 'listPets'
25
24
  * ```
26
25
  */
@@ -34,74 +33,38 @@ export const resolverTs = defineResolver<PluginTs>(() => {
34
33
  resolveName(name) {
35
34
  return this.default(name, 'function')
36
35
  },
37
- resolveTypedName(name) {
38
- return this.default(name, 'type')
39
- },
40
36
  resolvePathName(name, type) {
41
37
  return this.default(name, type)
42
38
  },
43
39
  resolveParamName(node, param) {
44
- return this.resolveName(`${node.operationId} ${this.default(param.in)} ${param.name}`)
45
- },
46
- resolveParamTypedName(node, param) {
47
- return this.resolveTypedName(`${node.operationId} ${this.default(param.in)} ${param.name}`)
40
+ return this.resolveName(`${node.operationId} ${param.in} ${param.name}`)
48
41
  },
49
42
  resolveResponseStatusName(node, statusCode) {
50
43
  return this.resolveName(`${node.operationId} Status ${statusCode}`)
51
44
  },
52
- resolveResponseStatusTypedName(node, statusCode) {
53
- return this.resolveTypedName(`${node.operationId} Status ${statusCode}`)
54
- },
55
45
  resolveDataName(node) {
56
46
  return this.resolveName(`${node.operationId} Data`)
57
47
  },
58
- resolveDataTypedName(node) {
59
- return this.resolveTypedName(`${node.operationId} Data`)
60
- },
61
48
  resolveRequestConfigName(node) {
62
49
  return this.resolveName(`${node.operationId} RequestConfig`)
63
50
  },
64
- resolveRequestConfigTypedName(node) {
65
- return this.resolveTypedName(`${node.operationId} RequestConfig`)
66
- },
67
51
  resolveResponsesName(node) {
68
52
  return this.resolveName(`${node.operationId} Responses`)
69
53
  },
70
- resolveResponsesTypedName(node) {
71
- return this.resolveTypedName(`${node.operationId} Responses`)
72
- },
73
54
  resolveResponseName(node) {
74
55
  return this.resolveName(`${node.operationId} Response`)
75
56
  },
76
- resolveResponseTypedName(node) {
77
- return this.resolveTypedName(`${node.operationId} Response`)
78
- },
79
- resolveEnumKeyTypedName(node, enumTypeSuffix = 'key') {
80
- return `${this.resolveTypedName(node.name ?? '')}${enumTypeSuffix}`
81
- },
82
- resolvePathParamsName(_node) {
83
- throw new Error("resolvePathParamsName is only available with compatibilityPreset: 'kubbV4'. Use resolveParamName per individual parameter instead.")
84
- },
85
- resolvePathParamsTypedName(_node) {
86
- throw new Error(
87
- "resolvePathParamsTypedName is only available with compatibilityPreset: 'kubbV4'. Use resolveParamTypedName per individual parameter instead.",
88
- )
89
- },
90
- resolveQueryParamsName(_node) {
91
- throw new Error("resolveQueryParamsName is only available with compatibilityPreset: 'kubbV4'. Use resolveParamName per individual parameter instead.")
57
+ resolveEnumKeyName(node, enumTypeSuffix = 'key') {
58
+ return `${this.resolveName(node.name ?? '')}${enumTypeSuffix}`
92
59
  },
93
- resolveQueryParamsTypedName(_node) {
94
- throw new Error(
95
- "resolveQueryParamsTypedName is only available with compatibilityPreset: 'kubbV4'. Use resolveParamTypedName per individual parameter instead.",
96
- )
60
+ resolvePathParamsName(node, param) {
61
+ return this.resolveParamName(node, param)
97
62
  },
98
- resolveHeaderParamsName(_node) {
99
- throw new Error("resolveHeaderParamsName is only available with compatibilityPreset: 'kubbV4'. Use resolveParamName per individual parameter instead.")
63
+ resolveQueryParamsName(node, param) {
64
+ return this.resolveParamName(node, param)
100
65
  },
101
- resolveHeaderParamsTypedName(_node) {
102
- throw new Error(
103
- "resolveHeaderParamsTypedName is only available with compatibilityPreset: 'kubbV4'. Use resolveParamTypedName per individual parameter instead.",
104
- )
66
+ resolveHeaderParamsName(node, param) {
67
+ return this.resolveParamName(node, param)
105
68
  },
106
69
  }
107
70
  })
@@ -35,53 +35,26 @@ export const resolverTsLegacy = defineResolver<PluginTs>(() => {
35
35
  }
36
36
  return this.resolveName(`${node.operationId} ${statusCode}`)
37
37
  },
38
- resolveResponseStatusTypedName(node, statusCode) {
39
- if (statusCode === 'default') {
40
- return this.resolveTypedName(`${node.operationId} Error`)
41
- }
42
- return this.resolveTypedName(`${node.operationId} ${statusCode}`)
43
- },
44
38
  resolveDataName(node) {
45
39
  const suffix = node.method === 'GET' ? 'QueryRequest' : 'MutationRequest'
46
40
  return this.resolveName(`${node.operationId} ${suffix}`)
47
41
  },
48
- resolveDataTypedName(node) {
49
- const suffix = node.method === 'GET' ? 'QueryRequest' : 'MutationRequest'
50
- return this.resolveTypedName(`${node.operationId} ${suffix}`)
51
- },
52
42
  resolveResponsesName(node) {
53
43
  const suffix = node.method === 'GET' ? 'Query' : 'Mutation'
54
- return `${this.default(node.operationId, 'function')}${suffix}`
55
- },
56
- resolveResponsesTypedName(node) {
57
- const suffix = node.method === 'GET' ? 'Query' : 'Mutation'
58
- return `${this.default(node.operationId, 'type')}${suffix}`
44
+ return this.resolveName(`${node.operationId} ${suffix}`)
59
45
  },
60
46
  resolveResponseName(node) {
61
47
  const suffix = node.method === 'GET' ? 'QueryResponse' : 'MutationResponse'
62
48
  return this.resolveName(`${node.operationId} ${suffix}`)
63
49
  },
64
- resolveResponseTypedName(node) {
65
- const suffix = node.method === 'GET' ? 'QueryResponse' : 'MutationResponse'
66
- return this.resolveTypedName(`${node.operationId} ${suffix}`)
67
- },
68
- resolvePathParamsName(node) {
50
+ resolvePathParamsName(node, _param) {
69
51
  return this.resolveName(`${node.operationId} PathParams`)
70
52
  },
71
- resolvePathParamsTypedName(node) {
72
- return this.resolveTypedName(`${node.operationId} PathParams`)
73
- },
74
- resolveQueryParamsName(node) {
53
+ resolveQueryParamsName(node, _param) {
75
54
  return this.resolveName(`${node.operationId} QueryParams`)
76
55
  },
77
- resolveQueryParamsTypedName(node) {
78
- return this.resolveTypedName(`${node.operationId} QueryParams`)
79
- },
80
- resolveHeaderParamsName(node) {
56
+ resolveHeaderParamsName(node, _param) {
81
57
  return this.resolveName(`${node.operationId} HeaderParams`)
82
58
  },
83
- resolveHeaderParamsTypedName(node) {
84
- return this.resolveTypedName(`${node.operationId} HeaderParams`)
85
- },
86
59
  }
87
60
  })
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,94 @@ 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
- }
201
-
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
- }
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
210
40
 
211
- /**
212
- * Options for building an operation-level schema (`data`, `responses`, `responseUnion`).
213
- */
214
- type BuildOperationSchemaOptions = {
215
- node: OperationNode
216
- resolver: ResolverTs
217
- }
218
-
219
- /**
220
- * The concrete builder type for `@kubb/plugin-ts`.
221
- * Extends the base `Builder` with schema-building helpers used by the v5 type generator.
222
- */
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
- }
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
+ }
241
102
 
242
103
  export type Options = {
243
104
  /**
@@ -253,7 +114,7 @@ export type Options = {
253
114
  /**
254
115
  * Group the clients based on the provided name.
255
116
  */
256
- group?: Group
117
+ group?: UserGroup
257
118
  /**
258
119
  * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
259
120
  */
@@ -371,7 +232,7 @@ export type Options = {
371
232
 
372
233
  type ResolvedOptions = {
373
234
  output: Output
374
- group: Options['group']
235
+ group: Group | undefined
375
236
  enumType: NonNullable<Options['enumType']>
376
237
  enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>
377
238
  enumKeyCasing: NonNullable<Options['enumKeyCasing']>
@@ -379,8 +240,7 @@ type ResolvedOptions = {
379
240
  arrayType: NonNullable<Options['arrayType']>
380
241
  syntaxType: NonNullable<Options['syntaxType']>
381
242
  paramsCasing: Options['paramsCasing']
382
- resolver: ResolverTs
383
243
  transformers: Array<Visitor>
384
244
  }
385
245
 
386
- export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs, BuilderTs>
246
+ 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
+ }