@kubb/plugin-oas 3.0.0-alpha.9 → 3.0.0-beta.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.
Files changed (99) hide show
  1. package/README.md +14 -5
  2. package/dist/OperationGenerator-Dko8Xtd7.d.cts +561 -0
  3. package/dist/OperationGenerator-Dko8Xtd7.d.ts +561 -0
  4. package/dist/{Schema-B1vcPGiK.d.ts → Schema-C2cbPYX1.d.cts} +1 -12
  5. package/dist/{Schema-DoSFh7Qd.d.cts → Schema-CbtIvprh.d.ts} +1 -12
  6. package/dist/chunk-2TGWPVZN.cjs +92 -0
  7. package/dist/chunk-2TGWPVZN.cjs.map +1 -0
  8. package/dist/chunk-A3ROGKLW.cjs +752 -0
  9. package/dist/chunk-A3ROGKLW.cjs.map +1 -0
  10. package/dist/chunk-ABOQ73FL.cjs +36 -0
  11. package/dist/chunk-ABOQ73FL.cjs.map +1 -0
  12. package/dist/chunk-BG77DP54.js +30 -0
  13. package/dist/chunk-BG77DP54.js.map +1 -0
  14. package/dist/chunk-GF26SDHQ.js +28 -0
  15. package/dist/chunk-GF26SDHQ.js.map +1 -0
  16. package/dist/chunk-JA75IPYU.js +744 -0
  17. package/dist/chunk-JA75IPYU.js.map +1 -0
  18. package/dist/chunk-PADR76WZ.cjs +4 -0
  19. package/dist/chunk-PADR76WZ.cjs.map +1 -0
  20. package/dist/chunk-QAFBZLJA.cjs +48 -0
  21. package/dist/{chunk-SZDO532A.js.map → chunk-QAFBZLJA.cjs.map} +1 -1
  22. package/dist/chunk-R47XMJ32.js +3 -0
  23. package/dist/chunk-R47XMJ32.js.map +1 -0
  24. package/dist/chunk-TNWNNVQW.js +88 -0
  25. package/dist/chunk-TNWNNVQW.js.map +1 -0
  26. package/dist/chunk-XNCEFOE6.js +45 -0
  27. package/dist/chunk-XNCEFOE6.js.map +1 -0
  28. package/dist/chunk-ZWHQ54JM.cjs +32 -0
  29. package/dist/chunk-ZWHQ54JM.cjs.map +1 -0
  30. package/dist/components.cjs +20 -12
  31. package/dist/components.cjs.map +1 -1
  32. package/dist/components.d.cts +3 -6
  33. package/dist/components.d.ts +3 -6
  34. package/dist/components.js +3 -12
  35. package/dist/components.js.map +1 -1
  36. package/dist/generators.cjs +14 -0
  37. package/dist/generators.cjs.map +1 -0
  38. package/dist/generators.d.cts +9 -0
  39. package/dist/generators.d.ts +9 -0
  40. package/dist/generators.js +5 -0
  41. package/dist/generators.js.map +1 -0
  42. package/dist/hooks.cjs +90 -57
  43. package/dist/hooks.cjs.map +1 -1
  44. package/dist/hooks.d.cts +37 -10
  45. package/dist/hooks.d.ts +37 -10
  46. package/dist/hooks.js +79 -53
  47. package/dist/hooks.js.map +1 -1
  48. package/dist/index.cjs +142 -189
  49. package/dist/index.cjs.map +1 -1
  50. package/dist/index.d.cts +2 -5
  51. package/dist/index.d.ts +2 -5
  52. package/dist/index.js +82 -156
  53. package/dist/index.js.map +1 -1
  54. package/dist/utils.cjs +32 -45
  55. package/dist/utils.cjs.map +1 -1
  56. package/dist/utils.d.cts +4 -13
  57. package/dist/utils.d.ts +4 -13
  58. package/dist/utils.js +8 -44
  59. package/dist/utils.js.map +1 -1
  60. package/package.json +20 -14
  61. package/src/OperationGenerator.ts +30 -39
  62. package/src/SchemaGenerator.ts +70 -11
  63. package/src/SchemaMapper.ts +24 -5
  64. package/src/components/Schema.tsx +1 -99
  65. package/src/generator.tsx +22 -18
  66. package/src/generators/index.ts +1 -0
  67. package/src/generators/jsonGenerator.ts +32 -0
  68. package/src/hooks/index.ts +2 -0
  69. package/src/hooks/useOperationManager.ts +56 -31
  70. package/src/hooks/useSchemaManager.ts +77 -0
  71. package/src/index.ts +2 -4
  72. package/src/plugin.ts +69 -56
  73. package/src/types.ts +29 -22
  74. package/src/utils/getParams.ts +1 -1
  75. package/src/utils/getSchemaFactory.ts +1 -1
  76. package/src/utils/index.ts +0 -1
  77. package/src/utils/parseFromConfig.ts +7 -7
  78. package/dist/OperationGenerator-By5WOmWB.d.ts +0 -165
  79. package/dist/OperationGenerator-Gd1X7wUz.d.cts +0 -165
  80. package/dist/SchemaMapper-sGcY1xL5.d.cts +0 -247
  81. package/dist/SchemaMapper-sGcY1xL5.d.ts +0 -247
  82. package/dist/chunk-75BIOXB7.cjs +0 -7
  83. package/dist/chunk-75BIOXB7.cjs.map +0 -1
  84. package/dist/chunk-IAUV3UKH.cjs +0 -3965
  85. package/dist/chunk-IAUV3UKH.cjs.map +0 -1
  86. package/dist/chunk-M347763D.js +0 -3965
  87. package/dist/chunk-M347763D.js.map +0 -1
  88. package/dist/chunk-N7EEVJA6.js +0 -35
  89. package/dist/chunk-N7EEVJA6.js.map +0 -1
  90. package/dist/chunk-NU4F7G47.cjs +0 -89
  91. package/dist/chunk-NU4F7G47.cjs.map +0 -1
  92. package/dist/chunk-O76YQFZB.cjs +0 -35
  93. package/dist/chunk-O76YQFZB.cjs.map +0 -1
  94. package/dist/chunk-SQ64ESS4.js +0 -7
  95. package/dist/chunk-SQ64ESS4.js.map +0 -1
  96. package/dist/chunk-SZDO532A.js +0 -89
  97. package/dist/types-CZTUCaE5.d.cts +0 -145
  98. package/dist/types-CZTUCaE5.d.ts +0 -145
  99. 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,33 @@ type SchemaNames = {
25
25
  }
26
26
 
27
27
  type UseOperationManagerResult = {
28
- getName: (operation: OperationType, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string
29
- getFile: (operation: OperationType, params?: { pluginKey?: Plugin['key']; extName?: KubbFile.Extname }) => KubbFile.File<FileMeta>
30
- groupSchemasByName: (operation: OperationType, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => SchemaNames
31
- getSchemas: (
32
- operation: Operation,
33
- params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] },
34
- forStatusCode?: string | number,
35
- ) => OperationSchemas
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
+ getFile: (
38
+ operation: OperationType,
39
+ params?: {
40
+ prefix?: string
41
+ suffix?: string
42
+ pluginKey?: Plugin['key']
43
+ extname?: KubbFile.Extname
44
+ tag?: string
45
+ },
46
+ ) => KubbFile.File<FileMeta>
47
+ groupSchemasByName: (
48
+ operation: OperationType,
49
+ params: {
50
+ pluginKey?: Plugin['key']
51
+ type: ResolveNameParams['type']
52
+ },
53
+ ) => SchemaNames
54
+ getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas
36
55
  }
37
56
 
38
57
  /**
@@ -42,27 +61,38 @@ export function useOperationManager(): UseOperationManagerResult {
42
61
  const { plugin, pluginManager } = useApp()
43
62
  const { generator } = useContext(Oas.Context)
44
63
 
45
- if (!generator) {
46
- throw new Error(`'generator' is not defined`)
47
- }
48
-
49
- const getName: UseOperationManagerResult['getName'] = (operation, { pluginKey = plugin.key, type }) => {
64
+ const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginKey = plugin.key, type }) => {
50
65
  return pluginManager.resolveName({
51
- name: operation.getOperationId(),
66
+ name: `${prefix} ${operation.getOperationId()} ${suffix}`,
52
67
  pluginKey,
53
68
  type,
54
69
  })
55
70
  }
56
71
 
57
- const getFile: UseOperationManagerResult['getFile'] = (operation, { pluginKey = plugin.key, extName = '.ts' } = {}) => {
58
- // needed for the `output.group`
59
- const tag = operation.getTags().at(0)?.name
60
- //TODO replace with group
61
- const name = getName(operation, { type: 'file', pluginKey })
72
+ const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {
73
+ if (!generator) {
74
+ throw new Error(`'generator' is not defined`)
75
+ }
62
76
 
77
+ return generator.getSchemas(operation, {
78
+ resolveName: (name) =>
79
+ pluginManager.resolveName({
80
+ name,
81
+ pluginKey: params?.pluginKey,
82
+ type: params?.type,
83
+ }),
84
+ })
85
+ }
86
+
87
+ //TODO replace tag with group
88
+ const getFile: UseOperationManagerResult['getFile'] = (
89
+ operation,
90
+ { prefix, suffix, pluginKey = plugin.key, tag = operation.getTags().at(0)?.name, extname = '.ts' } = {},
91
+ ) => {
92
+ const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })
63
93
  const file = pluginManager.getFile({
64
94
  name,
65
- extName,
95
+ extname,
66
96
  pluginKey,
67
97
  options: { type: 'file', pluginKey, tag },
68
98
  })
@@ -79,6 +109,10 @@ export function useOperationManager(): UseOperationManagerResult {
79
109
  }
80
110
 
81
111
  const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {
112
+ if (!generator) {
113
+ throw new Error(`'generator' is not defined`)
114
+ }
115
+
82
116
  const schemas = generator.getSchemas(operation)
83
117
 
84
118
  const errors = (schemas.errors || []).reduce(
@@ -149,16 +183,7 @@ export function useOperationManager(): UseOperationManagerResult {
149
183
  return {
150
184
  getName,
151
185
  getFile,
152
- getSchemas: (operation, params, forStatusCode) =>
153
- generator.getSchemas(operation, {
154
- forStatusCode,
155
- resolveName: (name) =>
156
- pluginManager.resolveName({
157
- name,
158
- pluginKey: params?.pluginKey,
159
- type: params?.type,
160
- }),
161
- }),
186
+ getSchemas,
162
187
  groupSchemasByName,
163
188
  }
164
189
  }
@@ -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 || !item.args.isImportable) {
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/index.ts CHANGED
@@ -1,7 +1,4 @@
1
- export type {
2
- GetOperationGeneratorOptions,
3
- OperationMethodResult,
4
- } from './OperationGenerator.ts'
1
+ export type { OperationMethodResult } from './OperationGenerator.ts'
5
2
  export { OperationGenerator } from './OperationGenerator.ts'
6
3
  export { pluginOas, pluginOasName } from './plugin.ts'
7
4
  export type {
@@ -13,6 +10,7 @@ export type { SchemaMethodResult } from './SchemaGenerator.ts'
13
10
  export { SchemaGenerator } from './SchemaGenerator.ts'
14
11
  export type {
15
12
  Schema,
13
+ SchemaTree,
16
14
  SchemaKeyword,
17
15
  SchemaKeywordBase,
18
16
  SchemaKeywordMapper,
package/src/plugin.ts CHANGED
@@ -1,34 +1,35 @@
1
- import path from 'node:path'
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, OasTypes } from '@kubb/oas'
12
- import type { FormatOptions } from '@kubb/oas/parser'
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 = { path: 'schemas', export: false },
20
- experimentalFilter: filter,
21
- experimentalSort: sort,
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, formatOptions }: { config: Config; logger: Logger; formatOptions?: FormatOptions }): Promise<Oas> => {
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, formatOptions, oasClass)
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, {}, oasClass)
43
+ return parseFromConfig(config, oasClass)
43
44
  }
44
45
  }
45
46
 
46
47
  return {
47
48
  name: pluginOasName,
48
- output:
49
- output === false
50
- ? {
51
- path: '',
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(formatOptions) {
64
- return getOas({ config, logger, formatOptions })
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
- const baseURL = oasInstance.api.servers?.at(serverIndex)?.url
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 root = path.resolve(this.config.root, this.config.output.path)
94
- const schemas = getSchemas({ oas, contentType })
95
-
96
- const mapSchema = async ([name, schema]: [string, OasTypes.SchemaObject]) => {
97
- const baseName = `${camelCase(name)}.json` as `${string}.json`
98
- const resolvedPath = path.resolve(root, output.path, baseName)
99
-
100
- await this.addFile({
101
- path: resolvedPath,
102
- baseName,
103
- meta: {
104
- pluginKey: this.plugin.key,
105
- },
106
- sources: [
107
- {
108
- name: camelCase(name),
109
- isExportable: false,
110
- isIndexable: false,
111
- value: JSON.stringify(schema),
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
- const promises = Object.entries(schemas).map(mapSchema)
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 { FormatOptions } from '@kubb/oas/parser'
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: (formatOptions?: FormatOptions) => Promise<Oas>
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,11 @@ export type Options = {
25
25
  * @default true
26
26
  */
27
27
  validate?: boolean
28
- output?:
29
- | {
30
- /**
31
- * Relative path to save the JSON models.
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
+ * Specify the export location for the files and define the behavior of the output
30
+ * @default { path: 'schemas', barrelType: 'named' }
31
+ */
32
+ output?: Output
40
33
  /**
41
34
  * Which server to use from the array of `servers.url[serverIndex]`
42
35
  * @example
@@ -47,24 +40,28 @@ export type Options = {
47
40
  serverIndex?: number
48
41
  /**
49
42
  * Define which contentType should be used.
50
- * By default, this is set based on the first used contentType..
43
+ * By default, this is set based on the contentType being found.
51
44
  */
52
45
  contentType?: contentType
53
- experimentalFilter?: FormatOptions['filterSet']
54
- experimentalSort?: FormatOptions['sortSet']
46
+ /**
47
+ * Override some behaviour of the Oas class instance, see '@kubb/oas'
48
+ */
55
49
  oasClass?: typeof Oas
50
+ /**
51
+ * Define some generators next to the JSON generation
52
+ */
53
+ generators?: Array<Generator<PluginOas>>
56
54
  }
57
55
 
58
56
  /**
59
57
  * `propertyName` is the ref name + resolved with the nameResolver
60
- * @example `import { Pet } from './Pet'`
58
+ * @example import { Pet } from './Pet'
61
59
  *
62
60
  * `originalName` is the original name used(in PascalCase), only used to remove duplicates
63
61
  *
64
62
  * `pluginKey` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
65
63
  * @example import a type(plugin-ts) for a mock file(swagger-faker)
66
64
  */
67
-
68
65
  export type Ref = {
69
66
  propertyName: string
70
67
  originalName: string
@@ -92,7 +89,7 @@ export type OperationSchema = {
92
89
  /**
93
90
  * OperationName in PascalCase, only being used in OperationGenerator
94
91
  */
95
- operationName?: string
92
+ operationName: string
96
93
  description?: string
97
94
  statusCode?: number
98
95
  keys?: string[]
@@ -106,6 +103,7 @@ export type OperationSchemas = {
106
103
  headerParams?: OperationSchema & { keysToOmit?: never }
107
104
  request?: OperationSchema
108
105
  response: OperationSchema
106
+ responses: Array<OperationSchema>
109
107
  statusCodes?: Array<OperationSchema>
110
108
  errors?: Array<OperationSchema>
111
109
  }
@@ -130,6 +128,11 @@ type ByMethod = {
130
128
  type: 'method'
131
129
  pattern: HttpMethod | RegExp
132
130
  }
131
+ // TODO implement as alternative for ByMethod
132
+ type ByMethods = {
133
+ type: 'methods'
134
+ pattern: Array<HttpMethod>
135
+ }
133
136
 
134
137
  type BySchemaName = {
135
138
  type: 'schemaName'
@@ -143,4 +146,8 @@ export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | By
143
146
  options: Partial<TOptions>
144
147
  }
145
148
 
146
- export type PluginOas = PluginFactoryOptions<'plugin-oas', Options, Options, API, never>
149
+ type ResolvedOptions = Options & {
150
+ output: Output
151
+ }
152
+
153
+ export type PluginOas = PluginFactoryOptions<'plugin-oas', Options, ResolvedOptions, API, never>
@@ -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
  }
@@ -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 { type FormatOptions, parse } from '@kubb/oas/parser'
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, options: FormatOptions = {}, oasClass: typeof Oas = Oas): Promise<Oas> {
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, options, oasClass)
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, options, oasClass)
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, options, oasClass)
28
+ return parse(api, oasClass)
29
29
  }
30
30
 
31
31
  if (new URLPath(config.input.path).isURL) {
32
- return parse(config.input.path, options, oasClass)
32
+ return parse(config.input.path, oasClass)
33
33
  }
34
34
 
35
- return parse(resolve(config.root, config.input.path), options, oasClass)
35
+ return parse(resolve(config.root, config.input.path), oasClass)
36
36
  }