@kubb/plugin-oas 4.36.1 → 5.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.
- package/dist/{createGenerator-CBXpHeVY.d.ts → createGenerator-Cl7uTbJt.d.ts} +67 -61
- package/dist/{generators-CyWd3UXA.cjs → generators-BfTTScuN.cjs} +7 -7
- package/dist/generators-BfTTScuN.cjs.map +1 -0
- package/dist/{generators-D7C3CXsN.js → generators-BjsINk-u.js} +7 -7
- package/dist/generators-BjsINk-u.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +2 -2
- package/dist/generators.js +1 -1
- package/dist/hooks.cjs +42 -62
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +15 -32
- package/dist/hooks.js +45 -64
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +26 -13
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/dist/{requestBody-DIM-iDpM.cjs → requestBody-DyTNWJql.cjs} +45 -34
- package/dist/requestBody-DyTNWJql.cjs.map +1 -0
- package/dist/{requestBody-mUXoBwsu.js → requestBody-gV_d8sCu.js} +46 -35
- package/dist/requestBody-gV_d8sCu.js.map +1 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/OperationGenerator.ts +12 -12
- package/src/SchemaGenerator.ts +19 -22
- package/src/generators/createGenerator.ts +12 -15
- package/src/generators/createReactGenerator.ts +12 -15
- package/src/generators/jsonGenerator.ts +4 -4
- package/src/generators/types.ts +5 -40
- package/src/hooks/index.ts +0 -1
- package/src/hooks/useOas.ts +5 -2
- package/src/hooks/useOperationManager.ts +34 -34
- package/src/hooks/useSchemaManager.ts +16 -15
- package/src/index.ts +1 -1
- package/src/plugin.ts +6 -6
- package/src/types.ts +7 -6
- package/src/utils.tsx +53 -35
- package/dist/generators-CyWd3UXA.cjs.map +0 -1
- package/dist/generators-D7C3CXsN.js.map +0 -1
- package/dist/requestBody-DIM-iDpM.cjs.map +0 -1
- package/dist/requestBody-mUXoBwsu.js.map +0 -1
- package/src/hooks/useRootNode.ts +0 -25
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import type { AsyncEventEmitter } from '@internals/utils'
|
|
1
2
|
import { pascalCase } from '@internals/utils'
|
|
2
|
-
import type {
|
|
3
|
-
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
3
|
+
import type { FileMetaBase, KubbEvents, Plugin, PluginDriver, PluginFactoryOptions } from '@kubb/core'
|
|
4
|
+
import type { Fabric as FabricType, KubbFile } from '@kubb/fabric-core/types'
|
|
4
5
|
import type { contentType, HttpMethod, Oas, OasTypes, Operation, SchemaObject } from '@kubb/oas'
|
|
5
|
-
import type { Fabric } from '@kubb/react-fabric'
|
|
6
6
|
import pLimit from 'p-limit'
|
|
7
7
|
import type { CoreGenerator } from './generators/createGenerator.ts'
|
|
8
8
|
import type { ReactGenerator } from './generators/createReactGenerator.ts'
|
|
9
|
-
import type { Generator
|
|
9
|
+
import type { Generator } from './generators/types.ts'
|
|
10
10
|
import type { Exclude, Include, OperationSchemas, Override } from './types.ts'
|
|
11
11
|
import { withRequiredRequestBodySchema } from './utils/requestBody.ts'
|
|
12
12
|
import { buildOperation, buildOperations } from './utils.tsx'
|
|
@@ -14,13 +14,13 @@ import { buildOperation, buildOperations } from './utils.tsx'
|
|
|
14
14
|
export type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>
|
|
15
15
|
|
|
16
16
|
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
17
|
-
fabric:
|
|
17
|
+
fabric: FabricType
|
|
18
18
|
oas: Oas
|
|
19
19
|
exclude: Array<Exclude> | undefined
|
|
20
20
|
include: Array<Include> | undefined
|
|
21
21
|
override: Array<Override<TOptions>> | undefined
|
|
22
22
|
contentType: contentType | undefined
|
|
23
|
-
|
|
23
|
+
driver: PluginDriver
|
|
24
24
|
events?: AsyncEventEmitter<KubbEvents>
|
|
25
25
|
/**
|
|
26
26
|
* Current plugin
|
|
@@ -206,7 +206,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
|
|
|
206
206
|
)
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
async build(...generators: Array<Generator<TPluginOptions
|
|
209
|
+
async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
210
210
|
const operations = await this.getOperations()
|
|
211
211
|
|
|
212
212
|
// Increased parallelism for better performance
|
|
@@ -227,7 +227,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
|
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
// After the v2 guard above, all generators here are v1
|
|
230
|
-
const v1Generator = generator as ReactGenerator<TPluginOptions
|
|
230
|
+
const v1Generator = generator as ReactGenerator<TPluginOptions> | CoreGenerator<TPluginOptions>
|
|
231
231
|
|
|
232
232
|
const operationTasks = operations.map(({ operation, method }) =>
|
|
233
233
|
operationLimit(async () => {
|
|
@@ -235,7 +235,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
|
|
|
235
235
|
|
|
236
236
|
if (v1Generator.type === 'react') {
|
|
237
237
|
await buildOperation(operation, {
|
|
238
|
-
config: this.context.
|
|
238
|
+
config: this.context.driver.config,
|
|
239
239
|
fabric: this.context.fabric,
|
|
240
240
|
Component: v1Generator.Operation,
|
|
241
241
|
generator: this,
|
|
@@ -253,7 +253,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
|
|
|
253
253
|
|
|
254
254
|
const result = await v1Generator.operation?.({
|
|
255
255
|
generator: this,
|
|
256
|
-
config: this.context.
|
|
256
|
+
config: this.context.driver.config,
|
|
257
257
|
operation,
|
|
258
258
|
plugin: {
|
|
259
259
|
...this.context.plugin,
|
|
@@ -276,7 +276,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
|
|
|
276
276
|
operations.map((op) => op.operation),
|
|
277
277
|
{
|
|
278
278
|
fabric: this.context.fabric,
|
|
279
|
-
config: this.context.
|
|
279
|
+
config: this.context.driver.config,
|
|
280
280
|
Component: v1Generator.Operations,
|
|
281
281
|
generator: this,
|
|
282
282
|
plugin: this.context.plugin,
|
|
@@ -288,7 +288,7 @@ export class OperationGenerator<TPluginOptions extends PluginFactoryOptions = Pl
|
|
|
288
288
|
|
|
289
289
|
const operationsResult = await v1Generator.operations?.({
|
|
290
290
|
generator: this,
|
|
291
|
-
config: this.context.
|
|
291
|
+
config: this.context.driver.config,
|
|
292
292
|
operations: operations.map((op) => op.operation),
|
|
293
293
|
plugin: this.context.plugin,
|
|
294
294
|
})
|
package/src/SchemaGenerator.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import type { AsyncEventEmitter } from '@internals/utils'
|
|
1
2
|
import { getUniqueName, pascalCase, stringify } from '@internals/utils'
|
|
2
|
-
import type {
|
|
3
|
-
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
3
|
+
import type { FileMetaBase, KubbEvents, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
4
|
+
import type { Fabric as FabricType, KubbFile } from '@kubb/fabric-core/types'
|
|
4
5
|
import type { contentType, Oas, OasTypes, OpenAPIV3, SchemaObject } from '@kubb/oas'
|
|
5
6
|
import { isDiscriminator, isNullable, isReference, KUBB_INLINE_REF_PREFIX } from '@kubb/oas'
|
|
6
|
-
import type { Fabric } from '@kubb/react-fabric'
|
|
7
7
|
import pLimit from 'p-limit'
|
|
8
8
|
import { isDeepEqual, isNumber, uniqueWith } from 'remeda'
|
|
9
9
|
import type { CoreGenerator } from './generators/createGenerator.ts'
|
|
10
10
|
import type { ReactGenerator } from './generators/createReactGenerator.ts'
|
|
11
|
-
import type { Generator
|
|
11
|
+
import type { Generator } from './generators/types.ts'
|
|
12
12
|
import { isKeyword, type Schema, type SchemaKeywordMapper, schemaKeywords } from './SchemaMapper.ts'
|
|
13
13
|
import type { OperationSchema, Override, Refs } from './types.ts'
|
|
14
14
|
import { getSchemaFactory } from './utils/getSchemaFactory.ts'
|
|
@@ -24,9 +24,9 @@ const GENERATOR_CONCURRENCY = 3
|
|
|
24
24
|
const SCHEMA_CONCURRENCY = 30
|
|
25
25
|
|
|
26
26
|
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
27
|
-
fabric:
|
|
27
|
+
fabric: FabricType
|
|
28
28
|
oas: Oas
|
|
29
|
-
|
|
29
|
+
driver: PluginDriver
|
|
30
30
|
events?: AsyncEventEmitter<KubbEvents>
|
|
31
31
|
/**
|
|
32
32
|
* Current plugin
|
|
@@ -524,20 +524,20 @@ export class SchemaGenerator<
|
|
|
524
524
|
// Use the full $ref path to look up the collision-resolved name
|
|
525
525
|
const resolvedName = this.#schemaNameMapping.get($ref) || originalName
|
|
526
526
|
|
|
527
|
-
const propertyName = this.context.
|
|
527
|
+
const propertyName = this.context.driver.resolveName({
|
|
528
528
|
name: resolvedName,
|
|
529
|
-
|
|
529
|
+
pluginName: this.context.plugin.name,
|
|
530
530
|
type: 'function',
|
|
531
531
|
})
|
|
532
532
|
|
|
533
|
-
const fileName = this.context.
|
|
533
|
+
const fileName = this.context.driver.resolveName({
|
|
534
534
|
name: resolvedName,
|
|
535
|
-
|
|
535
|
+
pluginName: this.context.plugin.name,
|
|
536
536
|
type: 'file',
|
|
537
537
|
})
|
|
538
|
-
const file = this.context.
|
|
538
|
+
const file = this.context.driver.getFile({
|
|
539
539
|
name: fileName,
|
|
540
|
-
|
|
540
|
+
pluginName: this.context.plugin.name,
|
|
541
541
|
extname: '.ts',
|
|
542
542
|
})
|
|
543
543
|
|
|
@@ -968,9 +968,9 @@ export class SchemaGenerator<
|
|
|
968
968
|
const enumName = useCollisionDetection
|
|
969
969
|
? pascalCase(enumNameParts.join(' '))
|
|
970
970
|
: getUniqueName(pascalCase(enumNameParts.join(' ')), this.options.usedEnumNames || {})
|
|
971
|
-
const typeName = this.context.
|
|
971
|
+
const typeName = this.context.driver.resolveName({
|
|
972
972
|
name: enumName,
|
|
973
|
-
|
|
973
|
+
pluginName: this.context.plugin.name,
|
|
974
974
|
type: 'type',
|
|
975
975
|
})
|
|
976
976
|
|
|
@@ -1337,7 +1337,7 @@ export class SchemaGenerator<
|
|
|
1337
1337
|
return [{ keyword: emptyType }, ...baseItems]
|
|
1338
1338
|
}
|
|
1339
1339
|
|
|
1340
|
-
async build(...generators: Array<Generator<TPluginOptions
|
|
1340
|
+
async build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
1341
1341
|
const { oas, contentType, include } = this.context
|
|
1342
1342
|
|
|
1343
1343
|
// Initialize the name mapping if not already done
|
|
@@ -1360,10 +1360,7 @@ export class SchemaGenerator<
|
|
|
1360
1360
|
return this.#doBuild(schemas, generators)
|
|
1361
1361
|
}
|
|
1362
1362
|
|
|
1363
|
-
async #doBuild(
|
|
1364
|
-
schemas: Record<string, OasTypes.SchemaObject>,
|
|
1365
|
-
generators: Array<Generator<TPluginOptions, Version>>,
|
|
1366
|
-
): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
1363
|
+
async #doBuild(schemas: Record<string, OasTypes.SchemaObject>, generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
1367
1364
|
const schemaEntries = Object.entries(schemas)
|
|
1368
1365
|
|
|
1369
1366
|
const generatorLimit = pLimit(GENERATOR_CONCURRENCY)
|
|
@@ -1376,7 +1373,7 @@ export class SchemaGenerator<
|
|
|
1376
1373
|
}
|
|
1377
1374
|
|
|
1378
1375
|
// After the v2 guard above, all generators here are v1
|
|
1379
|
-
const v1Generator = generator as ReactGenerator<TPluginOptions
|
|
1376
|
+
const v1Generator = generator as ReactGenerator<TPluginOptions> | CoreGenerator<TPluginOptions>
|
|
1380
1377
|
|
|
1381
1378
|
const schemaTasks = schemaEntries.map(([name, schemaObject]) =>
|
|
1382
1379
|
schemaLimit(async () => {
|
|
@@ -1392,7 +1389,7 @@ export class SchemaGenerator<
|
|
|
1392
1389
|
tree,
|
|
1393
1390
|
},
|
|
1394
1391
|
{
|
|
1395
|
-
config: this.context.
|
|
1392
|
+
config: this.context.driver.config,
|
|
1396
1393
|
fabric: this.context.fabric,
|
|
1397
1394
|
Component: v1Generator.Schema,
|
|
1398
1395
|
generator: this,
|
|
@@ -1410,7 +1407,7 @@ export class SchemaGenerator<
|
|
|
1410
1407
|
}
|
|
1411
1408
|
|
|
1412
1409
|
const result = await v1Generator.schema?.({
|
|
1413
|
-
config: this.context.
|
|
1410
|
+
config: this.context.driver.config,
|
|
1414
1411
|
generator: this,
|
|
1415
1412
|
schema: {
|
|
1416
1413
|
name,
|
|
@@ -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
|
|
3
|
+
import type { OperationProps, OperationsProps, SchemaProps } from './types.ts'
|
|
4
4
|
|
|
5
|
-
type UserGenerator<TOptions extends PluginFactoryOptions
|
|
5
|
+
type UserGenerator<TOptions extends PluginFactoryOptions> = {
|
|
6
6
|
name: string
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
12
|
+
export type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
14
13
|
name: string
|
|
15
14
|
type: 'core'
|
|
16
|
-
version:
|
|
17
|
-
operations: (props: OperationsProps<TOptions
|
|
18
|
-
operation: (props: OperationProps<TOptions
|
|
19
|
-
schema: (props: SchemaProps<TOptions
|
|
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
|
|
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:
|
|
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
|
|
3
|
+
import type { OperationProps, OperationsProps, SchemaProps } from './types.ts'
|
|
4
4
|
|
|
5
|
-
type UserGenerator<TOptions extends PluginFactoryOptions
|
|
5
|
+
type UserGenerator<TOptions extends PluginFactoryOptions> = {
|
|
6
6
|
name: string
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
12
|
+
export type ReactGenerator<TOptions extends PluginFactoryOptions> = {
|
|
14
13
|
name: string
|
|
15
14
|
type: 'react'
|
|
16
|
-
version:
|
|
17
|
-
Operations: (props: OperationsProps<TOptions
|
|
18
|
-
Operation: (props: OperationProps<TOptions
|
|
19
|
-
Schema: (props: SchemaProps<TOptions
|
|
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
|
|
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:
|
|
31
|
+
version: '1',
|
|
35
32
|
Operations() {
|
|
36
33
|
return null
|
|
37
34
|
},
|
|
@@ -7,12 +7,12 @@ import { createGenerator } from './createGenerator.ts'
|
|
|
7
7
|
export const jsonGenerator = createGenerator<PluginOas>({
|
|
8
8
|
name: 'plugin-oas',
|
|
9
9
|
async schema({ schema, generator }) {
|
|
10
|
-
const {
|
|
11
|
-
const file =
|
|
10
|
+
const { driver, plugin } = generator.context
|
|
11
|
+
const file = driver.getFile({
|
|
12
12
|
name: camelCase(schema.name),
|
|
13
13
|
extname: '.json',
|
|
14
14
|
mode: 'split',
|
|
15
|
-
|
|
15
|
+
pluginName: plugin.name,
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
return [
|
|
@@ -29,7 +29,7 @@ export const jsonGenerator = createGenerator<PluginOas>({
|
|
|
29
29
|
banner: getBanner({
|
|
30
30
|
oas: generator.context.oas,
|
|
31
31
|
output: plugin.options.output,
|
|
32
|
-
config:
|
|
32
|
+
config: driver.config,
|
|
33
33
|
}),
|
|
34
34
|
format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),
|
|
35
35
|
},
|
package/src/generators/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { 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,43 +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
|
|
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
|
|
20
|
-
config: Config
|
|
21
|
-
plugin: Plugin<TOptions>
|
|
22
|
-
nodes: Array<OperationNode>
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type OperationV1Props<TOptions extends PluginFactoryOptions> = {
|
|
16
|
+
export type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
26
17
|
config: Config
|
|
27
18
|
generator: Omit<OperationGenerator<TOptions>, 'build'>
|
|
28
19
|
plugin: Plugin<TOptions>
|
|
29
20
|
operation: Operation
|
|
30
21
|
}
|
|
31
22
|
|
|
32
|
-
export type
|
|
33
|
-
config: Config
|
|
34
|
-
plugin: Plugin<TOptions>
|
|
35
|
-
node: OperationNode
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type OperationsProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2'
|
|
39
|
-
? OperationsV2Props<TOptions>
|
|
40
|
-
: OperationsV1Props<TOptions>
|
|
41
|
-
|
|
42
|
-
export type OperationProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2'
|
|
43
|
-
? OperationV2Props<TOptions>
|
|
44
|
-
: OperationV1Props<TOptions>
|
|
45
|
-
|
|
46
|
-
export type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
|
|
23
|
+
export type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
47
24
|
config: Config
|
|
48
25
|
generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>
|
|
49
26
|
plugin: Plugin<TOptions>
|
|
@@ -54,16 +31,4 @@ export type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
|
|
|
54
31
|
}
|
|
55
32
|
}
|
|
56
33
|
|
|
57
|
-
export type
|
|
58
|
-
config: Config
|
|
59
|
-
plugin: Plugin<TOptions>
|
|
60
|
-
node: SchemaNode
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export type SchemaProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2'
|
|
64
|
-
? SchemaV2Props<TOptions>
|
|
65
|
-
: SchemaV1Props<TOptions>
|
|
66
|
-
|
|
67
|
-
export type Generator<TOptions extends PluginFactoryOptions, TVersion extends Version = Version> =
|
|
68
|
-
| CoreGenerator<TOptions, TVersion>
|
|
69
|
-
| ReactGenerator<TOptions, TVersion>
|
|
34
|
+
export type Generator<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions> | CoreV2Generator<TOptions>
|
package/src/hooks/index.ts
CHANGED
package/src/hooks/useOas.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { Oas } from '@kubb/oas'
|
|
2
2
|
|
|
3
|
-
import {
|
|
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 } =
|
|
9
|
+
const { meta } = useFabric<{ oas: Oas }>()
|
|
7
10
|
|
|
8
11
|
return meta.oas
|
|
9
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { FileMetaBase,
|
|
2
|
-
import { usePlugin,
|
|
1
|
+
import type { FileMetaBase, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
|
+
import { usePlugin, usePluginDriver } from '@kubb/core/hooks'
|
|
3
3
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
4
4
|
import type { Operation, Operation as OperationType } from '@kubb/oas'
|
|
5
5
|
import type { OperationGenerator } from '../OperationGenerator.ts'
|
|
6
6
|
import type { OperationSchemas } from '../types.ts'
|
|
7
7
|
|
|
8
8
|
type FileMeta = FileMetaBase & {
|
|
9
|
-
|
|
9
|
+
pluginName: string
|
|
10
10
|
name: string
|
|
11
11
|
group?: {
|
|
12
12
|
tag?: string
|
|
@@ -31,7 +31,7 @@ type UseOperationManagerResult = {
|
|
|
31
31
|
params: {
|
|
32
32
|
prefix?: string
|
|
33
33
|
suffix?: string
|
|
34
|
-
|
|
34
|
+
pluginName?: string
|
|
35
35
|
type: ResolveNameParams['type']
|
|
36
36
|
},
|
|
37
37
|
) => string
|
|
@@ -40,7 +40,7 @@ type UseOperationManagerResult = {
|
|
|
40
40
|
params?: {
|
|
41
41
|
prefix?: string
|
|
42
42
|
suffix?: string
|
|
43
|
-
|
|
43
|
+
pluginName?: string
|
|
44
44
|
extname?: KubbFile.Extname
|
|
45
45
|
group?: {
|
|
46
46
|
tag?: string
|
|
@@ -51,11 +51,11 @@ type UseOperationManagerResult = {
|
|
|
51
51
|
groupSchemasByName: (
|
|
52
52
|
operation: OperationType,
|
|
53
53
|
params: {
|
|
54
|
-
|
|
54
|
+
pluginName?: string
|
|
55
55
|
type: ResolveNameParams['type']
|
|
56
56
|
},
|
|
57
57
|
) => SchemaNames
|
|
58
|
-
getSchemas: (operation: Operation, params?: {
|
|
58
|
+
getSchemas: (operation: Operation, params?: { pluginName?: string; type?: ResolveNameParams['type'] }) => OperationSchemas
|
|
59
59
|
getGroup: (operation: Operation) => FileMeta['group'] | undefined
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -66,12 +66,12 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
66
66
|
generator: Omit<OperationGenerator<TPluginOptions>, 'build'>,
|
|
67
67
|
): UseOperationManagerResult {
|
|
68
68
|
const plugin = usePlugin()
|
|
69
|
-
const
|
|
69
|
+
const driver = usePluginDriver()
|
|
70
70
|
|
|
71
|
-
const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '',
|
|
72
|
-
return
|
|
71
|
+
const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginName = plugin.name, type }) => {
|
|
72
|
+
return driver.resolveName({
|
|
73
73
|
name: `${prefix} ${operation.getOperationId()} ${suffix}`,
|
|
74
|
-
|
|
74
|
+
pluginName,
|
|
75
75
|
type,
|
|
76
76
|
})
|
|
77
77
|
}
|
|
@@ -90,23 +90,23 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
90
90
|
|
|
91
91
|
return generator.getSchemas(operation, {
|
|
92
92
|
resolveName: (name) =>
|
|
93
|
-
|
|
93
|
+
driver.resolveName({
|
|
94
94
|
name,
|
|
95
|
-
|
|
95
|
+
pluginName: params?.pluginName,
|
|
96
96
|
type: params?.type,
|
|
97
97
|
}),
|
|
98
98
|
})
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix,
|
|
102
|
-
const name = getName(operation, { type: 'file',
|
|
101
|
+
const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginName = plugin.name, extname = '.ts' } = {}) => {
|
|
102
|
+
const name = getName(operation, { type: 'file', pluginName, prefix, suffix })
|
|
103
103
|
const group = getGroup(operation)
|
|
104
104
|
|
|
105
|
-
const file =
|
|
105
|
+
const file = driver.getFile({
|
|
106
106
|
name,
|
|
107
107
|
extname,
|
|
108
|
-
|
|
109
|
-
options: { type: 'file',
|
|
108
|
+
pluginName,
|
|
109
|
+
options: { type: 'file', pluginName, group },
|
|
110
110
|
})
|
|
111
111
|
|
|
112
112
|
return {
|
|
@@ -114,13 +114,13 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
114
114
|
meta: {
|
|
115
115
|
...file.meta,
|
|
116
116
|
name,
|
|
117
|
-
|
|
117
|
+
pluginName,
|
|
118
118
|
group,
|
|
119
119
|
},
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, {
|
|
123
|
+
const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginName = plugin.name, type }) => {
|
|
124
124
|
if (!generator) {
|
|
125
125
|
throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`)
|
|
126
126
|
}
|
|
@@ -133,9 +133,9 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
133
133
|
return prev
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
prev[acc.statusCode] =
|
|
136
|
+
prev[acc.statusCode] = driver.resolveName({
|
|
137
137
|
name: acc.name,
|
|
138
|
-
|
|
138
|
+
pluginName,
|
|
139
139
|
type,
|
|
140
140
|
})
|
|
141
141
|
|
|
@@ -150,9 +150,9 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
150
150
|
return prev
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
prev[acc.statusCode] =
|
|
153
|
+
prev[acc.statusCode] = driver.resolveName({
|
|
154
154
|
name: acc.name,
|
|
155
|
-
|
|
155
|
+
pluginName,
|
|
156
156
|
type,
|
|
157
157
|
})
|
|
158
158
|
|
|
@@ -163,40 +163,40 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
163
163
|
|
|
164
164
|
return {
|
|
165
165
|
request: schemas.request?.name
|
|
166
|
-
?
|
|
166
|
+
? driver.resolveName({
|
|
167
167
|
name: schemas.request.name,
|
|
168
|
-
|
|
168
|
+
pluginName,
|
|
169
169
|
type,
|
|
170
170
|
})
|
|
171
171
|
: undefined,
|
|
172
172
|
parameters: {
|
|
173
173
|
path: schemas.pathParams?.name
|
|
174
|
-
?
|
|
174
|
+
? driver.resolveName({
|
|
175
175
|
name: schemas.pathParams.name,
|
|
176
|
-
|
|
176
|
+
pluginName,
|
|
177
177
|
type,
|
|
178
178
|
})
|
|
179
179
|
: undefined,
|
|
180
180
|
query: schemas.queryParams?.name
|
|
181
|
-
?
|
|
181
|
+
? driver.resolveName({
|
|
182
182
|
name: schemas.queryParams.name,
|
|
183
|
-
|
|
183
|
+
pluginName,
|
|
184
184
|
type,
|
|
185
185
|
})
|
|
186
186
|
: undefined,
|
|
187
187
|
header: schemas.headerParams?.name
|
|
188
|
-
?
|
|
188
|
+
? driver.resolveName({
|
|
189
189
|
name: schemas.headerParams.name,
|
|
190
|
-
|
|
190
|
+
pluginName,
|
|
191
191
|
type,
|
|
192
192
|
})
|
|
193
193
|
: undefined,
|
|
194
194
|
},
|
|
195
195
|
responses: {
|
|
196
196
|
...responses,
|
|
197
|
-
['default']:
|
|
197
|
+
['default']: driver.resolveName({
|
|
198
198
|
name: schemas.response.name,
|
|
199
|
-
|
|
199
|
+
pluginName,
|
|
200
200
|
type,
|
|
201
201
|
}),
|
|
202
202
|
...errors,
|