@kubb/plugin-oas 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.
- package/README.md +13 -4
- package/dist/OperationGenerator-CHXolL0o.d.cts +553 -0
- package/dist/OperationGenerator-CHXolL0o.d.ts +553 -0
- package/dist/Schema-Ch0dHkM5.d.ts +22 -0
- package/dist/Schema-ClNodlyP.d.cts +22 -0
- package/dist/chunk-6UWOTOZJ.cjs +92 -0
- package/dist/chunk-6UWOTOZJ.cjs.map +1 -0
- package/dist/chunk-AZKUU24F.js +700 -0
- package/dist/chunk-AZKUU24F.js.map +1 -0
- package/dist/chunk-DFQJ57GH.js +45 -0
- package/dist/chunk-DFQJ57GH.js.map +1 -0
- package/dist/chunk-GF26SDHQ.js +28 -0
- package/dist/chunk-GF26SDHQ.js.map +1 -0
- package/dist/chunk-HP5WAFBU.cjs +48 -0
- package/dist/chunk-HP5WAFBU.cjs.map +1 -0
- package/dist/chunk-JNGUNN72.cjs +708 -0
- package/dist/chunk-JNGUNN72.cjs.map +1 -0
- package/dist/chunk-PADR76WZ.cjs +4 -0
- package/dist/chunk-PADR76WZ.cjs.map +1 -0
- package/dist/chunk-R47XMJ32.js +3 -0
- package/dist/chunk-R47XMJ32.js.map +1 -0
- package/dist/{chunk-Y4V7HHX7.js → chunk-THGCWF2O.js} +8 -13
- package/dist/{chunk-Y4V7HHX7.js.map → chunk-THGCWF2O.js.map} +1 -1
- package/dist/chunk-TRA5BTWI.js +88 -0
- package/dist/chunk-TRA5BTWI.js.map +1 -0
- package/dist/chunk-UO57DZPV.cjs +36 -0
- package/dist/chunk-UO57DZPV.cjs.map +1 -0
- package/dist/chunk-ZWHQ54JM.cjs +32 -0
- package/dist/chunk-ZWHQ54JM.cjs.map +1 -0
- package/dist/components.cjs +20 -17
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +12 -8
- package/dist/components.d.ts +12 -8
- package/dist/components.js +3 -17
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +14 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +10 -0
- package/dist/generators.d.ts +10 -0
- package/dist/generators.js +5 -0
- package/dist/generators.js.map +1 -0
- package/dist/hooks.cjs +101 -57
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +40 -8
- package/dist/hooks.d.ts +40 -8
- package/dist/hooks.js +90 -53
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +283 -261
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -77
- package/dist/index.d.ts +6 -77
- package/dist/index.js +235 -240
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +32 -87
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -41
- package/dist/utils.d.ts +7 -41
- package/dist/utils.js +8 -86
- package/dist/utils.js.map +1 -1
- package/package.json +20 -14
- package/src/OperationGenerator.ts +75 -43
- package/src/SchemaGenerator.ts +44 -18
- package/src/SchemaMapper.ts +1 -1
- package/src/components/Oas.tsx +9 -3
- package/src/components/Operation.tsx +1 -1
- package/src/components/Schema.tsx +2 -102
- package/src/generator.tsx +133 -0
- package/src/generators/index.ts +1 -0
- package/src/generators/jsonGenerator.ts +32 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useOperationManager.ts +76 -28
- package/src/hooks/useSchemaManager.ts +77 -0
- package/src/index.ts +3 -9
- package/src/plugin.ts +64 -47
- package/src/types.ts +23 -12
- package/src/utils/getParams.ts +2 -2
- package/src/utils/index.ts +2 -2
- package/dist/OperationGenerator-CeM_9pxW.d.cts +0 -60
- package/dist/OperationGenerator-DhUhvRJE.d.ts +0 -60
- package/dist/Schema-DefwBJMc.d.ts +0 -35
- package/dist/Schema-an5hOrjZ.d.cts +0 -35
- package/dist/SchemaMapper-CsBQ6eEx.d.cts +0 -248
- package/dist/SchemaMapper-CsBQ6eEx.d.ts +0 -248
- package/dist/chunk-CJXRFYEF.cjs +0 -698
- package/dist/chunk-CJXRFYEF.cjs.map +0 -1
- package/dist/chunk-DRLYORTT.cjs +0 -3265
- package/dist/chunk-DRLYORTT.cjs.map +0 -1
- package/dist/chunk-K6KUETAI.js +0 -698
- package/dist/chunk-K6KUETAI.js.map +0 -1
- package/dist/chunk-LEACSHKT.js +0 -3265
- package/dist/chunk-LEACSHKT.js.map +0 -1
- package/dist/chunk-P42X362U.cjs +0 -101
- package/dist/chunk-P42X362U.cjs.map +0 -1
- package/dist/chunk-QLJIL3U5.cjs +0 -35
- package/dist/chunk-QLJIL3U5.cjs.map +0 -1
- package/dist/chunk-UB552H4J.js +0 -101
- package/dist/chunk-UB552H4J.js.map +0 -1
- package/dist/types-Dte3MA6H.d.cts +0 -143
- package/dist/types-Dte3MA6H.d.ts +0 -143
- package/src/utils/getGroupedByTagFiles.ts +0 -82
- package/src/utils/refSorter.ts +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-oas",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.21",
|
|
4
4
|
"description": "Generator swagger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -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
|
"./utils": {
|
|
29
34
|
"import": "./dist/utils.js",
|
|
30
35
|
"require": "./dist/utils.cjs",
|
|
@@ -56,6 +61,9 @@
|
|
|
56
61
|
],
|
|
57
62
|
"components": [
|
|
58
63
|
"./dist/components.d.ts"
|
|
64
|
+
],
|
|
65
|
+
"generators": [
|
|
66
|
+
"./dist/generators.d.ts"
|
|
59
67
|
]
|
|
60
68
|
}
|
|
61
69
|
},
|
|
@@ -67,24 +75,22 @@
|
|
|
67
75
|
],
|
|
68
76
|
"dependencies": {
|
|
69
77
|
"@stoplight/yaml": "^4.3.0",
|
|
70
|
-
"remeda": "^2.
|
|
71
|
-
"@kubb/core": "3.0.0-alpha.
|
|
72
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
73
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
74
|
-
"@kubb/react": "3.0.0-alpha.
|
|
78
|
+
"remeda": "^2.14.0",
|
|
79
|
+
"@kubb/core": "3.0.0-alpha.21",
|
|
80
|
+
"@kubb/fs": "3.0.0-alpha.21",
|
|
81
|
+
"@kubb/oas": "3.0.0-alpha.21",
|
|
82
|
+
"@kubb/react": "3.0.0-alpha.21"
|
|
75
83
|
},
|
|
76
84
|
"devDependencies": {
|
|
77
|
-
"@types/react": "^18.3.
|
|
78
|
-
"@types/react-dom": "^18.3.0",
|
|
85
|
+
"@types/react": "^18.3.8",
|
|
79
86
|
"react": "^18.3.1",
|
|
80
|
-
"tsup": "^8.
|
|
81
|
-
"typescript": "^5.
|
|
82
|
-
"@kubb/config-
|
|
83
|
-
"@kubb/config-
|
|
84
|
-
"@kubb/config-tsup": "3.0.0-alpha.2"
|
|
87
|
+
"tsup": "^8.3.0",
|
|
88
|
+
"typescript": "^5.6.2",
|
|
89
|
+
"@kubb/config-ts": "3.0.0-alpha.21",
|
|
90
|
+
"@kubb/config-tsup": "3.0.0-alpha.21"
|
|
85
91
|
},
|
|
86
92
|
"peerDependencies": {
|
|
87
|
-
"@kubb/react": "3.0.0-alpha.
|
|
93
|
+
"@kubb/react": "3.0.0-alpha.21"
|
|
88
94
|
},
|
|
89
95
|
"engines": {
|
|
90
96
|
"node": ">=20"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FileMetaBase
|
|
1
|
+
import { BaseGenerator, type FileMetaBase } from '@kubb/core'
|
|
2
2
|
import transformers from '@kubb/core/transformers'
|
|
3
3
|
|
|
4
4
|
import type { PluginFactoryOptions, PluginManager } from '@kubb/core'
|
|
@@ -6,9 +6,13 @@ import type * as KubbFile from '@kubb/fs/types'
|
|
|
6
6
|
|
|
7
7
|
import type { Plugin } from '@kubb/core'
|
|
8
8
|
import type { HttpMethod, Oas, OasTypes, Operation, contentType } from '@kubb/oas'
|
|
9
|
+
import type { Generator } from './generator.tsx'
|
|
9
10
|
import type { Exclude, Include, OperationSchemas, OperationsByMethod, Override } from './types.ts'
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated
|
|
14
|
+
*/
|
|
15
|
+
export type GetOperationGeneratorOptions<T = any> = any
|
|
12
16
|
|
|
13
17
|
export type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>
|
|
14
18
|
|
|
@@ -26,11 +30,10 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
26
30
|
mode: KubbFile.Mode
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
export
|
|
30
|
-
TOptions = unknown,
|
|
33
|
+
export class OperationGenerator<
|
|
31
34
|
TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,
|
|
32
35
|
TFileMeta extends FileMetaBase = FileMetaBase,
|
|
33
|
-
> extends
|
|
36
|
+
> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {
|
|
34
37
|
#operationsByMethod: OperationsByMethod = {}
|
|
35
38
|
get operationsByMethod(): OperationsByMethod {
|
|
36
39
|
return this.#operationsByMethod
|
|
@@ -40,7 +43,7 @@ export abstract class OperationGenerator<
|
|
|
40
43
|
this.#operationsByMethod = paths
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
#getOptions(operation: Operation, method: HttpMethod): Partial<
|
|
46
|
+
#getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']> {
|
|
44
47
|
const { override = [] } = this.context
|
|
45
48
|
|
|
46
49
|
return (
|
|
@@ -65,6 +68,7 @@ export abstract class OperationGenerator<
|
|
|
65
68
|
})?.options || {}
|
|
66
69
|
)
|
|
67
70
|
}
|
|
71
|
+
|
|
68
72
|
/**
|
|
69
73
|
*
|
|
70
74
|
* @deprecated
|
|
@@ -93,6 +97,7 @@ export abstract class OperationGenerator<
|
|
|
93
97
|
|
|
94
98
|
return matched
|
|
95
99
|
}
|
|
100
|
+
|
|
96
101
|
/**
|
|
97
102
|
*
|
|
98
103
|
* @deprecated
|
|
@@ -124,14 +129,17 @@ export abstract class OperationGenerator<
|
|
|
124
129
|
|
|
125
130
|
getSchemas(
|
|
126
131
|
operation: Operation,
|
|
127
|
-
{
|
|
132
|
+
{
|
|
133
|
+
resolveName = (name) => name,
|
|
134
|
+
}: {
|
|
135
|
+
resolveName?: (name: string) => string
|
|
136
|
+
} = {},
|
|
128
137
|
): OperationSchemas {
|
|
129
138
|
const pathParamsSchema = this.context.oas.getParametersSchema(operation, 'path')
|
|
130
139
|
const queryParamsSchema = this.context.oas.getParametersSchema(operation, 'query')
|
|
131
140
|
const headerParamsSchema = this.context.oas.getParametersSchema(operation, 'header')
|
|
132
141
|
const requestSchema = this.context.oas.getRequestSchema(operation)
|
|
133
|
-
const responseStatusCode =
|
|
134
|
-
forStatusCode || (operation.schema.responses && Object.keys(operation.schema.responses).find((key) => key.startsWith('2'))) || 200
|
|
142
|
+
const responseStatusCode = (operation.schema.responses && Object.keys(operation.schema.responses).find((key) => key.startsWith('2'))) || 200
|
|
135
143
|
const responseSchema = this.context.oas.getResponseSchema(operation, responseStatusCode)
|
|
136
144
|
const statusCodes = operation.getResponseStatusCodes().map((statusCode) => {
|
|
137
145
|
let name = statusCode
|
|
@@ -217,20 +225,9 @@ export abstract class OperationGenerator<
|
|
|
217
225
|
}
|
|
218
226
|
}
|
|
219
227
|
|
|
220
|
-
|
|
221
|
-
return {
|
|
222
|
-
get: this.get,
|
|
223
|
-
post: this.post,
|
|
224
|
-
patch: this.patch,
|
|
225
|
-
put: this.put,
|
|
226
|
-
delete: this.delete,
|
|
227
|
-
head: undefined,
|
|
228
|
-
options: undefined,
|
|
229
|
-
trace: undefined,
|
|
230
|
-
} as const
|
|
231
|
-
}
|
|
228
|
+
#methods = ['get', 'post', 'patch', 'put', 'delete']
|
|
232
229
|
|
|
233
|
-
async build(): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
230
|
+
async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
234
231
|
const { oas } = this.context
|
|
235
232
|
|
|
236
233
|
const paths = oas.getPaths()
|
|
@@ -239,7 +236,7 @@ export abstract class OperationGenerator<
|
|
|
239
236
|
|
|
240
237
|
methods.forEach((method) => {
|
|
241
238
|
const operation = oas.operation(path, method)
|
|
242
|
-
if (operation && this.#methods
|
|
239
|
+
if (operation && [this.#methods].some((methods) => method === operation.method)) {
|
|
243
240
|
const isExcluded = this.#isExcluded(operation, method)
|
|
244
241
|
const isIncluded = this.context.include ? this.#isIncluded(operation, method) : true
|
|
245
242
|
|
|
@@ -267,21 +264,43 @@ export abstract class OperationGenerator<
|
|
|
267
264
|
methods.forEach((method) => {
|
|
268
265
|
const { operation } = this.operationsByMethod[path]?.[method]!
|
|
269
266
|
const options = this.#getOptions(operation, method)
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
267
|
+
|
|
268
|
+
const methodToCall = this[method as keyof typeof this] as any
|
|
269
|
+
|
|
270
|
+
if (typeof methodToCall === 'function') {
|
|
271
|
+
const promiseMethod = methodToCall?.call(this, operation, {
|
|
272
|
+
...this.options,
|
|
273
|
+
...options,
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
if (promiseMethod) {
|
|
277
|
+
acc.push(promiseMethod)
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
274
281
|
const promiseOperation = this.operation.call(this, operation, {
|
|
275
282
|
...this.options,
|
|
276
283
|
...options,
|
|
277
284
|
})
|
|
278
285
|
|
|
279
|
-
if (promiseMethod) {
|
|
280
|
-
acc.push(promiseMethod)
|
|
281
|
-
}
|
|
282
286
|
if (promiseOperation) {
|
|
283
287
|
acc.push(promiseOperation)
|
|
284
288
|
}
|
|
289
|
+
|
|
290
|
+
generators?.forEach((generator) => {
|
|
291
|
+
const promise = generator.operation?.({
|
|
292
|
+
instance: this,
|
|
293
|
+
operation,
|
|
294
|
+
options: {
|
|
295
|
+
...this.options,
|
|
296
|
+
...options,
|
|
297
|
+
},
|
|
298
|
+
} as any) as Promise<Array<KubbFile.File<TFileMeta>>>
|
|
299
|
+
|
|
300
|
+
if (promise) {
|
|
301
|
+
acc.push(promise)
|
|
302
|
+
}
|
|
303
|
+
})
|
|
285
304
|
})
|
|
286
305
|
|
|
287
306
|
return acc
|
|
@@ -291,6 +310,19 @@ export abstract class OperationGenerator<
|
|
|
291
310
|
|
|
292
311
|
promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod))
|
|
293
312
|
|
|
313
|
+
generators?.forEach((generator) => {
|
|
314
|
+
const promise = generator.operations?.({
|
|
315
|
+
instance: this,
|
|
316
|
+
operations: operations.flat().filter(Boolean),
|
|
317
|
+
operationsByMethod: this.operationsByMethod,
|
|
318
|
+
options: this.options,
|
|
319
|
+
} as any) as Promise<Array<KubbFile.File<TFileMeta>>>
|
|
320
|
+
|
|
321
|
+
if (promise) {
|
|
322
|
+
promises.push(promise)
|
|
323
|
+
}
|
|
324
|
+
})
|
|
325
|
+
|
|
294
326
|
const files = await Promise.all(promises)
|
|
295
327
|
|
|
296
328
|
// using .flat because operationGenerator[method] can return a array of files or just one file
|
|
@@ -300,48 +332,48 @@ export abstract class OperationGenerator<
|
|
|
300
332
|
/**
|
|
301
333
|
* Operation
|
|
302
334
|
*/
|
|
303
|
-
async operation(operation: Operation, options:
|
|
304
|
-
return
|
|
335
|
+
async operation(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
336
|
+
return []
|
|
305
337
|
}
|
|
306
338
|
|
|
307
339
|
/**
|
|
308
340
|
* GET
|
|
309
341
|
*/
|
|
310
|
-
async get(operation: Operation, options:
|
|
311
|
-
return
|
|
342
|
+
async get(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
343
|
+
return []
|
|
312
344
|
}
|
|
313
345
|
|
|
314
346
|
/**
|
|
315
347
|
* POST
|
|
316
348
|
*/
|
|
317
|
-
async post(operation: Operation, options:
|
|
318
|
-
return
|
|
349
|
+
async post(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
350
|
+
return []
|
|
319
351
|
}
|
|
320
352
|
/**
|
|
321
353
|
* PATCH
|
|
322
354
|
*/
|
|
323
|
-
async patch(operation: Operation, options:
|
|
324
|
-
return
|
|
355
|
+
async patch(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
356
|
+
return []
|
|
325
357
|
}
|
|
326
358
|
|
|
327
359
|
/**
|
|
328
360
|
* PUT
|
|
329
361
|
*/
|
|
330
|
-
async put(operation: Operation, options:
|
|
331
|
-
return
|
|
362
|
+
async put(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
363
|
+
return []
|
|
332
364
|
}
|
|
333
365
|
|
|
334
366
|
/**
|
|
335
367
|
* DELETE
|
|
336
368
|
*/
|
|
337
|
-
async delete(operation: Operation, options:
|
|
338
|
-
return
|
|
369
|
+
async delete(operation: Operation, options: TPluginOptions['resolvedOptions']): OperationMethodResult<TFileMeta> {
|
|
370
|
+
return []
|
|
339
371
|
}
|
|
340
372
|
|
|
341
373
|
/**
|
|
342
374
|
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
343
375
|
*/
|
|
344
376
|
async all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta> {
|
|
345
|
-
return
|
|
377
|
+
return []
|
|
346
378
|
}
|
|
347
379
|
}
|
package/src/SchemaGenerator.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FileMetaBase
|
|
1
|
+
import { BaseGenerator, type FileMetaBase } from '@kubb/core'
|
|
2
2
|
import transformers, { pascalCase } from '@kubb/core/transformers'
|
|
3
3
|
import { getUniqueName } from '@kubb/core/utils'
|
|
4
4
|
|
|
@@ -13,6 +13,7 @@ import type * as KubbFile from '@kubb/fs/types'
|
|
|
13
13
|
|
|
14
14
|
import type { Oas, OpenAPIV3, SchemaObject, contentType } from '@kubb/oas'
|
|
15
15
|
import type { Schema, SchemaKeywordMapper } from './SchemaMapper.ts'
|
|
16
|
+
import type { Generator } from './generator.tsx'
|
|
16
17
|
import type { OperationSchema, Override, Refs } from './types.ts'
|
|
17
18
|
|
|
18
19
|
export type GetSchemaGeneratorOptions<T extends SchemaGenerator<any, any, any>> = T extends SchemaGenerator<infer Options, any, any> ? Options : never
|
|
@@ -63,11 +64,11 @@ type SchemaProps = {
|
|
|
63
64
|
parentName?: string
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
export
|
|
67
|
+
export class SchemaGenerator<
|
|
67
68
|
TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions,
|
|
68
69
|
TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,
|
|
69
70
|
TFileMeta extends FileMetaBase = FileMetaBase,
|
|
70
|
-
> extends
|
|
71
|
+
> extends BaseGenerator<TOptions, Context<TOptions, TPluginOptions>> {
|
|
71
72
|
// Collect the types of all referenced schemas, so we can export them later
|
|
72
73
|
refs: Refs = {}
|
|
73
74
|
|
|
@@ -360,7 +361,7 @@ export abstract class SchemaGenerator<
|
|
|
360
361
|
return [
|
|
361
362
|
{
|
|
362
363
|
keyword: schemaKeywords.ref,
|
|
363
|
-
args: { name: ref.propertyName, path: ref?.path
|
|
364
|
+
args: { name: ref.propertyName, path: ref?.path },
|
|
364
365
|
},
|
|
365
366
|
]
|
|
366
367
|
}
|
|
@@ -378,12 +379,6 @@ export abstract class SchemaGenerator<
|
|
|
378
379
|
const options = this.#getOptions({ schema: _schema, name })
|
|
379
380
|
const unknownReturn = this.#getUnknownReturn({ schema: _schema, name })
|
|
380
381
|
const { schema, version } = this.#getParsedSchemaObject(_schema)
|
|
381
|
-
const resolvedName = this.context.pluginManager.resolveName({
|
|
382
|
-
name: `${parentName || ''} ${name}`,
|
|
383
|
-
pluginKey: this.context.plugin.key,
|
|
384
|
-
type: 'type',
|
|
385
|
-
})
|
|
386
|
-
|
|
387
382
|
if (!schema) {
|
|
388
383
|
return [{ keyword: unknownReturn }]
|
|
389
384
|
}
|
|
@@ -407,12 +402,16 @@ export abstract class SchemaGenerator<
|
|
|
407
402
|
keyword: schemaKeywords.default,
|
|
408
403
|
args: transformers.stringify(schema.default),
|
|
409
404
|
})
|
|
410
|
-
}
|
|
411
|
-
if (typeof schema.default === 'boolean') {
|
|
405
|
+
} else if (typeof schema.default === 'boolean') {
|
|
412
406
|
baseItems.push({
|
|
413
407
|
keyword: schemaKeywords.default,
|
|
414
408
|
args: schema.default ?? false,
|
|
415
409
|
})
|
|
410
|
+
} else {
|
|
411
|
+
baseItems.push({
|
|
412
|
+
keyword: schemaKeywords.default,
|
|
413
|
+
args: schema.default,
|
|
414
|
+
})
|
|
416
415
|
}
|
|
417
416
|
}
|
|
418
417
|
|
|
@@ -809,7 +808,7 @@ export abstract class SchemaGenerator<
|
|
|
809
808
|
].filter(Boolean)
|
|
810
809
|
}
|
|
811
810
|
|
|
812
|
-
if (!['boolean', 'object', 'number', 'string', 'integer'].includes(schema.type)) {
|
|
811
|
+
if (!['boolean', 'object', 'number', 'string', 'integer', 'null'].includes(schema.type)) {
|
|
813
812
|
this.context.pluginManager.logger.emit('warning', `Schema type '${schema.type}' is not valid for schema ${parentName}.${name}`)
|
|
814
813
|
}
|
|
815
814
|
|
|
@@ -820,14 +819,18 @@ export abstract class SchemaGenerator<
|
|
|
820
819
|
return [{ keyword: unknownReturn }]
|
|
821
820
|
}
|
|
822
821
|
|
|
823
|
-
async build(): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
822
|
+
async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
824
823
|
const { oas, contentType, include } = this.context
|
|
825
824
|
|
|
826
825
|
const schemas = getSchemas({ oas, contentType, includes: include })
|
|
827
826
|
|
|
828
|
-
const promises = Object.entries(schemas).reduce((acc, [name,
|
|
827
|
+
const promises = Object.entries(schemas).reduce((acc, [name, value]) => {
|
|
828
|
+
if (!value) {
|
|
829
|
+
return acc
|
|
830
|
+
}
|
|
831
|
+
|
|
829
832
|
const options = this.#getOptions({ name })
|
|
830
|
-
const promiseOperation = this.schema.call(this, name,
|
|
833
|
+
const promiseOperation = this.schema.call(this, name, value, {
|
|
831
834
|
...this.options,
|
|
832
835
|
...options,
|
|
833
836
|
})
|
|
@@ -836,17 +839,40 @@ export abstract class SchemaGenerator<
|
|
|
836
839
|
acc.push(promiseOperation)
|
|
837
840
|
}
|
|
838
841
|
|
|
842
|
+
generators?.forEach((generator) => {
|
|
843
|
+
const tree = this.parse({ schema: value, name: name })
|
|
844
|
+
|
|
845
|
+
const promise = generator.schema?.({
|
|
846
|
+
instance: this,
|
|
847
|
+
schema: {
|
|
848
|
+
name,
|
|
849
|
+
value,
|
|
850
|
+
tree,
|
|
851
|
+
},
|
|
852
|
+
options: {
|
|
853
|
+
...this.options,
|
|
854
|
+
...options,
|
|
855
|
+
},
|
|
856
|
+
} as any) as Promise<Array<KubbFile.File<TFileMeta>>>
|
|
857
|
+
|
|
858
|
+
if (promise) {
|
|
859
|
+
acc.push(promise)
|
|
860
|
+
}
|
|
861
|
+
})
|
|
862
|
+
|
|
839
863
|
return acc
|
|
840
864
|
}, [] as SchemaMethodResult<TFileMeta>[])
|
|
841
865
|
|
|
842
866
|
const files = await Promise.all(promises)
|
|
843
867
|
|
|
844
|
-
// using .flat because schemaGenerator[method] can return
|
|
868
|
+
// using .flat because schemaGenerator[method] can return an array of files or just one file
|
|
845
869
|
return files.flat().filter(Boolean)
|
|
846
870
|
}
|
|
847
871
|
|
|
848
872
|
/**
|
|
849
873
|
* Schema
|
|
850
874
|
*/
|
|
851
|
-
|
|
875
|
+
async schema(name: string, object: SchemaObject, options: TOptions): SchemaMethodResult<TFileMeta> {
|
|
876
|
+
return []
|
|
877
|
+
}
|
|
852
878
|
}
|
package/src/SchemaMapper.ts
CHANGED
|
@@ -51,7 +51,7 @@ export type SchemaKeywordMapper = {
|
|
|
51
51
|
union: { keyword: 'union'; args: Schema[] }
|
|
52
52
|
ref: {
|
|
53
53
|
keyword: 'ref'
|
|
54
|
-
args: { name: string; path: KubbFile.OptionalPath
|
|
54
|
+
args: { name: string; path: KubbFile.OptionalPath }
|
|
55
55
|
}
|
|
56
56
|
matches: { keyword: 'matches'; args?: string }
|
|
57
57
|
boolean: { keyword: 'boolean' }
|
package/src/components/Oas.tsx
CHANGED
|
@@ -4,20 +4,26 @@ import { Operation } from './Operation.tsx'
|
|
|
4
4
|
import { Schema } from './Schema.tsx'
|
|
5
5
|
|
|
6
6
|
import type { Oas as OasType, Operation as OperationType } from '@kubb/oas'
|
|
7
|
-
import type { KubbNode } from '@kubb/react'
|
|
7
|
+
import type { KubbNode } from '@kubb/react/types'
|
|
8
8
|
import type { OperationGenerator } from '../OperationGenerator.ts'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
11
11
|
oas: OasType
|
|
12
12
|
operations?: OperationType[]
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated
|
|
15
|
+
*/
|
|
16
|
+
generator?: Omit<OperationGenerator, 'build'>
|
|
14
17
|
children?: KubbNode
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
type OasContextProps = {
|
|
18
21
|
oas?: OasType
|
|
19
22
|
operations?: OperationType[]
|
|
20
|
-
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated
|
|
25
|
+
*/
|
|
26
|
+
generator?: Omit<OperationGenerator, 'build'>
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
const OasContext = createContext<OasContextProps>({})
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createContext } from '@kubb/react'
|
|
2
2
|
|
|
3
|
-
import { schemaKeywords } from '../SchemaMapper.ts'
|
|
4
|
-
import { useSchema } from '../hooks/useSchema.ts'
|
|
5
|
-
|
|
6
|
-
import type * as KubbFile from '@kubb/fs/types'
|
|
7
3
|
import type { SchemaObject } from '@kubb/oas'
|
|
8
|
-
import type { KubbNode } from '@kubb/react'
|
|
9
|
-
import type { ReactNode } from 'react'
|
|
10
|
-
import { SchemaGenerator } from '../SchemaGenerator.ts'
|
|
4
|
+
import type { KubbNode } from '@kubb/react/types'
|
|
11
5
|
import type { Schema as SchemaType } from '../SchemaMapper.ts'
|
|
12
|
-
import type { PluginOas } from '../types.ts'
|
|
13
6
|
|
|
14
7
|
export type SchemaContextProps = {
|
|
15
8
|
name: string
|
|
@@ -33,97 +26,4 @@ export function Schema({ name, value, tree = [], children }: Props): KubbNode {
|
|
|
33
26
|
return <SchemaContext.Provider value={{ name, schema: value, tree }}>{children}</SchemaContext.Provider>
|
|
34
27
|
}
|
|
35
28
|
|
|
36
|
-
type FileProps = {
|
|
37
|
-
isTypeOnly?: boolean
|
|
38
|
-
output: string | undefined
|
|
39
|
-
children?: KubbNode
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
Schema.File = function ({ output, isTypeOnly, children }: FileProps): ReactNode {
|
|
43
|
-
const { plugin, pluginManager, mode } = useApp<PluginOas>()
|
|
44
|
-
const { name } = useSchema()
|
|
45
|
-
|
|
46
|
-
if (mode === 'single') {
|
|
47
|
-
const baseName = output as KubbFile.BaseName
|
|
48
|
-
const resolvedPath = pluginManager.resolvePath({
|
|
49
|
-
baseName: '',
|
|
50
|
-
pluginKey: plugin.key,
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
if (!resolvedPath) {
|
|
54
|
-
return null
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<Parser language="typescript">
|
|
59
|
-
<File
|
|
60
|
-
baseName={baseName}
|
|
61
|
-
path={resolvedPath}
|
|
62
|
-
meta={{
|
|
63
|
-
pluginKey: plugin.key,
|
|
64
|
-
}}
|
|
65
|
-
>
|
|
66
|
-
{children}
|
|
67
|
-
</File>
|
|
68
|
-
</Parser>
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const baseName = `${pluginManager.resolveName({
|
|
73
|
-
name,
|
|
74
|
-
pluginKey: plugin.key,
|
|
75
|
-
type: 'file',
|
|
76
|
-
})}.ts` as const
|
|
77
|
-
const resolvedPath = pluginManager.resolvePath({
|
|
78
|
-
baseName,
|
|
79
|
-
pluginKey: plugin.key,
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
if (!resolvedPath) {
|
|
83
|
-
return null
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return (
|
|
87
|
-
<Parser language="typescript">
|
|
88
|
-
<File
|
|
89
|
-
baseName={baseName}
|
|
90
|
-
path={resolvedPath}
|
|
91
|
-
meta={{
|
|
92
|
-
pluginKey: plugin.key,
|
|
93
|
-
}}
|
|
94
|
-
>
|
|
95
|
-
<Schema.Imports isTypeOnly={isTypeOnly} />
|
|
96
|
-
{children}
|
|
97
|
-
</File>
|
|
98
|
-
</Parser>
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
type SchemaImportsProps = {
|
|
103
|
-
isTypeOnly?: boolean
|
|
104
|
-
extName?: KubbFile.Extname
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
Schema.Imports = ({ isTypeOnly, extName }: SchemaImportsProps): ReactNode => {
|
|
108
|
-
const { tree } = useSchema()
|
|
109
|
-
const { path: root } = useFile()
|
|
110
|
-
|
|
111
|
-
const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)
|
|
112
|
-
|
|
113
|
-
return (
|
|
114
|
-
<>
|
|
115
|
-
{refs
|
|
116
|
-
?.map((item, i) => {
|
|
117
|
-
if (!item.args.path) {
|
|
118
|
-
return undefined
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return (
|
|
122
|
-
<File.Import key={i} extName={extName} root={root} name={[item.args.name]} path={item.args.path} isTypeOnly={item.args.isTypeOnly ?? isTypeOnly} />
|
|
123
|
-
)
|
|
124
|
-
})
|
|
125
|
-
.filter(Boolean)}
|
|
126
|
-
</>
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
29
|
Schema.Context = SchemaContext
|