@kubb/plugin-oas 5.0.0-alpha.3 → 5.0.0-alpha.31
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/SchemaMapper-CeavHZlp.cjs.map +1 -1
- package/dist/SchemaMapper-CqMkO2T1.js.map +1 -1
- package/dist/{SchemaMapper-SneuY1wg.d.ts → SchemaMapper-gGBRHCTB.d.ts} +2 -2
- package/dist/{createGenerator-jtR_okrd.d.ts → createGenerator-eLDSS4c0.d.ts} +114 -63
- 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 +25 -21
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +5 -3
- package/dist/hooks.js +27 -23
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +50 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +26 -52
- package/dist/index.js +49 -44
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/{requestBody-BJJL0mpy.cjs → requestBody-94hwM4b-.cjs} +115 -304
- package/dist/requestBody-94hwM4b-.cjs.map +1 -0
- package/dist/{requestBody-CSL-jLGQ.js → requestBody-BO3N7fWH.js} +107 -290
- package/dist/requestBody-BO3N7fWH.js.map +1 -0
- package/dist/utils.cjs +61 -11
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +3 -4
- package/dist/utils.js +61 -11
- package/dist/utils.js.map +1 -1
- package/package.json +8 -12
- package/src/OperationGenerator.ts +70 -84
- package/src/SchemaGenerator.ts +59 -80
- package/src/SchemaMapper.ts +1 -1
- package/src/generators/createGenerator.ts +13 -17
- 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 -43
- package/src/hooks/useOas.ts +5 -2
- package/src/hooks/useOperationManager.ts +20 -20
- package/src/hooks/useSchemaManager.ts +5 -6
- package/src/index.ts +2 -2
- package/src/plugin.ts +13 -9
- package/src/types.ts +11 -5
- package/src/utils/getBanner.ts +1 -1
- package/src/utils/getFooter.ts +1 -1
- package/src/utils/getImports.ts +1 -1
- package/src/utils/getParams.ts +2 -2
- package/src/utils.tsx +51 -151
- 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-BJJL0mpy.cjs.map +0 -1
- package/dist/requestBody-CSL-jLGQ.js.map +0 -1
|
@@ -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 { 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
|
|
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
|
-
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
|
|
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
|
|
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>
|
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,6 +1,5 @@
|
|
|
1
|
-
import type { FileMetaBase, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
|
-
import {
|
|
3
|
-
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
1
|
+
import type { FileMetaBase, KubbFile, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
|
+
import { useDriver, usePlugin } from '@kubb/core/hooks'
|
|
4
3
|
import type { Operation, Operation as OperationType } from '@kubb/oas'
|
|
5
4
|
import type { OperationGenerator } from '../OperationGenerator.ts'
|
|
6
5
|
import type { OperationSchemas } from '../types.ts'
|
|
@@ -66,10 +65,11 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
66
65
|
generator: Omit<OperationGenerator<TPluginOptions>, 'build'>,
|
|
67
66
|
): UseOperationManagerResult {
|
|
68
67
|
const plugin = usePlugin()
|
|
69
|
-
const
|
|
68
|
+
const driver = useDriver()
|
|
69
|
+
const defaultPluginName = plugin.name
|
|
70
70
|
|
|
71
|
-
const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginName =
|
|
72
|
-
return
|
|
71
|
+
const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginName = defaultPluginName, type }) => {
|
|
72
|
+
return driver.resolveName({
|
|
73
73
|
name: `${prefix} ${operation.getOperationId()} ${suffix}`,
|
|
74
74
|
pluginName,
|
|
75
75
|
type,
|
|
@@ -78,7 +78,7 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
78
78
|
|
|
79
79
|
const getGroup: UseOperationManagerResult['getGroup'] = (operation) => {
|
|
80
80
|
return {
|
|
81
|
-
tag: operation.getTags().at(0)?.name,
|
|
81
|
+
tag: operation.getTags().at(0)?.name ?? 'default',
|
|
82
82
|
path: operation.path,
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -90,19 +90,19 @@ 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
|
-
pluginName: params?.pluginName,
|
|
95
|
+
pluginName: params?.pluginName ?? defaultPluginName,
|
|
96
96
|
type: params?.type,
|
|
97
97
|
}),
|
|
98
98
|
})
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginName =
|
|
101
|
+
const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginName = defaultPluginName, extname = '.ts' } = {}) => {
|
|
102
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
108
|
pluginName,
|
|
@@ -120,12 +120,12 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginName =
|
|
123
|
+
const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginName = defaultPluginName, type }) => {
|
|
124
124
|
if (!generator) {
|
|
125
125
|
throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`)
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
const schemas =
|
|
128
|
+
const schemas = getSchemas(operation)
|
|
129
129
|
|
|
130
130
|
const errors = (schemas.errors || []).reduce(
|
|
131
131
|
(prev, acc) => {
|
|
@@ -133,7 +133,7 @@ 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,
|
|
@@ -150,7 +150,7 @@ 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,
|
|
@@ -163,7 +163,7 @@ 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,
|
|
@@ -171,21 +171,21 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
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,
|
|
@@ -194,7 +194,7 @@ export function useOperationManager<TPluginOptions extends PluginFactoryOptions
|
|
|
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,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { FileMetaBase, ResolveNameParams } from '@kubb/core'
|
|
2
|
-
import {
|
|
3
|
-
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
1
|
+
import type { FileMetaBase, KubbFile, ResolveNameParams } from '@kubb/core'
|
|
2
|
+
import { useDriver, usePlugin } from '@kubb/core/hooks'
|
|
4
3
|
|
|
5
4
|
type FileMeta = FileMetaBase & {
|
|
6
5
|
pluginName: string
|
|
@@ -33,10 +32,10 @@ type UseSchemaManagerResult = {
|
|
|
33
32
|
*/
|
|
34
33
|
export function useSchemaManager(): UseSchemaManagerResult {
|
|
35
34
|
const plugin = usePlugin()
|
|
36
|
-
const
|
|
35
|
+
const driver = useDriver()
|
|
37
36
|
|
|
38
37
|
const getName: UseSchemaManagerResult['getName'] = (name, { pluginName = plugin.name, type }) => {
|
|
39
|
-
return
|
|
38
|
+
return driver.resolveName({
|
|
40
39
|
name,
|
|
41
40
|
pluginName,
|
|
42
41
|
type,
|
|
@@ -46,7 +45,7 @@ export function useSchemaManager(): UseSchemaManagerResult {
|
|
|
46
45
|
const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginName = plugin.name, extname = '.ts', group } = {}) => {
|
|
47
46
|
const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginName })
|
|
48
47
|
|
|
49
|
-
const file =
|
|
48
|
+
const file = driver.getFile({
|
|
50
49
|
name: resolvedName,
|
|
51
50
|
extname,
|
|
52
51
|
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,9 +1,10 @@
|
|
|
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 KubbEvents, type UserGroup } from '@kubb/core'
|
|
5
5
|
import type { Oas } from '@kubb/oas'
|
|
6
6
|
import { parseFromConfig, resolveServerUrl } from '@kubb/oas'
|
|
7
|
+
import { version } from '../package.json'
|
|
7
8
|
import { jsonGenerator } from './generators'
|
|
8
9
|
import { OperationGenerator } from './OperationGenerator.ts'
|
|
9
10
|
import { SchemaGenerator } from './SchemaGenerator.ts'
|
|
@@ -11,7 +12,7 @@ import type { PluginOas } from './types.ts'
|
|
|
11
12
|
|
|
12
13
|
export const pluginOasName = 'plugin-oas' satisfies PluginOas['name']
|
|
13
14
|
|
|
14
|
-
export const pluginOas =
|
|
15
|
+
export const pluginOas = createPlugin<PluginOas>((options) => {
|
|
15
16
|
const {
|
|
16
17
|
output = {
|
|
17
18
|
path: 'schemas',
|
|
@@ -60,11 +61,14 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
60
61
|
|
|
61
62
|
return {
|
|
62
63
|
name: pluginOasName,
|
|
64
|
+
version,
|
|
63
65
|
options: {
|
|
64
66
|
output,
|
|
65
67
|
validate,
|
|
66
68
|
discriminator,
|
|
67
69
|
...options,
|
|
70
|
+
exclude: [],
|
|
71
|
+
override: [],
|
|
68
72
|
},
|
|
69
73
|
inject() {
|
|
70
74
|
const config = this.config
|
|
@@ -99,8 +103,8 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
99
103
|
}
|
|
100
104
|
},
|
|
101
105
|
resolvePath(baseName, pathMode, options) {
|
|
102
|
-
const root =
|
|
103
|
-
const mode = pathMode ?? getMode(
|
|
106
|
+
const root = this.root
|
|
107
|
+
const mode = pathMode ?? this.getMode(output)
|
|
104
108
|
|
|
105
109
|
if (mode === 'single') {
|
|
106
110
|
/**
|
|
@@ -111,7 +115,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
111
115
|
}
|
|
112
116
|
|
|
113
117
|
if (group && (options?.group?.path || options?.group?.tag)) {
|
|
114
|
-
const groupName:
|
|
118
|
+
const groupName: UserGroup['name'] = group?.name
|
|
115
119
|
? group.name
|
|
116
120
|
: (ctx) => {
|
|
117
121
|
if (group?.type === 'path') {
|
|
@@ -132,7 +136,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
132
136
|
|
|
133
137
|
return path.resolve(root, output.path, baseName)
|
|
134
138
|
},
|
|
135
|
-
async
|
|
139
|
+
async buildStart() {
|
|
136
140
|
const oas = await this.getOas({ validate })
|
|
137
141
|
|
|
138
142
|
if (!output || generators.length === 0) {
|
|
@@ -152,7 +156,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
152
156
|
{
|
|
153
157
|
fabric: this.fabric,
|
|
154
158
|
oas,
|
|
155
|
-
|
|
159
|
+
driver: this.driver,
|
|
156
160
|
events: this.events,
|
|
157
161
|
plugin: this.plugin,
|
|
158
162
|
contentType,
|
|
@@ -169,7 +173,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
169
173
|
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
170
174
|
fabric: this.fabric,
|
|
171
175
|
oas,
|
|
172
|
-
|
|
176
|
+
driver: this.driver,
|
|
173
177
|
events: this.events,
|
|
174
178
|
plugin: this.plugin,
|
|
175
179
|
contentType,
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
1
|
+
import type { KubbFile, Output, PluginFactoryOptions, ResolveNameParams, UserGroup } from '@kubb/core'
|
|
3
2
|
|
|
4
3
|
import type { contentType, HttpMethod, Oas, Operation, SchemaObject } from '@kubb/oas'
|
|
5
4
|
import type { Generator } from './generators/types.ts'
|
|
@@ -16,6 +15,9 @@ type Context = {
|
|
|
16
15
|
declare global {
|
|
17
16
|
namespace Kubb {
|
|
18
17
|
interface PluginContext extends Context {}
|
|
18
|
+
interface PluginRegistry {
|
|
19
|
+
'plugin-oas': PluginOas
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -42,7 +44,7 @@ export type Options = {
|
|
|
42
44
|
/**
|
|
43
45
|
* Group the JSON files based on the provided name.
|
|
44
46
|
*/
|
|
45
|
-
group?:
|
|
47
|
+
group?: UserGroup
|
|
46
48
|
/**
|
|
47
49
|
* Which server to use from the array of `servers.url[serverIndex]`
|
|
48
50
|
* @example
|
|
@@ -220,15 +222,19 @@ type ByContentType = {
|
|
|
220
222
|
pattern: string | RegExp
|
|
221
223
|
}
|
|
222
224
|
|
|
223
|
-
export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType
|
|
224
|
-
export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType
|
|
225
|
+
export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
|
|
226
|
+
export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
|
|
225
227
|
|
|
226
228
|
export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
229
|
+
// should be options: Omit<Partial<TOptions>, 'override'>
|
|
227
230
|
options: Partial<TOptions>
|
|
228
231
|
}
|
|
229
232
|
|
|
230
233
|
type ResolvedOptions = Options & {
|
|
231
234
|
output: Output<Oas>
|
|
235
|
+
exclude: Array<Exclude>
|
|
236
|
+
include?: Array<Include>
|
|
237
|
+
override: Array<Override<ResolvedOptions>>
|
|
232
238
|
}
|
|
233
239
|
|
|
234
240
|
export type PluginOas = PluginFactoryOptions<'plugin-oas', Options, ResolvedOptions, Context, ResolvePathOptions>
|
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/getImports.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
|
|