@kubb/plugin-zod 3.0.0-alpha.3 → 3.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 (85) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-3ST47CH3.js +237 -0
  3. package/dist/chunk-3ST47CH3.js.map +1 -0
  4. package/dist/chunk-FLFW72FT.cjs +344 -0
  5. package/dist/chunk-FLFW72FT.cjs.map +1 -0
  6. package/dist/chunk-RSWFWAY4.cjs +246 -0
  7. package/dist/chunk-RSWFWAY4.cjs.map +1 -0
  8. package/dist/chunk-UONLSRDV.js +337 -0
  9. package/dist/chunk-UONLSRDV.js.map +1 -0
  10. package/dist/components.cjs +11 -6
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +20 -19
  13. package/dist/components.d.ts +20 -19
  14. package/dist/components.js +2 -10
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +17 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +10 -0
  19. package/dist/generators.d.ts +10 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +12 -4
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +4 -137
  25. package/dist/index.d.ts +4 -137
  26. package/dist/index.js +3 -8
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-mos5lUbD.d.cts +113 -0
  29. package/dist/types-mos5lUbD.d.ts +113 -0
  30. package/package.json +19 -21
  31. package/src/components/Operations.tsx +19 -103
  32. package/src/components/Zod.tsx +66 -0
  33. package/src/components/index.ts +1 -2
  34. package/src/generators/__snapshots__/anyof.ts +3 -0
  35. package/src/generators/__snapshots__/createPet.ts +15 -0
  36. package/src/generators/__snapshots__/createPetWithUnknownTypeAny.ts +13 -0
  37. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +15 -0
  38. package/src/generators/__snapshots__/deletePet.ts +3 -0
  39. package/src/generators/__snapshots__/discriminator.ts +3 -0
  40. package/src/generators/__snapshots__/enumBooleanLiteral.ts +3 -0
  41. package/src/generators/__snapshots__/enumNamesType.ts +3 -0
  42. package/src/generators/__snapshots__/enumNullable.ts +3 -0
  43. package/src/generators/__snapshots__/enumSingleLiteral.ts +3 -0
  44. package/src/generators/__snapshots__/enumVarNamesType.ts +3 -0
  45. package/src/generators/__snapshots__/example.ts +3 -0
  46. package/src/generators/__snapshots__/getPets.ts +18 -0
  47. package/src/generators/__snapshots__/mixedValueTypeConst.ts +6 -0
  48. package/src/generators/__snapshots__/nullableString.ts +3 -0
  49. package/src/generators/__snapshots__/nullableStringUuid.ts +3 -0
  50. package/src/generators/__snapshots__/nullableStringWithAnyOf.ts +3 -0
  51. package/src/generators/__snapshots__/numberValueConst.ts +6 -0
  52. package/src/generators/__snapshots__/oneof.ts +3 -0
  53. package/src/generators/__snapshots__/operations.ts +46 -0
  54. package/src/generators/__snapshots__/optionalPetInfer.ts +5 -0
  55. package/src/generators/__snapshots__/optionalPetTyped.ts +3 -0
  56. package/src/generators/__snapshots__/order.ts +3 -0
  57. package/src/generators/__snapshots__/orderDateTyeString.ts +10 -0
  58. package/src/generators/__snapshots__/orderDateTypeFalse.ts +3 -0
  59. package/src/generators/__snapshots__/orderDateTypeString.ts +3 -0
  60. package/src/generators/__snapshots__/pet.ts +3 -0
  61. package/src/generators/__snapshots__/petArray.ts +6 -0
  62. package/src/generators/__snapshots__/petCoercion.ts +3 -0
  63. package/src/generators/__snapshots__/petTupleObject.ts +6 -0
  64. package/src/generators/__snapshots__/petWithMapper.ts +3 -0
  65. package/src/generators/__snapshots__/pets.ts +3 -0
  66. package/src/generators/__snapshots__/recursive.ts +3 -0
  67. package/src/generators/__snapshots__/showPetById.ts +18 -0
  68. package/src/generators/__snapshots__/stringValueConst.ts +6 -0
  69. package/src/generators/__snapshots__/uuidSchema.ts +3 -0
  70. package/src/generators/index.ts +2 -0
  71. package/src/generators/operationsGenerator.tsx +39 -0
  72. package/src/generators/zodGenerator.tsx +121 -0
  73. package/src/parser/index.ts +34 -10
  74. package/src/plugin.ts +21 -38
  75. package/src/types.ts +41 -69
  76. package/dist/Operations-BlQtRP31.d.cts +0 -47
  77. package/dist/Operations-BlQtRP31.d.ts +0 -47
  78. package/dist/chunk-7X3NWYUN.cjs +0 -1242
  79. package/dist/chunk-7X3NWYUN.cjs.map +0 -1
  80. package/dist/chunk-XCGVHLYD.js +0 -1242
  81. package/dist/chunk-XCGVHLYD.js.map +0 -1
  82. package/src/SchemaGenerator.tsx +0 -22
  83. package/src/components/OperationSchema.tsx +0 -64
  84. package/src/components/Schema.tsx +0 -162
  85. package/src/components/__snapshots__/operations.ts +0 -50
@@ -0,0 +1,121 @@
1
+ import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'
2
+ import { Oas } from '@kubb/plugin-oas/components'
3
+ import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
4
+ import { pluginTsName } from '@kubb/plugin-ts'
5
+ import { File, useApp } from '@kubb/react'
6
+ import { Zod } from '../components'
7
+ import type { PluginZod } from '../types'
8
+
9
+ export const zodGenerator = createReactGenerator<PluginZod>({
10
+ name: 'zod',
11
+ Operation({ operation, options }) {
12
+ const { coercion, inferred, typed, mapper } = options
13
+
14
+ const { plugin, pluginManager, mode } = useApp<PluginZod>()
15
+ const oas = useOas()
16
+ const { getSchemas, getFile } = useOperationManager()
17
+ const schemaManager = useSchemaManager()
18
+
19
+ const file = getFile(operation)
20
+ const schemas = getSchemas(operation)
21
+ const schemaGenerator = new SchemaGenerator(options, {
22
+ oas,
23
+ plugin,
24
+ pluginManager,
25
+ mode,
26
+ override: options.override,
27
+ })
28
+
29
+ const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]
30
+ .flat()
31
+ .filter(Boolean)
32
+
33
+ const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {
34
+ // hack so Params can be optional when needed
35
+ const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required
36
+ const optional = !required && !!name.includes('Params')
37
+ const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)
38
+ const imports = schemaManager.getImports(tree)
39
+
40
+ const zod = {
41
+ name: schemaManager.getName(name, { type: 'function' }),
42
+ inferTypeName: schemaManager.getName(name, { type: 'type' }),
43
+ file: schemaManager.getFile(name),
44
+ }
45
+
46
+ const type = {
47
+ name: schemaManager.getName(name, { type: 'type', pluginKey: [pluginTsName] }),
48
+ file: schemaManager.getFile(options.operationName || name, { pluginKey: [pluginTsName], tag: options.operation?.getTags()[0]?.name }),
49
+ }
50
+
51
+ return (
52
+ <Oas.Schema key={i} name={name} value={schema} tree={tree}>
53
+ {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}
54
+ {imports.map((imp, index) => (
55
+ <File.Import key={index} root={file.path} path={imp.path} name={imp.name} />
56
+ ))}
57
+ <Zod
58
+ name={zod.name}
59
+ typeName={typed ? type.name : undefined}
60
+ inferTypeName={inferred ? zod.inferTypeName : undefined}
61
+ description={description}
62
+ tree={tree}
63
+ mapper={mapper}
64
+ coercion={coercion}
65
+ keysToOmit={keysToOmit}
66
+ />
67
+ </Oas.Schema>
68
+ )
69
+ }
70
+
71
+ return (
72
+ <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>
73
+ <File.Import name={['z']} path={plugin.options.importPath} />
74
+ {operationSchemas.map(mapOperationSchema)}
75
+ </File>
76
+ )
77
+ },
78
+ Schema({ schema, options }) {
79
+ const { coercion, inferred, typed, mapper, importPath } = options
80
+
81
+ const { getName, getFile, getImports } = useSchemaManager()
82
+ const {
83
+ plugin: {
84
+ options: { output },
85
+ },
86
+ } = useApp<PluginZod>()
87
+
88
+ const imports = getImports(schema.tree)
89
+
90
+ const zod = {
91
+ name: getName(schema.name, { type: 'function' }),
92
+ inferTypeName: getName(schema.name, { type: 'type' }),
93
+ file: getFile(schema.name),
94
+ }
95
+
96
+ const type = {
97
+ name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),
98
+ file: getFile(schema.name, { pluginKey: [pluginTsName] }),
99
+ }
100
+
101
+ return (
102
+ <File baseName={zod.file.baseName} path={zod.file.path} meta={zod.file.meta} banner={output?.banner} footer={output?.footer}>
103
+ <File.Import name={['z']} path={importPath} />
104
+ {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}
105
+ {imports.map((imp, index) => (
106
+ <File.Import key={index} root={zod.file.path} path={imp.path} name={imp.name} />
107
+ ))}
108
+
109
+ <Zod
110
+ name={zod.name}
111
+ typeName={typed ? type.name : undefined}
112
+ inferTypeName={inferred ? zod.inferTypeName : undefined}
113
+ description={schema.value.description}
114
+ tree={schema.tree}
115
+ mapper={mapper}
116
+ coercion={coercion}
117
+ />
118
+ </File>
119
+ )
120
+ },
121
+ })
@@ -3,7 +3,7 @@ import { type SchemaKeywordMapper, isKeyword, schemaKeywords } from '@kubb/plugi
3
3
 
4
4
  import type { Schema, SchemaKeywordBase, SchemaMapper } from '@kubb/plugin-oas'
5
5
 
6
- export const zodKeywordMapper = {
6
+ const zodKeywordMapper = {
7
7
  any: () => 'z.any()',
8
8
  unknown: () => 'z.unknown()',
9
9
  number: (coercion?: boolean, min?: number, max?: number) => {
@@ -12,7 +12,11 @@ export const zodKeywordMapper = {
12
12
  .join('')
13
13
  },
14
14
  integer: (coercion?: boolean, min?: number, max?: number) => {
15
- return [coercion ? 'z.coerce.number()' : 'z.number()', min !== undefined ? `.min(${min})` : undefined, max !== undefined ? `.max(${max})` : undefined]
15
+ return [
16
+ coercion ? 'z.coerce.number().int()' : 'z.number().int()',
17
+ min !== undefined ? `.min(${min})` : undefined,
18
+ max !== undefined ? `.max(${max})` : undefined,
19
+ ]
16
20
  .filter(Boolean)
17
21
  .join('')
18
22
  },
@@ -35,7 +39,7 @@ export const zodKeywordMapper = {
35
39
  tuple: (items: string[] = []) => `z.tuple([${items?.join(', ')}])`,
36
40
  enum: (items: string[] = []) => `z.enum([${items?.join(', ')}])`,
37
41
  union: (items: string[] = []) => `z.union([${items?.join(', ')}])`,
38
- const: (value?: string | number) => `z.literal(${value ?? ''})`,
42
+ const: (value?: string | number | boolean) => `z.literal(${value ?? ''})`,
39
43
  /**
40
44
  * ISO 8601
41
45
  */
@@ -98,6 +102,7 @@ export const zodKeywordMapper = {
98
102
  password: undefined,
99
103
  phone: undefined,
100
104
  readOnly: undefined,
105
+ writeOnly: undefined,
101
106
  ref: (value?: string) => (value ? `z.lazy(() => ${value})` : undefined),
102
107
  blob: () => 'z.string()',
103
108
  deprecated: undefined,
@@ -201,6 +206,17 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
201
206
 
202
207
  if (isKeyword(current, schemaKeywords.enum)) {
203
208
  if (current.args.asConst) {
209
+ if (current.args.items.length === 1) {
210
+ return parse(
211
+ current,
212
+ {
213
+ keyword: schemaKeywords.const,
214
+ args: current.args.items[0],
215
+ },
216
+ options,
217
+ )
218
+ }
219
+
204
220
  return zodKeywordMapper.union(
205
221
  current.args.items
206
222
  .map((schema) => {
@@ -219,6 +235,10 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
219
235
 
220
236
  return zodKeywordMapper.enum(
221
237
  current.args.items.map((schema) => {
238
+ if (schema.format === 'boolean') {
239
+ return transformers.stringify(schema.value)
240
+ }
241
+
222
242
  if (schema.format === 'number') {
223
243
  return transformers.stringify(schema.value)
224
244
  }
@@ -259,7 +279,7 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
259
279
  ? current.args.additionalProperties
260
280
  .map((schema) => parse(current, schema, options))
261
281
  .filter(Boolean)
262
- .at(0)
282
+ .join('')
263
283
  : undefined
264
284
 
265
285
  const text = [
@@ -272,17 +292,17 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
272
292
  }
273
293
 
274
294
  if (isKeyword(current, schemaKeywords.tuple)) {
275
- return zodKeywordMapper.tuple(
276
- sort(current.args.items)
277
- .map((schema) => parse(current, schema, options))
278
- .filter(Boolean),
279
- )
295
+ return zodKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean))
280
296
  }
281
297
 
282
298
  if (isKeyword(current, schemaKeywords.const)) {
283
299
  if (current.args.format === 'number' && current.args.value !== undefined) {
284
300
  return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()))
285
301
  }
302
+
303
+ if (current.args.format === 'boolean' && current.args.value !== undefined) {
304
+ return zodKeywordMapper.const(current.args.value)
305
+ }
286
306
  return zodKeywordMapper.const(transformers.stringify(current.args.value))
287
307
  }
288
308
 
@@ -308,10 +328,14 @@ export function parse(parent: Schema | undefined, current: Schema, options: Pars
308
328
  return zodKeywordMapper.string(options.coercion)
309
329
  }
310
330
 
311
- if (isKeyword(current, schemaKeywords.number) || isKeyword(current, schemaKeywords.integer)) {
331
+ if (isKeyword(current, schemaKeywords.number)) {
312
332
  return zodKeywordMapper.number(options.coercion)
313
333
  }
314
334
 
335
+ if (isKeyword(current, schemaKeywords.integer)) {
336
+ return zodKeywordMapper.integer(options.coercion)
337
+ }
338
+
315
339
  if (isKeyword(current, schemaKeywords.min)) {
316
340
  return zodKeywordMapper.min(current.args)
317
341
  }
package/src/plugin.ts CHANGED
@@ -3,21 +3,21 @@ 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 { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
7
- import { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'
6
+ import { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'
7
+
8
8
  import { pluginTsName } from '@kubb/plugin-ts'
9
9
 
10
10
  import type { Plugin } from '@kubb/core'
11
11
  import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
12
- import { Operations } from './components/Operations.tsx'
12
+ import { operationsGenerator } from './generators'
13
+ import { zodGenerator } from './generators/zodGenerator.tsx'
13
14
  import type { PluginZod } from './types.ts'
14
- import { zodParser } from './SchemaGenerator.tsx'
15
15
 
16
16
  export const pluginZodName = 'plugin-zod' satisfies PluginZod['name']
17
17
 
18
18
  export const pluginZod = createPlugin<PluginZod>((options) => {
19
19
  const {
20
- output = { path: 'zod' },
20
+ output = { path: 'zod', barrelType: 'named' },
21
21
  group,
22
22
  exclude = [],
23
23
  include,
@@ -26,33 +26,31 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
26
26
  dateType = 'string',
27
27
  unknownType = 'any',
28
28
  typed = false,
29
- typedSchema = false,
30
29
  mapper = {},
31
- templates,
30
+ operations = false,
32
31
  importPath = 'zod',
33
32
  coercion = false,
33
+ inferred = false,
34
+ generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),
34
35
  } = options
35
36
  const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
36
37
 
37
38
  return {
38
39
  name: pluginZodName,
39
40
  options: {
40
- extName: output.extName,
41
+ output,
41
42
  transformers,
42
43
  include,
43
44
  exclude,
44
45
  override,
45
46
  typed,
46
- typedSchema,
47
47
  dateType,
48
48
  unknownType,
49
49
  mapper,
50
50
  importPath,
51
51
  coercion,
52
- templates: {
53
- operations: Operations.templates,
54
- ...templates,
55
- },
52
+ operations,
53
+ inferred,
56
54
  },
57
55
  pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),
58
56
  resolvePath(baseName, pathMode, options) {
@@ -109,7 +107,7 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
109
107
  output: output.path,
110
108
  })
111
109
 
112
- const schemaFiles = await schemaGenerator.build(zodParser)
110
+ const schemaFiles = await schemaGenerator.build(...generators)
113
111
  await this.addFile(...schemaFiles)
114
112
 
115
113
  const operationGenerator = new OperationGenerator(this.plugin.options, {
@@ -123,36 +121,21 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
123
121
  mode,
124
122
  })
125
123
 
126
- const operationFiles = await operationGenerator.build(zodParser)
124
+ const operationFiles = await operationGenerator.build(...generators)
127
125
  await this.addFile(...operationFiles)
128
- },
129
- async buildEnd() {
130
- if (this.config.output.write === false) {
131
- return
132
- }
133
-
134
- const root = path.resolve(this.config.root, this.config.output.path)
135
-
136
- if (group?.type === 'tag') {
137
- const rootFiles = await getGroupedByTagFiles({
138
- logger: this.logger,
139
- files: this.fileManager.files,
140
- plugin: this.plugin,
141
- template,
142
- exportAs: group.exportAs || '{{tag}}Schemas',
143
- root,
144
- output,
145
- })
146
-
147
- await this.addFile(...rootFiles)
148
- }
149
126
 
150
- await this.fileManager.addIndexes({
127
+ const barrelFiles = await this.fileManager.getBarrelFiles({
128
+ type: output.barrelType ?? 'named',
151
129
  root,
152
130
  output,
153
- meta: { pluginKey: this.plugin.key },
131
+ files: this.fileManager.files,
132
+ meta: {
133
+ pluginKey: this.plugin.key,
134
+ },
154
135
  logger: this.logger,
155
136
  })
137
+
138
+ await this.addFile(...barrelFiles)
156
139
  },
157
140
  }
158
141
  })
package/src/types.ts CHANGED
@@ -1,35 +1,12 @@
1
- import type { Plugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
- import type * as KubbFile from '@kubb/fs/types'
1
+ import type { Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
3
2
  import type { SchemaObject } from '@kubb/oas'
4
- import type { Exclude, Include, Override, ResolvePathOptions, Schema } from '@kubb/plugin-oas'
5
- import type { Operations } from './components/Operations'
6
-
7
- type Templates = {
8
- operations?: typeof Operations.templates | false
9
- }
3
+ import type { Exclude, Generator, Include, Override, ResolvePathOptions, Schema } from '@kubb/plugin-oas'
10
4
 
11
5
  export type Options = {
12
- output?: {
13
- /**
14
- * Relative path to save the Zod schemas.
15
- * When output is a file it will save all models inside that file else it will create a file per schema item.
16
- * @default 'zod'
17
- */
18
- path: string
19
- /**
20
- * Name to be used for the `export * as {{exportAs}} from './'`
21
- */
22
- exportAs?: string
23
- /**
24
- * Add an extension to the generated imports and exports, default it will not use an extension
25
- */
26
- extName?: KubbFile.Extname
27
- /**
28
- * Define what needs to exported, here you can also disable the export of barrel files
29
- * @default `'barrel'`
30
- */
31
- exportType?: 'barrel' | 'barrelNamed' | false
32
- }
6
+ /**
7
+ * @default 'zod'
8
+ */
9
+ output?: Output
33
10
  /**
34
11
  * Group the Zod schemas based on the provided name.
35
12
  */
@@ -64,30 +41,15 @@ export type Options = {
64
41
  * Array containing override parameters to override `options` based on tags/operations/methods/paths.
65
42
  */
66
43
  override?: Array<Override<ResolvedOptions>>
67
- transformers?: {
68
- /**
69
- * Customize the names based on the type that is provided by the plugin.
70
- */
71
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
72
- /**
73
- * Receive schema and baseName(propertName) and return FakerMeta array
74
- * TODO TODO add docs
75
- * @beta
76
- */
77
- schema?: (
78
- props: {
79
- schema?: SchemaObject
80
- name?: string
81
- parentName?: string
82
- },
83
- defaultSchemas: Schema[],
84
- ) => Schema[] | undefined
85
- }
86
- mapper?: Record<string, string>
87
44
  /**
88
- * Make it possible to override one of the templates
45
+ * Path to Zod
46
+ * It will be used as `import { z } from '${importPath}'`.
47
+ * It allows both relative and absolute path.
48
+ * the path will be applied as is, so relative path should be based on the file being generated.
49
+ * @default 'zod'
89
50
  */
90
- templates?: Partial<Templates>
51
+ importPath?: string
52
+
91
53
  /**
92
54
  * Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
93
55
  * False will fallback on a simple z.string() format
@@ -106,40 +68,50 @@ export type Options = {
106
68
  /**
107
69
  * Return Zod generated schema as type with z.infer<TYPE>
108
70
  */
109
- typedSchema?: boolean
71
+ inferred?: boolean
110
72
  /**
111
73
  * Use of z.coerce.string() instead of z.string()
112
74
  */
113
75
  coercion?: boolean
76
+ operations?: boolean
77
+ mapper?: Record<string, string>
78
+ transformers?: {
79
+ /**
80
+ * Customize the names based on the type that is provided by the plugin.
81
+ */
82
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
83
+ /**
84
+ * Receive schema and baseName(propertName) and return FakerMeta array
85
+ * TODO TODO add docs
86
+ * @beta
87
+ */
88
+ schema?: (
89
+ props: {
90
+ schema?: SchemaObject
91
+ name?: string
92
+ parentName?: string
93
+ },
94
+ defaultSchemas: Schema[],
95
+ ) => Schema[] | undefined
96
+ }
114
97
  /**
115
- * Path to Zod
116
- * It will be used as `import { z } from '${importPath}'`.
117
- * It allows both relative and absolute path.
118
- * the path will be applied as is, so relative path should be based on the file being generated.
119
- * @default 'zod'
98
+ * Define some generators next to the zod generators
120
99
  */
121
- importPath?: string
100
+ generators?: Array<Generator<PluginZod>>
122
101
  }
123
102
 
124
103
  type ResolvedOptions = {
125
- extName: KubbFile.Extname | undefined
104
+ output: Output
105
+ override: NonNullable<Options['override']>
126
106
  transformers: NonNullable<Options['transformers']>
127
- exclude: Options['exclude']
128
- include: Options['include']
129
- override: Options['override']
130
107
  dateType: NonNullable<Options['dateType']>
131
108
  unknownType: NonNullable<Options['unknownType']>
132
109
  typed: NonNullable<Options['typed']>
133
- typedSchema: NonNullable<Options['typedSchema']>
134
- templates: NonNullable<Templates>
110
+ inferred: NonNullable<Options['inferred']>
135
111
  mapper: NonNullable<Options['mapper']>
136
112
  importPath: NonNullable<Options['importPath']>
137
113
  coercion: NonNullable<Options['coercion']>
138
- }
139
-
140
- export type FileMeta = {
141
- pluginKey?: Plugin['key']
142
- tag?: string
114
+ operations: NonNullable<Options['coercion']>
143
115
  }
144
116
 
145
117
  export type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>
@@ -1,47 +0,0 @@
1
- import { Operation } from '@kubb/oas';
2
- import { KubbNode } from '@kubb/react';
3
- import { ComponentType, ComponentProps } from 'react';
4
-
5
- type TemplateProps = {
6
- /**
7
- * Name of the function
8
- */
9
- operationsName: string;
10
- /**
11
- * Name of the function
12
- */
13
- pathsName: string;
14
- operations: Operation[];
15
- };
16
- declare function Template({ operationsName, pathsName, operations }: TemplateProps): KubbNode;
17
- type RootTemplateProps = {
18
- children?: React.ReactNode;
19
- };
20
- declare function RootTemplate({ children }: RootTemplateProps): JSX.Element;
21
- declare const defaultTemplates: {
22
- readonly default: typeof Template;
23
- readonly root: typeof RootTemplate;
24
- };
25
- type Templates = Partial<typeof defaultTemplates>;
26
- type Props = {
27
- /**
28
- * This will make it possible to override the default behaviour.
29
- */
30
- Template?: ComponentType<ComponentProps<typeof Template>>;
31
- };
32
- declare function Operations({ Template }: Props): KubbNode;
33
- declare namespace Operations {
34
- var File: (props: FileProps) => KubbNode;
35
- var templates: {
36
- readonly default: typeof Template;
37
- readonly root: typeof RootTemplate;
38
- };
39
- }
40
- type FileProps = {
41
- /**
42
- * This will make it possible to override the default behaviour.
43
- */
44
- templates?: Templates;
45
- };
46
-
47
- export { Operations as O };
@@ -1,47 +0,0 @@
1
- import { Operation } from '@kubb/oas';
2
- import { KubbNode } from '@kubb/react';
3
- import { ComponentType, ComponentProps } from 'react';
4
-
5
- type TemplateProps = {
6
- /**
7
- * Name of the function
8
- */
9
- operationsName: string;
10
- /**
11
- * Name of the function
12
- */
13
- pathsName: string;
14
- operations: Operation[];
15
- };
16
- declare function Template({ operationsName, pathsName, operations }: TemplateProps): KubbNode;
17
- type RootTemplateProps = {
18
- children?: React.ReactNode;
19
- };
20
- declare function RootTemplate({ children }: RootTemplateProps): JSX.Element;
21
- declare const defaultTemplates: {
22
- readonly default: typeof Template;
23
- readonly root: typeof RootTemplate;
24
- };
25
- type Templates = Partial<typeof defaultTemplates>;
26
- type Props = {
27
- /**
28
- * This will make it possible to override the default behaviour.
29
- */
30
- Template?: ComponentType<ComponentProps<typeof Template>>;
31
- };
32
- declare function Operations({ Template }: Props): KubbNode;
33
- declare namespace Operations {
34
- var File: (props: FileProps) => KubbNode;
35
- var templates: {
36
- readonly default: typeof Template;
37
- readonly root: typeof RootTemplate;
38
- };
39
- }
40
- type FileProps = {
41
- /**
42
- * This will make it possible to override the default behaviour.
43
- */
44
- templates?: Templates;
45
- };
46
-
47
- export { Operations as O };