@kubb/plugin-oas 5.0.0-alpha.2 → 5.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{createGenerator-B8BypXNu.d.ts → createGenerator-BiZ9IsdY.d.ts} +106 -58
- package/dist/{generators-vAAte6w6.cjs → generators-85sP4GIS.cjs} +7 -7
- package/dist/generators-85sP4GIS.cjs.map +1 -0
- package/dist/{generators-B8HiBWvT.js → generators-hPE06pZB.js} +7 -7
- package/dist/generators-hPE06pZB.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +4 -3
- package/dist/generators.js +1 -1
- package/dist/{getFooter-Pw3tLCiV.js → getFooter-Dz4u5Mg4.js} +5 -2
- package/dist/getFooter-Dz4u5Mg4.js.map +1 -0
- package/dist/{getFooter-BBzsC616.cjs → getFooter-gshcRE1-.cjs} +5 -2
- package/dist/getFooter-gshcRE1-.cjs.map +1 -0
- package/dist/hooks.cjs +26 -45
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +6 -23
- package/dist/hooks.js +29 -47
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +15 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +22 -38
- package/dist/index.js +14 -14
- package/dist/index.js.map +1 -1
- package/dist/{requestBody-FpiwLR1p.cjs → requestBody-BHEEK1Z3.cjs} +87 -126
- package/dist/requestBody-BHEEK1Z3.cjs.map +1 -0
- package/dist/{requestBody-DQMKhTin.js → requestBody-bs_SwfEj.js} +77 -116
- package/dist/requestBody-bs_SwfEj.js.map +1 -0
- package/dist/utils.cjs +61 -11
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +61 -11
- package/dist/utils.js.map +1 -1
- package/package.json +7 -7
- package/src/OperationGenerator.ts +15 -15
- package/src/SchemaGenerator.ts +17 -20
- package/src/generators/createGenerator.ts +12 -15
- package/src/generators/createReactGenerator.ts +12 -15
- package/src/generators/index.ts +2 -2
- package/src/generators/jsonGenerator.ts +3 -3
- 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 +19 -18
- package/src/hooks/useSchemaManager.ts +5 -4
- package/src/index.ts +2 -2
- package/src/plugin.ts +5 -5
- package/src/types.ts +3 -2
- package/src/utils/getBanner.ts +1 -1
- package/src/utils/getFooter.ts +1 -1
- package/src/utils/getParams.ts +2 -2
- package/src/utils.tsx +50 -137
- package/dist/generators-B8HiBWvT.js.map +0 -1
- package/dist/generators-vAAte6w6.cjs.map +0 -1
- package/dist/getFooter-BBzsC616.cjs.map +0 -1
- package/dist/getFooter-Pw3tLCiV.js.map +0 -1
- package/dist/requestBody-DQMKhTin.js.map +0 -1
- package/dist/requestBody-FpiwLR1p.cjs.map +0 -1
- package/src/hooks/useRootNode.ts +0 -25
|
@@ -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
|
},
|
package/src/generators/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createGenerator } from './createGenerator.ts'
|
|
2
|
-
export { createReactGenerator } from './createReactGenerator.ts'
|
|
1
|
+
export { type CoreGenerator, createGenerator } from './createGenerator.ts'
|
|
2
|
+
export { createReactGenerator, type ReactGenerator } from './createReactGenerator.ts'
|
|
3
3
|
export { jsonGenerator } from './jsonGenerator.ts'
|
|
4
4
|
export type { Generator } from './types.ts'
|
|
@@ -7,8 +7,8 @@ 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',
|
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
import type { FileMetaBase, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
|
-
import {
|
|
2
|
+
import { useDriver, usePlugin } 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'
|
|
@@ -66,10 +66,11 @@ 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 = useDriver()
|
|
70
|
+
const defaultPluginName = plugin.name
|
|
70
71
|
|
|
71
|
-
const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginName =
|
|
72
|
-
return
|
|
72
|
+
const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginName = defaultPluginName, type }) => {
|
|
73
|
+
return driver.resolveName({
|
|
73
74
|
name: `${prefix} ${operation.getOperationId()} ${suffix}`,
|
|
74
75
|
pluginName,
|
|
75
76
|
type,
|
|
@@ -78,7 +79,7 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
78
79
|
|
|
79
80
|
const getGroup: UseOperationManagerResult['getGroup'] = (operation) => {
|
|
80
81
|
return {
|
|
81
|
-
tag: operation.getTags().at(0)?.name,
|
|
82
|
+
tag: operation.getTags().at(0)?.name ?? 'default',
|
|
82
83
|
path: operation.path,
|
|
83
84
|
}
|
|
84
85
|
}
|
|
@@ -90,19 +91,19 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
90
91
|
|
|
91
92
|
return generator.getSchemas(operation, {
|
|
92
93
|
resolveName: (name) =>
|
|
93
|
-
|
|
94
|
+
driver.resolveName({
|
|
94
95
|
name,
|
|
95
|
-
pluginName: params?.pluginName,
|
|
96
|
+
pluginName: params?.pluginName ?? defaultPluginName,
|
|
96
97
|
type: params?.type,
|
|
97
98
|
}),
|
|
98
99
|
})
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginName =
|
|
102
|
+
const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginName = defaultPluginName, extname = '.ts' } = {}) => {
|
|
102
103
|
const name = getName(operation, { type: 'file', pluginName, prefix, suffix })
|
|
103
104
|
const group = getGroup(operation)
|
|
104
105
|
|
|
105
|
-
const file =
|
|
106
|
+
const file = driver.getFile({
|
|
106
107
|
name,
|
|
107
108
|
extname,
|
|
108
109
|
pluginName,
|
|
@@ -120,12 +121,12 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
|
|
123
|
-
const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginName =
|
|
124
|
+
const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginName = defaultPluginName, type }) => {
|
|
124
125
|
if (!generator) {
|
|
125
126
|
throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`)
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
const schemas =
|
|
129
|
+
const schemas = getSchemas(operation)
|
|
129
130
|
|
|
130
131
|
const errors = (schemas.errors || []).reduce(
|
|
131
132
|
(prev, acc) => {
|
|
@@ -133,7 +134,7 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
133
134
|
return prev
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
prev[acc.statusCode] =
|
|
137
|
+
prev[acc.statusCode] = driver.resolveName({
|
|
137
138
|
name: acc.name,
|
|
138
139
|
pluginName,
|
|
139
140
|
type,
|
|
@@ -150,7 +151,7 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
150
151
|
return prev
|
|
151
152
|
}
|
|
152
153
|
|
|
153
|
-
prev[acc.statusCode] =
|
|
154
|
+
prev[acc.statusCode] = driver.resolveName({
|
|
154
155
|
name: acc.name,
|
|
155
156
|
pluginName,
|
|
156
157
|
type,
|
|
@@ -163,7 +164,7 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
163
164
|
|
|
164
165
|
return {
|
|
165
166
|
request: schemas.request?.name
|
|
166
|
-
?
|
|
167
|
+
? driver.resolveName({
|
|
167
168
|
name: schemas.request.name,
|
|
168
169
|
pluginName,
|
|
169
170
|
type,
|
|
@@ -171,21 +172,21 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
171
172
|
: undefined,
|
|
172
173
|
parameters: {
|
|
173
174
|
path: schemas.pathParams?.name
|
|
174
|
-
?
|
|
175
|
+
? driver.resolveName({
|
|
175
176
|
name: schemas.pathParams.name,
|
|
176
177
|
pluginName,
|
|
177
178
|
type,
|
|
178
179
|
})
|
|
179
180
|
: undefined,
|
|
180
181
|
query: schemas.queryParams?.name
|
|
181
|
-
?
|
|
182
|
+
? driver.resolveName({
|
|
182
183
|
name: schemas.queryParams.name,
|
|
183
184
|
pluginName,
|
|
184
185
|
type,
|
|
185
186
|
})
|
|
186
187
|
: undefined,
|
|
187
188
|
header: schemas.headerParams?.name
|
|
188
|
-
?
|
|
189
|
+
? driver.resolveName({
|
|
189
190
|
name: schemas.headerParams.name,
|
|
190
191
|
pluginName,
|
|
191
192
|
type,
|
|
@@ -194,7 +195,7 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
194
195
|
},
|
|
195
196
|
responses: {
|
|
196
197
|
...responses,
|
|
197
|
-
['default']:
|
|
198
|
+
['default']: driver.resolveName({
|
|
198
199
|
name: schemas.response.name,
|
|
199
200
|
pluginName,
|
|
200
201
|
type,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FileMetaBase, ResolveNameParams } from '@kubb/core'
|
|
2
|
-
import {
|
|
2
|
+
import { useDriver, usePlugin } from '@kubb/core/hooks'
|
|
3
3
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
4
4
|
|
|
5
5
|
type FileMeta = FileMetaBase & {
|
|
@@ -29,13 +29,14 @@ type UseSchemaManagerResult = {
|
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* `useSchemaManager` returns helper functions to get the schema file and schema name.
|
|
32
|
+
* @deprecated
|
|
32
33
|
*/
|
|
33
34
|
export function useSchemaManager(): UseSchemaManagerResult {
|
|
34
35
|
const plugin = usePlugin()
|
|
35
|
-
const
|
|
36
|
+
const driver = useDriver()
|
|
36
37
|
|
|
37
38
|
const getName: UseSchemaManagerResult['getName'] = (name, { pluginName = plugin.name, type }) => {
|
|
38
|
-
return
|
|
39
|
+
return driver.resolveName({
|
|
39
40
|
name,
|
|
40
41
|
pluginName,
|
|
41
42
|
type,
|
|
@@ -45,7 +46,7 @@ export function useSchemaManager(): UseSchemaManagerResult {
|
|
|
45
46
|
const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginName = plugin.name, extname = '.ts', group } = {}) => {
|
|
46
47
|
const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginName })
|
|
47
48
|
|
|
48
|
-
const file =
|
|
49
|
+
const file = driver.getFile({
|
|
49
50
|
name: resolvedName,
|
|
50
51
|
extname,
|
|
51
52
|
pluginName,
|
package/src/index.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type {
|
|
|
25
25
|
} from './SchemaMapper.ts'
|
|
26
26
|
export { isKeyword, schemaKeywords } from './SchemaMapper.ts'
|
|
27
27
|
export type * from './types.ts'
|
|
28
|
-
export {
|
|
28
|
+
export { renderOperation, renderOperations, renderSchema } from './utils.tsx'
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* @deprecated use `import { createGenerator } from '@kubb/plugin-oas/generators'`
|
|
@@ -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
|
|
43
|
+
export type Generator<TOptions extends PluginFactoryOptions> = _Generator<TOptions>
|
package/src/plugin.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
+
import type { AsyncEventEmitter } from '@internals/utils'
|
|
2
3
|
import { camelCase } from '@internals/utils'
|
|
3
|
-
import type
|
|
4
|
-
import { type Config, definePlugin, type Group, getMode, type KubbEvents } from '@kubb/core'
|
|
4
|
+
import { type Config, createPlugin, type Group, getMode, type KubbEvents } from '@kubb/core'
|
|
5
5
|
import type { Oas } from '@kubb/oas'
|
|
6
6
|
import { parseFromConfig, resolveServerUrl } from '@kubb/oas'
|
|
7
7
|
import { jsonGenerator } from './generators'
|
|
@@ -11,7 +11,7 @@ import type { PluginOas } from './types.ts'
|
|
|
11
11
|
|
|
12
12
|
export const pluginOasName = 'plugin-oas' satisfies PluginOas['name']
|
|
13
13
|
|
|
14
|
-
export const pluginOas =
|
|
14
|
+
export const pluginOas = createPlugin<PluginOas>((options) => {
|
|
15
15
|
const {
|
|
16
16
|
output = {
|
|
17
17
|
path: 'schemas',
|
|
@@ -152,7 +152,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
152
152
|
{
|
|
153
153
|
fabric: this.fabric,
|
|
154
154
|
oas,
|
|
155
|
-
|
|
155
|
+
driver: this.driver,
|
|
156
156
|
events: this.events,
|
|
157
157
|
plugin: this.plugin,
|
|
158
158
|
contentType,
|
|
@@ -169,7 +169,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
169
169
|
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
170
170
|
fabric: this.fabric,
|
|
171
171
|
oas,
|
|
172
|
-
|
|
172
|
+
driver: this.driver,
|
|
173
173
|
events: this.events,
|
|
174
174
|
plugin: this.plugin,
|
|
175
175
|
contentType,
|
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/getBanner.ts
CHANGED
|
@@ -67,7 +67,7 @@ export function getBanner<TOas extends Oas>({ output, oas, config }: Props<TOas>
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
if (isFunction(output.banner)) {
|
|
70
|
-
return `${output.banner(oas)}\n${banner}`
|
|
70
|
+
return `${output.banner(oas as any)}\n${banner}`
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
return `${output.banner}\n${banner}`
|
package/src/utils/getFooter.ts
CHANGED
package/src/utils/getParams.ts
CHANGED
|
@@ -20,7 +20,7 @@ export function getASTParams(
|
|
|
20
20
|
override?: (data: FunctionParamsAST) => FunctionParamsAST
|
|
21
21
|
} = {},
|
|
22
22
|
): FunctionParamsAST[] {
|
|
23
|
-
if (!operationSchema
|
|
23
|
+
if (!operationSchema?.schema.properties || !operationSchema.name) {
|
|
24
24
|
return []
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -82,7 +82,7 @@ export function getParamsMapping(
|
|
|
82
82
|
casing?: 'camelcase'
|
|
83
83
|
} = {},
|
|
84
84
|
): Record<string, string> | undefined {
|
|
85
|
-
if (!operationSchema
|
|
85
|
+
if (!operationSchema?.schema.properties) {
|
|
86
86
|
return undefined
|
|
87
87
|
}
|
|
88
88
|
|