@kubb/plugin-oas 5.0.0-alpha.3 → 5.0.0-alpha.30

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 (61) hide show
  1. package/dist/{SchemaMapper-SneuY1wg.d.ts → SchemaMapper-CLIXrzqv.d.ts} +3 -3
  2. package/dist/SchemaMapper-CeavHZlp.cjs.map +1 -1
  3. package/dist/SchemaMapper-CqMkO2T1.js.map +1 -1
  4. package/dist/{createGenerator-jtR_okrd.d.ts → createGenerator-DL3CAvaU.d.ts} +121 -70
  5. package/dist/{generators-vAAte6w6.cjs → generators-85sP4GIS.cjs} +7 -7
  6. package/dist/generators-85sP4GIS.cjs.map +1 -0
  7. package/dist/{generators-B8HiBWvT.js → generators-hPE06pZB.js} +7 -7
  8. package/dist/generators-hPE06pZB.js.map +1 -0
  9. package/dist/generators.cjs +1 -1
  10. package/dist/generators.d.ts +4 -3
  11. package/dist/generators.js +1 -1
  12. package/dist/{getFooter-Pw3tLCiV.js → getFooter-Dz4u5Mg4.js} +5 -2
  13. package/dist/getFooter-Dz4u5Mg4.js.map +1 -0
  14. package/dist/{getFooter-BBzsC616.cjs → getFooter-gshcRE1-.cjs} +5 -2
  15. package/dist/getFooter-gshcRE1-.cjs.map +1 -0
  16. package/dist/hooks.cjs +25 -21
  17. package/dist/hooks.cjs.map +1 -1
  18. package/dist/hooks.d.ts +10 -7
  19. package/dist/hooks.js +27 -23
  20. package/dist/hooks.js.map +1 -1
  21. package/dist/index.cjs +50 -45
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.ts +26 -52
  24. package/dist/index.js +49 -44
  25. package/dist/index.js.map +1 -1
  26. package/dist/mocks.d.ts +1 -1
  27. package/dist/{requestBody-BJJL0mpy.cjs → requestBody-94hwM4b-.cjs} +115 -304
  28. package/dist/requestBody-94hwM4b-.cjs.map +1 -0
  29. package/dist/{requestBody-CSL-jLGQ.js → requestBody-BO3N7fWH.js} +107 -290
  30. package/dist/requestBody-BO3N7fWH.js.map +1 -0
  31. package/dist/utils.cjs +61 -11
  32. package/dist/utils.cjs.map +1 -1
  33. package/dist/utils.d.ts +4 -4
  34. package/dist/utils.js +61 -11
  35. package/dist/utils.js.map +1 -1
  36. package/package.json +8 -12
  37. package/src/OperationGenerator.ts +72 -86
  38. package/src/SchemaGenerator.ts +61 -82
  39. package/src/SchemaMapper.ts +2 -2
  40. package/src/generators/createGenerator.ts +13 -16
  41. package/src/generators/createReactGenerator.ts +12 -15
  42. package/src/generators/index.ts +2 -2
  43. package/src/generators/jsonGenerator.ts +3 -3
  44. package/src/generators/types.ts +5 -43
  45. package/src/hooks/useOas.ts +5 -2
  46. package/src/hooks/useOperationManager.ts +22 -21
  47. package/src/hooks/useSchemaManager.ts +8 -8
  48. package/src/index.ts +2 -2
  49. package/src/plugin.ts +13 -9
  50. package/src/types.ts +15 -8
  51. package/src/utils/getBanner.ts +1 -1
  52. package/src/utils/getFooter.ts +1 -1
  53. package/src/utils/getImports.ts +3 -3
  54. package/src/utils/getParams.ts +2 -2
  55. package/src/utils.tsx +51 -151
  56. package/dist/generators-B8HiBWvT.js.map +0 -1
  57. package/dist/generators-vAAte6w6.cjs.map +0 -1
  58. package/dist/getFooter-BBzsC616.cjs.map +0 -1
  59. package/dist/getFooter-Pw3tLCiV.js.map +0 -1
  60. package/dist/requestBody-BJJL0mpy.cjs.map +0 -1
  61. package/dist/requestBody-CSL-jLGQ.js.map +0 -1
package/src/plugin.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import path from 'node:path'
2
+ import type { AsyncEventEmitter } from '@internals/utils'
2
3
  import { camelCase } from '@internals/utils'
3
- import type { AsyncEventEmitter } from '@kubb/core'
4
- import { type Config, definePlugin, type Group, getMode, type KubbEvents } from '@kubb/core'
4
+ import { type Config, createPlugin, type KubbEvents, type UserGroup } from '@kubb/core'
5
5
  import type { Oas } from '@kubb/oas'
6
6
  import { parseFromConfig, resolveServerUrl } from '@kubb/oas'
7
+ import { version } from '../package.json'
7
8
  import { jsonGenerator } from './generators'
8
9
  import { OperationGenerator } from './OperationGenerator.ts'
9
10
  import { SchemaGenerator } from './SchemaGenerator.ts'
@@ -11,7 +12,7 @@ import type { PluginOas } from './types.ts'
11
12
 
12
13
  export const pluginOasName = 'plugin-oas' satisfies PluginOas['name']
13
14
 
14
- export const pluginOas = definePlugin<PluginOas>((options) => {
15
+ export const pluginOas = createPlugin<PluginOas>((options) => {
15
16
  const {
16
17
  output = {
17
18
  path: 'schemas',
@@ -60,11 +61,14 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
60
61
 
61
62
  return {
62
63
  name: pluginOasName,
64
+ version,
63
65
  options: {
64
66
  output,
65
67
  validate,
66
68
  discriminator,
67
69
  ...options,
70
+ exclude: [],
71
+ override: [],
68
72
  },
69
73
  inject() {
70
74
  const config = this.config
@@ -99,8 +103,8 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
99
103
  }
100
104
  },
101
105
  resolvePath(baseName, pathMode, options) {
102
- const root = path.resolve(this.config.root, this.config.output.path)
103
- const mode = pathMode ?? getMode(path.resolve(root, output.path))
106
+ const root = this.root
107
+ const mode = pathMode ?? this.getMode(output)
104
108
 
105
109
  if (mode === 'single') {
106
110
  /**
@@ -111,7 +115,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
111
115
  }
112
116
 
113
117
  if (group && (options?.group?.path || options?.group?.tag)) {
114
- const groupName: Group['name'] = group?.name
118
+ const groupName: UserGroup['name'] = group?.name
115
119
  ? group.name
116
120
  : (ctx) => {
117
121
  if (group?.type === 'path') {
@@ -132,7 +136,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
132
136
 
133
137
  return path.resolve(root, output.path, baseName)
134
138
  },
135
- async install() {
139
+ async buildStart() {
136
140
  const oas = await this.getOas({ validate })
137
141
 
138
142
  if (!output || generators.length === 0) {
@@ -152,7 +156,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
152
156
  {
153
157
  fabric: this.fabric,
154
158
  oas,
155
- pluginManager: this.pluginManager,
159
+ driver: this.driver,
156
160
  events: this.events,
157
161
  plugin: this.plugin,
158
162
  contentType,
@@ -169,7 +173,7 @@ export const pluginOas = definePlugin<PluginOas>((options) => {
169
173
  const operationGenerator = new OperationGenerator(this.plugin.options, {
170
174
  fabric: this.fabric,
171
175
  oas,
172
- pluginManager: this.pluginManager,
176
+ driver: this.driver,
173
177
  events: this.events,
174
178
  plugin: this.plugin,
175
179
  contentType,
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
- import type { KubbFile } from '@kubb/fabric-core/types'
1
+ import type { Output, PluginFactoryOptions, ResolveNameParams, UserGroup } from '@kubb/core'
2
+ import type { FabricFile } from '@kubb/fabric-core/types'
3
3
 
4
4
  import type { contentType, HttpMethod, Oas, Operation, SchemaObject } from '@kubb/oas'
5
5
  import type { Generator } from './generators/types.ts'
@@ -16,6 +16,9 @@ type Context = {
16
16
  declare global {
17
17
  namespace Kubb {
18
18
  interface PluginContext extends Context {}
19
+ interface PluginRegistry {
20
+ 'plugin-oas': PluginOas
21
+ }
19
22
  }
20
23
  }
21
24
 
@@ -42,7 +45,7 @@ export type Options = {
42
45
  /**
43
46
  * Group the JSON files based on the provided name.
44
47
  */
45
- group?: Group
48
+ group?: UserGroup
46
49
  /**
47
50
  * Which server to use from the array of `servers.url[serverIndex]`
48
51
  * @example
@@ -142,7 +145,7 @@ export type Options = {
142
145
  export type Ref = {
143
146
  propertyName: string
144
147
  originalName: string
145
- path: KubbFile.Path
148
+ path: FabricFile.Path
146
149
  pluginName?: string
147
150
  }
148
151
  export type Refs = Record<string, Ref>
@@ -152,8 +155,8 @@ export type Resolver = {
152
155
  * Original name or name resolved by `resolveName({ name: operation?.getOperationId() as string, pluginName })`
153
156
  */
154
157
  name: string
155
- baseName: KubbFile.BaseName
156
- path: KubbFile.Path
158
+ baseName: FabricFile.BaseName
159
+ path: FabricFile.Path
157
160
  }
158
161
 
159
162
  export type OperationSchema = {
@@ -220,15 +223,19 @@ type ByContentType = {
220
223
  pattern: string | RegExp
221
224
  }
222
225
 
223
- export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType
224
- export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType
226
+ export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
227
+ export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
225
228
 
226
229
  export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
230
+ // should be options: Omit<Partial<TOptions>, 'override'>
227
231
  options: Partial<TOptions>
228
232
  }
229
233
 
230
234
  type ResolvedOptions = Options & {
231
235
  output: Output<Oas>
236
+ exclude: Array<Exclude>
237
+ include?: Array<Include>
238
+ override: Array<Override<ResolvedOptions>>
232
239
  }
233
240
 
234
241
  export type PluginOas = PluginFactoryOptions<'plugin-oas', Options, ResolvedOptions, Context, ResolvePathOptions>
@@ -67,7 +67,7 @@ export function getBanner<TOas extends Oas>({ output, oas, config }: Props<TOas>
67
67
  }
68
68
 
69
69
  if (isFunction(output.banner)) {
70
- return `${output.banner(oas)}\n${banner}`
70
+ return `${output.banner(oas as any)}\n${banner}`
71
71
  }
72
72
 
73
73
  return `${output.banner}\n${banner}`
@@ -13,7 +13,7 @@ export function getFooter<TOas extends Oas>({ output, oas }: Props<TOas>) {
13
13
  }
14
14
 
15
15
  if (isFunction(output.footer)) {
16
- return output.footer(oas)
16
+ return output.footer(oas as any)
17
17
  }
18
18
 
19
19
  return output.footer
@@ -1,4 +1,4 @@
1
- import type { KubbFile } from '@kubb/fabric-core/types'
1
+ import type { FabricFile } from '@kubb/fabric-core/types'
2
2
  import { SchemaGenerator } from '../SchemaGenerator.ts'
3
3
  import type { Schema } from '../SchemaMapper'
4
4
  import { schemaKeywords } from '../SchemaMapper'
@@ -6,7 +6,7 @@ import { schemaKeywords } from '../SchemaMapper'
6
6
  /**
7
7
  * Get imports from a schema tree by extracting all ref schemas that are importable
8
8
  */
9
- export function getImports(tree: Array<Schema>): Array<KubbFile.Import> {
9
+ export function getImports(tree: Array<Schema>): Array<FabricFile.Import> {
10
10
  const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)
11
11
 
12
12
  if (!refs) return []
@@ -20,7 +20,7 @@ export function getImports(tree: Array<Schema>): Array<KubbFile.Import> {
20
20
  return {
21
21
  name: [item.args.name],
22
22
  path: item.args.path,
23
- } satisfies KubbFile.Import
23
+ } satisfies FabricFile.Import
24
24
  })
25
25
  .filter((x): x is NonNullable<typeof x> => x !== undefined)
26
26
  }
@@ -20,7 +20,7 @@ export function getASTParams(
20
20
  override?: (data: FunctionParamsAST) => FunctionParamsAST
21
21
  } = {},
22
22
  ): FunctionParamsAST[] {
23
- if (!operationSchema || !operationSchema.schema.properties || !operationSchema.name) {
23
+ if (!operationSchema?.schema.properties || !operationSchema.name) {
24
24
  return []
25
25
  }
26
26
 
@@ -82,7 +82,7 @@ export function getParamsMapping(
82
82
  casing?: 'camelcase'
83
83
  } = {},
84
84
  ): Record<string, string> | undefined {
85
- if (!operationSchema || !operationSchema.schema.properties) {
85
+ if (!operationSchema?.schema.properties) {
86
86
  return undefined
87
87
  }
88
88
 
package/src/utils.tsx CHANGED
@@ -1,207 +1,107 @@
1
- import type { OperationNode, SchemaNode } from '@kubb/ast/types'
2
- import type { Adapter, Config, Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'
3
- import type { KubbFile } from '@kubb/fabric-core/types'
1
+ import type { Config, Plugin, PluginFactoryOptions } from '@kubb/core'
4
2
  import type { Operation, SchemaObject } from '@kubb/oas'
5
- import { App, createReactFabric, type Fabric } from '@kubb/react-fabric'
3
+ import { createReactFabric, Fabric } from '@kubb/react-fabric'
4
+ import type { Fabric as FabricType } from '@kubb/react-fabric/types'
6
5
  import type { ReactGenerator } from './generators/createReactGenerator.ts'
7
6
  import type { OperationGenerator } from './OperationGenerator.ts'
8
7
  import type { SchemaGenerator, SchemaGeneratorOptions } from './SchemaGenerator.ts'
9
8
  import type { Schema } from './SchemaMapper.ts'
10
9
 
11
- type BuildOperationsBaseOptions<TOptions extends PluginFactoryOptions> = {
10
+ type BuildOperationsV1Options<TOptions extends PluginFactoryOptions> = {
12
11
  config: Config
13
- fabric: Fabric
12
+ fabric: FabricType
14
13
  plugin: Plugin<TOptions>
15
- }
16
-
17
- type BuildOperationsV1Options<TOptions extends PluginFactoryOptions> = BuildOperationsBaseOptions<TOptions> & {
18
- version?: '1'
19
- Component: ReactGenerator<any, '1'>['Operations']
14
+ Component: ReactGenerator<TOptions>['Operations']
20
15
  generator: Omit<OperationGenerator<TOptions>, 'build'>
21
16
  }
22
17
 
23
- type BuildOperationsV2Options<TOptions extends PluginFactoryOptions> = BuildOperationsBaseOptions<TOptions> & {
24
- version: '2'
25
- Component: ReactGenerator<any, '2'>['Operations']
26
- adapter: Adapter
27
- pluginManager: PluginManager
28
- mode: KubbFile.Mode
29
- }
30
-
31
- function isBuildOperationsV1Options<TOptions extends PluginFactoryOptions>(
32
- options: BuildOperationsV1Options<TOptions> | BuildOperationsV2Options<TOptions>,
33
- ): options is BuildOperationsV1Options<TOptions> {
34
- return (options.version ?? '1') === '1'
35
- }
36
-
37
- export async function buildOperations<TOptions extends PluginFactoryOptions>(
18
+ /**
19
+ * Renders a React component for a list of operations (V1 generators).
20
+ */
21
+ export async function renderOperations<TOptions extends PluginFactoryOptions>(
38
22
  operations: Array<Operation>,
39
23
  options: BuildOperationsV1Options<TOptions>,
40
- ): Promise<void>
41
- export async function buildOperations<TOptions extends PluginFactoryOptions>(
42
- nodes: Array<OperationNode>,
43
- options: BuildOperationsV2Options<TOptions>,
44
- ): Promise<void>
45
- export async function buildOperations<TOptions extends PluginFactoryOptions>(
46
- operationsOrNodes: Array<Operation> | Array<OperationNode>,
47
- options: BuildOperationsV1Options<TOptions> | BuildOperationsV2Options<TOptions>,
48
24
  ): Promise<void> {
49
- const { config, fabric, plugin } = options
25
+ const { config, fabric, plugin, Component, generator } = options
50
26
 
51
- if (!options.Component) {
27
+ if (!Component) {
52
28
  return undefined
53
29
  }
54
30
 
31
+ const { driver, oas, mode } = generator.context
55
32
  const fabricChild = createReactFabric()
56
33
 
57
- if (isBuildOperationsV1Options(options)) {
58
- const { generator, Component } = options
59
- const { pluginManager, oas, mode } = generator.context
60
-
61
- await fabricChild.render(
62
- <App meta={{ pluginManager, plugin, mode, oas }}>
63
- <Component config={config} operations={operationsOrNodes as Array<Operation>} generator={generator} plugin={plugin} />
64
- </App>,
65
- )
66
- } else {
67
- const { Component, adapter } = options
68
-
69
- await fabricChild.render(
70
- <App meta={{ plugin }}>
71
- <Component config={config} adapter={adapter} nodes={operationsOrNodes as Array<OperationNode>} options={plugin.options} />
72
- </App>,
73
- )
74
- }
34
+ await fabricChild.render(
35
+ <Fabric meta={{ driver, plugin, mode, oas }}>
36
+ <Component config={config} operations={operations} generator={generator} plugin={plugin} />
37
+ </Fabric>,
38
+ )
75
39
 
76
- await fabric.context.fileManager.upsert(...fabricChild.files)
40
+ fabric.context.fileManager.upsert(...fabricChild.files)
77
41
  fabricChild.unmount()
78
42
  }
79
43
 
80
- type BuildOperationBaseOptions<TOptions extends PluginFactoryOptions> = {
44
+ type BuildOperationV1Options<TOptions extends PluginFactoryOptions> = {
81
45
  config: Config
82
- fabric: Fabric
46
+ fabric: FabricType
83
47
  plugin: Plugin<TOptions>
84
- }
85
-
86
- type BuildOperationV1Options<TOptions extends PluginFactoryOptions> = BuildOperationBaseOptions<TOptions> & {
87
- version?: '1'
88
- Component: ReactGenerator<any, '1'>['Operation']
48
+ Component: ReactGenerator<TOptions>['Operation']
89
49
  generator: Omit<OperationGenerator<TOptions>, 'build'>
90
50
  }
91
51
 
92
- type BuildOperationV2Options<TOptions extends PluginFactoryOptions> = BuildOperationBaseOptions<TOptions> & {
93
- version: '2'
94
- Component: ReactGenerator<any, '2'>['Operation']
95
- adapter: Adapter
96
- pluginManager: PluginManager
97
- mode: KubbFile.Mode
98
- }
99
-
100
- function isBuildOperationV1Options<TOptions extends PluginFactoryOptions>(
101
- options: BuildOperationV1Options<TOptions> | BuildOperationV2Options<TOptions>,
102
- ): options is BuildOperationV1Options<TOptions> {
103
- return (options.version ?? '1') === '1'
104
- }
105
-
106
- export async function buildOperation<TOptions extends PluginFactoryOptions>(operation: Operation, options: BuildOperationV1Options<TOptions>): Promise<void>
107
- export async function buildOperation<TOptions extends PluginFactoryOptions>(node: OperationNode, options: BuildOperationV2Options<TOptions>): Promise<void>
108
- export async function buildOperation<TOptions extends PluginFactoryOptions>(
109
- operationOrNode: Operation | OperationNode,
110
- options: BuildOperationV1Options<TOptions> | BuildOperationV2Options<TOptions>,
111
- ): Promise<void> {
112
- const { config, fabric, plugin } = options
52
+ /**
53
+ * Renders a React component for a single operation (V1 generators).
54
+ */
55
+ export async function renderOperation<TOptions extends PluginFactoryOptions>(operation: Operation, options: BuildOperationV1Options<TOptions>): Promise<void> {
56
+ const { config, fabric, plugin, Component, generator } = options
113
57
 
114
- if (!options.Component) {
58
+ if (!Component) {
115
59
  return undefined
116
60
  }
117
61
 
62
+ const { driver, oas, mode } = generator.context
118
63
  const fabricChild = createReactFabric()
119
64
 
120
- if (isBuildOperationV1Options(options)) {
121
- const { generator, Component } = options
122
- const { pluginManager, oas, mode } = generator.context
123
-
124
- await fabricChild.render(
125
- <App meta={{ pluginManager, plugin, mode, oas }}>
126
- <Component config={config} operation={operationOrNode as Operation} plugin={plugin} generator={generator} />
127
- </App>,
128
- )
129
- } else {
130
- const { Component, adapter, pluginManager, mode } = options
131
-
132
- await fabricChild.render(
133
- <App meta={{ plugin, pluginManager, mode }}>
134
- <Component config={config} adapter={adapter} node={operationOrNode as OperationNode} options={plugin.options} />
135
- </App>,
136
- )
137
- }
65
+ await fabricChild.render(
66
+ <Fabric meta={{ driver, plugin, mode, oas }}>
67
+ <Component config={config} operation={operation} plugin={plugin} generator={generator} />
68
+ </Fabric>,
69
+ )
138
70
 
139
- await fabric.context.fileManager.upsert(...fabricChild.files)
71
+ fabric.context.fileManager.upsert(...fabricChild.files)
140
72
  fabricChild.unmount()
141
73
  }
142
74
 
143
- type BuildSchemaBaseOptions<TOptions extends PluginFactoryOptions> = {
75
+ type BuildSchemaV1Options<TOptions extends PluginFactoryOptions> = {
144
76
  config: Config
145
- fabric: Fabric
77
+ fabric: FabricType
146
78
  plugin: Plugin<TOptions>
147
- }
148
-
149
- type BuildSchemaV1Options<TOptions extends PluginFactoryOptions> = BuildSchemaBaseOptions<TOptions> & {
150
- version?: '1'
151
- Component: ReactGenerator<any, '1'>['Schema']
79
+ Component: ReactGenerator<TOptions>['Schema']
152
80
  generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>
153
81
  }
154
82
 
155
- type BuildSchemaV2Options<TOptions extends PluginFactoryOptions> = BuildSchemaBaseOptions<TOptions> & {
156
- version: '2'
157
- Component: ReactGenerator<any, '2'>['Schema']
158
- adapter: Adapter
159
- pluginManager: PluginManager
160
- mode: KubbFile.Mode
161
- }
162
-
163
- function isBuildSchemaV1Options<TOptions extends PluginFactoryOptions>(
164
- options: BuildSchemaV1Options<TOptions> | BuildSchemaV2Options<TOptions>,
165
- ): options is BuildSchemaV1Options<TOptions> {
166
- return (options.version ?? '1') === '1'
167
- }
168
-
169
- export async function buildSchema<TOptions extends PluginFactoryOptions>(
83
+ /**
84
+ * Renders a React component for a single schema (V1 generators).
85
+ */
86
+ export async function renderSchema<TOptions extends PluginFactoryOptions>(
170
87
  schema: { name: string; tree: Array<Schema>; value: SchemaObject },
171
88
  options: BuildSchemaV1Options<TOptions>,
172
- ): Promise<void>
173
- export async function buildSchema<TOptions extends PluginFactoryOptions>(schema: SchemaNode, options: BuildSchemaV2Options<TOptions>): Promise<void>
174
- export async function buildSchema<TOptions extends PluginFactoryOptions>(
175
- schema: { name: string; tree: Array<Schema>; value: SchemaObject } | SchemaNode,
176
- options: BuildSchemaV1Options<TOptions> | BuildSchemaV2Options<TOptions>,
177
89
  ): Promise<void> {
178
- const { config, fabric, plugin } = options
90
+ const { config, fabric, plugin, Component, generator } = options
179
91
 
180
- if (!options.Component) {
92
+ if (!Component) {
181
93
  return undefined
182
94
  }
183
95
 
96
+ const { driver, oas, mode } = generator.context
184
97
  const fabricChild = createReactFabric()
185
98
 
186
- if (isBuildSchemaV1Options(options)) {
187
- const { generator, Component } = options
188
- const { pluginManager, oas, mode } = generator.context
189
-
190
- await fabricChild.render(
191
- <App meta={{ pluginManager, plugin, mode, oas }}>
192
- <Component config={config} schema={schema as { name: string; tree: Array<Schema>; value: SchemaObject }} plugin={plugin} generator={generator} />
193
- </App>,
194
- )
195
- } else {
196
- const { Component, adapter, pluginManager, mode } = options
197
-
198
- await fabricChild.render(
199
- <App meta={{ plugin, pluginManager, mode }}>
200
- <Component config={config} adapter={adapter} node={schema as SchemaNode} options={plugin.options} />
201
- </App>,
202
- )
203
- }
99
+ await fabricChild.render(
100
+ <Fabric meta={{ driver, plugin, mode, oas }}>
101
+ <Component config={config} schema={schema} plugin={plugin} generator={generator} />
102
+ </Fabric>,
103
+ )
204
104
 
205
- await fabric.context.fileManager.upsert(...fabricChild.files)
105
+ fabric.context.fileManager.upsert(...fabricChild.files)
206
106
  fabricChild.unmount()
207
107
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-B8HiBWvT.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 pluginName: plugin.name,\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,YAAY,OAAO;IACpB,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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-vAAte6w6.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 pluginName: plugin.name,\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,YAAY,OAAO;IACpB,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":"getFooter-BBzsC616.cjs","names":["path"],"sources":["../../../internals/utils/src/casing.ts","../src/utils/getBanner.ts","../src/utils/getFooter.ts"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport type { Config, Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n config?: Config\n}\n\n/**\n * Generate a default banner for files created by Kubb\n * @returns A string with the default banner\n */\nfunction getDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n // If there's any error in parsing the Oas data, return a simpler banner\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function getBanner<TOas extends Oas>({ output, oas, config }: Props<TOas>): string {\n let banner = ''\n if (config?.output?.defaultBanner !== false && config) {\n const { title, description, version } = oas.api?.info || {}\n\n banner = getDefaultBanner({ title, description, version, config })\n }\n\n if (!output.banner) {\n return banner\n }\n\n if (isFunction(output.banner)) {\n return `${output.banner(oas)}\\n${banner}`\n }\n\n return `${output.banner}\\n${banner}`\n}\n","import type { Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n}\n\nexport function getFooter<TOas extends Oas>({ output, oas }: Props<TOas>) {\n if (!output.footer) {\n return undefined\n }\n\n if (isFunction(output.footer)) {\n return output.footer(oas)\n }\n\n return output.footer\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;AAQjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,IAAI;AAC7B,QAAO,MAAM,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;AAWtF,SAAgB,UAAU,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;AAClG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAAM,WAAW,UAAU,MAAM,SAAS;EAAE;EAAQ;EAAQ,GAAG,EAAE,CAAC,CAAC;AAGpG,QAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,MAAM;;;;;;;;;;AAW9D,SAAgB,WAAW,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;AACnG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAAM,WAAY,SAAS,WAAW,MAAM;EAAE;EAAQ;EAAQ,CAAC,GAAG,UAAU,KAAK,CAAE;AAGpH,QAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,KAAK;;;;;;;;AC5D7D,SAAS,iBAAiB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACrJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,UAAU,OAAO,MACnB,UAASA,UAAAA,QAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AAEf,SAAO;;;AAIX,SAAgB,UAA4B,EAAE,QAAQ,KAAK,UAA+B;CACxF,IAAI,SAAS;AACb,KAAI,QAAQ,QAAQ,kBAAkB,SAAS,QAAQ;EACrD,MAAM,EAAE,OAAO,aAAa,YAAY,IAAI,KAAK,QAAQ,EAAE;AAE3D,WAAS,iBAAiB;GAAE;GAAO;GAAa;GAAS;GAAQ,CAAC;;AAGpE,KAAI,CAAC,OAAO,OACV,QAAO;AAGT,MAAA,GAAA,OAAA,YAAe,OAAO,OAAO,CAC3B,QAAO,GAAG,OAAO,OAAO,IAAI,CAAC,IAAI;AAGnC,QAAO,GAAG,OAAO,OAAO,IAAI;;;;AC/D9B,SAAgB,UAA4B,EAAE,QAAQ,OAAoB;AACxE,KAAI,CAAC,OAAO,OACV;AAGF,MAAA,GAAA,OAAA,YAAe,OAAO,OAAO,CAC3B,QAAO,OAAO,OAAO,IAAI;AAG3B,QAAO,OAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"getFooter-Pw3tLCiV.js","names":[],"sources":["../../../internals/utils/src/casing.ts","../src/utils/getBanner.ts","../src/utils/getFooter.ts"],"sourcesContent":["type Options = {\n /** When `true`, dot-separated segments are split on `.` and joined with `/` after casing. */\n isFile?: boolean\n /** Text prepended before casing is applied. */\n prefix?: string\n /** Text appended before casing is applied. */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n const normalized = text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n\n const words = normalized.split(/[\\s\\-_./\\\\:]+/).filter(Boolean)\n\n return words\n .map((word, i) => {\n const allUpper = word.length > 1 && word === word.toUpperCase()\n if (allUpper) return word\n if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1)\n return word.charAt(0).toUpperCase() + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Splits `text` on `.` and applies `transformPart` to each segment.\n * The last segment receives `isLast = true`, all earlier segments receive `false`.\n * Segments are joined with `/` to form a file path.\n */\nfunction applyToFileParts(text: string, transformPart: (part: string, isLast: boolean) => string): string {\n const parts = text.split('.')\n return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join('/')\n}\n\n/**\n * Converts `text` to camelCase.\n * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.\n *\n * @example\n * camelCase('hello-world') // 'helloWorld'\n * camelCase('pet.petId', { isFile: true }) // 'pet/petId'\n */\nexport function camelCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? { prefix, suffix } : {}))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.\n *\n * @example\n * pascalCase('hello-world') // 'HelloWorld'\n * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'\n */\nexport function pascalCase(text: string, { isFile, prefix = '', suffix = '' }: Options = {}): string {\n if (isFile) {\n return applyToFileParts(text, (part, isLast) => (isLast ? pascalCase(part, { prefix, suffix }) : camelCase(part)))\n }\n\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n\n/**\n * Converts `text` to snake_case.\n *\n * @example\n * snakeCase('helloWorld') // 'hello_world'\n * snakeCase('Hello-World') // 'hello_world'\n */\nexport function snakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n const processed = `${prefix} ${text} ${suffix}`.trim()\n return processed\n .replace(/([a-z])([A-Z])/g, '$1_$2')\n .replace(/[\\s\\-.]+/g, '_')\n .replace(/[^a-zA-Z0-9_]/g, '')\n .toLowerCase()\n .split('_')\n .filter(Boolean)\n .join('_')\n}\n\n/**\n * Converts `text` to SCREAMING_SNAKE_CASE.\n *\n * @example\n * screamingSnakeCase('helloWorld') // 'HELLO_WORLD'\n */\nexport function screamingSnakeCase(text: string, { prefix = '', suffix = '' }: Omit<Options, 'isFile'> = {}): string {\n return snakeCase(text, { prefix, suffix }).toUpperCase()\n}\n","import path from 'node:path'\nimport type { Config, Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n config?: Config\n}\n\n/**\n * Generate a default banner for files created by Kubb\n * @returns A string with the default banner\n */\nfunction getDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n // If there's any error in parsing the Oas data, return a simpler banner\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function getBanner<TOas extends Oas>({ output, oas, config }: Props<TOas>): string {\n let banner = ''\n if (config?.output?.defaultBanner !== false && config) {\n const { title, description, version } = oas.api?.info || {}\n\n banner = getDefaultBanner({ title, description, version, config })\n }\n\n if (!output.banner) {\n return banner\n }\n\n if (isFunction(output.banner)) {\n return `${output.banner(oas)}\\n${banner}`\n }\n\n return `${output.banner}\\n${banner}`\n}\n","import type { Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n}\n\nexport function getFooter<TOas extends Oas>({ output, oas }: Props<TOas>) {\n if (!output.footer) {\n return undefined\n }\n\n if (isFunction(output.footer)) {\n return output.footer(oas)\n }\n\n return output.footer\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAS,gBAAgB,MAAc,QAAyB;AAS9D,QARmB,KAChB,MAAM,CACN,QAAQ,qBAAqB,QAAQ,CACrC,QAAQ,yBAAyB,QAAQ,CACzC,QAAQ,gBAAgB,QAAQ,CAEV,MAAM,gBAAgB,CAAC,OAAO,QAAQ,CAG5D,KAAK,MAAM,MAAM;AAEhB,MADiB,KAAK,SAAS,KAAK,SAAS,KAAK,aAAa,CACjD,QAAO;AACrB,MAAI,MAAM,KAAK,CAAC,OAAQ,QAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;AAC3E,SAAO,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE;GACnD,CACD,KAAK,GAAG,CACR,QAAQ,iBAAiB,GAAG;;;;;;;AAQjC,SAAS,iBAAiB,MAAc,eAAkE;CACxG,MAAM,QAAQ,KAAK,MAAM,IAAI;AAC7B,QAAO,MAAM,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,MAAM,SAAS,EAAE,CAAC,CAAC,KAAK,IAAI;;;;;;;;;;AAWtF,SAAgB,UAAU,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;AAClG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAAM,WAAW,UAAU,MAAM,SAAS;EAAE;EAAQ;EAAQ,GAAG,EAAE,CAAC,CAAC;AAGpG,QAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,MAAM;;;;;;;;;;AAW9D,SAAgB,WAAW,MAAc,EAAE,QAAQ,SAAS,IAAI,SAAS,OAAgB,EAAE,EAAU;AACnG,KAAI,OACF,QAAO,iBAAiB,OAAO,MAAM,WAAY,SAAS,WAAW,MAAM;EAAE;EAAQ;EAAQ,CAAC,GAAG,UAAU,KAAK,CAAE;AAGpH,QAAO,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,KAAK;;;;;;;;AC5D7D,SAAS,iBAAiB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACrJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,UAAU,OAAO,MACnB,UAAS,KAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AAEf,SAAO;;;AAIX,SAAgB,UAA4B,EAAE,QAAQ,KAAK,UAA+B;CACxF,IAAI,SAAS;AACb,KAAI,QAAQ,QAAQ,kBAAkB,SAAS,QAAQ;EACrD,MAAM,EAAE,OAAO,aAAa,YAAY,IAAI,KAAK,QAAQ,EAAE;AAE3D,WAAS,iBAAiB;GAAE;GAAO;GAAa;GAAS;GAAQ,CAAC;;AAGpE,KAAI,CAAC,OAAO,OACV,QAAO;AAGT,KAAI,WAAW,OAAO,OAAO,CAC3B,QAAO,GAAG,OAAO,OAAO,IAAI,CAAC,IAAI;AAGnC,QAAO,GAAG,OAAO,OAAO,IAAI;;;;AC/D9B,SAAgB,UAA4B,EAAE,QAAQ,OAAoB;AACxE,KAAI,CAAC,OAAO,OACV;AAGF,KAAI,WAAW,OAAO,OAAO,CAC3B,QAAO,OAAO,OAAO,IAAI;AAG3B,QAAO,OAAO"}