@kubb/plugin-oas 3.0.0-alpha.1 → 3.0.0-alpha.11
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/OperationGenerator-By5WOmWB.d.ts +165 -0
- package/dist/OperationGenerator-Gd1X7wUz.d.cts +165 -0
- package/dist/{Schema-DefwBJMc.d.ts → Schema-B1vcPGiK.d.ts} +3 -5
- package/dist/{Schema-an5hOrjZ.d.cts → Schema-DoSFh7Qd.d.cts} +3 -5
- package/dist/{SchemaMapper-CsBQ6eEx.d.cts → SchemaMapper-sGcY1xL5.d.cts} +1 -2
- package/dist/{SchemaMapper-CsBQ6eEx.d.ts → SchemaMapper-sGcY1xL5.d.ts} +1 -2
- package/dist/{chunk-LEACSHKT.js → chunk-2X5GZFQP.js} +712 -44
- package/dist/chunk-2X5GZFQP.js.map +1 -0
- package/dist/{chunk-DRLYORTT.cjs → chunk-47SNBYWH.cjs} +750 -69
- package/dist/chunk-47SNBYWH.cjs.map +1 -0
- package/dist/{chunk-UB552H4J.js → chunk-4VKHSKYX.js} +7 -24
- package/dist/{chunk-UB552H4J.js.map → chunk-4VKHSKYX.js.map} +1 -1
- package/dist/{chunk-Y4V7HHX7.js → chunk-4WUMV7QX.js} +9 -12
- package/dist/chunk-4WUMV7QX.js.map +1 -0
- package/dist/chunk-6AVEWDKE.cjs +8 -0
- package/dist/chunk-6AVEWDKE.cjs.map +1 -0
- package/dist/chunk-S6RFFHLW.cjs +38 -0
- package/dist/chunk-S6RFFHLW.cjs.map +1 -0
- package/dist/chunk-WN5S6RCU.js +6 -0
- package/dist/chunk-WN5S6RCU.js.map +1 -0
- package/dist/chunk-XQPCA75E.cjs +90 -0
- package/dist/chunk-XQPCA75E.cjs.map +1 -0
- package/dist/components.cjs +21 -17
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +13 -7
- package/dist/components.d.ts +13 -7
- package/dist/components.js +4 -17
- package/dist/components.js.map +1 -1
- package/dist/hooks.cjs +30 -35
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +4 -4
- package/dist/hooks.d.ts +4 -4
- package/dist/hooks.js +10 -23
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +315 -262
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -77
- package/dist/index.d.ts +8 -77
- package/dist/index.js +270 -239
- package/dist/index.js.map +1 -1
- package/dist/{types-Dte3MA6H.d.cts → types-CZTUCaE5.d.cts} +3 -1
- package/dist/{types-Dte3MA6H.d.ts → types-CZTUCaE5.d.ts} +3 -1
- package/dist/utils.cjs +39 -73
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -33
- package/dist/utils.d.ts +7 -33
- package/dist/utils.js +10 -67
- package/dist/utils.js.map +1 -1
- package/package.json +11 -10
- package/src/OperationGenerator.ts +68 -32
- package/src/SchemaGenerator.ts +32 -15
- 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 +29 -31
- package/src/generator.tsx +125 -0
- package/src/hooks/useOperationManager.ts +1 -0
- package/src/index.ts +3 -9
- package/src/plugin.ts +25 -38
- package/src/types.ts +2 -0
- package/src/utils/getParams.ts +1 -1
- package/src/utils/index.ts +2 -1
- package/dist/OperationGenerator-CeM_9pxW.d.cts +0 -60
- package/dist/OperationGenerator-DhUhvRJE.d.ts +0 -60
- package/dist/chunk-CJXRFYEF.cjs +0 -698
- package/dist/chunk-CJXRFYEF.cjs.map +0 -1
- 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.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-Y4V7HHX7.js.map +0 -1
- package/src/utils/getGroupedByTagFiles.ts +0 -82
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.11",
|
|
4
4
|
"description": "Generator swagger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -67,24 +67,25 @@
|
|
|
67
67
|
],
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@stoplight/yaml": "^4.3.0",
|
|
70
|
+
"execa": "^9.3.1",
|
|
70
71
|
"remeda": "^2.11.0",
|
|
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.
|
|
72
|
+
"@kubb/core": "3.0.0-alpha.11",
|
|
73
|
+
"@kubb/fs": "3.0.0-alpha.11",
|
|
74
|
+
"@kubb/oas": "3.0.0-alpha.11",
|
|
75
|
+
"@kubb/react": "3.0.0-alpha.11"
|
|
75
76
|
},
|
|
76
77
|
"devDependencies": {
|
|
77
|
-
"@types/react": "^18.3.
|
|
78
|
+
"@types/react": "^18.3.5",
|
|
78
79
|
"@types/react-dom": "^18.3.0",
|
|
79
80
|
"react": "^18.3.1",
|
|
80
81
|
"tsup": "^8.2.4",
|
|
81
82
|
"typescript": "^5.5.4",
|
|
82
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
83
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
84
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
83
|
+
"@kubb/config-biome": "3.0.0-alpha.11",
|
|
84
|
+
"@kubb/config-ts": "3.0.0-alpha.11",
|
|
85
|
+
"@kubb/config-tsup": "3.0.0-alpha.11"
|
|
85
86
|
},
|
|
86
87
|
"peerDependencies": {
|
|
87
|
-
"@kubb/react": "3.0.0-alpha.
|
|
88
|
+
"@kubb/react": "3.0.0-alpha.11"
|
|
88
89
|
},
|
|
89
90
|
"engines": {
|
|
90
91
|
"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,8 +6,12 @@ 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
|
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated
|
|
14
|
+
*/
|
|
11
15
|
export type GetOperationGeneratorOptions<T extends OperationGenerator<any, any, any>> = T extends OperationGenerator<infer Options, any, any> ? Options : never
|
|
12
16
|
|
|
13
17
|
export type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>
|
|
@@ -26,11 +30,11 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
26
30
|
mode: KubbFile.Mode
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
export
|
|
33
|
+
export class OperationGenerator<
|
|
30
34
|
TOptions = unknown,
|
|
31
35
|
TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,
|
|
32
36
|
TFileMeta extends FileMetaBase = FileMetaBase,
|
|
33
|
-
> extends
|
|
37
|
+
> extends BaseGenerator<TOptions, Context<TOptions, TPluginOptions>> {
|
|
34
38
|
#operationsByMethod: OperationsByMethod = {}
|
|
35
39
|
get operationsByMethod(): OperationsByMethod {
|
|
36
40
|
return this.#operationsByMethod
|
|
@@ -65,6 +69,7 @@ export abstract class OperationGenerator<
|
|
|
65
69
|
})?.options || {}
|
|
66
70
|
)
|
|
67
71
|
}
|
|
72
|
+
|
|
68
73
|
/**
|
|
69
74
|
*
|
|
70
75
|
* @deprecated
|
|
@@ -93,6 +98,7 @@ export abstract class OperationGenerator<
|
|
|
93
98
|
|
|
94
99
|
return matched
|
|
95
100
|
}
|
|
101
|
+
|
|
96
102
|
/**
|
|
97
103
|
*
|
|
98
104
|
* @deprecated
|
|
@@ -124,7 +130,13 @@ export abstract class OperationGenerator<
|
|
|
124
130
|
|
|
125
131
|
getSchemas(
|
|
126
132
|
operation: Operation,
|
|
127
|
-
{
|
|
133
|
+
{
|
|
134
|
+
forStatusCode,
|
|
135
|
+
resolveName = (name) => name,
|
|
136
|
+
}: {
|
|
137
|
+
forStatusCode?: string | number
|
|
138
|
+
resolveName?: (name: string) => string
|
|
139
|
+
} = {},
|
|
128
140
|
): OperationSchemas {
|
|
129
141
|
const pathParamsSchema = this.context.oas.getParametersSchema(operation, 'path')
|
|
130
142
|
const queryParamsSchema = this.context.oas.getParametersSchema(operation, 'query')
|
|
@@ -217,20 +229,9 @@ export abstract class OperationGenerator<
|
|
|
217
229
|
}
|
|
218
230
|
}
|
|
219
231
|
|
|
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
|
-
}
|
|
232
|
+
#methods = ['get', 'post', 'patch', 'put', 'delete']
|
|
232
233
|
|
|
233
|
-
async build(): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
234
|
+
async build(...generators: Array<Generator<Extract<TOptions, PluginFactoryOptions>>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
234
235
|
const { oas } = this.context
|
|
235
236
|
|
|
236
237
|
const paths = oas.getPaths()
|
|
@@ -239,7 +240,7 @@ export abstract class OperationGenerator<
|
|
|
239
240
|
|
|
240
241
|
methods.forEach((method) => {
|
|
241
242
|
const operation = oas.operation(path, method)
|
|
242
|
-
if (operation && this.#methods
|
|
243
|
+
if (operation && [this.#methods].some((methods) => method === operation.method)) {
|
|
243
244
|
const isExcluded = this.#isExcluded(operation, method)
|
|
244
245
|
const isIncluded = this.context.include ? this.#isIncluded(operation, method) : true
|
|
245
246
|
|
|
@@ -267,21 +268,43 @@ export abstract class OperationGenerator<
|
|
|
267
268
|
methods.forEach((method) => {
|
|
268
269
|
const { operation } = this.operationsByMethod[path]?.[method]!
|
|
269
270
|
const options = this.#getOptions(operation, method)
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
271
|
+
|
|
272
|
+
const methodToCall = this[method as keyof typeof this] as any
|
|
273
|
+
|
|
274
|
+
if (typeof methodToCall === 'function') {
|
|
275
|
+
const promiseMethod = methodToCall?.call(this, operation, {
|
|
276
|
+
...this.options,
|
|
277
|
+
...options,
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
if (promiseMethod) {
|
|
281
|
+
acc.push(promiseMethod)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
274
285
|
const promiseOperation = this.operation.call(this, operation, {
|
|
275
286
|
...this.options,
|
|
276
287
|
...options,
|
|
277
288
|
})
|
|
278
289
|
|
|
279
|
-
if (promiseMethod) {
|
|
280
|
-
acc.push(promiseMethod)
|
|
281
|
-
}
|
|
282
290
|
if (promiseOperation) {
|
|
283
291
|
acc.push(promiseOperation)
|
|
284
292
|
}
|
|
293
|
+
|
|
294
|
+
generators?.forEach((generator) => {
|
|
295
|
+
const promise = generator.operation?.({
|
|
296
|
+
instance: this,
|
|
297
|
+
operation,
|
|
298
|
+
options: {
|
|
299
|
+
...this.options,
|
|
300
|
+
...options,
|
|
301
|
+
},
|
|
302
|
+
} as any) as Promise<Array<KubbFile.File<TFileMeta>>>
|
|
303
|
+
|
|
304
|
+
if (promise) {
|
|
305
|
+
acc.push(promise)
|
|
306
|
+
}
|
|
307
|
+
})
|
|
285
308
|
})
|
|
286
309
|
|
|
287
310
|
return acc
|
|
@@ -291,6 +314,19 @@ export abstract class OperationGenerator<
|
|
|
291
314
|
|
|
292
315
|
promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod))
|
|
293
316
|
|
|
317
|
+
generators?.forEach((generator) => {
|
|
318
|
+
const promise = generator.operations?.({
|
|
319
|
+
instance: this,
|
|
320
|
+
operations: operations.flat().filter(Boolean),
|
|
321
|
+
operationsByMethod: this.operationsByMethod,
|
|
322
|
+
options: this.options,
|
|
323
|
+
} as any) as Promise<Array<KubbFile.File<TFileMeta>>>
|
|
324
|
+
|
|
325
|
+
if (promise) {
|
|
326
|
+
promises.push(promise)
|
|
327
|
+
}
|
|
328
|
+
})
|
|
329
|
+
|
|
294
330
|
const files = await Promise.all(promises)
|
|
295
331
|
|
|
296
332
|
// using .flat because operationGenerator[method] can return a array of files or just one file
|
|
@@ -301,47 +337,47 @@ export abstract class OperationGenerator<
|
|
|
301
337
|
* Operation
|
|
302
338
|
*/
|
|
303
339
|
async operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
304
|
-
return
|
|
340
|
+
return []
|
|
305
341
|
}
|
|
306
342
|
|
|
307
343
|
/**
|
|
308
344
|
* GET
|
|
309
345
|
*/
|
|
310
346
|
async get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
311
|
-
return
|
|
347
|
+
return []
|
|
312
348
|
}
|
|
313
349
|
|
|
314
350
|
/**
|
|
315
351
|
* POST
|
|
316
352
|
*/
|
|
317
353
|
async post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
318
|
-
return
|
|
354
|
+
return []
|
|
319
355
|
}
|
|
320
356
|
/**
|
|
321
357
|
* PATCH
|
|
322
358
|
*/
|
|
323
359
|
async patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
324
|
-
return
|
|
360
|
+
return []
|
|
325
361
|
}
|
|
326
362
|
|
|
327
363
|
/**
|
|
328
364
|
* PUT
|
|
329
365
|
*/
|
|
330
366
|
async put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
331
|
-
return
|
|
367
|
+
return []
|
|
332
368
|
}
|
|
333
369
|
|
|
334
370
|
/**
|
|
335
371
|
* DELETE
|
|
336
372
|
*/
|
|
337
373
|
async delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
338
|
-
return
|
|
374
|
+
return []
|
|
339
375
|
}
|
|
340
376
|
|
|
341
377
|
/**
|
|
342
378
|
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
343
379
|
*/
|
|
344
380
|
async all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta> {
|
|
345
|
-
return
|
|
381
|
+
return []
|
|
346
382
|
}
|
|
347
383
|
}
|
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
|
|
|
@@ -820,7 +819,7 @@ 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<Extract<TOptions, PluginFactoryOptions>>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
824
823
|
const { oas, contentType, include } = this.context
|
|
825
824
|
|
|
826
825
|
const schemas = getSchemas({ oas, contentType, includes: include })
|
|
@@ -836,17 +835,35 @@ export abstract class SchemaGenerator<
|
|
|
836
835
|
acc.push(promiseOperation)
|
|
837
836
|
}
|
|
838
837
|
|
|
838
|
+
generators?.forEach((generator) => {
|
|
839
|
+
const promise = generator.schema?.({
|
|
840
|
+
instance: this,
|
|
841
|
+
name,
|
|
842
|
+
schema,
|
|
843
|
+
options: {
|
|
844
|
+
...this.options,
|
|
845
|
+
...options,
|
|
846
|
+
},
|
|
847
|
+
} as any) as Promise<Array<KubbFile.File<TFileMeta>>>
|
|
848
|
+
|
|
849
|
+
if (promise) {
|
|
850
|
+
acc.push(promise)
|
|
851
|
+
}
|
|
852
|
+
})
|
|
853
|
+
|
|
839
854
|
return acc
|
|
840
855
|
}, [] as SchemaMethodResult<TFileMeta>[])
|
|
841
856
|
|
|
842
857
|
const files = await Promise.all(promises)
|
|
843
858
|
|
|
844
|
-
// using .flat because schemaGenerator[method] can return
|
|
859
|
+
// using .flat because schemaGenerator[method] can return an array of files or just one file
|
|
845
860
|
return files.flat().filter(Boolean)
|
|
846
861
|
}
|
|
847
862
|
|
|
848
863
|
/**
|
|
849
864
|
* Schema
|
|
850
865
|
*/
|
|
851
|
-
|
|
866
|
+
async schema(name: string, object: SchemaObject, options: TOptions): SchemaMethodResult<TFileMeta> {
|
|
867
|
+
return []
|
|
868
|
+
}
|
|
852
869
|
}
|
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,11 +1,11 @@
|
|
|
1
|
-
import { File,
|
|
1
|
+
import { File, createContext, useApp, useFile } from '@kubb/react'
|
|
2
2
|
|
|
3
3
|
import { schemaKeywords } from '../SchemaMapper.ts'
|
|
4
4
|
import { useSchema } from '../hooks/useSchema.ts'
|
|
5
5
|
|
|
6
6
|
import type * as KubbFile from '@kubb/fs/types'
|
|
7
7
|
import type { SchemaObject } from '@kubb/oas'
|
|
8
|
-
import type { KubbNode } from '@kubb/react'
|
|
8
|
+
import type { KubbNode } from '@kubb/react/types'
|
|
9
9
|
import type { ReactNode } from 'react'
|
|
10
10
|
import { SchemaGenerator } from '../SchemaGenerator.ts'
|
|
11
11
|
import type { Schema as SchemaType } from '../SchemaMapper.ts'
|
|
@@ -44,7 +44,12 @@ Schema.File = function ({ output, isTypeOnly, children }: FileProps): ReactNode
|
|
|
44
44
|
const { name } = useSchema()
|
|
45
45
|
|
|
46
46
|
if (mode === 'single') {
|
|
47
|
-
const baseName =
|
|
47
|
+
const baseName = `${pluginManager.resolveName({
|
|
48
|
+
name,
|
|
49
|
+
pluginKey: plugin.key,
|
|
50
|
+
type: 'file',
|
|
51
|
+
})}.ts` as const
|
|
52
|
+
|
|
48
53
|
const resolvedPath = pluginManager.resolvePath({
|
|
49
54
|
baseName: '',
|
|
50
55
|
pluginKey: plugin.key,
|
|
@@ -55,17 +60,15 @@ Schema.File = function ({ output, isTypeOnly, children }: FileProps): ReactNode
|
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
return (
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
</File>
|
|
68
|
-
</Parser>
|
|
63
|
+
<File
|
|
64
|
+
baseName={baseName}
|
|
65
|
+
path={resolvedPath}
|
|
66
|
+
meta={{
|
|
67
|
+
pluginKey: plugin.key,
|
|
68
|
+
}}
|
|
69
|
+
>
|
|
70
|
+
{children}
|
|
71
|
+
</File>
|
|
69
72
|
)
|
|
70
73
|
}
|
|
71
74
|
|
|
@@ -84,27 +87,24 @@ Schema.File = function ({ output, isTypeOnly, children }: FileProps): ReactNode
|
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
return (
|
|
87
|
-
<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
</File>
|
|
98
|
-
</Parser>
|
|
90
|
+
<File
|
|
91
|
+
baseName={baseName}
|
|
92
|
+
path={resolvedPath}
|
|
93
|
+
meta={{
|
|
94
|
+
pluginKey: plugin.key,
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
<Schema.Imports isTypeOnly={isTypeOnly} />
|
|
98
|
+
{children}
|
|
99
|
+
</File>
|
|
99
100
|
)
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
type SchemaImportsProps = {
|
|
103
104
|
isTypeOnly?: boolean
|
|
104
|
-
extName?: KubbFile.Extname
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
Schema.Imports = ({ isTypeOnly
|
|
107
|
+
Schema.Imports = ({ isTypeOnly }: SchemaImportsProps): ReactNode => {
|
|
108
108
|
const { tree } = useSchema()
|
|
109
109
|
const { path: root } = useFile()
|
|
110
110
|
|
|
@@ -118,9 +118,7 @@ Schema.Imports = ({ isTypeOnly, extName }: SchemaImportsProps): ReactNode => {
|
|
|
118
118
|
return undefined
|
|
119
119
|
}
|
|
120
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
|
-
)
|
|
121
|
+
return <File.Import key={i} root={root} name={[item.args.name]} path={item.args.path} isTypeOnly={isTypeOnly} />
|
|
124
122
|
})
|
|
125
123
|
.filter(Boolean)}
|
|
126
124
|
</>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { PluginFactoryOptions } from '@kubb/core'
|
|
2
|
+
import type * as KubbFile from '@kubb/fs/types'
|
|
3
|
+
import type { Operation, SchemaObject } from '@kubb/oas'
|
|
4
|
+
import { Oas } from '@kubb/plugin-oas/components'
|
|
5
|
+
import { App, createRoot } from '@kubb/react'
|
|
6
|
+
import type { KubbNode } from '@kubb/react/types'
|
|
7
|
+
import type { OperationGenerator } from './OperationGenerator.ts'
|
|
8
|
+
import type { SchemaGenerator, SchemaGeneratorOptions } from './SchemaGenerator.ts'
|
|
9
|
+
import type { OperationsByMethod } from './types.ts'
|
|
10
|
+
|
|
11
|
+
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
12
|
+
instance: Omit<OperationGenerator<TOptions>, 'build'>
|
|
13
|
+
options: TOptions['resolvedOptions']
|
|
14
|
+
operations: Array<Operation>
|
|
15
|
+
operationsByMethod: OperationsByMethod
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
19
|
+
instance: Omit<OperationGenerator<TOptions>, 'build'>
|
|
20
|
+
options: TOptions['resolvedOptions']
|
|
21
|
+
operation: Operation
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
25
|
+
instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>
|
|
26
|
+
name: string
|
|
27
|
+
schema: SchemaObject
|
|
28
|
+
options: TOptions['resolvedOptions']
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type GeneratorOptions<TOptions extends PluginFactoryOptions> = {
|
|
32
|
+
name: string
|
|
33
|
+
operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>
|
|
34
|
+
operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>
|
|
35
|
+
schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>
|
|
39
|
+
|
|
40
|
+
export function createGenerator<TOptions extends PluginFactoryOptions>(parseOptions: GeneratorOptions<TOptions>): Generator<TOptions> {
|
|
41
|
+
return parseOptions
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type ReactGeneratorOptions<TOptions extends PluginFactoryOptions> = {
|
|
45
|
+
name: string
|
|
46
|
+
Operations?: (props: OperationsProps<TOptions>) => KubbNode
|
|
47
|
+
Operation?: (props: OperationProps<TOptions>) => KubbNode
|
|
48
|
+
Schema?: (props: SchemaProps<TOptions>) => KubbNode
|
|
49
|
+
/**
|
|
50
|
+
* Combine all react nodes and only render ones(to string or render)
|
|
51
|
+
*/
|
|
52
|
+
render?: () => any
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function createReactGenerator<TOptions extends PluginFactoryOptions>(parseOptions: ReactGeneratorOptions<TOptions>): Generator<TOptions> {
|
|
56
|
+
return {
|
|
57
|
+
...parseOptions,
|
|
58
|
+
async operations({ instance, options, operations, operationsByMethod }) {
|
|
59
|
+
if (!parseOptions.Operations) {
|
|
60
|
+
return []
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { pluginManager, oas, plugin, mode } = instance.context
|
|
64
|
+
const root = createRoot({
|
|
65
|
+
logger: pluginManager.logger,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
root.render(
|
|
69
|
+
<App pluginManager={pluginManager} plugin={plugin} mode={mode}>
|
|
70
|
+
<Oas oas={oas} operations={operations} generator={instance}>
|
|
71
|
+
<parseOptions.Operations operations={operations} instance={instance} operationsByMethod={operationsByMethod} options={options} />
|
|
72
|
+
</Oas>
|
|
73
|
+
</App>,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
return root.files
|
|
77
|
+
},
|
|
78
|
+
async operation({ instance, operation, options }) {
|
|
79
|
+
if (!parseOptions.Operation) {
|
|
80
|
+
return []
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const { pluginManager, oas, plugin, mode } = instance.context
|
|
84
|
+
const root = createRoot({
|
|
85
|
+
logger: pluginManager.logger,
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
root.render(
|
|
89
|
+
<App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
|
|
90
|
+
<Oas oas={oas} operations={[operation]} generator={instance}>
|
|
91
|
+
<Oas.Operation operation={operation}>
|
|
92
|
+
<parseOptions.Operation operation={operation} options={options} instance={instance} />
|
|
93
|
+
</Oas.Operation>
|
|
94
|
+
</Oas>
|
|
95
|
+
</App>,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
return root.files
|
|
99
|
+
},
|
|
100
|
+
async schema({ instance, schema, name, options }) {
|
|
101
|
+
if (!parseOptions.Schema) {
|
|
102
|
+
return []
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const { pluginManager, oas, plugin, mode } = instance.context
|
|
106
|
+
const root = createRoot({
|
|
107
|
+
logger: pluginManager.logger,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
const tree = instance.parse({ schema, name })
|
|
111
|
+
|
|
112
|
+
root.render(
|
|
113
|
+
<App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
|
|
114
|
+
<Oas oas={oas}>
|
|
115
|
+
<Oas.Schema name={name} value={schema} tree={tree}>
|
|
116
|
+
<parseOptions.Schema schema={schema} options={options} instance={instance} name={name} />
|
|
117
|
+
</Oas.Schema>
|
|
118
|
+
</Oas>
|
|
119
|
+
</App>,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
return root.files
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -57,6 +57,7 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
57
57
|
const getFile: UseOperationManagerResult['getFile'] = (operation, { pluginKey = plugin.key, extName = '.ts' } = {}) => {
|
|
58
58
|
// needed for the `output.group`
|
|
59
59
|
const tag = operation.getTags().at(0)?.name
|
|
60
|
+
//TODO replace with group
|
|
60
61
|
const name = getName(operation, { type: 'file', pluginKey })
|
|
61
62
|
|
|
62
63
|
const file = pluginManager.getFile({
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { pluginOas } from './plugin.ts'
|
|
2
|
-
|
|
3
1
|
export type {
|
|
4
2
|
GetOperationGeneratorOptions,
|
|
5
3
|
OperationMethodResult,
|
|
@@ -22,10 +20,6 @@ export type {
|
|
|
22
20
|
} from './SchemaMapper.ts'
|
|
23
21
|
export { isKeyword, schemaKeywords } from './SchemaMapper.ts'
|
|
24
22
|
export type * from './types.ts'
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
const definePluginDefault = pluginOas
|
|
30
|
-
|
|
31
|
-
export default definePluginDefault
|
|
23
|
+
export { createGenerator, createReactGenerator } from './generator.tsx'
|
|
24
|
+
export type { ReactGeneratorOptions } from './generator.tsx'
|
|
25
|
+
export type { Generator, GeneratorOptions } from './generator.tsx'
|