@kubb/plugin-oas 3.0.0-alpha.1 → 3.0.0-alpha.11

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.
Files changed (76) hide show
  1. package/dist/OperationGenerator-By5WOmWB.d.ts +165 -0
  2. package/dist/OperationGenerator-Gd1X7wUz.d.cts +165 -0
  3. package/dist/{Schema-DefwBJMc.d.ts → Schema-B1vcPGiK.d.ts} +3 -5
  4. package/dist/{Schema-an5hOrjZ.d.cts → Schema-DoSFh7Qd.d.cts} +3 -5
  5. package/dist/{SchemaMapper-CsBQ6eEx.d.cts → SchemaMapper-sGcY1xL5.d.cts} +1 -2
  6. package/dist/{SchemaMapper-CsBQ6eEx.d.ts → SchemaMapper-sGcY1xL5.d.ts} +1 -2
  7. package/dist/{chunk-LEACSHKT.js → chunk-2X5GZFQP.js} +712 -44
  8. package/dist/chunk-2X5GZFQP.js.map +1 -0
  9. package/dist/{chunk-DRLYORTT.cjs → chunk-47SNBYWH.cjs} +750 -69
  10. package/dist/chunk-47SNBYWH.cjs.map +1 -0
  11. package/dist/{chunk-UB552H4J.js → chunk-4VKHSKYX.js} +7 -24
  12. package/dist/{chunk-UB552H4J.js.map → chunk-4VKHSKYX.js.map} +1 -1
  13. package/dist/{chunk-Y4V7HHX7.js → chunk-4WUMV7QX.js} +9 -12
  14. package/dist/chunk-4WUMV7QX.js.map +1 -0
  15. package/dist/chunk-6AVEWDKE.cjs +8 -0
  16. package/dist/chunk-6AVEWDKE.cjs.map +1 -0
  17. package/dist/chunk-S6RFFHLW.cjs +38 -0
  18. package/dist/chunk-S6RFFHLW.cjs.map +1 -0
  19. package/dist/chunk-WN5S6RCU.js +6 -0
  20. package/dist/chunk-WN5S6RCU.js.map +1 -0
  21. package/dist/chunk-XQPCA75E.cjs +90 -0
  22. package/dist/chunk-XQPCA75E.cjs.map +1 -0
  23. package/dist/components.cjs +21 -17
  24. package/dist/components.cjs.map +1 -1
  25. package/dist/components.d.cts +13 -7
  26. package/dist/components.d.ts +13 -7
  27. package/dist/components.js +4 -17
  28. package/dist/components.js.map +1 -1
  29. package/dist/hooks.cjs +30 -35
  30. package/dist/hooks.cjs.map +1 -1
  31. package/dist/hooks.d.cts +4 -4
  32. package/dist/hooks.d.ts +4 -4
  33. package/dist/hooks.js +10 -23
  34. package/dist/hooks.js.map +1 -1
  35. package/dist/index.cjs +315 -262
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.cts +8 -77
  38. package/dist/index.d.ts +8 -77
  39. package/dist/index.js +270 -239
  40. package/dist/index.js.map +1 -1
  41. package/dist/{types-Dte3MA6H.d.cts → types-CZTUCaE5.d.cts} +3 -1
  42. package/dist/{types-Dte3MA6H.d.ts → types-CZTUCaE5.d.ts} +3 -1
  43. package/dist/utils.cjs +39 -73
  44. package/dist/utils.cjs.map +1 -1
  45. package/dist/utils.d.cts +7 -33
  46. package/dist/utils.d.ts +7 -33
  47. package/dist/utils.js +10 -67
  48. package/dist/utils.js.map +1 -1
  49. package/package.json +11 -10
  50. package/src/OperationGenerator.ts +68 -32
  51. package/src/SchemaGenerator.ts +32 -15
  52. package/src/SchemaMapper.ts +1 -1
  53. package/src/components/Oas.tsx +9 -3
  54. package/src/components/Operation.tsx +1 -1
  55. package/src/components/Schema.tsx +29 -31
  56. package/src/generator.tsx +125 -0
  57. package/src/hooks/useOperationManager.ts +1 -0
  58. package/src/index.ts +3 -9
  59. package/src/plugin.ts +25 -38
  60. package/src/types.ts +2 -0
  61. package/src/utils/getParams.ts +1 -1
  62. package/src/utils/index.ts +2 -1
  63. package/dist/OperationGenerator-CeM_9pxW.d.cts +0 -60
  64. package/dist/OperationGenerator-DhUhvRJE.d.ts +0 -60
  65. package/dist/chunk-CJXRFYEF.cjs +0 -698
  66. package/dist/chunk-CJXRFYEF.cjs.map +0 -1
  67. package/dist/chunk-DRLYORTT.cjs.map +0 -1
  68. package/dist/chunk-K6KUETAI.js +0 -698
  69. package/dist/chunk-K6KUETAI.js.map +0 -1
  70. package/dist/chunk-LEACSHKT.js.map +0 -1
  71. package/dist/chunk-P42X362U.cjs +0 -101
  72. package/dist/chunk-P42X362U.cjs.map +0 -1
  73. package/dist/chunk-QLJIL3U5.cjs +0 -35
  74. package/dist/chunk-QLJIL3U5.cjs.map +0 -1
  75. package/dist/chunk-Y4V7HHX7.js.map +0 -1
  76. package/src/utils/getGroupedByTagFiles.ts +0 -82
package/src/plugin.ts CHANGED
@@ -4,13 +4,13 @@ import { createPlugin } from '@kubb/core'
4
4
  import { camelCase } from '@kubb/core/transformers'
5
5
 
6
6
  import { getSchemas } from './utils/getSchemas.ts'
7
+ import { parseFromConfig } from './utils/parseFromConfig.ts'
7
8
 
8
9
  import type { Config } from '@kubb/core'
9
10
  import type { Logger } from '@kubb/core/logger'
10
11
  import type { Oas, OasTypes } from '@kubb/oas'
11
12
  import type { FormatOptions } from '@kubb/oas/parser'
12
13
  import type { PluginOas } from './types.ts'
13
- import { parseFromConfig } from './utils/parseFromConfig.ts'
14
14
 
15
15
  export const pluginOasName = 'plugin-oas' satisfies PluginOas['name']
16
16
 
@@ -45,9 +45,18 @@ export const pluginOas = createPlugin<PluginOas>((options) => {
45
45
 
46
46
  return {
47
47
  name: pluginOasName,
48
+ output:
49
+ output === false
50
+ ? {
51
+ path: '',
52
+ exportType: false,
53
+ }
54
+ : {
55
+ exportType: 'barrelNamed',
56
+ ...output,
57
+ },
48
58
  options,
49
-
50
- api() {
59
+ context() {
51
60
  const { config, logger } = this
52
61
 
53
62
  return {
@@ -66,25 +75,6 @@ export const pluginOas = createPlugin<PluginOas>((options) => {
66
75
  contentType,
67
76
  }
68
77
  },
69
- resolvePath(baseName) {
70
- if (output === false) {
71
- return undefined
72
- }
73
-
74
- const root = path.resolve(this.config.root, this.config.output.path)
75
-
76
- return path.resolve(root, output.path, baseName)
77
- },
78
- resolveName(name, type) {
79
- return camelCase(name, { isFile: type === 'file' })
80
- },
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
78
  async buildStart() {
89
79
  if (!output) {
90
80
  return
@@ -99,31 +89,28 @@ export const pluginOas = createPlugin<PluginOas>((options) => {
99
89
  },
100
90
  })
101
91
  await oas.dereference()
92
+
93
+ const root = path.resolve(this.config.root, this.config.output.path)
102
94
  const schemas = getSchemas({ oas, contentType })
103
95
 
104
96
  const mapSchema = async ([name, schema]: [string, OasTypes.SchemaObject]) => {
105
- const resolvedPath = this.resolvePath({
106
- baseName: `${name}.json`,
107
- pluginKey: this.plugin.key,
108
- })
109
-
110
- const resvoledFileName = this.resolveName({
111
- name: `${name}.json`,
112
- pluginKey: [pluginOasName],
113
- type: 'file',
114
- }) as `${string}.json`
115
-
116
- if (!resolvedPath) {
117
- return
118
- }
97
+ const baseName = `${camelCase(name)}.json` as `${string}.json`
98
+ const resolvedPath = path.resolve(root, output.path, baseName)
119
99
 
120
100
  await this.addFile({
121
101
  path: resolvedPath,
122
- baseName: resvoledFileName,
123
- source: JSON.stringify(schema),
102
+ baseName,
124
103
  meta: {
125
104
  pluginKey: this.plugin.key,
126
105
  },
106
+ sources: [
107
+ {
108
+ name: camelCase(name),
109
+ isExportable: false,
110
+ isIndexable: false,
111
+ value: JSON.stringify(schema),
112
+ },
113
+ ],
127
114
  })
128
115
  }
129
116
 
package/src/types.ts CHANGED
@@ -33,6 +33,8 @@ export type Options = {
33
33
  * @default 'schemas'
34
34
  */
35
35
  path: string
36
+ extName?: KubbFile.Extname
37
+ exportType?: 'barrel' | 'barrelNamed' | false
36
38
  }
37
39
  | false
38
40
  /**
@@ -2,7 +2,7 @@ import { isParameterObject } from '@kubb/oas'
2
2
 
3
3
  import type { FunctionParamsAST } from '@kubb/core/utils'
4
4
  import type { OasTypes } from '@kubb/oas'
5
- import type { Params } from '@kubb/react'
5
+ import type { Params } from '@kubb/react/types'
6
6
  import type { OperationSchema } from '../types.ts'
7
7
  import { camelCase } from '@kubb/core/transformers'
8
8
  /**
@@ -1,8 +1,9 @@
1
1
  export { getComments } from './getComments.ts'
2
- export { getGroupedByTagFiles } from './getGroupedByTagFiles.ts'
3
2
  export { getASTParams, getPathParams } from './getParams.ts'
4
3
  export { getSchemaFactory } from './getSchemaFactory.ts'
5
4
  export type { GetSchemasProps } from './getSchemas.ts'
6
5
  export { getSchemas } from './getSchemas.ts'
7
6
  export { refsSorter } from './refSorter.ts'
8
7
  export { parseFromConfig } from './parseFromConfig.ts'
8
+
9
+ export { isOptional } from '@kubb/oas'
@@ -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 };