@kubb/plugin-zod 3.0.0-alpha.0 → 3.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/plugin.ts CHANGED
@@ -3,15 +3,13 @@ import path from 'node:path'
3
3
  import { FileManager, PluginManager, createPlugin } from '@kubb/core'
4
4
  import { camelCase, pascalCase } from '@kubb/core/transformers'
5
5
  import { renderTemplate } from '@kubb/core/utils'
6
- import { pluginOasName } from '@kubb/plugin-oas'
7
- import { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'
8
- import { pluginTsName } from '@kubb/plugin-ts'
6
+ import { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'
9
7
 
10
- import { OperationGenerator } from './OperationGenerator.tsx'
11
- import { SchemaGenerator } from './SchemaGenerator.tsx'
8
+ import { pluginTsName } from '@kubb/plugin-ts'
12
9
 
13
10
  import type { Plugin } from '@kubb/core'
14
11
  import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
12
+ import { zodParser } from './SchemaGenerator.tsx'
15
13
  import { Operations } from './components/Operations.tsx'
16
14
  import type { PluginZod } from './types.ts'
17
15
 
@@ -38,6 +36,10 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
38
36
 
39
37
  return {
40
38
  name: pluginZodName,
39
+ output: {
40
+ exportType: 'barrelNamed',
41
+ ...output,
42
+ },
41
43
  options: {
42
44
  extName: output.extName,
43
45
  transformers,
@@ -93,17 +95,10 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
93
95
 
94
96
  return resolvedName
95
97
  },
96
- async writeFile(path, source) {
97
- if (!path.endsWith('.ts') || !source) {
98
- return
99
- }
100
-
101
- return this.fileManager.write(path, source, { sanity: false })
102
- },
103
98
  async buildStart() {
104
99
  const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])
105
100
 
106
- const oas = await swaggerPlugin.api.getOas()
101
+ const oas = await swaggerPlugin.context.getOas()
107
102
  const root = path.resolve(this.config.root, this.config.output.path)
108
103
  const mode = FileManager.getMode(path.resolve(root, output.path))
109
104
 
@@ -111,57 +106,43 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
111
106
  oas,
112
107
  pluginManager: this.pluginManager,
113
108
  plugin: this.plugin,
114
- contentType: swaggerPlugin.api.contentType,
109
+ contentType: swaggerPlugin.context.contentType,
115
110
  include: undefined,
116
111
  override,
117
112
  mode,
118
113
  output: output.path,
119
114
  })
120
115
 
121
- const schemaFiles = await schemaGenerator.build()
116
+ const schemaFiles = await schemaGenerator.build(zodParser)
122
117
  await this.addFile(...schemaFiles)
123
118
 
124
119
  const operationGenerator = new OperationGenerator(this.plugin.options, {
125
120
  oas,
126
121
  pluginManager: this.pluginManager,
127
122
  plugin: this.plugin,
128
- contentType: swaggerPlugin.api.contentType,
123
+ contentType: swaggerPlugin.context.contentType,
129
124
  exclude,
130
125
  include,
131
126
  override,
132
127
  mode,
133
128
  })
134
129
 
135
- const operationFiles = await operationGenerator.build()
130
+ const operationFiles = await operationGenerator.build(zodParser)
136
131
  await this.addFile(...operationFiles)
137
- },
138
- async buildEnd() {
139
- if (this.config.output.write === false) {
140
- return
141
- }
142
132
 
143
- const root = path.resolve(this.config.root, this.config.output.path)
144
-
145
- if (group?.type === 'tag') {
146
- const rootFiles = await getGroupedByTagFiles({
147
- logger: this.logger,
148
- files: this.fileManager.files,
149
- plugin: this.plugin,
150
- template,
151
- exportAs: group.exportAs || '{{tag}}Schemas',
133
+ if (this.config.output.exportType) {
134
+ const barrelFiles = await this.fileManager.getBarrelFiles({
152
135
  root,
153
136
  output,
137
+ files: this.fileManager.files,
138
+ meta: {
139
+ pluginKey: this.plugin.key,
140
+ },
141
+ logger: this.logger,
154
142
  })
155
143
 
156
- await this.addFile(...rootFiles)
144
+ await this.addFile(...barrelFiles)
157
145
  }
158
-
159
- await this.fileManager.addIndexes({
160
- root,
161
- output,
162
- meta: { pluginKey: this.plugin.key },
163
- logger: this.logger,
164
- })
165
146
  },
166
147
  }
167
148
  })
package/src/types.ts CHANGED
@@ -143,9 +143,3 @@ export type FileMeta = {
143
143
  }
144
144
 
145
145
  export type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>
146
-
147
- declare module '@kubb/core' {
148
- export interface _Register {
149
- ['@kubb/plugin-zod']: PluginZod
150
- }
151
- }