@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,9 +1,9 @@
|
|
|
1
|
-
import type { FileMetaBase,
|
|
2
|
-
import { usePlugin,
|
|
1
|
+
import type { FileMetaBase, ResolveNameParams } from '@kubb/core'
|
|
2
|
+
import { usePlugin, usePluginDriver } from '@kubb/core/hooks'
|
|
3
3
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
4
4
|
|
|
5
5
|
type FileMeta = FileMetaBase & {
|
|
6
|
-
|
|
6
|
+
pluginName: string
|
|
7
7
|
name: string
|
|
8
8
|
group?: {
|
|
9
9
|
tag?: string
|
|
@@ -12,11 +12,11 @@ type FileMeta = FileMetaBase & {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
type UseSchemaManagerResult = {
|
|
15
|
-
getName: (name: string, params: {
|
|
15
|
+
getName: (name: string, params: { pluginName?: string; type: ResolveNameParams['type'] }) => string
|
|
16
16
|
getFile: (
|
|
17
17
|
name: string,
|
|
18
18
|
params?: {
|
|
19
|
-
|
|
19
|
+
pluginName?: string
|
|
20
20
|
mode?: KubbFile.Mode
|
|
21
21
|
extname?: KubbFile.Extname
|
|
22
22
|
group?: {
|
|
@@ -29,27 +29,28 @@ 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 = usePluginDriver()
|
|
36
37
|
|
|
37
|
-
const getName: UseSchemaManagerResult['getName'] = (name, {
|
|
38
|
-
return
|
|
38
|
+
const getName: UseSchemaManagerResult['getName'] = (name, { pluginName = plugin.name, type }) => {
|
|
39
|
+
return driver.resolveName({
|
|
39
40
|
name,
|
|
40
|
-
|
|
41
|
+
pluginName,
|
|
41
42
|
type,
|
|
42
43
|
})
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split',
|
|
46
|
-
const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file',
|
|
46
|
+
const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginName = plugin.name, extname = '.ts', group } = {}) => {
|
|
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
|
-
options: { type: 'file',
|
|
52
|
+
pluginName,
|
|
53
|
+
options: { type: 'file', pluginName, group },
|
|
53
54
|
})
|
|
54
55
|
|
|
55
56
|
return {
|
|
@@ -57,7 +58,7 @@ export function useSchemaManager(): UseSchemaManagerResult {
|
|
|
57
58
|
meta: {
|
|
58
59
|
...file.meta,
|
|
59
60
|
name: resolvedName,
|
|
60
|
-
|
|
61
|
+
pluginName,
|
|
61
62
|
},
|
|
62
63
|
}
|
|
63
64
|
}
|
package/src/index.ts
CHANGED
|
@@ -40,4 +40,4 @@ export const createReactGenerator = _createReactGenerator
|
|
|
40
40
|
/**
|
|
41
41
|
* @deprecated use `import { Generator } from '@kubb/plugin-oas/generators'`
|
|
42
42
|
*/
|
|
43
|
-
export type Generator<TOptions extends PluginFactoryOptions
|
|
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',
|
|
@@ -135,7 +135,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
|
|
|
135
135
|
async install() {
|
|
136
136
|
const oas = await this.getOas({ validate })
|
|
137
137
|
|
|
138
|
-
if (!output) {
|
|
138
|
+
if (!output || generators.length === 0) {
|
|
139
139
|
return
|
|
140
140
|
}
|
|
141
141
|
|
|
@@ -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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Group, Output,
|
|
1
|
+
import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
2
|
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
3
3
|
|
|
4
4
|
import type { contentType, HttpMethod, Oas, Operation, SchemaObject } from '@kubb/oas'
|
|
@@ -20,7 +20,7 @@ declare global {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export type ResolvePathOptions = {
|
|
23
|
-
|
|
23
|
+
pluginName?: string
|
|
24
24
|
group?: {
|
|
25
25
|
tag?: string
|
|
26
26
|
path?: string
|
|
@@ -136,14 +136,14 @@ export type Options = {
|
|
|
136
136
|
*
|
|
137
137
|
* `originalName` is the original name used(in PascalCase), only used to remove duplicates
|
|
138
138
|
*
|
|
139
|
-
* `
|
|
139
|
+
* `pluginName` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
|
|
140
140
|
* @example import a type(plugin-ts) for a mock file(swagger-faker)
|
|
141
141
|
*/
|
|
142
142
|
export type Ref = {
|
|
143
143
|
propertyName: string
|
|
144
144
|
originalName: string
|
|
145
145
|
path: KubbFile.Path
|
|
146
|
-
|
|
146
|
+
pluginName?: string
|
|
147
147
|
}
|
|
148
148
|
export type Refs = Record<string, Ref>
|
|
149
149
|
|
|
@@ -220,10 +220,11 @@ type ByContentType = {
|
|
|
220
220
|
pattern: string | RegExp
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType
|
|
224
|
-
export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType
|
|
223
|
+
export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
|
|
224
|
+
export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
|
|
225
225
|
|
|
226
226
|
export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
227
|
+
// should be options: Omit<Partial<TOptions>, 'override'>
|
|
227
228
|
options: Partial<TOptions>
|
|
228
229
|
}
|
|
229
230
|
|
package/src/utils.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { OperationNode, SchemaNode } from '@kubb/ast/types'
|
|
2
|
-
import type { Config, Plugin, PluginFactoryOptions } from '@kubb/core'
|
|
2
|
+
import type { Adapter, Config, Plugin, PluginDriver, PluginFactoryOptions, ReactGeneratorV2 } from '@kubb/core'
|
|
3
|
+
import type { KubbFile } from '@kubb/fabric-core/types'
|
|
3
4
|
import type { Operation, SchemaObject } from '@kubb/oas'
|
|
4
|
-
import {
|
|
5
|
+
import { createReactFabric, Fabric } from '@kubb/react-fabric'
|
|
6
|
+
import type { Fabric as FabricType } from '@kubb/react-fabric/types'
|
|
5
7
|
import type { ReactGenerator } from './generators/createReactGenerator.ts'
|
|
6
8
|
import type { OperationGenerator } from './OperationGenerator.ts'
|
|
7
9
|
import type { SchemaGenerator, SchemaGeneratorOptions } from './SchemaGenerator.ts'
|
|
@@ -9,19 +11,23 @@ import type { Schema } from './SchemaMapper.ts'
|
|
|
9
11
|
|
|
10
12
|
type BuildOperationsBaseOptions<TOptions extends PluginFactoryOptions> = {
|
|
11
13
|
config: Config
|
|
12
|
-
fabric:
|
|
14
|
+
fabric: FabricType
|
|
13
15
|
plugin: Plugin<TOptions>
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
type BuildOperationsV1Options<TOptions extends PluginFactoryOptions> = BuildOperationsBaseOptions<TOptions> & {
|
|
17
19
|
version?: '1'
|
|
18
|
-
Component: ReactGenerator<
|
|
20
|
+
Component: ReactGenerator<TOptions>['Operations']
|
|
19
21
|
generator: Omit<OperationGenerator<TOptions>, 'build'>
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
type BuildOperationsV2Options<TOptions extends PluginFactoryOptions> = BuildOperationsBaseOptions<TOptions> & {
|
|
23
25
|
version: '2'
|
|
24
|
-
Component:
|
|
26
|
+
Component: ReactGeneratorV2<TOptions>['Operations'] | undefined
|
|
27
|
+
adapter: Adapter
|
|
28
|
+
driver: PluginDriver
|
|
29
|
+
mode: KubbFile.Mode
|
|
30
|
+
options: TOptions['resolvedOptions']
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
function isBuildOperationsV1Options<TOptions extends PluginFactoryOptions>(
|
|
@@ -52,41 +58,46 @@ export async function buildOperations<TOptions extends PluginFactoryOptions>(
|
|
|
52
58
|
|
|
53
59
|
if (isBuildOperationsV1Options(options)) {
|
|
54
60
|
const { generator, Component } = options
|
|
55
|
-
const {
|
|
61
|
+
const { driver, oas, mode } = generator.context
|
|
56
62
|
|
|
57
63
|
await fabricChild.render(
|
|
58
|
-
<
|
|
64
|
+
<Fabric meta={{ driver, plugin, mode, oas }}>
|
|
59
65
|
<Component config={config} operations={operationsOrNodes as Array<Operation>} generator={generator} plugin={plugin} />
|
|
60
|
-
</
|
|
66
|
+
</Fabric>,
|
|
61
67
|
)
|
|
62
68
|
} else {
|
|
63
|
-
const { Component } = options
|
|
69
|
+
const { Component, adapter } = options
|
|
70
|
+
|
|
64
71
|
await fabricChild.render(
|
|
65
|
-
<
|
|
66
|
-
<Component config={config} nodes={operationsOrNodes as Array<OperationNode>}
|
|
67
|
-
</
|
|
72
|
+
<Fabric meta={{ plugin }}>
|
|
73
|
+
<Component config={config} adapter={adapter} nodes={operationsOrNodes as Array<OperationNode>} options={options.options} />
|
|
74
|
+
</Fabric>,
|
|
68
75
|
)
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
|
|
78
|
+
fabric.context.fileManager.upsert(...fabricChild.files)
|
|
72
79
|
fabricChild.unmount()
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
type BuildOperationBaseOptions<TOptions extends PluginFactoryOptions> = {
|
|
76
83
|
config: Config
|
|
77
|
-
fabric:
|
|
84
|
+
fabric: FabricType
|
|
78
85
|
plugin: Plugin<TOptions>
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
type BuildOperationV1Options<TOptions extends PluginFactoryOptions> = BuildOperationBaseOptions<TOptions> & {
|
|
82
89
|
version?: '1'
|
|
83
|
-
Component: ReactGenerator<
|
|
90
|
+
Component: ReactGenerator<TOptions>['Operation']
|
|
84
91
|
generator: Omit<OperationGenerator<TOptions>, 'build'>
|
|
85
92
|
}
|
|
86
93
|
|
|
87
94
|
type BuildOperationV2Options<TOptions extends PluginFactoryOptions> = BuildOperationBaseOptions<TOptions> & {
|
|
88
95
|
version: '2'
|
|
89
|
-
Component:
|
|
96
|
+
Component: ReactGeneratorV2<TOptions>['Operation'] | undefined
|
|
97
|
+
adapter: Adapter
|
|
98
|
+
driver: PluginDriver
|
|
99
|
+
mode: KubbFile.Mode
|
|
100
|
+
options: TOptions['resolvedOptions']
|
|
90
101
|
}
|
|
91
102
|
|
|
92
103
|
function isBuildOperationV1Options<TOptions extends PluginFactoryOptions>(
|
|
@@ -111,41 +122,46 @@ export async function buildOperation<TOptions extends PluginFactoryOptions>(
|
|
|
111
122
|
|
|
112
123
|
if (isBuildOperationV1Options(options)) {
|
|
113
124
|
const { generator, Component } = options
|
|
114
|
-
const {
|
|
125
|
+
const { driver, oas, mode } = generator.context
|
|
115
126
|
|
|
116
127
|
await fabricChild.render(
|
|
117
|
-
<
|
|
128
|
+
<Fabric meta={{ driver, plugin, mode, oas }}>
|
|
118
129
|
<Component config={config} operation={operationOrNode as Operation} plugin={plugin} generator={generator} />
|
|
119
|
-
</
|
|
130
|
+
</Fabric>,
|
|
120
131
|
)
|
|
121
132
|
} else {
|
|
122
|
-
const { Component } = options
|
|
133
|
+
const { Component, adapter, driver, mode } = options
|
|
134
|
+
|
|
123
135
|
await fabricChild.render(
|
|
124
|
-
<
|
|
125
|
-
<Component config={config} node={operationOrNode as OperationNode}
|
|
126
|
-
</
|
|
136
|
+
<Fabric meta={{ plugin, driver, mode }}>
|
|
137
|
+
<Component config={config} adapter={adapter} node={operationOrNode as OperationNode} options={options.options} />
|
|
138
|
+
</Fabric>,
|
|
127
139
|
)
|
|
128
140
|
}
|
|
129
141
|
|
|
130
|
-
|
|
142
|
+
fabric.context.fileManager.upsert(...fabricChild.files)
|
|
131
143
|
fabricChild.unmount()
|
|
132
144
|
}
|
|
133
145
|
|
|
134
146
|
type BuildSchemaBaseOptions<TOptions extends PluginFactoryOptions> = {
|
|
135
147
|
config: Config
|
|
136
|
-
fabric:
|
|
148
|
+
fabric: FabricType
|
|
137
149
|
plugin: Plugin<TOptions>
|
|
138
150
|
}
|
|
139
151
|
|
|
140
152
|
type BuildSchemaV1Options<TOptions extends PluginFactoryOptions> = BuildSchemaBaseOptions<TOptions> & {
|
|
141
153
|
version?: '1'
|
|
142
|
-
Component: ReactGenerator<
|
|
154
|
+
Component: ReactGenerator<TOptions>['Schema']
|
|
143
155
|
generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>
|
|
144
156
|
}
|
|
145
157
|
|
|
146
158
|
type BuildSchemaV2Options<TOptions extends PluginFactoryOptions> = BuildSchemaBaseOptions<TOptions> & {
|
|
147
159
|
version: '2'
|
|
148
|
-
Component:
|
|
160
|
+
Component: ReactGeneratorV2<TOptions>['Schema'] | undefined
|
|
161
|
+
adapter: Adapter
|
|
162
|
+
driver: PluginDriver
|
|
163
|
+
mode: KubbFile.Mode
|
|
164
|
+
options: TOptions['resolvedOptions']
|
|
149
165
|
}
|
|
150
166
|
|
|
151
167
|
function isBuildSchemaV1Options<TOptions extends PluginFactoryOptions>(
|
|
@@ -173,22 +189,24 @@ export async function buildSchema<TOptions extends PluginFactoryOptions>(
|
|
|
173
189
|
|
|
174
190
|
if (isBuildSchemaV1Options(options)) {
|
|
175
191
|
const { generator, Component } = options
|
|
176
|
-
const {
|
|
192
|
+
const { driver, oas, mode } = generator.context
|
|
177
193
|
|
|
178
194
|
await fabricChild.render(
|
|
179
|
-
<
|
|
195
|
+
<Fabric meta={{ driver, plugin, mode, oas }}>
|
|
180
196
|
<Component config={config} schema={schema as { name: string; tree: Array<Schema>; value: SchemaObject }} plugin={plugin} generator={generator} />
|
|
181
|
-
</
|
|
197
|
+
</Fabric>,
|
|
182
198
|
)
|
|
183
199
|
} else {
|
|
184
|
-
const { Component } = options
|
|
200
|
+
const { Component, adapter, driver, mode } = options
|
|
201
|
+
|
|
185
202
|
await fabricChild.render(
|
|
186
|
-
<
|
|
187
|
-
<Component config={config} node={schema as SchemaNode}
|
|
188
|
-
</
|
|
203
|
+
<Fabric meta={{ plugin, driver, mode }}>
|
|
204
|
+
<Component config={config} adapter={adapter} node={schema as SchemaNode} options={options.options} />
|
|
205
|
+
</Fabric>,
|
|
189
206
|
)
|
|
190
207
|
}
|
|
191
208
|
|
|
192
|
-
|
|
209
|
+
fabric.context.fileManager.upsert(...fabricChild.files)
|
|
210
|
+
|
|
193
211
|
fabricChild.unmount()
|
|
194
212
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-CyWd3UXA.cjs","names":["camelCase","getBanner","getFooter"],"sources":["../src/generators/createGenerator.ts","../src/generators/createReactGenerator.ts","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { OperationProps, OperationsProps, SchemaProps, Version } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n version?: TVersion\n operations?: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n operation?: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n schema?: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n}\n\nexport type CoreGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n type: 'core'\n version: TVersion\n operations: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n operation: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n schema: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n}\n\nexport function createGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(\n generator: UserGenerator<TOptions, TVersion>,\n): CoreGenerator<TOptions, TVersion> {\n return {\n type: 'core',\n version: (generator.version ?? '1') as TVersion,\n async operations() {\n return []\n },\n async operation() {\n return []\n },\n async schema() {\n return []\n },\n ...generator,\n }\n}\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport type { OperationProps, OperationsProps, SchemaProps, Version } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n version?: TVersion\n Operations?: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode\n Operation?: (props: OperationProps<TOptions, TVersion>) => FabricReactNode\n Schema?: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode\n}\n\nexport type ReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n type: 'react'\n version: TVersion\n Operations: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode\n Operation: (props: OperationProps<TOptions, TVersion>) => FabricReactNode\n Schema: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode\n}\n\n/****\n * Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.\n *\n * The returned generator exposes async methods for generating files from operations, a single operation, or a schema, using the corresponding React components if provided. If a component is not defined, the method returns an empty array.\n *\n * @returns A generator object with async methods for operations, operation, and schema file generation.\n */\nexport function createReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(\n generator: UserGenerator<TOptions, TVersion>,\n): ReactGenerator<TOptions, TVersion> {\n return {\n type: 'react',\n version: (generator.version ?? '1') as TVersion,\n Operations() {\n return null\n },\n Operation() {\n return null\n },\n Schema() {\n return null\n },\n ...generator,\n }\n}\n","import { camelCase } from '@internals/utils'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\nimport { createGenerator } from './createGenerator.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, generator }) {\n const { pluginManager, plugin } = generator.context\n const file = pluginManager.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginKey: plugin.key,\n })\n\n return [\n {\n ...file,\n sources: [\n {\n name: camelCase(schema.name),\n isExportable: false,\n isIndexable: false,\n value: JSON.stringify(schema.value),\n },\n ],\n banner: getBanner({\n oas: generator.context.oas,\n output: plugin.options.output,\n config: pluginManager.config,\n }),\n format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;AAqBA,SAAgB,gBACd,WACmC;AACnC,QAAO;EACL,MAAM;EACN,SAAU,UAAU,WAAW;EAC/B,MAAM,aAAa;AACjB,UAAO,EAAE;;EAEX,MAAM,YAAY;AAChB,UAAO,EAAE;;EAEX,MAAM,SAAS;AACb,UAAO,EAAE;;EAEX,GAAG;EACJ;;;;;;;;;;;ACTH,SAAgB,qBACd,WACoC;AACpC,QAAO;EACL,MAAM;EACN,SAAU,UAAU,WAAW;EAC/B,aAAa;AACX,UAAO;;EAET,YAAY;AACV,UAAO;;EAET,SAAS;AACP,UAAO;;EAET,GAAG;EACJ;;;;ACtCH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,aAAa;EAClC,MAAM,EAAE,eAAe,WAAW,UAAU;AAQ5C,SAAO,CACL;GACE,GATS,cAAc,QAAQ;IACjC,MAAMA,kBAAAA,UAAU,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,WAAW,OAAO;IACnB,CAAC;GAKE,SAAS,CACP;IACE,MAAMA,kBAAAA,UAAU,OAAO,KAAK;IAC5B,cAAc;IACd,aAAa;IACb,OAAO,KAAK,UAAU,OAAO,MAAM;IACpC,CACF;GACD,QAAQC,kBAAAA,UAAU;IAChB,KAAK,UAAU,QAAQ;IACvB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,cAAc;IACvB,CAAC;GACF,QAAQC,kBAAAA,UAAU;IAAE,KAAK,UAAU,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GACjF,CACF;;CAEJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-D7C3CXsN.js","names":[],"sources":["../src/generators/createGenerator.ts","../src/generators/createReactGenerator.ts","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { OperationProps, OperationsProps, SchemaProps, Version } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n version?: TVersion\n operations?: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n operation?: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n schema?: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n}\n\nexport type CoreGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n type: 'core'\n version: TVersion\n operations: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n operation: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n schema: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>\n}\n\nexport function createGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(\n generator: UserGenerator<TOptions, TVersion>,\n): CoreGenerator<TOptions, TVersion> {\n return {\n type: 'core',\n version: (generator.version ?? '1') as TVersion,\n async operations() {\n return []\n },\n async operation() {\n return []\n },\n async schema() {\n return []\n },\n ...generator,\n }\n}\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport type { OperationProps, OperationsProps, SchemaProps, Version } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n version?: TVersion\n Operations?: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode\n Operation?: (props: OperationProps<TOptions, TVersion>) => FabricReactNode\n Schema?: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode\n}\n\nexport type ReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {\n name: string\n type: 'react'\n version: TVersion\n Operations: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode\n Operation: (props: OperationProps<TOptions, TVersion>) => FabricReactNode\n Schema: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode\n}\n\n/****\n * Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.\n *\n * The returned generator exposes async methods for generating files from operations, a single operation, or a schema, using the corresponding React components if provided. If a component is not defined, the method returns an empty array.\n *\n * @returns A generator object with async methods for operations, operation, and schema file generation.\n */\nexport function createReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'>(\n generator: UserGenerator<TOptions, TVersion>,\n): ReactGenerator<TOptions, TVersion> {\n return {\n type: 'react',\n version: (generator.version ?? '1') as TVersion,\n Operations() {\n return null\n },\n Operation() {\n return null\n },\n Schema() {\n return null\n },\n ...generator,\n }\n}\n","import { camelCase } from '@internals/utils'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\nimport { createGenerator } from './createGenerator.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, generator }) {\n const { pluginManager, plugin } = generator.context\n const file = pluginManager.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginKey: plugin.key,\n })\n\n return [\n {\n ...file,\n sources: [\n {\n name: camelCase(schema.name),\n isExportable: false,\n isIndexable: false,\n value: JSON.stringify(schema.value),\n },\n ],\n banner: getBanner({\n oas: generator.context.oas,\n output: plugin.options.output,\n config: pluginManager.config,\n }),\n format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;AAqBA,SAAgB,gBACd,WACmC;AACnC,QAAO;EACL,MAAM;EACN,SAAU,UAAU,WAAW;EAC/B,MAAM,aAAa;AACjB,UAAO,EAAE;;EAEX,MAAM,YAAY;AAChB,UAAO,EAAE;;EAEX,MAAM,SAAS;AACb,UAAO,EAAE;;EAEX,GAAG;EACJ;;;;;;;;;;;ACTH,SAAgB,qBACd,WACoC;AACpC,QAAO;EACL,MAAM;EACN,SAAU,UAAU,WAAW;EAC/B,aAAa;AACX,UAAO;;EAET,YAAY;AACV,UAAO;;EAET,SAAS;AACP,UAAO;;EAET,GAAG;EACJ;;;;ACtCH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,aAAa;EAClC,MAAM,EAAE,eAAe,WAAW,UAAU;AAQ5C,SAAO,CACL;GACE,GATS,cAAc,QAAQ;IACjC,MAAM,UAAU,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,WAAW,OAAO;IACnB,CAAC;GAKE,SAAS,CACP;IACE,MAAM,UAAU,OAAO,KAAK;IAC5B,cAAc;IACd,aAAa;IACb,OAAO,KAAK,UAAU,OAAO,MAAM;IACpC,CACF;GACD,QAAQ,UAAU;IAChB,KAAK,UAAU,QAAQ;IACvB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,cAAc;IACvB,CAAC;GACF,QAAQ,UAAU;IAAE,KAAK,UAAU,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GACjF,CACF;;CAEJ,CAAC"}
|