@kubb/plugin-oas 3.0.0-alpha.1 → 3.0.0-alpha.3
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/OperationGenerator-D7rSlflc.d.cts +158 -0
- package/dist/OperationGenerator-vw0Zf-Mi.d.ts +158 -0
- package/dist/{Schema-an5hOrjZ.d.cts → Schema-DxyOIX7q.d.cts} +1 -1
- package/dist/{Schema-DefwBJMc.d.ts → Schema-gHgN14i2.d.ts} +1 -1
- package/dist/{SchemaMapper-CsBQ6eEx.d.cts → SchemaMapper-BM1IGWqD.d.cts} +1 -1
- package/dist/{SchemaMapper-CsBQ6eEx.d.ts → SchemaMapper-BM1IGWqD.d.ts} +1 -1
- package/dist/{chunk-DRLYORTT.cjs → chunk-264TCCJF.cjs} +715 -7
- package/dist/chunk-264TCCJF.cjs.map +1 -0
- package/dist/chunk-7KIEQOVZ.cjs +7 -0
- package/dist/chunk-7KIEQOVZ.cjs.map +1 -0
- package/dist/{chunk-LEACSHKT.js → chunk-FZN3PBEK.js} +713 -5
- package/dist/chunk-FZN3PBEK.js.map +1 -0
- package/dist/chunk-TWKZEVSM.js +7 -0
- package/dist/chunk-TWKZEVSM.js.map +1 -0
- package/dist/components.cjs +4 -9
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +12 -6
- package/dist/components.d.ts +12 -6
- package/dist/components.js +3 -8
- package/dist/components.js.map +1 -1
- package/dist/hooks.cjs +6 -7
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +3 -3
- package/dist/hooks.d.ts +3 -3
- package/dist/hooks.js +1 -2
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +225 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -77
- package/dist/index.d.ts +8 -77
- package/dist/index.js +207 -141
- package/dist/index.js.map +1 -1
- package/dist/{types-Dte3MA6H.d.cts → types-C2RXaY0_.d.cts} +1 -1
- package/dist/{types-Dte3MA6H.d.ts → types-C2RXaY0_.d.ts} +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +9 -9
- package/src/OperationGenerator.ts +62 -31
- package/src/SchemaGenerator.ts +23 -4
- package/src/components/Oas.tsx +8 -2
- package/src/index.ts +3 -9
- package/src/parser.tsx +120 -0
- package/src/plugin.ts +1 -9
- package/dist/OperationGenerator-CeM_9pxW.d.cts +0 -60
- package/dist/OperationGenerator-DhUhvRJE.d.ts +0 -60
- package/dist/chunk-CJXRFYEF.cjs +0 -698
- package/dist/chunk-CJXRFYEF.cjs.map +0 -1
- package/dist/chunk-DRLYORTT.cjs.map +0 -1
- package/dist/chunk-K6KUETAI.js +0 -698
- package/dist/chunk-K6KUETAI.js.map +0 -1
- package/dist/chunk-LEACSHKT.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-oas",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.3",
|
|
4
4
|
"description": "Generator swagger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -68,10 +68,10 @@
|
|
|
68
68
|
"dependencies": {
|
|
69
69
|
"@stoplight/yaml": "^4.3.0",
|
|
70
70
|
"remeda": "^2.11.0",
|
|
71
|
-
"@kubb/core": "3.0.0-alpha.
|
|
72
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
73
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
74
|
-
"@kubb/react": "3.0.0-alpha.
|
|
71
|
+
"@kubb/core": "3.0.0-alpha.3",
|
|
72
|
+
"@kubb/fs": "3.0.0-alpha.3",
|
|
73
|
+
"@kubb/oas": "3.0.0-alpha.3",
|
|
74
|
+
"@kubb/react": "3.0.0-alpha.3"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@types/react": "^18.3.4",
|
|
@@ -79,12 +79,12 @@
|
|
|
79
79
|
"react": "^18.3.1",
|
|
80
80
|
"tsup": "^8.2.4",
|
|
81
81
|
"typescript": "^5.5.4",
|
|
82
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
83
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
84
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
82
|
+
"@kubb/config-biome": "3.0.0-alpha.3",
|
|
83
|
+
"@kubb/config-ts": "3.0.0-alpha.3",
|
|
84
|
+
"@kubb/config-tsup": "3.0.0-alpha.3"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
|
-
"@kubb/react": "3.0.0-alpha.
|
|
87
|
+
"@kubb/react": "3.0.0-alpha.3"
|
|
88
88
|
},
|
|
89
89
|
"engines": {
|
|
90
90
|
"node": ">=20"
|
|
@@ -7,6 +7,7 @@ import type * as KubbFile from '@kubb/fs/types'
|
|
|
7
7
|
import type { Plugin } from '@kubb/core'
|
|
8
8
|
import type { HttpMethod, Oas, OasTypes, Operation, contentType } from '@kubb/oas'
|
|
9
9
|
import type { Exclude, Include, OperationSchemas, OperationsByMethod, Override } from './types.ts'
|
|
10
|
+
import type { Parser } from './parser.tsx'
|
|
10
11
|
|
|
11
12
|
export type GetOperationGeneratorOptions<T extends OperationGenerator<any, any, any>> = T extends OperationGenerator<infer Options, any, any> ? Options : never
|
|
12
13
|
|
|
@@ -26,7 +27,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
26
27
|
mode: KubbFile.Mode
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
export
|
|
30
|
+
export class OperationGenerator<
|
|
30
31
|
TOptions = unknown,
|
|
31
32
|
TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,
|
|
32
33
|
TFileMeta extends FileMetaBase = FileMetaBase,
|
|
@@ -65,6 +66,7 @@ export abstract class OperationGenerator<
|
|
|
65
66
|
})?.options || {}
|
|
66
67
|
)
|
|
67
68
|
}
|
|
69
|
+
|
|
68
70
|
/**
|
|
69
71
|
*
|
|
70
72
|
* @deprecated
|
|
@@ -93,6 +95,7 @@ export abstract class OperationGenerator<
|
|
|
93
95
|
|
|
94
96
|
return matched
|
|
95
97
|
}
|
|
98
|
+
|
|
96
99
|
/**
|
|
97
100
|
*
|
|
98
101
|
* @deprecated
|
|
@@ -124,7 +127,13 @@ export abstract class OperationGenerator<
|
|
|
124
127
|
|
|
125
128
|
getSchemas(
|
|
126
129
|
operation: Operation,
|
|
127
|
-
{
|
|
130
|
+
{
|
|
131
|
+
forStatusCode,
|
|
132
|
+
resolveName = (name) => name,
|
|
133
|
+
}: {
|
|
134
|
+
forStatusCode?: string | number
|
|
135
|
+
resolveName?: (name: string) => string
|
|
136
|
+
} = {},
|
|
128
137
|
): OperationSchemas {
|
|
129
138
|
const pathParamsSchema = this.context.oas.getParametersSchema(operation, 'path')
|
|
130
139
|
const queryParamsSchema = this.context.oas.getParametersSchema(operation, 'query')
|
|
@@ -217,20 +226,7 @@ export abstract class OperationGenerator<
|
|
|
217
226
|
}
|
|
218
227
|
}
|
|
219
228
|
|
|
220
|
-
|
|
221
|
-
return {
|
|
222
|
-
get: this.get,
|
|
223
|
-
post: this.post,
|
|
224
|
-
patch: this.patch,
|
|
225
|
-
put: this.put,
|
|
226
|
-
delete: this.delete,
|
|
227
|
-
head: undefined,
|
|
228
|
-
options: undefined,
|
|
229
|
-
trace: undefined,
|
|
230
|
-
} as const
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async build(): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
229
|
+
async build(...parsers: Array<Parser<Extract<TOptions, PluginFactoryOptions>>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
234
230
|
const { oas } = this.context
|
|
235
231
|
|
|
236
232
|
const paths = oas.getPaths()
|
|
@@ -239,7 +235,7 @@ export abstract class OperationGenerator<
|
|
|
239
235
|
|
|
240
236
|
methods.forEach((method) => {
|
|
241
237
|
const operation = oas.operation(path, method)
|
|
242
|
-
if (operation
|
|
238
|
+
if (operation) {
|
|
243
239
|
const isExcluded = this.#isExcluded(operation, method)
|
|
244
240
|
const isIncluded = this.context.include ? this.#isIncluded(operation, method) : true
|
|
245
241
|
|
|
@@ -267,21 +263,43 @@ export abstract class OperationGenerator<
|
|
|
267
263
|
methods.forEach((method) => {
|
|
268
264
|
const { operation } = this.operationsByMethod[path]?.[method]!
|
|
269
265
|
const options = this.#getOptions(operation, method)
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
266
|
+
|
|
267
|
+
const methodToCall = this[method as keyof typeof this] as any
|
|
268
|
+
|
|
269
|
+
if (typeof methodToCall === 'function') {
|
|
270
|
+
const promiseMethod = methodToCall?.call(this, operation, {
|
|
271
|
+
...this.options,
|
|
272
|
+
...options,
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
if (promiseMethod) {
|
|
276
|
+
acc.push(promiseMethod)
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
274
280
|
const promiseOperation = this.operation.call(this, operation, {
|
|
275
281
|
...this.options,
|
|
276
282
|
...options,
|
|
277
283
|
})
|
|
278
284
|
|
|
279
|
-
if (promiseMethod) {
|
|
280
|
-
acc.push(promiseMethod)
|
|
281
|
-
}
|
|
282
285
|
if (promiseOperation) {
|
|
283
286
|
acc.push(promiseOperation)
|
|
284
287
|
}
|
|
288
|
+
|
|
289
|
+
parsers?.forEach((parser) => {
|
|
290
|
+
const promise = parser.operation?.({
|
|
291
|
+
instance: this,
|
|
292
|
+
operation,
|
|
293
|
+
options: {
|
|
294
|
+
...this.options,
|
|
295
|
+
...options,
|
|
296
|
+
},
|
|
297
|
+
} as any) as Promise<Array<KubbFile.File<TFileMeta>>>
|
|
298
|
+
|
|
299
|
+
if (promise) {
|
|
300
|
+
acc.push(promise)
|
|
301
|
+
}
|
|
302
|
+
})
|
|
285
303
|
})
|
|
286
304
|
|
|
287
305
|
return acc
|
|
@@ -291,6 +309,19 @@ export abstract class OperationGenerator<
|
|
|
291
309
|
|
|
292
310
|
promises.push(this.all(operations.flat().filter(Boolean), this.operationsByMethod))
|
|
293
311
|
|
|
312
|
+
parsers?.forEach((parser) => {
|
|
313
|
+
const promise = parser.operations?.({
|
|
314
|
+
instance: this,
|
|
315
|
+
operations: operations.flat().filter(Boolean),
|
|
316
|
+
operationsByMethod: this.operationsByMethod,
|
|
317
|
+
options: this.options,
|
|
318
|
+
} as any) as Promise<Array<KubbFile.File<TFileMeta>>>
|
|
319
|
+
|
|
320
|
+
if (promise) {
|
|
321
|
+
promises.push(promise)
|
|
322
|
+
}
|
|
323
|
+
})
|
|
324
|
+
|
|
294
325
|
const files = await Promise.all(promises)
|
|
295
326
|
|
|
296
327
|
// using .flat because operationGenerator[method] can return a array of files or just one file
|
|
@@ -301,47 +332,47 @@ export abstract class OperationGenerator<
|
|
|
301
332
|
* Operation
|
|
302
333
|
*/
|
|
303
334
|
async operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
304
|
-
return
|
|
335
|
+
return []
|
|
305
336
|
}
|
|
306
337
|
|
|
307
338
|
/**
|
|
308
339
|
* GET
|
|
309
340
|
*/
|
|
310
341
|
async get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
311
|
-
return
|
|
342
|
+
return []
|
|
312
343
|
}
|
|
313
344
|
|
|
314
345
|
/**
|
|
315
346
|
* POST
|
|
316
347
|
*/
|
|
317
348
|
async post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
318
|
-
return
|
|
349
|
+
return []
|
|
319
350
|
}
|
|
320
351
|
/**
|
|
321
352
|
* PATCH
|
|
322
353
|
*/
|
|
323
354
|
async patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
324
|
-
return
|
|
355
|
+
return []
|
|
325
356
|
}
|
|
326
357
|
|
|
327
358
|
/**
|
|
328
359
|
* PUT
|
|
329
360
|
*/
|
|
330
361
|
async put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
331
|
-
return
|
|
362
|
+
return []
|
|
332
363
|
}
|
|
333
364
|
|
|
334
365
|
/**
|
|
335
366
|
* DELETE
|
|
336
367
|
*/
|
|
337
368
|
async delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta> {
|
|
338
|
-
return
|
|
369
|
+
return []
|
|
339
370
|
}
|
|
340
371
|
|
|
341
372
|
/**
|
|
342
373
|
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
343
374
|
*/
|
|
344
375
|
async all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta> {
|
|
345
|
-
return
|
|
376
|
+
return []
|
|
346
377
|
}
|
|
347
378
|
}
|
package/src/SchemaGenerator.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type * as KubbFile from '@kubb/fs/types'
|
|
|
14
14
|
import type { Oas, OpenAPIV3, SchemaObject, contentType } from '@kubb/oas'
|
|
15
15
|
import type { Schema, SchemaKeywordMapper } from './SchemaMapper.ts'
|
|
16
16
|
import type { OperationSchema, Override, Refs } from './types.ts'
|
|
17
|
+
import type { Parser } from './parser.tsx'
|
|
17
18
|
|
|
18
19
|
export type GetSchemaGeneratorOptions<T extends SchemaGenerator<any, any, any>> = T extends SchemaGenerator<infer Options, any, any> ? Options : never
|
|
19
20
|
|
|
@@ -63,7 +64,7 @@ type SchemaProps = {
|
|
|
63
64
|
parentName?: string
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
export
|
|
67
|
+
export class SchemaGenerator<
|
|
67
68
|
TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions,
|
|
68
69
|
TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions,
|
|
69
70
|
TFileMeta extends FileMetaBase = FileMetaBase,
|
|
@@ -820,7 +821,7 @@ export abstract class SchemaGenerator<
|
|
|
820
821
|
return [{ keyword: unknownReturn }]
|
|
821
822
|
}
|
|
822
823
|
|
|
823
|
-
async build(): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
824
|
+
async build(...parsers: Array<Parser<Extract<TOptions, PluginFactoryOptions>>>): Promise<Array<KubbFile.File<TFileMeta>>> {
|
|
824
825
|
const { oas, contentType, include } = this.context
|
|
825
826
|
|
|
826
827
|
const schemas = getSchemas({ oas, contentType, includes: include })
|
|
@@ -836,17 +837,35 @@ export abstract class SchemaGenerator<
|
|
|
836
837
|
acc.push(promiseOperation)
|
|
837
838
|
}
|
|
838
839
|
|
|
840
|
+
parsers?.forEach((parser) => {
|
|
841
|
+
const promise = parser.schema?.({
|
|
842
|
+
instance: this,
|
|
843
|
+
name,
|
|
844
|
+
schema,
|
|
845
|
+
options: {
|
|
846
|
+
...this.options,
|
|
847
|
+
...options,
|
|
848
|
+
},
|
|
849
|
+
} as any) as Promise<Array<KubbFile.File<TFileMeta>>>
|
|
850
|
+
|
|
851
|
+
if (promise) {
|
|
852
|
+
acc.push(promise)
|
|
853
|
+
}
|
|
854
|
+
})
|
|
855
|
+
|
|
839
856
|
return acc
|
|
840
857
|
}, [] as SchemaMethodResult<TFileMeta>[])
|
|
841
858
|
|
|
842
859
|
const files = await Promise.all(promises)
|
|
843
860
|
|
|
844
|
-
// using .flat because schemaGenerator[method] can return
|
|
861
|
+
// using .flat because schemaGenerator[method] can return an array of files or just one file
|
|
845
862
|
return files.flat().filter(Boolean)
|
|
846
863
|
}
|
|
847
864
|
|
|
848
865
|
/**
|
|
849
866
|
* Schema
|
|
850
867
|
*/
|
|
851
|
-
|
|
868
|
+
async schema(name: string, object: SchemaObject, options: TOptions): SchemaMethodResult<TFileMeta> {
|
|
869
|
+
return []
|
|
870
|
+
}
|
|
852
871
|
}
|
package/src/components/Oas.tsx
CHANGED
|
@@ -10,14 +10,20 @@ import type { OperationGenerator } from '../OperationGenerator.ts'
|
|
|
10
10
|
type Props = {
|
|
11
11
|
oas: OasType
|
|
12
12
|
operations?: OperationType[]
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated
|
|
15
|
+
*/
|
|
16
|
+
generator?: Omit<OperationGenerator, 'build'>
|
|
14
17
|
children?: KubbNode
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
type OasContextProps = {
|
|
18
21
|
oas?: OasType
|
|
19
22
|
operations?: OperationType[]
|
|
20
|
-
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated
|
|
25
|
+
*/
|
|
26
|
+
generator?: Omit<OperationGenerator, 'build'>
|
|
21
27
|
}
|
|
22
28
|
|
|
23
29
|
const OasContext = createContext<OasContextProps>({})
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { pluginOas } from './plugin.ts'
|
|
2
|
-
|
|
3
1
|
export type {
|
|
4
2
|
GetOperationGeneratorOptions,
|
|
5
3
|
OperationMethodResult,
|
|
@@ -22,10 +20,6 @@ export type {
|
|
|
22
20
|
} from './SchemaMapper.ts'
|
|
23
21
|
export { isKeyword, schemaKeywords } from './SchemaMapper.ts'
|
|
24
22
|
export type * from './types.ts'
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
const definePluginDefault = pluginOas
|
|
30
|
-
|
|
31
|
-
export default definePluginDefault
|
|
23
|
+
export { createParser, createReactParser } from './parser.tsx'
|
|
24
|
+
export type { ParserReactOptions } from './parser.tsx'
|
|
25
|
+
export type { Parser, ParserOptions } from './parser.tsx'
|
package/src/parser.tsx
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { PluginFactoryOptions } from '@kubb/core'
|
|
2
|
+
import type { Operation, SchemaObject } from '@kubb/oas'
|
|
3
|
+
import { App, createRoot, type KubbNode } from '@kubb/react'
|
|
4
|
+
import type * as KubbFile from '@kubb/fs/types'
|
|
5
|
+
import type { OperationsByMethod } from './types.ts'
|
|
6
|
+
import { Oas } from '@kubb/plugin-oas/components'
|
|
7
|
+
import type { OperationGenerator } from './OperationGenerator.ts'
|
|
8
|
+
import type { SchemaGenerator, SchemaGeneratorOptions } from './SchemaGenerator.ts'
|
|
9
|
+
|
|
10
|
+
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
11
|
+
instance: Omit<OperationGenerator<TOptions>, 'build'>
|
|
12
|
+
options: TOptions['resolvedOptions']
|
|
13
|
+
operations: Array<Operation>
|
|
14
|
+
operationsByMethod: OperationsByMethod
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
18
|
+
instance: Omit<OperationGenerator<TOptions>, 'build'>
|
|
19
|
+
options: TOptions['resolvedOptions']
|
|
20
|
+
operation: Operation
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
24
|
+
instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>
|
|
25
|
+
name: string
|
|
26
|
+
schema: SchemaObject
|
|
27
|
+
options: TOptions['resolvedOptions']
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type ParserOptions<TOptions extends PluginFactoryOptions> = {
|
|
31
|
+
name: string
|
|
32
|
+
operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>
|
|
33
|
+
operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>
|
|
34
|
+
schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type Parser<TOptions extends PluginFactoryOptions> = ParserOptions<TOptions>
|
|
38
|
+
|
|
39
|
+
export function createParser<TOptions extends PluginFactoryOptions>(parseOptions: ParserOptions<TOptions>): Parser<TOptions> {
|
|
40
|
+
return parseOptions
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ParserReactOptions<TOptions extends PluginFactoryOptions> = {
|
|
44
|
+
name: string
|
|
45
|
+
Operations?: (props: OperationsProps<TOptions>) => KubbNode
|
|
46
|
+
Operation?: (props: OperationProps<TOptions>) => KubbNode
|
|
47
|
+
Schema?: (props: SchemaProps<TOptions>) => KubbNode
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function createReactParser<TOptions extends PluginFactoryOptions>(parseOptions: ParserReactOptions<TOptions>): Parser<TOptions> {
|
|
51
|
+
return {
|
|
52
|
+
...parseOptions,
|
|
53
|
+
async operations({ instance, options, operations, operationsByMethod }) {
|
|
54
|
+
if (!parseOptions.Operations) {
|
|
55
|
+
return []
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const { pluginManager, oas, plugin, mode } = instance.context
|
|
59
|
+
const root = createRoot({
|
|
60
|
+
logger: pluginManager.logger,
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
root.render(
|
|
64
|
+
<App pluginManager={pluginManager} plugin={plugin} mode={mode}>
|
|
65
|
+
<Oas oas={oas} operations={operations} generator={instance}>
|
|
66
|
+
<parseOptions.Operations operations={operations} instance={instance} operationsByMethod={operationsByMethod} options={options} />
|
|
67
|
+
</Oas>
|
|
68
|
+
</App>,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
return root.files
|
|
72
|
+
},
|
|
73
|
+
async operation({ instance, operation, options }) {
|
|
74
|
+
if (!parseOptions.Operation) {
|
|
75
|
+
return []
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const { pluginManager, oas, plugin, mode } = instance.context
|
|
79
|
+
const root = createRoot({
|
|
80
|
+
logger: pluginManager.logger,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
root.render(
|
|
84
|
+
<App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
|
|
85
|
+
<Oas oas={oas} operations={[operation]} generator={instance}>
|
|
86
|
+
<Oas.Operation operation={operation}>
|
|
87
|
+
<parseOptions.Operation operation={operation} options={options} instance={instance} />
|
|
88
|
+
</Oas.Operation>
|
|
89
|
+
</Oas>
|
|
90
|
+
</App>,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
return root.files
|
|
94
|
+
},
|
|
95
|
+
async schema({ instance, schema, name, options }) {
|
|
96
|
+
if (!parseOptions.Schema) {
|
|
97
|
+
return []
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const { pluginManager, oas, plugin, mode } = instance.context
|
|
101
|
+
const root = createRoot({
|
|
102
|
+
logger: pluginManager.logger,
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const tree = instance.parse({ schema, name })
|
|
106
|
+
|
|
107
|
+
root.render(
|
|
108
|
+
<App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
|
|
109
|
+
<Oas oas={oas}>
|
|
110
|
+
<Oas.Schema name={name} value={schema} tree={tree}>
|
|
111
|
+
<parseOptions.Schema schema={schema} options={options} instance={instance} name={name} />
|
|
112
|
+
</Oas.Schema>
|
|
113
|
+
</Oas>
|
|
114
|
+
</App>,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
return root.files
|
|
118
|
+
},
|
|
119
|
+
}
|
|
120
|
+
}
|
package/src/plugin.ts
CHANGED
|
@@ -46,8 +46,7 @@ export const pluginOas = createPlugin<PluginOas>((options) => {
|
|
|
46
46
|
return {
|
|
47
47
|
name: pluginOasName,
|
|
48
48
|
options,
|
|
49
|
-
|
|
50
|
-
api() {
|
|
49
|
+
context() {
|
|
51
50
|
const { config, logger } = this
|
|
52
51
|
|
|
53
52
|
return {
|
|
@@ -78,13 +77,6 @@ export const pluginOas = createPlugin<PluginOas>((options) => {
|
|
|
78
77
|
resolveName(name, type) {
|
|
79
78
|
return camelCase(name, { isFile: type === 'file' })
|
|
80
79
|
},
|
|
81
|
-
async writeFile(path, source) {
|
|
82
|
-
if (!path.endsWith('.json') || !source) {
|
|
83
|
-
return
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return this.fileManager.write(path, source, { sanity: false })
|
|
87
|
-
},
|
|
88
80
|
async buildStart() {
|
|
89
81
|
if (!output) {
|
|
90
82
|
return
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { FileMetaBase, PluginFactoryOptions, Generator, PluginManager, Plugin } from '@kubb/core';
|
|
2
|
-
import * as KubbFile from '@kubb/fs/types';
|
|
3
|
-
import { Operation, Oas, contentType } from '@kubb/oas';
|
|
4
|
-
import { g as OperationsByMethod, f as OperationSchemas, E as Exclude, I as Include, b as Override } from './types-Dte3MA6H.cjs';
|
|
5
|
-
|
|
6
|
-
type GetOperationGeneratorOptions<T extends OperationGenerator<any, any, any>> = T extends OperationGenerator<infer Options, any, any> ? Options : never;
|
|
7
|
-
type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
|
|
8
|
-
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
9
|
-
oas: Oas;
|
|
10
|
-
exclude: Array<Exclude> | undefined;
|
|
11
|
-
include: Array<Include> | undefined;
|
|
12
|
-
override: Array<Override<TOptions>> | undefined;
|
|
13
|
-
contentType: contentType | undefined;
|
|
14
|
-
pluginManager: PluginManager;
|
|
15
|
-
/**
|
|
16
|
-
* Current plugin
|
|
17
|
-
*/
|
|
18
|
-
plugin: Plugin<TPluginOptions>;
|
|
19
|
-
mode: KubbFile.Mode;
|
|
20
|
-
};
|
|
21
|
-
declare abstract class OperationGenerator<TOptions = unknown, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
|
|
22
|
-
#private;
|
|
23
|
-
get operationsByMethod(): OperationsByMethod;
|
|
24
|
-
set operationsByMethod(paths: OperationsByMethod);
|
|
25
|
-
getSchemas(operation: Operation, { forStatusCode, resolveName }?: {
|
|
26
|
-
forStatusCode?: string | number;
|
|
27
|
-
resolveName?: (name: string) => string;
|
|
28
|
-
}): OperationSchemas;
|
|
29
|
-
build(): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
30
|
-
/**
|
|
31
|
-
* Operation
|
|
32
|
-
*/
|
|
33
|
-
operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
34
|
-
/**
|
|
35
|
-
* GET
|
|
36
|
-
*/
|
|
37
|
-
get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
38
|
-
/**
|
|
39
|
-
* POST
|
|
40
|
-
*/
|
|
41
|
-
post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
42
|
-
/**
|
|
43
|
-
* PATCH
|
|
44
|
-
*/
|
|
45
|
-
patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
46
|
-
/**
|
|
47
|
-
* PUT
|
|
48
|
-
*/
|
|
49
|
-
put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
50
|
-
/**
|
|
51
|
-
* DELETE
|
|
52
|
-
*/
|
|
53
|
-
delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
54
|
-
/**
|
|
55
|
-
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
56
|
-
*/
|
|
57
|
-
all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export { type GetOperationGeneratorOptions as G, type OperationMethodResult as O, OperationGenerator as a };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { FileMetaBase, PluginFactoryOptions, Generator, PluginManager, Plugin } from '@kubb/core';
|
|
2
|
-
import * as KubbFile from '@kubb/fs/types';
|
|
3
|
-
import { Operation, Oas, contentType } from '@kubb/oas';
|
|
4
|
-
import { g as OperationsByMethod, f as OperationSchemas, E as Exclude, I as Include, b as Override } from './types-Dte3MA6H.js';
|
|
5
|
-
|
|
6
|
-
type GetOperationGeneratorOptions<T extends OperationGenerator<any, any, any>> = T extends OperationGenerator<infer Options, any, any> ? Options : never;
|
|
7
|
-
type OperationMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<TFileMeta> | Array<KubbFile.File<TFileMeta>> | null>;
|
|
8
|
-
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
9
|
-
oas: Oas;
|
|
10
|
-
exclude: Array<Exclude> | undefined;
|
|
11
|
-
include: Array<Include> | undefined;
|
|
12
|
-
override: Array<Override<TOptions>> | undefined;
|
|
13
|
-
contentType: contentType | undefined;
|
|
14
|
-
pluginManager: PluginManager;
|
|
15
|
-
/**
|
|
16
|
-
* Current plugin
|
|
17
|
-
*/
|
|
18
|
-
plugin: Plugin<TPluginOptions>;
|
|
19
|
-
mode: KubbFile.Mode;
|
|
20
|
-
};
|
|
21
|
-
declare abstract class OperationGenerator<TOptions = unknown, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends Generator<TOptions, Context<TOptions, TPluginOptions>> {
|
|
22
|
-
#private;
|
|
23
|
-
get operationsByMethod(): OperationsByMethod;
|
|
24
|
-
set operationsByMethod(paths: OperationsByMethod);
|
|
25
|
-
getSchemas(operation: Operation, { forStatusCode, resolveName }?: {
|
|
26
|
-
forStatusCode?: string | number;
|
|
27
|
-
resolveName?: (name: string) => string;
|
|
28
|
-
}): OperationSchemas;
|
|
29
|
-
build(): Promise<Array<KubbFile.File<TFileMeta>>>;
|
|
30
|
-
/**
|
|
31
|
-
* Operation
|
|
32
|
-
*/
|
|
33
|
-
operation(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
34
|
-
/**
|
|
35
|
-
* GET
|
|
36
|
-
*/
|
|
37
|
-
get(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
38
|
-
/**
|
|
39
|
-
* POST
|
|
40
|
-
*/
|
|
41
|
-
post(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
42
|
-
/**
|
|
43
|
-
* PATCH
|
|
44
|
-
*/
|
|
45
|
-
patch(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
46
|
-
/**
|
|
47
|
-
* PUT
|
|
48
|
-
*/
|
|
49
|
-
put(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
50
|
-
/**
|
|
51
|
-
* DELETE
|
|
52
|
-
*/
|
|
53
|
-
delete(operation: Operation, options: TOptions): OperationMethodResult<TFileMeta>;
|
|
54
|
-
/**
|
|
55
|
-
* Combination of GET, POST, PATCH, PUT, DELETE
|
|
56
|
-
*/
|
|
57
|
-
all(operations: Operation[], paths: OperationsByMethod): OperationMethodResult<TFileMeta>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export { type GetOperationGeneratorOptions as G, type OperationMethodResult as O, OperationGenerator as a };
|