@kubb/plugin-oas 3.0.0-alpha.9 → 3.0.0-beta.2
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/README.md +14 -5
- package/dist/OperationGenerator-BgQeGRzk.d.cts +550 -0
- package/dist/OperationGenerator-BgQeGRzk.d.ts +550 -0
- package/dist/{Schema-B1vcPGiK.d.ts → Schema-1iM2I0dK.d.ts} +1 -12
- package/dist/{Schema-DoSFh7Qd.d.cts → Schema-5o-c5UOy.d.cts} +1 -12
- package/dist/chunk-ABOQ73FL.cjs +36 -0
- package/dist/chunk-ABOQ73FL.cjs.map +1 -0
- package/dist/chunk-BG77DP54.js +30 -0
- package/dist/chunk-BG77DP54.js.map +1 -0
- package/dist/chunk-GF26SDHQ.js +28 -0
- package/dist/chunk-GF26SDHQ.js.map +1 -0
- package/dist/chunk-PADR76WZ.cjs +4 -0
- package/dist/chunk-PADR76WZ.cjs.map +1 -0
- package/dist/chunk-QAFBZLJA.cjs +48 -0
- package/dist/chunk-QAFBZLJA.cjs.map +1 -0
- package/dist/chunk-QT6ZFRNJ.cjs +752 -0
- package/dist/chunk-QT6ZFRNJ.cjs.map +1 -0
- package/dist/chunk-QWO5NQGQ.js +88 -0
- package/dist/chunk-QWO5NQGQ.js.map +1 -0
- package/dist/chunk-R47XMJ32.js +3 -0
- package/dist/chunk-R47XMJ32.js.map +1 -0
- package/dist/chunk-SR63CBLH.cjs +92 -0
- package/dist/chunk-SR63CBLH.cjs.map +1 -0
- package/dist/chunk-V2JO6RHI.js +744 -0
- package/dist/chunk-V2JO6RHI.js.map +1 -0
- package/dist/chunk-XNCEFOE6.js +45 -0
- package/dist/chunk-XNCEFOE6.js.map +1 -0
- package/dist/chunk-ZWHQ54JM.cjs +32 -0
- package/dist/chunk-ZWHQ54JM.cjs.map +1 -0
- package/dist/components.cjs +20 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +3 -6
- package/dist/components.d.ts +3 -6
- package/dist/components.js +3 -12
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +14 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +9 -0
- package/dist/generators.d.ts +9 -0
- package/dist/generators.js +5 -0
- package/dist/generators.js.map +1 -0
- package/dist/hooks.cjs +102 -57
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +41 -10
- package/dist/hooks.d.ts +41 -10
- package/dist/hooks.js +91 -53
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +134 -185
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -5
- package/dist/index.d.ts +2 -5
- package/dist/index.js +68 -146
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +32 -45
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +4 -13
- package/dist/utils.d.ts +4 -13
- package/dist/utils.js +8 -44
- package/dist/utils.js.map +1 -1
- package/package.json +20 -14
- package/src/OperationGenerator.ts +11 -23
- package/src/SchemaGenerator.ts +68 -9
- package/src/SchemaMapper.ts +6 -4
- package/src/components/Schema.tsx +1 -99
- package/src/generator.tsx +22 -18
- package/src/generators/index.ts +1 -0
- package/src/generators/jsonGenerator.ts +32 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useOperationManager.ts +77 -30
- package/src/hooks/useSchemaManager.ts +77 -0
- package/src/plugin.ts +69 -56
- package/src/types.ts +24 -18
- package/src/utils/getParams.ts +1 -1
- package/src/utils/getSchemaFactory.ts +1 -1
- package/src/utils/index.ts +0 -1
- package/src/utils/parseFromConfig.ts +7 -7
- package/dist/OperationGenerator-By5WOmWB.d.ts +0 -165
- package/dist/OperationGenerator-Gd1X7wUz.d.cts +0 -165
- package/dist/SchemaMapper-sGcY1xL5.d.cts +0 -247
- package/dist/SchemaMapper-sGcY1xL5.d.ts +0 -247
- package/dist/chunk-75BIOXB7.cjs +0 -7
- package/dist/chunk-75BIOXB7.cjs.map +0 -1
- package/dist/chunk-IAUV3UKH.cjs +0 -3965
- package/dist/chunk-IAUV3UKH.cjs.map +0 -1
- package/dist/chunk-M347763D.js +0 -3965
- package/dist/chunk-M347763D.js.map +0 -1
- package/dist/chunk-N7EEVJA6.js +0 -35
- package/dist/chunk-N7EEVJA6.js.map +0 -1
- package/dist/chunk-NU4F7G47.cjs +0 -89
- package/dist/chunk-NU4F7G47.cjs.map +0 -1
- package/dist/chunk-O76YQFZB.cjs +0 -35
- package/dist/chunk-O76YQFZB.cjs.map +0 -1
- package/dist/chunk-SQ64ESS4.js +0 -7
- package/dist/chunk-SQ64ESS4.js.map +0 -1
- package/dist/chunk-SZDO532A.js +0 -89
- package/dist/chunk-SZDO532A.js.map +0 -1
- package/dist/types-CZTUCaE5.d.cts +0 -145
- package/dist/types-CZTUCaE5.d.ts +0 -145
- package/src/utils/refSorter.ts +0 -13
|
@@ -13,7 +13,7 @@ type FileMeta = FileMetaBase & {
|
|
|
13
13
|
tag?: string
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
type SchemaNames = {
|
|
16
|
+
export type SchemaNames = {
|
|
17
17
|
request: string | undefined
|
|
18
18
|
parameters: {
|
|
19
19
|
path: string | undefined
|
|
@@ -25,14 +25,41 @@ type SchemaNames = {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
type UseOperationManagerResult = {
|
|
28
|
-
getName: (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
getName: (
|
|
29
|
+
operation: OperationType,
|
|
30
|
+
params: {
|
|
31
|
+
prefix?: string
|
|
32
|
+
suffix?: string
|
|
33
|
+
pluginKey?: Plugin['key']
|
|
34
|
+
type: ResolveNameParams['type']
|
|
35
|
+
},
|
|
36
|
+
) => string
|
|
37
|
+
getSchemaName: (
|
|
32
38
|
operation: Operation,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
key: keyof Omit<OperationSchemas, 'errors' | 'statusCodes'>,
|
|
40
|
+
params?: {
|
|
41
|
+
pluginKey?: Plugin['key']
|
|
42
|
+
type?: ResolveNameParams['type']
|
|
43
|
+
},
|
|
44
|
+
) => string
|
|
45
|
+
getFile: (
|
|
46
|
+
operation: OperationType,
|
|
47
|
+
params?: {
|
|
48
|
+
prefix?: string
|
|
49
|
+
suffix?: string
|
|
50
|
+
pluginKey?: Plugin['key']
|
|
51
|
+
extname?: KubbFile.Extname
|
|
52
|
+
tag?: string
|
|
53
|
+
},
|
|
54
|
+
) => KubbFile.File<FileMeta>
|
|
55
|
+
groupSchemasByName: (
|
|
56
|
+
operation: OperationType,
|
|
57
|
+
params: {
|
|
58
|
+
pluginKey?: Plugin['key']
|
|
59
|
+
type: ResolveNameParams['type']
|
|
60
|
+
},
|
|
61
|
+
) => SchemaNames
|
|
62
|
+
getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas
|
|
36
63
|
}
|
|
37
64
|
|
|
38
65
|
/**
|
|
@@ -42,27 +69,51 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
42
69
|
const { plugin, pluginManager } = useApp()
|
|
43
70
|
const { generator } = useContext(Oas.Context)
|
|
44
71
|
|
|
45
|
-
|
|
46
|
-
throw new Error(`'generator' is not defined`)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const getName: UseOperationManagerResult['getName'] = (operation, { pluginKey = plugin.key, type }) => {
|
|
72
|
+
const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginKey = plugin.key, type }) => {
|
|
50
73
|
return pluginManager.resolveName({
|
|
51
|
-
name: operation.getOperationId()
|
|
74
|
+
name: `${prefix} ${operation.getOperationId()} ${suffix}`,
|
|
52
75
|
pluginKey,
|
|
53
76
|
type,
|
|
54
77
|
})
|
|
55
78
|
}
|
|
56
79
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const name = getName(operation, { type: 'file', pluginKey })
|
|
80
|
+
const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {
|
|
81
|
+
if (!generator) {
|
|
82
|
+
throw new Error(`'generator' is not defined`)
|
|
83
|
+
}
|
|
62
84
|
|
|
85
|
+
return generator.getSchemas(operation, {
|
|
86
|
+
resolveName: (name) =>
|
|
87
|
+
pluginManager.resolveName({
|
|
88
|
+
name,
|
|
89
|
+
pluginKey: params?.pluginKey,
|
|
90
|
+
type: params?.type,
|
|
91
|
+
}),
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const getSchemaName: UseOperationManagerResult['getSchemaName'] = (operation, key, { pluginKey = plugin.key, type } = {}) => {
|
|
96
|
+
const schemas = getSchemas(operation)
|
|
97
|
+
|
|
98
|
+
if (!schemas[key]?.name) {
|
|
99
|
+
throw new Error(`SchemaName not found for ${operation.getOperationId()}`)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return pluginManager.resolveName({
|
|
103
|
+
name: schemas[key]?.name,
|
|
104
|
+
pluginKey,
|
|
105
|
+
type,
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
//TODO replace tag with group
|
|
109
|
+
const getFile: UseOperationManagerResult['getFile'] = (
|
|
110
|
+
operation,
|
|
111
|
+
{ prefix, suffix, pluginKey = plugin.key, tag = operation.getTags().at(0)?.name, extname = '.ts' } = {},
|
|
112
|
+
) => {
|
|
113
|
+
const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })
|
|
63
114
|
const file = pluginManager.getFile({
|
|
64
115
|
name,
|
|
65
|
-
|
|
116
|
+
extname,
|
|
66
117
|
pluginKey,
|
|
67
118
|
options: { type: 'file', pluginKey, tag },
|
|
68
119
|
})
|
|
@@ -79,6 +130,10 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
79
130
|
}
|
|
80
131
|
|
|
81
132
|
const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {
|
|
133
|
+
if (!generator) {
|
|
134
|
+
throw new Error(`'generator' is not defined`)
|
|
135
|
+
}
|
|
136
|
+
|
|
82
137
|
const schemas = generator.getSchemas(operation)
|
|
83
138
|
|
|
84
139
|
const errors = (schemas.errors || []).reduce(
|
|
@@ -149,16 +204,8 @@ export function useOperationManager(): UseOperationManagerResult {
|
|
|
149
204
|
return {
|
|
150
205
|
getName,
|
|
151
206
|
getFile,
|
|
152
|
-
getSchemas
|
|
153
|
-
|
|
154
|
-
forStatusCode,
|
|
155
|
-
resolveName: (name) =>
|
|
156
|
-
pluginManager.resolveName({
|
|
157
|
-
name,
|
|
158
|
-
pluginKey: params?.pluginKey,
|
|
159
|
-
type: params?.type,
|
|
160
|
-
}),
|
|
161
|
-
}),
|
|
207
|
+
getSchemas,
|
|
208
|
+
getSchemaName,
|
|
162
209
|
groupSchemasByName,
|
|
163
210
|
}
|
|
164
211
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useApp } from '@kubb/react'
|
|
2
|
+
|
|
3
|
+
import type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'
|
|
4
|
+
import type * as KubbFile from '@kubb/fs/types'
|
|
5
|
+
import type { Mode } from '@kubb/fs/types'
|
|
6
|
+
import { SchemaGenerator } from '../SchemaGenerator.ts'
|
|
7
|
+
import { type Schema, schemaKeywords } from '../SchemaMapper'
|
|
8
|
+
|
|
9
|
+
type FileMeta = FileMetaBase & {
|
|
10
|
+
pluginKey: Plugin['key']
|
|
11
|
+
name: string
|
|
12
|
+
tag?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type UseSchemaManagerResult = {
|
|
16
|
+
getName: (name: string, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string
|
|
17
|
+
getFile: (name: string, params?: { pluginKey?: Plugin['key']; mode?: Mode; extname?: KubbFile.Extname; tag?: string }) => KubbFile.File<FileMeta>
|
|
18
|
+
getImports: (tree: Array<Schema>) => Array<KubbFile.Import>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.
|
|
23
|
+
*/
|
|
24
|
+
export function useSchemaManager(): UseSchemaManagerResult {
|
|
25
|
+
const { mode, plugin, pluginManager, fileManager } = useApp()
|
|
26
|
+
|
|
27
|
+
const getName: UseSchemaManagerResult['getName'] = (name, { pluginKey = plugin.key, type }) => {
|
|
28
|
+
return pluginManager.resolveName({
|
|
29
|
+
name,
|
|
30
|
+
pluginKey,
|
|
31
|
+
type,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
//TODO replace tag with group
|
|
35
|
+
const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', tag } = {}) => {
|
|
36
|
+
const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginKey })
|
|
37
|
+
|
|
38
|
+
const file = pluginManager.getFile({
|
|
39
|
+
name: resolvedName,
|
|
40
|
+
extname,
|
|
41
|
+
pluginKey,
|
|
42
|
+
options: { type: 'file', pluginKey, tag },
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
...file,
|
|
47
|
+
meta: {
|
|
48
|
+
...file.meta,
|
|
49
|
+
name: resolvedName,
|
|
50
|
+
pluginKey,
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const getImports: UseSchemaManagerResult['getImports'] = (tree) => {
|
|
56
|
+
const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)
|
|
57
|
+
|
|
58
|
+
return refs
|
|
59
|
+
?.map((item, i) => {
|
|
60
|
+
if (!item.args.path) {
|
|
61
|
+
return undefined
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
name: [item.args.name],
|
|
66
|
+
path: item.args.path,
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
.filter(Boolean)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
getName,
|
|
74
|
+
getFile,
|
|
75
|
+
getImports,
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/plugin.ts
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { createPlugin } from '@kubb/core'
|
|
4
|
-
import { camelCase } from '@kubb/core/transformers'
|
|
1
|
+
import { FileManager, createPlugin } from '@kubb/core'
|
|
5
2
|
|
|
6
3
|
import { getSchemas } from './utils/getSchemas.ts'
|
|
7
4
|
import { parseFromConfig } from './utils/parseFromConfig.ts'
|
|
8
5
|
|
|
6
|
+
import path from 'node:path'
|
|
9
7
|
import type { Config } from '@kubb/core'
|
|
10
8
|
import type { Logger } from '@kubb/core/logger'
|
|
11
|
-
import type { Oas
|
|
12
|
-
import
|
|
9
|
+
import type { Oas } from '@kubb/oas'
|
|
10
|
+
import { OperationGenerator } from './OperationGenerator.ts'
|
|
11
|
+
import { SchemaGenerator } from './SchemaGenerator.ts'
|
|
12
|
+
import { jsonGenerator } from './generators'
|
|
13
13
|
import type { PluginOas } from './types.ts'
|
|
14
14
|
|
|
15
15
|
export const pluginOasName = 'plugin-oas' satisfies PluginOas['name']
|
|
16
16
|
|
|
17
17
|
export const pluginOas = createPlugin<PluginOas>((options) => {
|
|
18
18
|
const {
|
|
19
|
-
output = {
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
output = {
|
|
20
|
+
path: 'schemas',
|
|
21
|
+
},
|
|
22
22
|
validate = true,
|
|
23
|
+
generators = [jsonGenerator],
|
|
23
24
|
serverIndex = 0,
|
|
24
25
|
contentType,
|
|
25
26
|
oasClass,
|
|
26
27
|
} = options
|
|
27
28
|
|
|
28
|
-
const getOas = async ({ config, logger
|
|
29
|
+
const getOas = async ({ config, logger }: { config: Config; logger: Logger }): Promise<Oas> => {
|
|
29
30
|
try {
|
|
30
31
|
// needs to be in a different variable or the catch here will not work(return of a promise instead)
|
|
31
|
-
const oas = await parseFromConfig(config,
|
|
32
|
+
const oas = await parseFromConfig(config, oasClass)
|
|
32
33
|
|
|
33
34
|
if (validate) {
|
|
34
35
|
await oas.valdiate()
|
|
@@ -39,29 +40,22 @@ export const pluginOas = createPlugin<PluginOas>((options) => {
|
|
|
39
40
|
const error = e as Error
|
|
40
41
|
|
|
41
42
|
logger.emit('warning', error?.message)
|
|
42
|
-
return parseFromConfig(config,
|
|
43
|
+
return parseFromConfig(config, oasClass)
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
return {
|
|
47
48
|
name: pluginOasName,
|
|
48
|
-
|
|
49
|
-
output
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
exportType: false,
|
|
53
|
-
}
|
|
54
|
-
: {
|
|
55
|
-
exportType: 'barrelNamed',
|
|
56
|
-
...output,
|
|
57
|
-
},
|
|
58
|
-
options,
|
|
49
|
+
options: {
|
|
50
|
+
output,
|
|
51
|
+
...options,
|
|
52
|
+
},
|
|
59
53
|
context() {
|
|
60
54
|
const { config, logger } = this
|
|
61
55
|
|
|
62
56
|
return {
|
|
63
|
-
getOas(
|
|
64
|
-
return getOas({ config, logger
|
|
57
|
+
getOas() {
|
|
58
|
+
return getOas({ config, logger })
|
|
65
59
|
},
|
|
66
60
|
async getSchemas({ includes } = {}) {
|
|
67
61
|
const oas = await this.getOas()
|
|
@@ -69,12 +63,25 @@ export const pluginOas = createPlugin<PluginOas>((options) => {
|
|
|
69
63
|
},
|
|
70
64
|
async getBaseURL() {
|
|
71
65
|
const oasInstance = await this.getOas()
|
|
72
|
-
|
|
73
|
-
return baseURL
|
|
66
|
+
return oasInstance.api.servers?.at(serverIndex)?.url
|
|
74
67
|
},
|
|
75
68
|
contentType,
|
|
76
69
|
}
|
|
77
70
|
},
|
|
71
|
+
resolvePath(baseName, pathMode, options) {
|
|
72
|
+
const root = path.resolve(this.config.root, this.config.output.path)
|
|
73
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
|
74
|
+
|
|
75
|
+
if (mode === 'single') {
|
|
76
|
+
/**
|
|
77
|
+
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
78
|
+
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
79
|
+
*/
|
|
80
|
+
return path.resolve(root, output.path)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return path.resolve(root, output.path, baseName)
|
|
84
|
+
},
|
|
78
85
|
async buildStart() {
|
|
79
86
|
if (!output) {
|
|
80
87
|
return
|
|
@@ -83,39 +90,45 @@ export const pluginOas = createPlugin<PluginOas>((options) => {
|
|
|
83
90
|
const oas = await getOas({
|
|
84
91
|
config: this.config,
|
|
85
92
|
logger: this.logger,
|
|
86
|
-
formatOptions: {
|
|
87
|
-
filterSet: filter,
|
|
88
|
-
sortSet: sort,
|
|
89
|
-
},
|
|
90
93
|
})
|
|
91
94
|
await oas.dereference()
|
|
92
95
|
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
96
|
+
const schemaGenerator = new SchemaGenerator(
|
|
97
|
+
{
|
|
98
|
+
unknownType: 'unknown',
|
|
99
|
+
dateType: 'date',
|
|
100
|
+
transformers: {},
|
|
101
|
+
...this.plugin.options,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
oas,
|
|
105
|
+
pluginManager: this.pluginManager,
|
|
106
|
+
plugin: this.plugin,
|
|
107
|
+
contentType,
|
|
108
|
+
include: undefined,
|
|
109
|
+
override: undefined,
|
|
110
|
+
mode: 'split',
|
|
111
|
+
output: output.path,
|
|
112
|
+
},
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
const schemaFiles = await schemaGenerator.build(...generators)
|
|
116
|
+
await this.addFile(...schemaFiles)
|
|
117
|
+
|
|
118
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
119
|
+
oas,
|
|
120
|
+
pluginManager: this.pluginManager,
|
|
121
|
+
plugin: this.plugin,
|
|
122
|
+
contentType,
|
|
123
|
+
exclude: undefined,
|
|
124
|
+
include: undefined,
|
|
125
|
+
override: undefined,
|
|
126
|
+
mode: 'split',
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
const operationFiles = await operationGenerator.build(...generators)
|
|
116
130
|
|
|
117
|
-
|
|
118
|
-
await Promise.all(promises)
|
|
131
|
+
await this.addFile(...operationFiles)
|
|
119
132
|
},
|
|
120
133
|
}
|
|
121
134
|
})
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Plugin } from '@kubb/core'
|
|
1
|
+
import type { Output, Plugin } from '@kubb/core'
|
|
2
2
|
import type { PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
3
3
|
import type * as KubbFile from '@kubb/fs/types'
|
|
4
4
|
|
|
5
5
|
import type { HttpMethod, Oas, Operation, SchemaObject, contentType } from '@kubb/oas'
|
|
6
|
-
import type {
|
|
6
|
+
import type { Generator } from './generator.tsx'
|
|
7
7
|
import type { GetSchemasProps } from './utils/getSchemas.ts'
|
|
8
8
|
|
|
9
9
|
export type ResolvePathOptions = {
|
|
@@ -13,7 +13,7 @@ export type ResolvePathOptions = {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export type API = {
|
|
16
|
-
getOas: (
|
|
16
|
+
getOas: () => Promise<Oas>
|
|
17
17
|
getSchemas: (options?: Pick<GetSchemasProps, 'includes'>) => Promise<Record<string, SchemaObject>>
|
|
18
18
|
getBaseURL: () => Promise<string | undefined>
|
|
19
19
|
contentType?: contentType
|
|
@@ -25,18 +25,10 @@ export type Options = {
|
|
|
25
25
|
* @default true
|
|
26
26
|
*/
|
|
27
27
|
validate?: boolean
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* False will not generate the schema JSON's.
|
|
33
|
-
* @default 'schemas'
|
|
34
|
-
*/
|
|
35
|
-
path: string
|
|
36
|
-
extName?: KubbFile.Extname
|
|
37
|
-
exportType?: 'barrel' | 'barrelNamed' | false
|
|
38
|
-
}
|
|
39
|
-
| false
|
|
28
|
+
/**
|
|
29
|
+
* @default 'schemas'
|
|
30
|
+
*/
|
|
31
|
+
output?: Output
|
|
40
32
|
/**
|
|
41
33
|
* Which server to use from the array of `servers.url[serverIndex]`
|
|
42
34
|
* @example
|
|
@@ -50,9 +42,14 @@ export type Options = {
|
|
|
50
42
|
* By default, this is set based on the first used contentType..
|
|
51
43
|
*/
|
|
52
44
|
contentType?: contentType
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Override some behaviour of the Oas class instance, see '@kubb/oas'
|
|
47
|
+
*/
|
|
55
48
|
oasClass?: typeof Oas
|
|
49
|
+
/**
|
|
50
|
+
* Define some generators next to the JSON generation
|
|
51
|
+
*/
|
|
52
|
+
generators?: Array<Generator<PluginOas>>
|
|
56
53
|
}
|
|
57
54
|
|
|
58
55
|
/**
|
|
@@ -130,6 +127,11 @@ type ByMethod = {
|
|
|
130
127
|
type: 'method'
|
|
131
128
|
pattern: HttpMethod | RegExp
|
|
132
129
|
}
|
|
130
|
+
// TODO implement as alternative for ByMethod
|
|
131
|
+
type ByMethods = {
|
|
132
|
+
type: 'methods'
|
|
133
|
+
pattern: Array<HttpMethod>
|
|
134
|
+
}
|
|
133
135
|
|
|
134
136
|
type BySchemaName = {
|
|
135
137
|
type: 'schemaName'
|
|
@@ -143,4 +145,8 @@ export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | By
|
|
|
143
145
|
options: Partial<TOptions>
|
|
144
146
|
}
|
|
145
147
|
|
|
146
|
-
|
|
148
|
+
type ResolvedOptions = Options & {
|
|
149
|
+
output: Output
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export type PluginOas = PluginFactoryOptions<'plugin-oas', Options, ResolvedOptions, API, never>
|
package/src/utils/getParams.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isParameterObject } from '@kubb/oas'
|
|
2
2
|
|
|
3
|
+
import { camelCase } from '@kubb/core/transformers'
|
|
3
4
|
import type { FunctionParamsAST } from '@kubb/core/utils'
|
|
4
5
|
import type { OasTypes } from '@kubb/oas'
|
|
5
6
|
import type { Params } from '@kubb/react/types'
|
|
6
7
|
import type { OperationSchema } from '../types.ts'
|
|
7
|
-
import { camelCase } from '@kubb/core/transformers'
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
10
|
* @deprecated
|
|
@@ -26,7 +26,7 @@ export function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (s
|
|
|
26
26
|
const version = isOpenApiV3_1Document(oas.api) ? '3.1' : '3.0'
|
|
27
27
|
|
|
28
28
|
return {
|
|
29
|
-
schema,
|
|
29
|
+
schema: oas.dereferenceWithRef(schema),
|
|
30
30
|
version,
|
|
31
31
|
} as SchemaResult<TWithRef>
|
|
32
32
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -3,7 +3,6 @@ export { getASTParams, getPathParams } from './getParams.ts'
|
|
|
3
3
|
export { getSchemaFactory } from './getSchemaFactory.ts'
|
|
4
4
|
export type { GetSchemasProps } from './getSchemas.ts'
|
|
5
5
|
export { getSchemas } from './getSchemas.ts'
|
|
6
|
-
export { refsSorter } from './refSorter.ts'
|
|
7
6
|
export { parseFromConfig } from './parseFromConfig.ts'
|
|
8
7
|
|
|
9
8
|
export { isOptional } from '@kubb/oas'
|
|
@@ -2,35 +2,35 @@ import { resolve } from 'node:path'
|
|
|
2
2
|
|
|
3
3
|
import { URLPath } from '@kubb/core/utils'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { parse } from '@kubb/oas/parser'
|
|
6
6
|
|
|
7
7
|
import type { Config } from '@kubb/core'
|
|
8
8
|
import { Oas, type OasTypes } from '@kubb/oas'
|
|
9
9
|
import yaml from '@stoplight/yaml'
|
|
10
10
|
|
|
11
|
-
export function parseFromConfig(config: Config,
|
|
11
|
+
export function parseFromConfig(config: Config, oasClass: typeof Oas = Oas): Promise<Oas> {
|
|
12
12
|
if ('data' in config.input) {
|
|
13
13
|
if (typeof config.input.data === 'object') {
|
|
14
14
|
const api: OasTypes.OASDocument = JSON.parse(JSON.stringify(config.input.data)) as OasTypes.OASDocument
|
|
15
|
-
return parse(api,
|
|
15
|
+
return parse(api, oasClass)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
19
|
const api: string = yaml.parse(config.input.data as string) as string
|
|
20
20
|
|
|
21
|
-
return parse(api,
|
|
21
|
+
return parse(api, oasClass)
|
|
22
22
|
} catch (e) {
|
|
23
23
|
/* empty */
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const api: OasTypes.OASDocument = JSON.parse(JSON.stringify(config.input.data)) as OasTypes.OASDocument
|
|
27
27
|
|
|
28
|
-
return parse(api,
|
|
28
|
+
return parse(api, oasClass)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
if (new URLPath(config.input.path).isURL) {
|
|
32
|
-
return parse(config.input.path,
|
|
32
|
+
return parse(config.input.path, oasClass)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
return parse(resolve(config.root, config.input.path),
|
|
35
|
+
return parse(resolve(config.root, config.input.path), oasClass)
|
|
36
36
|
}
|