@kubb/plugin-oas 5.0.0-alpha.3 → 5.0.0-alpha.5

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 (39) hide show
  1. package/dist/{createGenerator-jtR_okrd.d.ts → createGenerator-B_7cgcmg.d.ts} +33 -59
  2. package/dist/{generators-vAAte6w6.cjs → generators-D_7I5QrN.cjs} +3 -3
  3. package/dist/generators-D_7I5QrN.cjs.map +1 -0
  4. package/dist/{generators-B8HiBWvT.js → generators-DxN9Dqyi.js} +3 -3
  5. package/dist/generators-DxN9Dqyi.js.map +1 -0
  6. package/dist/generators.cjs +1 -1
  7. package/dist/generators.d.ts +2 -2
  8. package/dist/generators.js +1 -1
  9. package/dist/hooks.cjs +4 -1
  10. package/dist/hooks.cjs.map +1 -1
  11. package/dist/hooks.d.ts +4 -1
  12. package/dist/hooks.js +5 -2
  13. package/dist/hooks.js.map +1 -1
  14. package/dist/index.cjs +2 -2
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.ts +16 -13
  17. package/dist/index.js +2 -2
  18. package/dist/index.js.map +1 -1
  19. package/dist/{requestBody-BJJL0mpy.cjs → requestBody-BWo89xcg.cjs} +13 -13
  20. package/dist/requestBody-BWo89xcg.cjs.map +1 -0
  21. package/dist/{requestBody-CSL-jLGQ.js → requestBody-Cs-1vKOq.js} +14 -14
  22. package/dist/requestBody-Cs-1vKOq.js.map +1 -0
  23. package/dist/utils.cjs +1 -1
  24. package/dist/utils.d.ts +1 -1
  25. package/dist/utils.js +1 -1
  26. package/package.json +7 -7
  27. package/src/OperationGenerator.ts +5 -6
  28. package/src/SchemaGenerator.ts +6 -10
  29. package/src/generators/createGenerator.ts +12 -15
  30. package/src/generators/createReactGenerator.ts +12 -15
  31. package/src/generators/types.ts +5 -43
  32. package/src/hooks/useOas.ts +5 -2
  33. package/src/index.ts +1 -1
  34. package/src/types.ts +3 -2
  35. package/src/utils.tsx +34 -29
  36. package/dist/generators-B8HiBWvT.js.map +0 -1
  37. package/dist/generators-vAAte6w6.cjs.map +0 -1
  38. package/dist/requestBody-BJJL0mpy.cjs.map +0 -1
  39. package/dist/requestBody-CSL-jLGQ.js.map +0 -1
package/dist/utils.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("./chunk-ByKO4r7w.cjs");
3
3
  const require_getFooter = require("./getFooter-BBzsC616.cjs");
4
- const require_requestBody = require("./requestBody-BJJL0mpy.cjs");
4
+ const require_requestBody = require("./requestBody-BWo89xcg.cjs");
5
5
  const require_SchemaMapper = require("./SchemaMapper-CeavHZlp.cjs");
6
6
  let _kubb_oas = require("@kubb/oas");
7
7
  //#region ../../internals/utils/src/reserved.ts
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { g as OperationSchema } from "./createGenerator-jtR_okrd.js";
2
+ import { h as OperationSchema } from "./createGenerator-B_7cgcmg.js";
3
3
  import { t as Schema } from "./SchemaMapper-SneuY1wg.js";
4
4
  import { Oas, OasTypes, OpenAPIV3, OpenAPIV3_1, Operation, SchemaObject, contentType, isOptional } from "@kubb/oas";
5
5
  import { Config, FunctionParamsAST, Output } from "@kubb/core";
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./chunk--u3MIqq1.js";
2
2
  import { n as getBanner, r as camelCase, t as getFooter } from "./getFooter-Pw3tLCiV.js";
3
- import { n as withRequiredRequestBodySchema, r as SchemaGenerator, s as getSchemaFactory, t as isRequestBodyRequired } from "./requestBody-CSL-jLGQ.js";
3
+ import { n as withRequiredRequestBodySchema, r as SchemaGenerator, s as getSchemaFactory, t as isRequestBodyRequired } from "./requestBody-Cs-1vKOq.js";
4
4
  import { n as schemaKeywords } from "./SchemaMapper-CqMkO2T1.js";
5
5
  import { isOptional } from "@kubb/oas";
6
6
  //#region ../../internals/utils/src/reserved.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-oas",
3
- "version": "5.0.0-alpha.3",
3
+ "version": "5.0.0-alpha.5",
4
4
  "description": "OpenAPI Specification (OAS) plugin for Kubb, providing core functionality for parsing and processing OpenAPI/Swagger schemas for code generation.",
5
5
  "keywords": [
6
6
  "openapi",
@@ -81,15 +81,15 @@
81
81
  }
82
82
  ],
83
83
  "dependencies": {
84
- "@kubb/fabric-core": "0.13.3",
85
- "@kubb/react-fabric": "0.13.3",
84
+ "@kubb/fabric-core": "0.14.0",
85
+ "@kubb/react-fabric": "0.14.0",
86
86
  "remeda": "^2.33.6",
87
- "@kubb/core": "5.0.0-alpha.3",
88
- "@kubb/oas": "5.0.0-alpha.3"
87
+ "@kubb/core": "5.0.0-alpha.5",
88
+ "@kubb/oas": "5.0.0-alpha.5"
89
89
  },
90
90
  "peerDependencies": {
91
- "@kubb/fabric-core": "0.13.3",
92
- "@kubb/react-fabric": "0.13.3"
91
+ "@kubb/fabric-core": "0.14.0",
92
+ "@kubb/react-fabric": "0.14.0"
93
93
  },
94
94
  "engines": {
95
95
  "node": ">=22"
@@ -1,12 +1,11 @@
1
1
  import { pascalCase } from '@internals/utils'
2
2
  import type { AsyncEventEmitter, FileMetaBase, KubbEvents, Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'
3
- import type { KubbFile } from '@kubb/fabric-core/types'
3
+ import type { Fabric as FabricType, KubbFile } from '@kubb/fabric-core/types'
4
4
  import type { contentType, HttpMethod, Oas, OasTypes, Operation, SchemaObject } from '@kubb/oas'
5
- import type { Fabric } from '@kubb/react-fabric'
6
5
  import pLimit from 'p-limit'
7
6
  import type { CoreGenerator } from './generators/createGenerator.ts'
8
7
  import type { ReactGenerator } from './generators/createReactGenerator.ts'
9
- import type { Generator, Version } from './generators/types.ts'
8
+ import type { Generator } from './generators/types.ts'
10
9
  import type { Exclude, Include, OperationSchemas, Override } from './types.ts'
11
10
  import { withRequiredRequestBodySchema } from './utils/requestBody.ts'
12
11
  import { buildOperation, buildOperations } from './utils.tsx'
@@ -14,7 +13,7 @@ import { buildOperation, buildOperations } from './utils.tsx'
14
13
  export type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>
15
14
 
16
15
  type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
17
- fabric: Fabric
16
+ fabric: FabricType
18
17
  oas: Oas
19
18
  exclude: Array<Exclude> | undefined
20
19
  include: Array<Include> | undefined
@@ -206,7 +205,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
206
205
  )
207
206
  }
208
207
 
209
- async build(...generators: Array<Generator<TPluginOptions, Version>>): Promise<Array<KubbFile.File<TFileMeta>>> {
208
+ async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
210
209
  const operations = await this.getOperations()
211
210
 
212
211
  // Increased parallelism for better performance
@@ -227,7 +226,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
227
226
  }
228
227
 
229
228
  // After the v2 guard above, all generators here are v1
230
- const v1Generator = generator as ReactGenerator<TPluginOptions, '1'> | CoreGenerator<TPluginOptions, '1'>
229
+ const v1Generator = generator as ReactGenerator<TPluginOptions> | CoreGenerator<TPluginOptions>
231
230
 
232
231
  const operationTasks = operations.map(({ operation, method }) =>
233
232
  operationLimit(async () => {
@@ -1,14 +1,13 @@
1
1
  import { getUniqueName, pascalCase, stringify } from '@internals/utils'
2
2
  import type { AsyncEventEmitter, FileMetaBase, KubbEvents, Plugin, PluginFactoryOptions, PluginManager, ResolveNameParams } from '@kubb/core'
3
- import type { KubbFile } from '@kubb/fabric-core/types'
3
+ import type { Fabric as FabricType, KubbFile } from '@kubb/fabric-core/types'
4
4
  import type { contentType, Oas, OasTypes, OpenAPIV3, SchemaObject } from '@kubb/oas'
5
5
  import { isDiscriminator, isNullable, isReference, KUBB_INLINE_REF_PREFIX } from '@kubb/oas'
6
- import type { Fabric } from '@kubb/react-fabric'
7
6
  import pLimit from 'p-limit'
8
7
  import { isDeepEqual, isNumber, uniqueWith } from 'remeda'
9
8
  import type { CoreGenerator } from './generators/createGenerator.ts'
10
9
  import type { ReactGenerator } from './generators/createReactGenerator.ts'
11
- import type { Generator, Version } from './generators/types.ts'
10
+ import type { Generator } from './generators/types.ts'
12
11
  import { isKeyword, type Schema, type SchemaKeywordMapper, schemaKeywords } from './SchemaMapper.ts'
13
12
  import type { OperationSchema, Override, Refs } from './types.ts'
14
13
  import { getSchemaFactory } from './utils/getSchemaFactory.ts'
@@ -24,7 +23,7 @@ const GENERATOR_CONCURRENCY = 3
24
23
  const SCHEMA_CONCURRENCY = 30
25
24
 
26
25
  type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
27
- fabric: Fabric
26
+ fabric: FabricType
28
27
  oas: Oas
29
28
  pluginManager: PluginManager
30
29
  events?: AsyncEventEmitter<KubbEvents>
@@ -1337,7 +1336,7 @@ export class SchemaGenerator<
1337
1336
  return [{ keyword: emptyType }, ...baseItems]
1338
1337
  }
1339
1338
 
1340
- async build(...generators: Array<Generator<TPluginOptions, Version>>): Promise<Array<KubbFile.File<TFileMeta>>> {
1339
+ async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
1341
1340
  const { oas, contentType, include } = this.context
1342
1341
 
1343
1342
  // Initialize the name mapping if not already done
@@ -1360,10 +1359,7 @@ export class SchemaGenerator<
1360
1359
  return this.#doBuild(schemas, generators)
1361
1360
  }
1362
1361
 
1363
- async #doBuild(
1364
- schemas: Record<string, OasTypes.SchemaObject>,
1365
- generators: Array<Generator<TPluginOptions, Version>>,
1366
- ): Promise<Array<KubbFile.File<TFileMeta>>> {
1362
+ async #doBuild(schemas: Record<string, OasTypes.SchemaObject>, generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
1367
1363
  const schemaEntries = Object.entries(schemas)
1368
1364
 
1369
1365
  const generatorLimit = pLimit(GENERATOR_CONCURRENCY)
@@ -1376,7 +1372,7 @@ export class SchemaGenerator<
1376
1372
  }
1377
1373
 
1378
1374
  // After the v2 guard above, all generators here are v1
1379
- const v1Generator = generator as ReactGenerator<TPluginOptions, '1'> | CoreGenerator<TPluginOptions, '1'>
1375
+ const v1Generator = generator as ReactGenerator<TPluginOptions> | CoreGenerator<TPluginOptions>
1380
1376
 
1381
1377
  const schemaTasks = schemaEntries.map(([name, schemaObject]) =>
1382
1378
  schemaLimit(async () => {
@@ -1,30 +1,27 @@
1
1
  import type { PluginFactoryOptions } from '@kubb/core'
2
2
  import type { KubbFile } from '@kubb/fabric-core/types'
3
- import type { OperationProps, OperationsProps, SchemaProps, Version } from './types.ts'
3
+ import type { OperationProps, OperationsProps, SchemaProps } from './types.ts'
4
4
 
5
- type UserGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {
5
+ type UserGenerator<TOptions extends PluginFactoryOptions> = {
6
6
  name: string
7
- version?: TVersion
8
- operations?: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>
9
- operation?: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>
10
- schema?: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>
7
+ operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>
8
+ operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>
9
+ schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>
11
10
  }
12
11
 
13
- export type CoreGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {
12
+ export type CoreGenerator<TOptions extends PluginFactoryOptions> = {
14
13
  name: string
15
14
  type: 'core'
16
- version: TVersion
17
- operations: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>
18
- operation: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>
19
- schema: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>
15
+ version: '1'
16
+ operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>
17
+ operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>
18
+ schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>
20
19
  }
21
20
 
22
- export function createGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(
23
- generator: UserGenerator<TOptions, TVersion>,
24
- ): CoreGenerator<TOptions, TVersion> {
21
+ export function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions> {
25
22
  return {
26
23
  type: 'core',
27
- version: (generator.version ?? '1') as TVersion,
24
+ version: '1',
28
25
  async operations() {
29
26
  return []
30
27
  },
@@ -1,22 +1,21 @@
1
1
  import type { PluginFactoryOptions } from '@kubb/core'
2
2
  import type { FabricReactNode } from '@kubb/react-fabric/types'
3
- import type { OperationProps, OperationsProps, SchemaProps, Version } from './types.ts'
3
+ import type { OperationProps, OperationsProps, SchemaProps } from './types.ts'
4
4
 
5
- type UserGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {
5
+ type UserGenerator<TOptions extends PluginFactoryOptions> = {
6
6
  name: string
7
- version?: TVersion
8
- Operations?: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode
9
- Operation?: (props: OperationProps<TOptions, TVersion>) => FabricReactNode
10
- Schema?: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode
7
+ Operations?: (props: OperationsProps<TOptions>) => FabricReactNode
8
+ Operation?: (props: OperationProps<TOptions>) => FabricReactNode
9
+ Schema?: (props: SchemaProps<TOptions>) => FabricReactNode
11
10
  }
12
11
 
13
- export type ReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {
12
+ export type ReactGenerator<TOptions extends PluginFactoryOptions> = {
14
13
  name: string
15
14
  type: 'react'
16
- version: TVersion
17
- Operations: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode
18
- Operation: (props: OperationProps<TOptions, TVersion>) => FabricReactNode
19
- Schema: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode
15
+ version: '1'
16
+ Operations: (props: OperationsProps<TOptions>) => FabricReactNode
17
+ Operation: (props: OperationProps<TOptions>) => FabricReactNode
18
+ Schema: (props: SchemaProps<TOptions>) => FabricReactNode
20
19
  }
21
20
 
22
21
  /****
@@ -26,12 +25,10 @@ export type ReactGenerator<TOptions extends PluginFactoryOptions, TVersion exten
26
25
  *
27
26
  * @returns A generator object with async methods for operations, operation, and schema file generation.
28
27
  */
29
- export function createReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(
30
- generator: UserGenerator<TOptions, TVersion>,
31
- ): ReactGenerator<TOptions, TVersion> {
28
+ export function createReactGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): ReactGenerator<TOptions> {
32
29
  return {
33
30
  type: 'react',
34
- version: (generator.version ?? '1') as TVersion,
31
+ version: '1',
35
32
  Operations() {
36
33
  return null
37
34
  },
@@ -1,5 +1,4 @@
1
- import type { OperationNode, SchemaNode } from '@kubb/ast/types'
2
- import type { Adapter, Config, Plugin, PluginFactoryOptions } from '@kubb/core'
1
+ import type { Config, Generator as CoreV2Generator, Plugin, PluginFactoryOptions } from '@kubb/core'
3
2
  import type { Operation, SchemaObject } from '@kubb/oas'
4
3
  import type { OperationGenerator } from '../OperationGenerator.ts'
5
4
  import type { SchemaGenerator, SchemaGeneratorOptions } from '../SchemaGenerator.ts'
@@ -7,45 +6,21 @@ import type { Schema } from '../SchemaMapper.ts'
7
6
  import type { CoreGenerator } from './createGenerator.ts'
8
7
  import type { ReactGenerator } from './createReactGenerator.ts'
9
8
 
10
- export type Version = '1' | '2'
11
-
12
- export type OperationsV1Props<TOptions extends PluginFactoryOptions> = {
9
+ export type OperationsProps<TOptions extends PluginFactoryOptions> = {
13
10
  config: Config
14
11
  generator: Omit<OperationGenerator<TOptions>, 'build'>
15
12
  plugin: Plugin<TOptions>
16
13
  operations: Array<Operation>
17
14
  }
18
15
 
19
- export type OperationsV2Props<TOptions extends PluginFactoryOptions> = {
20
- config: Config
21
- adapter: Adapter
22
- options: Plugin<TOptions>['options']
23
- nodes: Array<OperationNode>
24
- }
25
-
26
- export type OperationV1Props<TOptions extends PluginFactoryOptions> = {
16
+ export type OperationProps<TOptions extends PluginFactoryOptions> = {
27
17
  config: Config
28
18
  generator: Omit<OperationGenerator<TOptions>, 'build'>
29
19
  plugin: Plugin<TOptions>
30
20
  operation: Operation
31
21
  }
32
22
 
33
- export type OperationV2Props<TOptions extends PluginFactoryOptions> = {
34
- config: Config
35
- adapter: Adapter
36
- options: Plugin<TOptions>['options']
37
- node: OperationNode
38
- }
39
-
40
- export type OperationsProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2'
41
- ? OperationsV2Props<TOptions>
42
- : OperationsV1Props<TOptions>
43
-
44
- export type OperationProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2'
45
- ? OperationV2Props<TOptions>
46
- : OperationV1Props<TOptions>
47
-
48
- export type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
23
+ export type SchemaProps<TOptions extends PluginFactoryOptions> = {
49
24
  config: Config
50
25
  generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>
51
26
  plugin: Plugin<TOptions>
@@ -56,17 +31,4 @@ export type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
56
31
  }
57
32
  }
58
33
 
59
- export type SchemaV2Props<TOptions extends PluginFactoryOptions> = {
60
- config: Config
61
- options: Plugin<TOptions>['options']
62
- node: SchemaNode
63
- adapter: Adapter
64
- }
65
-
66
- export type SchemaProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2'
67
- ? SchemaV2Props<TOptions>
68
- : SchemaV1Props<TOptions>
69
-
70
- export type Generator<TOptions extends PluginFactoryOptions, TVersion extends Version = Version> =
71
- | CoreGenerator<TOptions, TVersion>
72
- | ReactGenerator<TOptions, TVersion>
34
+ export type Generator<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions> | CoreV2Generator<TOptions>
@@ -1,9 +1,12 @@
1
1
  import type { Oas } from '@kubb/oas'
2
2
 
3
- import { useApp } from '@kubb/react-fabric'
3
+ import { useFabric } from '@kubb/react-fabric'
4
4
 
5
+ /**
6
+ * @deprecated use schemaNode or operationNode instead
7
+ */
5
8
  export function useOas(): Oas {
6
- const { meta } = useApp<{ oas: Oas }>()
9
+ const { meta } = useFabric<{ oas: Oas }>()
7
10
 
8
11
  return meta.oas
9
12
  }
package/src/index.ts CHANGED
@@ -40,4 +40,4 @@ export const createReactGenerator = _createReactGenerator
40
40
  /**
41
41
  * @deprecated use `import { Generator } from '@kubb/plugin-oas/generators'`
42
42
  */
43
- export type Generator<TOptions extends PluginFactoryOptions, TVersion extends import('./generators/types.ts').Version = '1'> = _Generator<TOptions, TVersion>
43
+ export type Generator<TOptions extends PluginFactoryOptions> = _Generator<TOptions>
package/src/types.ts CHANGED
@@ -220,10 +220,11 @@ type ByContentType = {
220
220
  pattern: string | RegExp
221
221
  }
222
222
 
223
- export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType
224
- export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType
223
+ export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
224
+ export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
225
225
 
226
226
  export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
227
+ // should be options: Omit<Partial<TOptions>, 'override'>
227
228
  options: Partial<TOptions>
228
229
  }
229
230
 
package/src/utils.tsx CHANGED
@@ -1,8 +1,9 @@
1
1
  import type { OperationNode, SchemaNode } from '@kubb/ast/types'
2
- import type { Adapter, Config, Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'
2
+ import type { Adapter, Config, Plugin, PluginFactoryOptions, PluginManager, ReactGeneratorV2 } from '@kubb/core'
3
3
  import type { KubbFile } from '@kubb/fabric-core/types'
4
4
  import type { Operation, SchemaObject } from '@kubb/oas'
5
- import { App, createReactFabric, type Fabric } from '@kubb/react-fabric'
5
+ import { createReactFabric, Fabric } from '@kubb/react-fabric'
6
+ import type { Fabric as FabricType } from '@kubb/react-fabric/types'
6
7
  import type { ReactGenerator } from './generators/createReactGenerator.ts'
7
8
  import type { OperationGenerator } from './OperationGenerator.ts'
8
9
  import type { SchemaGenerator, SchemaGeneratorOptions } from './SchemaGenerator.ts'
@@ -10,22 +11,23 @@ import type { Schema } from './SchemaMapper.ts'
10
11
 
11
12
  type BuildOperationsBaseOptions<TOptions extends PluginFactoryOptions> = {
12
13
  config: Config
13
- fabric: Fabric
14
+ fabric: FabricType
14
15
  plugin: Plugin<TOptions>
15
16
  }
16
17
 
17
18
  type BuildOperationsV1Options<TOptions extends PluginFactoryOptions> = BuildOperationsBaseOptions<TOptions> & {
18
19
  version?: '1'
19
- Component: ReactGenerator<any, '1'>['Operations']
20
+ Component: ReactGenerator<TOptions>['Operations']
20
21
  generator: Omit<OperationGenerator<TOptions>, 'build'>
21
22
  }
22
23
 
23
24
  type BuildOperationsV2Options<TOptions extends PluginFactoryOptions> = BuildOperationsBaseOptions<TOptions> & {
24
25
  version: '2'
25
- Component: ReactGenerator<any, '2'>['Operations']
26
+ Component: ReactGeneratorV2<TOptions>['Operations'] | undefined
26
27
  adapter: Adapter
27
28
  pluginManager: PluginManager
28
29
  mode: KubbFile.Mode
30
+ options: TOptions['resolvedOptions']
29
31
  }
30
32
 
31
33
  function isBuildOperationsV1Options<TOptions extends PluginFactoryOptions>(
@@ -59,42 +61,43 @@ export async function buildOperations<TOptions extends PluginFactoryOptions>(
59
61
  const { pluginManager, oas, mode } = generator.context
60
62
 
61
63
  await fabricChild.render(
62
- <App meta={{ pluginManager, plugin, mode, oas }}>
64
+ <Fabric meta={{ pluginManager, plugin, mode, oas }}>
63
65
  <Component config={config} operations={operationsOrNodes as Array<Operation>} generator={generator} plugin={plugin} />
64
- </App>,
66
+ </Fabric>,
65
67
  )
66
68
  } else {
67
69
  const { Component, adapter } = options
68
70
 
69
71
  await fabricChild.render(
70
- <App meta={{ plugin }}>
71
- <Component config={config} adapter={adapter} nodes={operationsOrNodes as Array<OperationNode>} options={plugin.options} />
72
- </App>,
72
+ <Fabric meta={{ plugin }}>
73
+ <Component config={config} adapter={adapter} nodes={operationsOrNodes as Array<OperationNode>} options={options.options} />
74
+ </Fabric>,
73
75
  )
74
76
  }
75
77
 
76
- await fabric.context.fileManager.upsert(...fabricChild.files)
78
+ fabric.context.fileManager.upsert(...fabricChild.files)
77
79
  fabricChild.unmount()
78
80
  }
79
81
 
80
82
  type BuildOperationBaseOptions<TOptions extends PluginFactoryOptions> = {
81
83
  config: Config
82
- fabric: Fabric
84
+ fabric: FabricType
83
85
  plugin: Plugin<TOptions>
84
86
  }
85
87
 
86
88
  type BuildOperationV1Options<TOptions extends PluginFactoryOptions> = BuildOperationBaseOptions<TOptions> & {
87
89
  version?: '1'
88
- Component: ReactGenerator<any, '1'>['Operation']
90
+ Component: ReactGenerator<TOptions>['Operation']
89
91
  generator: Omit<OperationGenerator<TOptions>, 'build'>
90
92
  }
91
93
 
92
94
  type BuildOperationV2Options<TOptions extends PluginFactoryOptions> = BuildOperationBaseOptions<TOptions> & {
93
95
  version: '2'
94
- Component: ReactGenerator<any, '2'>['Operation']
96
+ Component: ReactGeneratorV2<TOptions>['Operation'] | undefined
95
97
  adapter: Adapter
96
98
  pluginManager: PluginManager
97
99
  mode: KubbFile.Mode
100
+ options: TOptions['resolvedOptions']
98
101
  }
99
102
 
100
103
  function isBuildOperationV1Options<TOptions extends PluginFactoryOptions>(
@@ -122,42 +125,43 @@ export async function buildOperation<TOptions extends PluginFactoryOptions>(
122
125
  const { pluginManager, oas, mode } = generator.context
123
126
 
124
127
  await fabricChild.render(
125
- <App meta={{ pluginManager, plugin, mode, oas }}>
128
+ <Fabric meta={{ pluginManager, plugin, mode, oas }}>
126
129
  <Component config={config} operation={operationOrNode as Operation} plugin={plugin} generator={generator} />
127
- </App>,
130
+ </Fabric>,
128
131
  )
129
132
  } else {
130
133
  const { Component, adapter, pluginManager, mode } = options
131
134
 
132
135
  await fabricChild.render(
133
- <App meta={{ plugin, pluginManager, mode }}>
134
- <Component config={config} adapter={adapter} node={operationOrNode as OperationNode} options={plugin.options} />
135
- </App>,
136
+ <Fabric meta={{ plugin, pluginManager, mode }}>
137
+ <Component config={config} adapter={adapter} node={operationOrNode as OperationNode} options={options.options} />
138
+ </Fabric>,
136
139
  )
137
140
  }
138
141
 
139
- await fabric.context.fileManager.upsert(...fabricChild.files)
142
+ fabric.context.fileManager.upsert(...fabricChild.files)
140
143
  fabricChild.unmount()
141
144
  }
142
145
 
143
146
  type BuildSchemaBaseOptions<TOptions extends PluginFactoryOptions> = {
144
147
  config: Config
145
- fabric: Fabric
148
+ fabric: FabricType
146
149
  plugin: Plugin<TOptions>
147
150
  }
148
151
 
149
152
  type BuildSchemaV1Options<TOptions extends PluginFactoryOptions> = BuildSchemaBaseOptions<TOptions> & {
150
153
  version?: '1'
151
- Component: ReactGenerator<any, '1'>['Schema']
154
+ Component: ReactGenerator<TOptions>['Schema']
152
155
  generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>
153
156
  }
154
157
 
155
158
  type BuildSchemaV2Options<TOptions extends PluginFactoryOptions> = BuildSchemaBaseOptions<TOptions> & {
156
159
  version: '2'
157
- Component: ReactGenerator<any, '2'>['Schema']
160
+ Component: ReactGeneratorV2<TOptions>['Schema'] | undefined
158
161
  adapter: Adapter
159
162
  pluginManager: PluginManager
160
163
  mode: KubbFile.Mode
164
+ options: TOptions['resolvedOptions']
161
165
  }
162
166
 
163
167
  function isBuildSchemaV1Options<TOptions extends PluginFactoryOptions>(
@@ -188,20 +192,21 @@ export async function buildSchema<TOptions extends PluginFactoryOptions>(
188
192
  const { pluginManager, oas, mode } = generator.context
189
193
 
190
194
  await fabricChild.render(
191
- <App meta={{ pluginManager, plugin, mode, oas }}>
195
+ <Fabric meta={{ pluginManager, plugin, mode, oas }}>
192
196
  <Component config={config} schema={schema as { name: string; tree: Array<Schema>; value: SchemaObject }} plugin={plugin} generator={generator} />
193
- </App>,
197
+ </Fabric>,
194
198
  )
195
199
  } else {
196
200
  const { Component, adapter, pluginManager, mode } = options
197
201
 
198
202
  await fabricChild.render(
199
- <App meta={{ plugin, pluginManager, mode }}>
200
- <Component config={config} adapter={adapter} node={schema as SchemaNode} options={plugin.options} />
201
- </App>,
203
+ <Fabric meta={{ plugin, pluginManager, mode }}>
204
+ <Component config={config} adapter={adapter} node={schema as SchemaNode} options={options.options} />
205
+ </Fabric>,
202
206
  )
203
207
  }
204
208
 
205
- await fabric.context.fileManager.upsert(...fabricChild.files)
209
+ fabric.context.fileManager.upsert(...fabricChild.files)
210
+
206
211
  fabricChild.unmount()
207
212
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-B8HiBWvT.js","names":[],"sources":["../src/generators/createGenerator.ts","../src/generators/createReactGenerator.ts","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { OperationProps, OperationsProps, SchemaProps, Version } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n version?: TVersion\n operations?: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n operation?: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n schema?: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n}\n\nexport type CoreGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n type: 'core'\n version: TVersion\n operations: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n operation: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n schema: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n}\n\nexport function createGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(\n generator: UserGenerator<TOptions, TVersion>,\n): CoreGenerator<TOptions, TVersion> {\n return {\n type: 'core',\n version: (generator.version ?? '1') as TVersion,\n async operations() {\n return []\n },\n async operation() {\n return []\n },\n async schema() {\n return []\n },\n ...generator,\n }\n}\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport type { OperationProps, OperationsProps, SchemaProps, Version } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n version?: TVersion\n Operations?: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode\n Operation?: (props: OperationProps<TOptions, TVersion>) => FabricReactNode\n Schema?: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode\n}\n\nexport type ReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n type: 'react'\n version: TVersion\n Operations: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode\n Operation: (props: OperationProps<TOptions, TVersion>) => FabricReactNode\n Schema: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode\n}\n\n/****\n * Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.\n *\n * The returned generator exposes async methods for generating files from operations, a single operation, or a schema, using the corresponding React components if provided. If a component is not defined, the method returns an empty array.\n *\n * @returns A generator object with async methods for operations, operation, and schema file generation.\n */\nexport function createReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(\n generator: UserGenerator<TOptions, TVersion>,\n): ReactGenerator<TOptions, TVersion> {\n return {\n type: 'react',\n version: (generator.version ?? '1') as TVersion,\n Operations() {\n return null\n },\n Operation() {\n return null\n },\n Schema() {\n return null\n },\n ...generator,\n }\n}\n","import { camelCase } from '@internals/utils'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\nimport { createGenerator } from './createGenerator.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, generator }) {\n const { pluginManager, plugin } = generator.context\n const file = pluginManager.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginName: plugin.name,\n })\n\n return [\n {\n ...file,\n sources: [\n {\n name: camelCase(schema.name),\n isExportable: false,\n isIndexable: false,\n value: JSON.stringify(schema.value),\n },\n ],\n banner: getBanner({\n oas: generator.context.oas,\n output: plugin.options.output,\n config: pluginManager.config,\n }),\n format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;AAqBA,SAAgB,gBACd,WACmC;AACnC,QAAO;EACL,MAAM;EACN,SAAU,UAAU,WAAW;EAC/B,MAAM,aAAa;AACjB,UAAO,EAAE;;EAEX,MAAM,YAAY;AAChB,UAAO,EAAE;;EAEX,MAAM,SAAS;AACb,UAAO,EAAE;;EAEX,GAAG;EACJ;;;;;;;;;;;ACTH,SAAgB,qBACd,WACoC;AACpC,QAAO;EACL,MAAM;EACN,SAAU,UAAU,WAAW;EAC/B,aAAa;AACX,UAAO;;EAET,YAAY;AACV,UAAO;;EAET,SAAS;AACP,UAAO;;EAET,GAAG;EACJ;;;;ACtCH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,aAAa;EAClC,MAAM,EAAE,eAAe,WAAW,UAAU;AAQ5C,SAAO,CACL;GACE,GATS,cAAc,QAAQ;IACjC,MAAM,UAAU,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,YAAY,OAAO;IACpB,CAAC;GAKE,SAAS,CACP;IACE,MAAM,UAAU,OAAO,KAAK;IAC5B,cAAc;IACd,aAAa;IACb,OAAO,KAAK,UAAU,OAAO,MAAM;IACpC,CACF;GACD,QAAQ,UAAU;IAChB,KAAK,UAAU,QAAQ;IACvB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,cAAc;IACvB,CAAC;GACF,QAAQ,UAAU;IAAE,KAAK,UAAU,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GACjF,CACF;;CAEJ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-vAAte6w6.cjs","names":["camelCase","getBanner","getFooter"],"sources":["../src/generators/createGenerator.ts","../src/generators/createReactGenerator.ts","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { OperationProps, OperationsProps, SchemaProps, Version } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n version?: TVersion\n operations?: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n operation?: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n schema?: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n}\n\nexport type CoreGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n type: 'core'\n version: TVersion\n operations: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n operation: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n schema: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n}\n\nexport function createGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(\n generator: UserGenerator<TOptions, TVersion>,\n): CoreGenerator<TOptions, TVersion> {\n return {\n type: 'core',\n version: (generator.version ?? '1') as TVersion,\n async operations() {\n return []\n },\n async operation() {\n return []\n },\n async schema() {\n return []\n },\n ...generator,\n }\n}\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport type { OperationProps, OperationsProps, SchemaProps, Version } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n version?: TVersion\n Operations?: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode\n Operation?: (props: OperationProps<TOptions, TVersion>) => FabricReactNode\n Schema?: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode\n}\n\nexport type ReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n type: 'react'\n version: TVersion\n Operations: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode\n Operation: (props: OperationProps<TOptions, TVersion>) => FabricReactNode\n Schema: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode\n}\n\n/****\n * Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.\n *\n * The returned generator exposes async methods for generating files from operations, a single operation, or a schema, using the corresponding React components if provided. If a component is not defined, the method returns an empty array.\n *\n * @returns A generator object with async methods for operations, operation, and schema file generation.\n */\nexport function createReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(\n generator: UserGenerator<TOptions, TVersion>,\n): ReactGenerator<TOptions, TVersion> {\n return {\n type: 'react',\n version: (generator.version ?? '1') as TVersion,\n Operations() {\n return null\n },\n Operation() {\n return null\n },\n Schema() {\n return null\n },\n ...generator,\n }\n}\n","import { camelCase } from '@internals/utils'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\nimport { createGenerator } from './createGenerator.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, generator }) {\n const { pluginManager, plugin } = generator.context\n const file = pluginManager.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginName: plugin.name,\n })\n\n return [\n {\n ...file,\n sources: [\n {\n name: camelCase(schema.name),\n isExportable: false,\n isIndexable: false,\n value: JSON.stringify(schema.value),\n },\n ],\n banner: getBanner({\n oas: generator.context.oas,\n output: plugin.options.output,\n config: pluginManager.config,\n }),\n format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;AAqBA,SAAgB,gBACd,WACmC;AACnC,QAAO;EACL,MAAM;EACN,SAAU,UAAU,WAAW;EAC/B,MAAM,aAAa;AACjB,UAAO,EAAE;;EAEX,MAAM,YAAY;AAChB,UAAO,EAAE;;EAEX,MAAM,SAAS;AACb,UAAO,EAAE;;EAEX,GAAG;EACJ;;;;;;;;;;;ACTH,SAAgB,qBACd,WACoC;AACpC,QAAO;EACL,MAAM;EACN,SAAU,UAAU,WAAW;EAC/B,aAAa;AACX,UAAO;;EAET,YAAY;AACV,UAAO;;EAET,SAAS;AACP,UAAO;;EAET,GAAG;EACJ;;;;ACtCH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,aAAa;EAClC,MAAM,EAAE,eAAe,WAAW,UAAU;AAQ5C,SAAO,CACL;GACE,GATS,cAAc,QAAQ;IACjC,MAAMA,kBAAAA,UAAU,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,YAAY,OAAO;IACpB,CAAC;GAKE,SAAS,CACP;IACE,MAAMA,kBAAAA,UAAU,OAAO,KAAK;IAC5B,cAAc;IACd,aAAa;IACb,OAAO,KAAK,UAAU,OAAO,MAAM;IACpC,CACF;GACD,QAAQC,kBAAAA,UAAU;IAChB,KAAK,UAAU,QAAQ;IACvB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,cAAc;IACvB,CAAC;GACF,QAAQC,kBAAAA,UAAU;IAAE,KAAK,UAAU,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GACjF,CACF;;CAEJ,CAAC"}