@kubb/plugin-oas 3.0.0-alpha.0 → 3.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/OperationGenerator-By5WOmWB.d.ts +165 -0
  2. package/dist/OperationGenerator-Gd1X7wUz.d.cts +165 -0
  3. package/dist/{Schema-DefwBJMc.d.ts → Schema-B1vcPGiK.d.ts} +3 -5
  4. package/dist/{Schema-an5hOrjZ.d.cts → Schema-DoSFh7Qd.d.cts} +3 -5
  5. package/dist/{SchemaMapper-CsBQ6eEx.d.cts → SchemaMapper-sGcY1xL5.d.cts} +1 -2
  6. package/dist/{SchemaMapper-CsBQ6eEx.d.ts → SchemaMapper-sGcY1xL5.d.ts} +1 -2
  7. package/dist/chunk-75BIOXB7.cjs +7 -0
  8. package/dist/chunk-75BIOXB7.cjs.map +1 -0
  9. package/dist/{chunk-UKUEVTRB.cjs → chunk-IAUV3UKH.cjs} +735 -35
  10. package/dist/chunk-IAUV3UKH.cjs.map +1 -0
  11. package/dist/{chunk-QSM6A5QX.js → chunk-M347763D.js} +714 -14
  12. package/dist/chunk-M347763D.js.map +1 -0
  13. package/dist/{chunk-GUPCIAYT.js → chunk-N7EEVJA6.js} +3 -3
  14. package/dist/{chunk-J7IF3KA3.cjs → chunk-NU4F7G47.cjs} +4 -16
  15. package/dist/chunk-NU4F7G47.cjs.map +1 -0
  16. package/dist/{chunk-3UN2S6P2.cjs → chunk-O76YQFZB.cjs} +3 -3
  17. package/dist/{chunk-3UN2S6P2.cjs.map → chunk-O76YQFZB.cjs.map} +1 -1
  18. package/dist/chunk-SQ64ESS4.js +7 -0
  19. package/dist/chunk-SQ64ESS4.js.map +1 -0
  20. package/dist/{chunk-Y272OQMW.js → chunk-SZDO532A.js} +3 -15
  21. package/dist/chunk-SZDO532A.js.map +1 -0
  22. package/dist/components.cjs +4 -9
  23. package/dist/components.cjs.map +1 -1
  24. package/dist/components.d.cts +13 -7
  25. package/dist/components.d.ts +13 -7
  26. package/dist/components.js +3 -8
  27. package/dist/components.js.map +1 -1
  28. package/dist/hooks.cjs +12 -13
  29. package/dist/hooks.cjs.map +1 -1
  30. package/dist/hooks.d.cts +4 -4
  31. package/dist/hooks.d.ts +4 -4
  32. package/dist/hooks.js +2 -3
  33. package/dist/hooks.js.map +1 -1
  34. package/dist/index.cjs +282 -231
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +8 -77
  37. package/dist/index.d.ts +8 -77
  38. package/dist/index.js +274 -223
  39. package/dist/index.js.map +1 -1
  40. package/dist/{types-BP45TdiW.d.cts → types-CZTUCaE5.d.cts} +3 -6
  41. package/dist/{types-BP45TdiW.d.ts → types-CZTUCaE5.d.ts} +3 -6
  42. package/dist/utils.cjs +12 -54
  43. package/dist/utils.cjs.map +1 -1
  44. package/dist/utils.d.cts +7 -33
  45. package/dist/utils.d.ts +7 -33
  46. package/dist/utils.js +6 -48
  47. package/dist/utils.js.map +1 -1
  48. package/package.json +12 -11
  49. package/src/OperationGenerator.ts +68 -32
  50. package/src/SchemaGenerator.ts +32 -15
  51. package/src/SchemaMapper.ts +1 -1
  52. package/src/components/Oas.tsx +9 -3
  53. package/src/components/Operation.tsx +1 -1
  54. package/src/components/Schema.tsx +29 -31
  55. package/src/generator.tsx +125 -0
  56. package/src/hooks/useOperationManager.ts +1 -0
  57. package/src/index.ts +3 -9
  58. package/src/plugin.ts +25 -38
  59. package/src/types.ts +2 -6
  60. package/src/utils/getParams.ts +1 -1
  61. package/src/utils/index.ts +2 -1
  62. package/dist/OperationGenerator-B0RLFu4P.d.ts +0 -60
  63. package/dist/OperationGenerator-CrCcKl3S.d.cts +0 -60
  64. package/dist/chunk-J7IF3KA3.cjs.map +0 -1
  65. package/dist/chunk-K4GEQ3C2.cjs +0 -698
  66. package/dist/chunk-K4GEQ3C2.cjs.map +0 -1
  67. package/dist/chunk-QSM6A5QX.js.map +0 -1
  68. package/dist/chunk-UKUEVTRB.cjs.map +0 -1
  69. package/dist/chunk-Y272OQMW.js.map +0 -1
  70. package/dist/chunk-ZZ7ZC4TT.js +0 -698
  71. package/dist/chunk-ZZ7ZC4TT.js.map +0 -1
  72. package/src/utils/getGroupedByTagFiles.ts +0 -82
  73. /package/dist/{chunk-GUPCIAYT.js.map → chunk-N7EEVJA6.js.map} +0 -0
@@ -1,4 +1,4 @@
1
- import { type FileMetaBase, Generator } from '@kubb/core'
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 abstract class OperationGenerator<
33
+ export class OperationGenerator<
30
34
  TOptions = unknown,
31
35
  TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,
32
36
  TFileMeta extends FileMetaBase = FileMetaBase,
33
- > extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
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
- { forStatusCode, resolveName = (name) => name }: { forStatusCode?: string | number; resolveName?: (name: string) => string } = {},
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
- get #methods() {
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[method]) {
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
- const promiseMethod = this.#methods[method]?.call(this, operation, {
271
- ...this.options,
272
- ...options,
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 null
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 null
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 null
354
+ return []
319
355
  }
320
356
  /**
321
357
  * PATCH
322
358
  */
323
359
  async patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
324
- return null
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 null
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 null
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 null
381
+ return []
346
382
  }
347
383
  }
@@ -1,4 +1,4 @@
1
- import { type FileMetaBase, Generator } from '@kubb/core'
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 abstract class SchemaGenerator<
67
+ export class SchemaGenerator<
67
68
  TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions,
68
69
  TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,
69
70
  TFileMeta extends FileMetaBase = FileMetaBase,
70
- > extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
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, isTypeOnly: false },
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 a array of files or just one file
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
- abstract schema(name: string, object: SchemaObject, options: TOptions): SchemaMethodResult<TFileMeta>
866
+ async schema(name: string, object: SchemaObject, options: TOptions): SchemaMethodResult<TFileMeta> {
867
+ return []
868
+ }
852
869
  }
@@ -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; isTypeOnly?: boolean }
54
+ args: { name: string; path: KubbFile.OptionalPath }
55
55
  }
56
56
  matches: { keyword: 'matches'; args?: string }
57
57
  boolean: { keyword: 'boolean' }
@@ -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
- generator?: OperationGenerator
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
- generator?: OperationGenerator
23
+ /**
24
+ * @deprecated
25
+ */
26
+ generator?: Omit<OperationGenerator, 'build'>
21
27
  }
22
28
 
23
29
  const OasContext = createContext<OasContextProps>({})
@@ -1,7 +1,7 @@
1
1
  import { createContext } from '@kubb/react'
2
2
 
3
3
  import type { Operation as OperationType } from '@kubb/oas'
4
- import type { KubbNode } from '@kubb/react'
4
+ import type { KubbNode } from '@kubb/react/types'
5
5
 
6
6
  type Props = {
7
7
  operation: OperationType
@@ -1,11 +1,11 @@
1
- import { File, Parser, createContext, useApp, useFile } from '@kubb/react'
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 = output as KubbFile.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
- <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>
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
- <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>
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, extName }: SchemaImportsProps): ReactNode => {
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
- * @deprecated Use `import { pluginOas } from '@kubb/plugin-oas'` instead
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'