@kubb/plugin-ts 5.0.0-alpha.21 → 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.
- package/dist/index.cjs +1698 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +485 -4
- package/dist/index.js +1667 -41
- package/dist/index.js.map +1 -1
- package/package.json +3 -42
- package/src/components/Enum.tsx +15 -11
- package/src/components/Type.tsx +18 -7
- package/src/generators/typeGenerator.tsx +12 -21
- package/src/generators/typeGeneratorLegacy.tsx +30 -37
- package/src/index.ts +13 -1
- package/src/plugin.ts +62 -22
- package/src/presets.ts +22 -23
- package/src/printers/functionPrinter.ts +194 -0
- package/src/printers/printerTs.ts +16 -8
- package/src/resolvers/resolverTs.ts +10 -47
- package/src/resolvers/resolverTsLegacy.ts +4 -31
- package/src/types.ts +95 -205
- package/src/utils.ts +103 -0
- package/dist/Type-B6fo0gSk.js +0 -120
- package/dist/Type-B6fo0gSk.js.map +0 -1
- package/dist/Type-oFwUfkZv.cjs +0 -131
- package/dist/Type-oFwUfkZv.cjs.map +0 -1
- package/dist/builderTs-Cd3juc2G.cjs +0 -120
- package/dist/builderTs-Cd3juc2G.cjs.map +0 -1
- package/dist/builderTs-DausqHpc.js +0 -116
- package/dist/builderTs-DausqHpc.js.map +0 -1
- package/dist/builders.cjs +0 -3
- package/dist/builders.d.ts +0 -8
- package/dist/builders.js +0 -2
- package/dist/casing-BJHFg-zZ.js +0 -84
- package/dist/casing-BJHFg-zZ.js.map +0 -1
- package/dist/casing-DHfdqpLi.cjs +0 -107
- package/dist/casing-DHfdqpLi.cjs.map +0 -1
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/components.cjs +0 -4
- package/dist/components.d.ts +0 -67
- package/dist/components.js +0 -2
- package/dist/generators-ByK18qUn.js +0 -551
- package/dist/generators-ByK18qUn.js.map +0 -1
- package/dist/generators-aSsiTfUO.cjs +0 -563
- package/dist/generators-aSsiTfUO.cjs.map +0 -1
- package/dist/generators.cjs +0 -4
- package/dist/generators.d.ts +0 -12
- package/dist/generators.js +0 -2
- package/dist/printerTs-BgZucv4T.js +0 -559
- package/dist/printerTs-BgZucv4T.js.map +0 -1
- package/dist/printerTs-CFXc_LpP.cjs +0 -595
- package/dist/printerTs-CFXc_LpP.cjs.map +0 -1
- package/dist/printers.cjs +0 -3
- package/dist/printers.d.ts +0 -75
- package/dist/printers.js +0 -2
- package/dist/resolverTsLegacy-DLl854-P.js +0 -185
- package/dist/resolverTsLegacy-DLl854-P.js.map +0 -1
- package/dist/resolverTsLegacy-sJ16Iqrl.cjs +0 -196
- package/dist/resolverTsLegacy-sJ16Iqrl.cjs.map +0 -1
- package/dist/resolvers.cjs +0 -4
- package/dist/resolvers.d.ts +0 -52
- package/dist/resolvers.js +0 -2
- package/dist/types-BcyuFDn9.d.ts +0 -344
- package/src/builders/builderTs.ts +0 -92
- package/src/builders/index.ts +0 -1
- package/src/components/index.ts +0 -2
- package/src/generators/index.ts +0 -2
- package/src/printers/index.ts +0 -1
- 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,213 +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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 the `Key` suffix after applying the default naming convention.
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* resolver.resolveEnumKeyTypedName(node) // → 'PetStatusKey'
|
|
142
|
-
*/
|
|
143
|
-
resolveEnumKeyTypedName(node: SchemaNode): string
|
|
144
|
-
/**
|
|
145
|
-
* Resolves the variable/function name for an operation's grouped path parameters type.
|
|
146
|
-
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
147
|
-
*
|
|
148
|
-
* @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
|
|
149
|
-
* @example
|
|
150
|
-
* resolver.resolvePathParamsName(node) // → 'GetPetByIdPathParams'
|
|
151
|
-
*/
|
|
152
|
-
resolvePathParamsName?(node: OperationNode): string
|
|
153
|
-
/**
|
|
154
|
-
* Resolves the TypeScript type alias name for an operation's grouped path parameters type.
|
|
155
|
-
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
156
|
-
*
|
|
157
|
-
* @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
|
|
158
|
-
* @example
|
|
159
|
-
* resolver.resolvePathParamsTypedName(node) // → 'GetPetByIdPathParams'
|
|
160
|
-
*/
|
|
161
|
-
resolvePathParamsTypedName?(node: OperationNode): string
|
|
162
|
-
/**
|
|
163
|
-
* Resolves the variable/function name for an operation's grouped query parameters type.
|
|
164
|
-
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
165
|
-
*
|
|
166
|
-
* @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
|
|
167
|
-
* @example
|
|
168
|
-
* resolver.resolveQueryParamsName(node) // → 'FindPetsByStatusQueryParams'
|
|
169
|
-
*/
|
|
170
|
-
resolveQueryParamsName?(node: OperationNode): string
|
|
171
|
-
/**
|
|
172
|
-
* Resolves the TypeScript type alias name for an operation's grouped query parameters type.
|
|
173
|
-
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
174
|
-
*
|
|
175
|
-
* @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
|
|
176
|
-
* @example
|
|
177
|
-
* resolver.resolveQueryParamsTypedName(node) // → 'FindPetsByStatusQueryParams'
|
|
178
|
-
*/
|
|
179
|
-
resolveQueryParamsTypedName?(node: OperationNode): string
|
|
180
|
-
/**
|
|
181
|
-
* Resolves the variable/function name for an operation's grouped header parameters type.
|
|
182
|
-
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
183
|
-
*
|
|
184
|
-
* @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
|
|
185
|
-
* @example
|
|
186
|
-
* resolver.resolveHeaderParamsName(node) // → 'DeletePetHeaderParams'
|
|
187
|
-
*/
|
|
188
|
-
resolveHeaderParamsName?(node: OperationNode): string
|
|
189
|
-
/**
|
|
190
|
-
* Resolves the TypeScript type alias name for an operation's grouped header parameters type.
|
|
191
|
-
* Only available with `compatibilityPreset: 'kubbV4'`.
|
|
192
|
-
*
|
|
193
|
-
* @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
|
|
194
|
-
* @example
|
|
195
|
-
* resolver.resolveHeaderParamsTypedName(node) // → 'DeletePetHeaderParams'
|
|
196
|
-
*/
|
|
197
|
-
resolveHeaderParamsTypedName?(node: OperationNode): string
|
|
198
|
-
}
|
|
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
|
|
199
40
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
+
}
|
|
221
102
|
|
|
222
103
|
export type Options = {
|
|
223
104
|
/**
|
|
@@ -233,7 +114,7 @@ export type Options = {
|
|
|
233
114
|
/**
|
|
234
115
|
* Group the clients based on the provided name.
|
|
235
116
|
*/
|
|
236
|
-
group?:
|
|
117
|
+
group?: UserGroup
|
|
237
118
|
/**
|
|
238
119
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
239
120
|
*/
|
|
@@ -258,6 +139,15 @@ export type Options = {
|
|
|
258
139
|
* @note In Kubb v5, 'inlineLiteral' becomes the default.
|
|
259
140
|
*/
|
|
260
141
|
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral'
|
|
142
|
+
/**
|
|
143
|
+
* Suffix appended to the generated type alias name when `enumType` is `asConst` or `asPascalConst`.
|
|
144
|
+
*
|
|
145
|
+
* Only affects the type alias — the const object name is unchanged.
|
|
146
|
+
*
|
|
147
|
+
* @default 'Key'
|
|
148
|
+
* @example enumTypeSuffix: 'Value' → `export type PetStatusValue = …`
|
|
149
|
+
*/
|
|
150
|
+
enumTypeSuffix?: string
|
|
261
151
|
/**
|
|
262
152
|
* Choose the casing for enum key names.
|
|
263
153
|
* - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
|
|
@@ -342,15 +232,15 @@ export type Options = {
|
|
|
342
232
|
|
|
343
233
|
type ResolvedOptions = {
|
|
344
234
|
output: Output
|
|
345
|
-
group:
|
|
235
|
+
group: Group | undefined
|
|
346
236
|
enumType: NonNullable<Options['enumType']>
|
|
237
|
+
enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>
|
|
347
238
|
enumKeyCasing: NonNullable<Options['enumKeyCasing']>
|
|
348
239
|
optionalType: NonNullable<Options['optionalType']>
|
|
349
240
|
arrayType: NonNullable<Options['arrayType']>
|
|
350
241
|
syntaxType: NonNullable<Options['syntaxType']>
|
|
351
242
|
paramsCasing: Options['paramsCasing']
|
|
352
|
-
resolver: ResolverTs
|
|
353
243
|
transformers: Array<Visitor>
|
|
354
244
|
}
|
|
355
245
|
|
|
356
|
-
export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs
|
|
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
|
+
}
|
package/dist/Type-B6fo0gSk.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { t as camelCase } from "./casing-BJHFg-zZ.js";
|
|
3
|
-
import { a as ENUM_TYPES_WITH_TYPE_ONLY, i as ENUM_TYPES_WITH_RUNTIME_VALUE, n as createEnumDeclaration, o as trimQuotes, r as ENUM_TYPES_WITH_KEY_SUFFIX, t as printerTs } from "./printerTs-BgZucv4T.js";
|
|
4
|
-
import { collect, narrowSchema, schemaTypes } from "@kubb/ast";
|
|
5
|
-
import { File } from "@kubb/react-fabric";
|
|
6
|
-
import { safePrint } from "@kubb/fabric-core/parsers/typescript";
|
|
7
|
-
import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
|
|
8
|
-
//#region src/components/Enum.tsx
|
|
9
|
-
/**
|
|
10
|
-
* Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
|
|
11
|
-
*
|
|
12
|
-
* The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
|
|
13
|
-
* valid TypeScript identifier. The resolver normalizes it; for inline enum
|
|
14
|
-
* properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.
|
|
15
|
-
*/
|
|
16
|
-
function getEnumNames({ node, enumType, resolver }) {
|
|
17
|
-
const resolved = resolver.default(node.name, "type");
|
|
18
|
-
return {
|
|
19
|
-
enumName: enumType === "asPascalConst" ? resolved : camelCase(node.name),
|
|
20
|
-
typeName: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? `${resolved}Key` : resolved,
|
|
21
|
-
refName: resolved
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Renders the enum declaration(s) for a single named `EnumSchemaNode`.
|
|
26
|
-
*
|
|
27
|
-
* Depending on `enumType` this may emit:
|
|
28
|
-
* - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias
|
|
29
|
-
* - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
|
|
30
|
-
* - A union literal type alias (`literal`)
|
|
31
|
-
*
|
|
32
|
-
* The emitted `File.Source` nodes carry the resolved names so that the barrel
|
|
33
|
-
* index picks up the correct export identifiers.
|
|
34
|
-
*/
|
|
35
|
-
function Enum({ node, enumType, enumKeyCasing, resolver }) {
|
|
36
|
-
const { enumName, typeName, refName } = getEnumNames({
|
|
37
|
-
node,
|
|
38
|
-
enumType,
|
|
39
|
-
resolver
|
|
40
|
-
});
|
|
41
|
-
const [nameNode, typeNode] = createEnumDeclaration({
|
|
42
|
-
name: enumName,
|
|
43
|
-
typeName,
|
|
44
|
-
enums: node.namedEnumValues?.map((v) => [trimQuotes(v.name.toString()), v.value]) ?? node.enumValues?.filter((v) => v !== null && v !== void 0).map((v) => [trimQuotes(v.toString()), v]) ?? [],
|
|
45
|
-
type: enumType,
|
|
46
|
-
enumKeyCasing
|
|
47
|
-
});
|
|
48
|
-
const needsRefAlias = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && refName !== typeName;
|
|
49
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
50
|
-
nameNode && /* @__PURE__ */ jsx(File.Source, {
|
|
51
|
-
name: enumName,
|
|
52
|
-
isExportable: true,
|
|
53
|
-
isIndexable: true,
|
|
54
|
-
isTypeOnly: false,
|
|
55
|
-
children: safePrint(nameNode)
|
|
56
|
-
}),
|
|
57
|
-
/* @__PURE__ */ jsx(File.Source, {
|
|
58
|
-
name: typeName,
|
|
59
|
-
isIndexable: true,
|
|
60
|
-
isExportable: ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
|
|
61
|
-
isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
|
|
62
|
-
children: safePrint(typeNode)
|
|
63
|
-
}),
|
|
64
|
-
needsRefAlias && /* @__PURE__ */ jsx(File.Source, {
|
|
65
|
-
name: refName,
|
|
66
|
-
isExportable: true,
|
|
67
|
-
isIndexable: true,
|
|
68
|
-
isTypeOnly: true,
|
|
69
|
-
children: `export type ${refName} = ${typeName}`
|
|
70
|
-
})
|
|
71
|
-
] });
|
|
72
|
-
}
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/components/Type.tsx
|
|
75
|
-
function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description, resolver }) {
|
|
76
|
-
const resolvedDescription = description || node?.description;
|
|
77
|
-
const enumSchemaNodes = collect(node, { schema(n) {
|
|
78
|
-
const enumNode = narrowSchema(n, schemaTypes.enum);
|
|
79
|
-
if (enumNode?.name) return enumNode;
|
|
80
|
-
} });
|
|
81
|
-
const output = printerTs({
|
|
82
|
-
optionalType,
|
|
83
|
-
arrayType,
|
|
84
|
-
enumType,
|
|
85
|
-
typeName: name,
|
|
86
|
-
syntaxType,
|
|
87
|
-
description: resolvedDescription,
|
|
88
|
-
keysToOmit,
|
|
89
|
-
resolver
|
|
90
|
-
}).print(node);
|
|
91
|
-
if (!output) return;
|
|
92
|
-
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
|
|
93
|
-
return {
|
|
94
|
-
node,
|
|
95
|
-
...getEnumNames({
|
|
96
|
-
node,
|
|
97
|
-
enumType,
|
|
98
|
-
resolver
|
|
99
|
-
})
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
const shouldExportEnums = enumType !== "inlineLiteral";
|
|
103
|
-
const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
104
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ jsx(Enum, {
|
|
105
|
-
node,
|
|
106
|
-
enumType,
|
|
107
|
-
enumKeyCasing,
|
|
108
|
-
resolver
|
|
109
|
-
})), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
|
|
110
|
-
name: typedName,
|
|
111
|
-
isTypeOnly: true,
|
|
112
|
-
isExportable: true,
|
|
113
|
-
isIndexable: true,
|
|
114
|
-
children: output
|
|
115
|
-
})] });
|
|
116
|
-
}
|
|
117
|
-
//#endregion
|
|
118
|
-
export { Enum as n, Type as t };
|
|
119
|
-
|
|
120
|
-
//# sourceMappingURL=Type-B6fo0gSk.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Type-B6fo0gSk.js","names":["factory.createEnumDeclaration"],"sources":["../src/components/Enum.tsx","../src/components/Type.tsx"],"sourcesContent":["import { camelCase, trimQuotes } from '@internals/utils'\nimport type { EnumSchemaNode } from '@kubb/ast/types'\nimport { safePrint } from '@kubb/fabric-core/parsers/typescript'\nimport { File } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport { ENUM_TYPES_WITH_KEY_SUFFIX, ENUM_TYPES_WITH_RUNTIME_VALUE, ENUM_TYPES_WITH_TYPE_ONLY } from '../constants.ts'\nimport * as factory from '../factory.ts'\nimport type { PluginTs, ResolverTs } from '../types.ts'\n\ntype Props = {\n node: EnumSchemaNode\n enumType: PluginTs['resolvedOptions']['enumType']\n enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing']\n resolver: ResolverTs\n}\n\n/**\n * Resolves the runtime identifier name and the TypeScript type name for an enum schema node.\n *\n * The raw `node.name` may be a YAML key such as `\"enumNames.Type\"` which is not a\n * valid TypeScript identifier. The resolver normalizes it; for inline enum\n * properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.\n */\nexport function getEnumNames({ node, enumType, resolver }: { node: EnumSchemaNode; enumType: PluginTs['resolvedOptions']['enumType']; resolver: ResolverTs }): {\n enumName: string\n typeName: string\n /**\n * The PascalCase name that `$ref` importers will use to reference this enum type.\n * For `asConst`/`asPascalConst` this differs from `typeName` (which has a `Key` suffix).\n */\n refName: string\n} {\n const resolved = resolver.default(node.name!, 'type')\n const enumName = enumType === 'asPascalConst' ? resolved : camelCase(node.name!)\n const typeName = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? `${resolved}Key` : resolved\n\n return { enumName, typeName, refName: resolved }\n}\n\n/**\n * Renders the enum declaration(s) for a single named `EnumSchemaNode`.\n *\n * Depending on `enumType` this may emit:\n * - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias\n * - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)\n * - A union literal type alias (`literal`)\n *\n * The emitted `File.Source` nodes carry the resolved names so that the barrel\n * index picks up the correct export identifiers.\n */\nexport function Enum({ node, enumType, enumKeyCasing, resolver }: Props): FabricReactNode {\n const { enumName, typeName, refName } = getEnumNames({ node, enumType, resolver })\n\n const [nameNode, typeNode] = factory.createEnumDeclaration({\n name: enumName,\n typeName,\n enums: (node.namedEnumValues?.map((v) => [trimQuotes(v.name.toString()), v.value]) ??\n node.enumValues?.filter((v): v is NonNullable<typeof v> => v !== null && v !== undefined).map((v) => [trimQuotes(v.toString()), v]) ??\n []) as unknown as Array<[string, string]>,\n type: enumType,\n enumKeyCasing,\n })\n\n const needsRefAlias = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && refName !== typeName\n\n return (\n <>\n {nameNode && (\n <File.Source name={enumName} isExportable isIndexable isTypeOnly={false}>\n {safePrint(nameNode)}\n </File.Source>\n )}\n <File.Source name={typeName} isIndexable isExportable={ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType)} isTypeOnly={ENUM_TYPES_WITH_TYPE_ONLY.has(enumType)}>\n {safePrint(typeNode)}\n </File.Source>\n {needsRefAlias && (\n <File.Source name={refName} isExportable isIndexable isTypeOnly>\n {`export type ${refName} = ${typeName}`}\n </File.Source>\n )}\n </>\n )\n}\n","import { collect, narrowSchema, schemaTypes } from '@kubb/ast'\nimport type { EnumSchemaNode, SchemaNode } from '@kubb/ast/types'\nimport { File } from '@kubb/react-fabric'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport { printerTs } from '../printers/printerTs.ts'\nimport type { PluginTs } from '../types.ts'\nimport { Enum, getEnumNames } from './Enum.tsx'\n\ntype Props = {\n name: string\n typedName: string\n node: SchemaNode\n optionalType: PluginTs['resolvedOptions']['optionalType']\n arrayType: PluginTs['resolvedOptions']['arrayType']\n enumType: PluginTs['resolvedOptions']['enumType']\n enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing']\n syntaxType: PluginTs['resolvedOptions']['syntaxType']\n resolver: PluginTs['resolvedOptions']['resolver']\n description?: string\n keysToOmit?: string[]\n}\n\nexport function Type({\n name,\n typedName,\n node,\n keysToOmit,\n optionalType,\n arrayType,\n syntaxType,\n enumType,\n enumKeyCasing,\n description,\n resolver,\n}: Props): FabricReactNode {\n const resolvedDescription = description || node?.description\n const enumSchemaNodes = collect<EnumSchemaNode>(node, {\n schema(n): EnumSchemaNode | undefined {\n const enumNode = narrowSchema(n, schemaTypes.enum)\n if (enumNode?.name) return enumNode\n },\n })\n\n const printer = printerTs({ optionalType, arrayType, enumType, typeName: name, syntaxType, description: resolvedDescription, keysToOmit, resolver })\n const output = printer.print(node)\n\n if (!output) {\n return\n }\n\n const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {\n return {\n node,\n ...getEnumNames({ node, enumType, resolver }),\n }\n })\n\n // Skip enum exports when using inlineLiteral\n const shouldExportEnums = enumType !== 'inlineLiteral'\n const shouldExportType = enumType === 'inlineLiteral' || enums.every((item) => item.typeName !== name)\n\n return (\n <>\n {shouldExportEnums && enums.map(({ node }) => <Enum node={node} enumType={enumType} enumKeyCasing={enumKeyCasing} resolver={resolver} />)}\n {shouldExportType && (\n <File.Source name={typedName} isTypeOnly isExportable isIndexable>\n {output}\n </File.Source>\n )}\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAuBA,SAAgB,aAAa,EAAE,MAAM,UAAU,YAQ7C;CACA,MAAM,WAAW,SAAS,QAAQ,KAAK,MAAO,OAAO;AAIrD,QAAO;EAAE,UAHQ,aAAa,kBAAkB,WAAW,UAAU,KAAK,KAAM;EAG7D,UAFF,2BAA2B,IAAI,SAAS,GAAG,GAAG,SAAS,OAAO;EAElD,SAAS;EAAU;;;;;;;;;;;;;AAclD,SAAgB,KAAK,EAAE,MAAM,UAAU,eAAe,YAAoC;CACxF,MAAM,EAAE,UAAU,UAAU,YAAY,aAAa;EAAE;EAAM;EAAU;EAAU,CAAC;CAElF,MAAM,CAAC,UAAU,YAAYA,sBAA8B;EACzD,MAAM;EACN;EACA,OAAQ,KAAK,iBAAiB,KAAK,MAAM,CAAC,WAAW,EAAE,KAAK,UAAU,CAAC,EAAE,EAAE,MAAM,CAAC,IAChF,KAAK,YAAY,QAAQ,MAAkC,MAAM,QAAQ,MAAM,KAAA,EAAU,CAAC,KAAK,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,IACnI,EAAE;EACJ,MAAM;EACN;EACD,CAAC;CAEF,MAAM,gBAAgB,2BAA2B,IAAI,SAAS,IAAI,YAAY;AAE9E,QACE,qBAAA,UAAA,EAAA,UAAA;EACG,YACC,oBAAC,KAAK,QAAN;GAAa,MAAM;GAAU,cAAA;GAAa,aAAA;GAAY,YAAY;aAC/D,UAAU,SAAS;GACR,CAAA;EAEhB,oBAAC,KAAK,QAAN;GAAa,MAAM;GAAU,aAAA;GAAY,cAAc,8BAA8B,IAAI,SAAS;GAAE,YAAY,0BAA0B,IAAI,SAAS;aACpJ,UAAU,SAAS;GACR,CAAA;EACb,iBACC,oBAAC,KAAK,QAAN;GAAa,MAAM;GAAS,cAAA;GAAa,aAAA;GAAY,YAAA;aAClD,eAAe,QAAQ,KAAK;GACjB,CAAA;EAEf,EAAA,CAAA;;;;AC1DP,SAAgB,KAAK,EACnB,MACA,WACA,MACA,YACA,cACA,WACA,YACA,UACA,eACA,aACA,YACyB;CACzB,MAAM,sBAAsB,eAAe,MAAM;CACjD,MAAM,kBAAkB,QAAwB,MAAM,EACpD,OAAO,GAA+B;EACpC,MAAM,WAAW,aAAa,GAAG,YAAY,KAAK;AAClD,MAAI,UAAU,KAAM,QAAO;IAE9B,CAAC;CAGF,MAAM,SADU,UAAU;EAAE;EAAc;EAAW;EAAU,UAAU;EAAM;EAAY,aAAa;EAAqB;EAAY;EAAU,CAAC,CAC7H,MAAM,KAAK;AAElC,KAAI,CAAC,OACH;CAGF,MAAM,QAAQ,CAAC,GAAG,IAAI,IAAI,gBAAgB,KAAK,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,SAAS;AACzF,SAAO;GACL;GACA,GAAG,aAAa;IAAE;IAAM;IAAU;IAAU,CAAC;GAC9C;GACD;CAGF,MAAM,oBAAoB,aAAa;CACvC,MAAM,mBAAmB,aAAa,mBAAmB,MAAM,OAAO,SAAS,KAAK,aAAa,KAAK;AAEtG,QACE,qBAAA,UAAA,EAAA,UAAA,CACG,qBAAqB,MAAM,KAAK,EAAE,WAAW,oBAAC,MAAD;EAAY;EAAgB;EAAyB;EAAyB;EAAY,CAAA,CAAC,EACxI,oBACC,oBAAC,KAAK,QAAN;EAAa,MAAM;EAAW,YAAA;EAAW,cAAA;EAAa,aAAA;YACnD;EACW,CAAA,CAEf,EAAA,CAAA"}
|