@kubb/plugin-zod 3.5.12 → 3.6.0

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 (40) hide show
  1. package/dist/{chunk-6N5S7RR7.cjs → chunk-I76DWSTD.cjs} +22 -12
  2. package/dist/chunk-I76DWSTD.cjs.map +1 -0
  3. package/dist/{chunk-E2BLKQJO.cjs → chunk-UXPJE55C.cjs} +10 -10
  4. package/dist/chunk-UXPJE55C.cjs.map +1 -0
  5. package/dist/{chunk-CPI4DGDT.js → chunk-XP7EMBLS.js} +10 -10
  6. package/dist/chunk-XP7EMBLS.js.map +1 -0
  7. package/dist/{chunk-LBZ6BUKN.js → chunk-YJM2VGBB.js} +19 -9
  8. package/dist/chunk-YJM2VGBB.js.map +1 -0
  9. package/dist/components.cjs +3 -3
  10. package/dist/components.d.cts +5 -3
  11. package/dist/components.d.ts +5 -3
  12. package/dist/components.js +1 -1
  13. package/dist/generators.cjs +4 -4
  14. package/dist/generators.d.cts +1 -1
  15. package/dist/generators.d.ts +1 -1
  16. package/dist/generators.js +2 -2
  17. package/dist/index.cjs +6 -4
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +5 -3
  22. package/dist/index.js.map +1 -1
  23. package/dist/{types-PnaUmUK7.d.cts → types-DhDFwK1h.d.cts} +12 -0
  24. package/dist/{types-PnaUmUK7.d.ts → types-DhDFwK1h.d.ts} +12 -0
  25. package/package.json +13 -11
  26. package/src/components/Zod.tsx +11 -9
  27. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown_wrapOutput.ts +25 -0
  28. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown_wrapOutput_entire_.ts +26 -0
  29. package/src/generators/__snapshots__/createPet_wrapOutput.ts +25 -0
  30. package/src/generators/__snapshots__/deletePet_wrapOutput.ts +3 -0
  31. package/src/generators/__snapshots__/getPets_wrapOutput.ts +27 -0
  32. package/src/generators/__snapshots__/showPetById_wrapOutput.ts +25 -0
  33. package/src/generators/zodGenerator.tsx +14 -4
  34. package/src/parser.ts +7 -2
  35. package/src/plugin.ts +2 -0
  36. package/src/types.ts +9 -0
  37. package/dist/chunk-6N5S7RR7.cjs.map +0 -1
  38. package/dist/chunk-CPI4DGDT.js.map +0 -1
  39. package/dist/chunk-E2BLKQJO.cjs.map +0 -1
  40. package/dist/chunk-LBZ6BUKN.js.map +0 -1
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var chunk6N5S7RR7_cjs = require('./chunk-6N5S7RR7.cjs');
4
- require('./chunk-E2BLKQJO.cjs');
3
+ var chunkI76DWSTD_cjs = require('./chunk-I76DWSTD.cjs');
4
+ require('./chunk-UXPJE55C.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "operationsGenerator", {
9
9
  enumerable: true,
10
- get: function () { return chunk6N5S7RR7_cjs.operationsGenerator; }
10
+ get: function () { return chunkI76DWSTD_cjs.operationsGenerator; }
11
11
  });
12
12
  Object.defineProperty(exports, "zodGenerator", {
13
13
  enumerable: true,
14
- get: function () { return chunk6N5S7RR7_cjs.zodGenerator; }
14
+ get: function () { return chunkI76DWSTD_cjs.zodGenerator; }
15
15
  });
16
16
  //# sourceMappingURL=generators.cjs.map
17
17
  //# sourceMappingURL=generators.cjs.map
@@ -1,5 +1,5 @@
1
1
  import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
- import { P as PluginZod } from './types-PnaUmUK7.cjs';
2
+ import { P as PluginZod } from './types-DhDFwK1h.cjs';
3
3
  import '@kubb/core';
4
4
  import '@kubb/oas';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
- import { P as PluginZod } from './types-PnaUmUK7.js';
2
+ import { P as PluginZod } from './types-DhDFwK1h.js';
3
3
  import '@kubb/core';
4
4
  import '@kubb/oas';
5
5
 
@@ -1,4 +1,4 @@
1
- export { operationsGenerator, zodGenerator } from './chunk-LBZ6BUKN.js';
2
- import './chunk-CPI4DGDT.js';
1
+ export { operationsGenerator, zodGenerator } from './chunk-YJM2VGBB.js';
2
+ import './chunk-XP7EMBLS.js';
3
3
  //# sourceMappingURL=generators.js.map
4
4
  //# sourceMappingURL=generators.js.map
package/dist/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunk6N5S7RR7_cjs = require('./chunk-6N5S7RR7.cjs');
4
- require('./chunk-E2BLKQJO.cjs');
3
+ var chunkI76DWSTD_cjs = require('./chunk-I76DWSTD.cjs');
4
+ require('./chunk-UXPJE55C.cjs');
5
5
  var path = require('path');
6
6
  var core = require('@kubb/core');
7
7
  var transformers = require('@kubb/core/transformers');
@@ -29,7 +29,8 @@ var pluginZod = core.createPlugin((options) => {
29
29
  importPath = "zod",
30
30
  coercion = false,
31
31
  inferred = false,
32
- generators = [chunk6N5S7RR7_cjs.zodGenerator, operations ? chunk6N5S7RR7_cjs.operationsGenerator : undefined].filter(Boolean),
32
+ generators = [chunkI76DWSTD_cjs.zodGenerator, operations ? chunkI76DWSTD_cjs.operationsGenerator : undefined].filter(Boolean),
33
+ wrapOutput = undefined,
33
34
  contentType
34
35
  } = options;
35
36
  return {
@@ -48,7 +49,8 @@ var pluginZod = core.createPlugin((options) => {
48
49
  coercion,
49
50
  operations,
50
51
  inferred,
51
- group
52
+ group,
53
+ wrapOutput
52
54
  },
53
55
  pre: [pluginOas.pluginOasName, typed ? pluginTs.pluginTsName : undefined].filter(Boolean),
54
56
  resolvePath(baseName, pathMode, options2) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","zodGenerator","operationsGenerator","pluginOasName","pluginTsName","options","path","FileManager","camelCase","pascalCase","PluginManager","SchemaGenerator","OperationGenerator"],"mappings":";;;;;;;;;;;;;;AAcO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAYA,iBAAwB,CAAA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A,eAAe,IAAK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA;AAAA,QACA,OAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,MAAM,cAAiB,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AACnE,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,cAAc,CAAA;AAEpC,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n contentType,\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n },\n pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
1
+ {"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","zodGenerator","operationsGenerator","pluginOasName","pluginTsName","options","path","FileManager","camelCase","pascalCase","PluginManager","SchemaGenerator","OperationGenerator"],"mappings":";;;;;;;;;;;;;;AAcO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAYA,iBAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,KAAA,EAAO,YAAY,OAAQ,EAAA;AAAA,IAC5C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,kBACZC,iBAAe,EAAC;AAAA,IAChB,QAAW,GAAA,QAAA;AAAA,IACX,WAAc,GAAA,KAAA;AAAA,IACd,KAAQ,GAAA,KAAA;AAAA,IACR,SAAS,EAAC;AAAA,IACV,UAAa,GAAA,KAAA;AAAA,IACb,UAAa,GAAA,KAAA;AAAA,IACb,QAAW,GAAA,KAAA;AAAA,IACX,QAAW,GAAA,KAAA;AAAA,IACX,UAAA,GAAa,CAACC,8BAAc,EAAA,UAAA,GAAaC,wCAAsB,SAAS,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IACxF,UAAa,GAAA,SAAA;AAAA,IACb;AAAA,GACE,GA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AK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n wrapOutput = undefined,\n contentType,\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n wrapOutput,\n },\n pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginZod } from './types-PnaUmUK7.cjs';
2
+ import { O as Options, P as PluginZod } from './types-DhDFwK1h.cjs';
3
3
  import '@kubb/oas';
4
4
  import '@kubb/plugin-oas';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginZod } from './types-PnaUmUK7.js';
2
+ import { O as Options, P as PluginZod } from './types-DhDFwK1h.js';
3
3
  import '@kubb/oas';
4
4
  import '@kubb/plugin-oas';
5
5
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { zodGenerator, operationsGenerator } from './chunk-LBZ6BUKN.js';
2
- import './chunk-CPI4DGDT.js';
1
+ import { zodGenerator, operationsGenerator } from './chunk-YJM2VGBB.js';
2
+ import './chunk-XP7EMBLS.js';
3
3
  import path from 'node:path';
4
4
  import { createPlugin, FileManager, PluginManager } from '@kubb/core';
5
5
  import { camelCase, pascalCase } from '@kubb/core/transformers';
@@ -24,6 +24,7 @@ var pluginZod = createPlugin((options) => {
24
24
  coercion = false,
25
25
  inferred = false,
26
26
  generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),
27
+ wrapOutput = undefined,
27
28
  contentType
28
29
  } = options;
29
30
  return {
@@ -42,7 +43,8 @@ var pluginZod = createPlugin((options) => {
42
43
  coercion,
43
44
  operations,
44
45
  inferred,
45
- group
46
+ group,
47
+ wrapOutput
46
48
  },
47
49
  pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),
48
50
  resolvePath(baseName, pathMode, options2) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;AAcO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAY,YAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,KAAA,EAAO,YAAY,OAAQ,EAAA;AAAA,IAC5C,KAAA;AAAA,IACA,UAAU,EAAC;A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B,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AACnE,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,cAAc,CAAA;AAEpC,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n contentType,\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n },\n pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
1
+ {"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;AAcO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAY,YAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,KAAA,EAAO,YAAY,OAAQ,EAAA;AAAA,IAC5C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,eAAe,EAAC;AAAA,IAChB,QAAW,GAAA,QAAA;AAAA,IACX,WAAc,GAAA,KAAA;AAAA,IACd,KAAQ,GAAA,KAAA;AAAA,IACR,SAAS,EAAC;AAAA,IACV,UAAa,GAAA,KAAA;AAAA,IACb,UAAa,GAAA,KAAA;AAAA,IACb,QAAW,GAAA,KAAA;AAAA,IACX,QAAW,GAAA,KAAA;AAAA,IACX,UAAA,GAAa,CAAC,YAAc,EAAA,UAAA,GAAa,sBAAsB,SAAS,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IACxF,UAAa,GAAA,SAAA;AAAA,IACb;AAAA,GACE,GAAA,OAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,aAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,YAAA;AAAA,MACA,OAAA;AAAA,MACA,OAAA;AAAA,MACA,QAAA;AAAA,MACA,KAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA,MAAA;AAAA,MACA,UAAA;AAAA,MACA,QAAA;AAAA,MACA,UAAA;AAAA,MACA,QAAA;AAAA,MACA,KAA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AAA;AAAA,QACA,IAAA;AAAA,QACA,QAAQ,MAAO,CAAA;AAAA,OAChB,CAAA;AAED,MAAA,MAAM,WAAc,GAAA,MAAM,eAAgB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AAC7D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAEjC,MAAA,MAAM,kBAAqB,GAAA,IAAI,kBAAmB,CAAA,IAAA,CAAK,OAAO,OAAS,EAAA;AAAA,QACrE,GAAA;AAAA,QACA,eAAe,IAAK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA;AAAA,QACA,OAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,MAAM,cAAiB,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AACnE,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,cAAc,CAAA;AAEpC,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n wrapOutput = undefined,\n contentType,\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n wrapOutput,\n },\n pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
@@ -82,6 +82,17 @@ type Options = {
82
82
  parentName?: string;
83
83
  }, defaultSchemas: Schema[]) => Schema[] | undefined;
84
84
  };
85
+ /**
86
+ * Callback function to wrap the output of the generated zod schema
87
+ *
88
+ * This is useful for edge case scenarios where you might leverage something like `z.object({ ... }).openapi({ example: { some: "complex-example" }})`
89
+ * or `extendApi(z.object({ ... }), { example: { some: "complex-example", ...otherOpenApiProperties }})`
90
+ * while going from openapi -> zod -> openapi
91
+ */
92
+ wrapOutput?: (arg: {
93
+ output: string;
94
+ schema: SchemaObject;
95
+ }) => string | undefined;
85
96
  /**
86
97
  * Define some generators next to the zod generators
87
98
  */
@@ -100,6 +111,7 @@ type ResolvedOptions = {
100
111
  importPath: NonNullable<Options['importPath']>;
101
112
  coercion: NonNullable<Options['coercion']>;
102
113
  operations: NonNullable<Options['operations']>;
114
+ wrapOutput: Options['wrapOutput'];
103
115
  };
104
116
  type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
105
117
 
@@ -82,6 +82,17 @@ type Options = {
82
82
  parentName?: string;
83
83
  }, defaultSchemas: Schema[]) => Schema[] | undefined;
84
84
  };
85
+ /**
86
+ * Callback function to wrap the output of the generated zod schema
87
+ *
88
+ * This is useful for edge case scenarios where you might leverage something like `z.object({ ... }).openapi({ example: { some: "complex-example" }})`
89
+ * or `extendApi(z.object({ ... }), { example: { some: "complex-example", ...otherOpenApiProperties }})`
90
+ * while going from openapi -> zod -> openapi
91
+ */
92
+ wrapOutput?: (arg: {
93
+ output: string;
94
+ schema: SchemaObject;
95
+ }) => string | undefined;
85
96
  /**
86
97
  * Define some generators next to the zod generators
87
98
  */
@@ -100,6 +111,7 @@ type ResolvedOptions = {
100
111
  importPath: NonNullable<Options['importPath']>;
101
112
  coercion: NonNullable<Options['coercion']>;
102
113
  operations: NonNullable<Options['operations']>;
114
+ wrapOutput: Options['wrapOutput'];
103
115
  };
104
116
  type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
105
117
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-zod",
3
- "version": "3.5.12",
3
+ "version": "3.6.0",
4
4
  "description": "Generator plugin-zod",
5
5
  "keywords": [
6
6
  "typescript",
@@ -66,19 +66,21 @@
66
66
  "!/**/__tests__/**"
67
67
  ],
68
68
  "dependencies": {
69
- "@kubb/core": "3.5.12",
70
- "@kubb/fs": "3.5.12",
71
- "@kubb/oas": "3.5.12",
72
- "@kubb/parser-ts": "3.5.12",
73
- "@kubb/plugin-oas": "3.5.12",
74
- "@kubb/plugin-ts": "3.5.12",
75
- "@kubb/react": "3.5.12"
69
+ "@kubb/core": "3.6.0",
70
+ "@kubb/fs": "3.6.0",
71
+ "@kubb/oas": "3.6.0",
72
+ "@kubb/parser-ts": "3.6.0",
73
+ "@kubb/plugin-oas": "3.6.0",
74
+ "@kubb/plugin-ts": "3.6.0",
75
+ "@kubb/react": "3.6.0"
76
76
  },
77
77
  "devDependencies": {
78
+ "@asteasolutions/zod-to-openapi": "^7.3.0",
79
+ "@hono/zod-openapi": "^0.18.4",
78
80
  "tsup": "^8.3.6",
79
- "zod": "~3.24.1",
80
- "@kubb/config-ts": "3.5.12",
81
- "@kubb/config-tsup": "3.5.12"
81
+ "zod": "~3.24.2",
82
+ "@kubb/config-ts": "3.6.0",
83
+ "@kubb/config-tsup": "3.6.0"
82
84
  },
83
85
  "peerDependencies": {
84
86
  "@kubb/react": "^3.0.0"
@@ -4,19 +4,22 @@ import { isKeyword } from '@kubb/plugin-oas'
4
4
  import { Const, File, Type } from '@kubb/react'
5
5
  import * as parserZod from '../parser.ts'
6
6
  import type { PluginZod } from '../types.ts'
7
+ import type { SchemaObject } from '@kubb/oas'
7
8
 
8
9
  type Props = {
9
10
  name: string
10
11
  typeName?: string
11
12
  inferTypeName?: string
12
13
  tree: Array<Schema>
14
+ rawSchema: SchemaObject
13
15
  description?: string
14
16
  coercion: PluginZod['resolvedOptions']['coercion']
15
17
  mapper: PluginZod['resolvedOptions']['mapper']
16
18
  keysToOmit?: string[]
19
+ wrapOutput?: PluginZod['resolvedOptions']['wrapOutput']
17
20
  }
18
21
 
19
- export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, keysToOmit, description }: Props) {
22
+ export function Zod({ name, typeName, tree, rawSchema, inferTypeName, mapper, coercion, keysToOmit, description, wrapOutput }: Props) {
20
23
  const hasTuple = tree.some((item) => isKeyword(item, schemaKeywords.tuple))
21
24
 
22
25
  const output = parserZod
@@ -29,12 +32,17 @@ export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, key
29
32
  return true
30
33
  })
31
34
  .map((schema, _index, siblings) =>
32
- parserZod.parse({ parent: undefined, current: schema, siblings }, { name, keysToOmit, typeName, description, mapper, coercion }),
35
+ parserZod.parse({ parent: undefined, current: schema, siblings }, { name, keysToOmit, typeName, description, mapper, coercion, wrapOutput, rawSchema }),
33
36
  )
34
37
  .filter(Boolean)
35
38
  .join('')
36
39
 
37
40
  const suffix = output.endsWith('.nullable()') ? '.unwrap().and' : '.and'
41
+ const baseSchemaOutput =
42
+ [output, keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined].filter(Boolean).join('') ||
43
+ 'z.undefined()'
44
+ const wrappedSchemaOutput = wrapOutput ? wrapOutput({ output: baseSchemaOutput, schema: rawSchema }) || baseSchemaOutput : baseSchemaOutput
45
+ const finalOutput = typeName ? `${wrappedSchemaOutput} as unknown as ToZod<${typeName}>` : wrappedSchemaOutput
38
46
 
39
47
  return (
40
48
  <>
@@ -46,13 +54,7 @@ export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, key
46
54
  comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean),
47
55
  }}
48
56
  >
49
- {[
50
- output,
51
- keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined,
52
- typeName ? `as unknown as ToZod<${typeName}>` : undefined,
53
- ]
54
- .filter(Boolean)
55
- .join('') || 'z.undefined()'}
57
+ {finalOutput}
56
58
  </Const>
57
59
  </File.Source>
58
60
  {inferTypeName && (
@@ -0,0 +1,25 @@
1
+ import { z } from '@hono/zod-openapi'
2
+
3
+ /**
4
+ * @description Null response
5
+ */
6
+ export const createPets201 = z.unknown()
7
+
8
+ /**
9
+ * @description unexpected error
10
+ */
11
+ export const createPetsError = z
12
+ .lazy(() => error)
13
+ .openapi({
14
+ examples: [
15
+ { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
16
+ { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
17
+ ],
18
+ })
19
+
20
+ export const createPetsMutationRequest = z.object({
21
+ name: z.string().openapi({ example: 'Baxter' }),
22
+ tag: z.string(),
23
+ })
24
+
25
+ export const createPetsMutationResponse = z.lazy(() => createPets201)
@@ -0,0 +1,26 @@
1
+ import { z } from '@hono/zod-openapi'
2
+
3
+ /**
4
+ * @description Null response
5
+ */
6
+ export const createPets201 = z.unknown()
7
+
8
+ /**
9
+ * @description unexpected error
10
+ */
11
+ export const createPetsError = extendApi(
12
+ z.lazy(() => error),
13
+ {
14
+ examples: [
15
+ { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
16
+ { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
17
+ ],
18
+ },
19
+ )
20
+
21
+ export const createPetsMutationRequest = z.object({
22
+ name: extendApi(z.string(), { example: 'Baxter' }),
23
+ tag: z.string(),
24
+ })
25
+
26
+ export const createPetsMutationResponse = z.lazy(() => createPets201)
@@ -0,0 +1,25 @@
1
+ import { z } from '@hono/zod-openapi'
2
+
3
+ /**
4
+ * @description Null response
5
+ */
6
+ export const createPets201 = z.any()
7
+
8
+ /**
9
+ * @description unexpected error
10
+ */
11
+ export const createPetsError = z
12
+ .lazy(() => error)
13
+ .openapi({
14
+ examples: [
15
+ { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
16
+ { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
17
+ ],
18
+ })
19
+
20
+ export const createPetsMutationRequest = z.object({
21
+ name: z.string().openapi({ example: 'Baxter' }),
22
+ tag: z.string(),
23
+ })
24
+
25
+ export const createPetsMutationResponse = z.lazy(() => createPets201)
@@ -0,0 +1,3 @@
1
+ import { z } from '@hono/zod-openapi'
2
+
3
+ export const deletePetsPetidMutationResponse = z.any()
@@ -0,0 +1,27 @@
1
+ import { z } from '@hono/zod-openapi'
2
+
3
+ export const listPetsQueryParams = z
4
+ .object({
5
+ limit: z.string().describe('How many items to return at one time (max 100)').optional(),
6
+ offset: z.number().int().default(0),
7
+ })
8
+ .optional()
9
+
10
+ /**
11
+ * @description A paged array of pets
12
+ */
13
+ export const listPets200 = z.lazy(() => pets)
14
+
15
+ /**
16
+ * @description unexpected error
17
+ */
18
+ export const listPetsError = z
19
+ .lazy(() => error)
20
+ .openapi({
21
+ examples: [
22
+ { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
23
+ { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
24
+ ],
25
+ })
26
+
27
+ export const listPetsQueryResponse = z.lazy(() => listPets200)
@@ -0,0 +1,25 @@
1
+ import { z } from '@hono/zod-openapi'
2
+
3
+ export const showPetByIdPathParams = z.object({
4
+ petId: z.string().describe('The id of the pet to retrieve'),
5
+ testId: z.string().describe('The id of the pet to retrieve'),
6
+ })
7
+
8
+ /**
9
+ * @description Expected response to a valid request
10
+ */
11
+ export const showPetById200 = z.lazy(() => pet)
12
+
13
+ /**
14
+ * @description unexpected error
15
+ */
16
+ export const showPetByIdError = z
17
+ .lazy(() => error)
18
+ .openapi({
19
+ examples: [
20
+ { sample: { summary: 'A sample error', value: { code: 1, message: 'A sample error message' } } },
21
+ { other_example: { summary: 'Another sample error', value: { code: 2, message: 'A totally specific message' } } },
22
+ ],
23
+ })
24
+
25
+ export const showPetByIdQueryResponse = z.lazy(() => showPetById200)
@@ -10,7 +10,7 @@ import type { PluginZod } from '../types'
10
10
  export const zodGenerator = createReactGenerator<PluginZod>({
11
11
  name: 'zod',
12
12
  Operation({ operation, options }) {
13
- const { coercion, inferred, typed, mapper } = options
13
+ const { coercion, inferred, typed, mapper, wrapOutput } = options
14
14
 
15
15
  const { plugin, pluginManager, mode } = useApp<PluginZod>()
16
16
  const oas = useOas()
@@ -46,8 +46,14 @@ export const zodGenerator = createReactGenerator<PluginZod>({
46
46
  }
47
47
 
48
48
  const type = {
49
- name: schemaManager.getName(name, { type: 'type', pluginKey: [pluginTsName] }),
50
- file: schemaManager.getFile(options.operationName || name, { pluginKey: [pluginTsName], group }),
49
+ name: schemaManager.getName(name, {
50
+ type: 'type',
51
+ pluginKey: [pluginTsName],
52
+ }),
53
+ file: schemaManager.getFile(options.operationName || name, {
54
+ pluginKey: [pluginTsName],
55
+ group,
56
+ }),
51
57
  }
52
58
 
53
59
  return (
@@ -63,9 +69,11 @@ export const zodGenerator = createReactGenerator<PluginZod>({
63
69
  inferTypeName={inferred ? zod.inferTypeName : undefined}
64
70
  description={description}
65
71
  tree={tree}
72
+ rawSchema={schema}
66
73
  mapper={mapper}
67
74
  coercion={coercion}
68
75
  keysToOmit={keysToOmit}
76
+ wrapOutput={wrapOutput}
69
77
  />
70
78
  </Oas.Schema>
71
79
  )
@@ -85,7 +93,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
85
93
  )
86
94
  },
87
95
  Schema({ schema, options }) {
88
- const { coercion, inferred, typed, mapper, importPath } = options
96
+ const { coercion, inferred, typed, mapper, importPath, wrapOutput } = options
89
97
 
90
98
  const { getName, getFile, getImports } = useSchemaManager()
91
99
  const {
@@ -123,8 +131,10 @@ export const zodGenerator = createReactGenerator<PluginZod>({
123
131
  inferTypeName={inferred ? zod.inferTypeName : undefined}
124
132
  description={schema.value.description}
125
133
  tree={schema.tree}
134
+ rawSchema={schema.value}
126
135
  mapper={mapper}
127
136
  coercion={coercion}
137
+ wrapOutput={wrapOutput}
128
138
  />
129
139
  </File>
130
140
  )
package/src/parser.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import transformers from '@kubb/core/transformers'
2
+ import type { SchemaObject } from '@kubb/oas'
2
3
  import { type SchemaKeywordMapper, type SchemaTree, isKeyword, schemaKeywords } from '@kubb/plugin-oas'
3
4
 
4
5
  import type { Schema, SchemaKeywordBase, SchemaMapper } from '@kubb/plugin-oas'
@@ -188,6 +189,8 @@ type ParserOptions = {
188
189
  keysToOmit?: string[]
189
190
  mapper?: Record<string, string>
190
191
  coercion?: boolean | { dates?: boolean; strings?: boolean; numbers?: boolean }
192
+ wrapOutput?: (opts: { output: string; schema: any }) => string | undefined
193
+ rawSchema: SchemaObject
191
194
  }
192
195
 
193
196
  export function parse({ parent, current, siblings }: SchemaTree, options: ParserOptions): string | undefined {
@@ -291,10 +294,12 @@ export function parse({ parent, current, siblings }: SchemaTree, options: Parser
291
294
  return `"${name}": ${options.mapper?.[mappedName]}`
292
295
  }
293
296
 
294
- return `"${name}": ${sort(schemas)
297
+ const baseSchemaOutput = sort(schemas)
295
298
  .map((schema) => parse({ parent: current, current: schema, siblings: schemas }, options))
296
299
  .filter(Boolean)
297
- .join('')}`
300
+ .join('')
301
+
302
+ return `"${name}": ${options.wrapOutput ? options.wrapOutput({ output: baseSchemaOutput, schema: options.rawSchema?.properties?.[name] }) || baseSchemaOutput : baseSchemaOutput}`
298
303
  })
299
304
  .join(',\n')
300
305
 
package/src/plugin.ts CHANGED
@@ -31,6 +31,7 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
31
31
  coercion = false,
32
32
  inferred = false,
33
33
  generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),
34
+ wrapOutput = undefined,
34
35
  contentType,
35
36
  } = options
36
37
 
@@ -51,6 +52,7 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
51
52
  operations,
52
53
  inferred,
53
54
  group,
55
+ wrapOutput,
54
56
  },
55
57
  pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),
56
58
  resolvePath(baseName, pathMode, options) {
package/src/types.ts CHANGED
@@ -88,6 +88,14 @@ export type Options = {
88
88
  defaultSchemas: Schema[],
89
89
  ) => Schema[] | undefined
90
90
  }
91
+ /**
92
+ * Callback function to wrap the output of the generated zod schema
93
+ *
94
+ * This is useful for edge case scenarios where you might leverage something like `z.object({ ... }).openapi({ example: { some: "complex-example" }})`
95
+ * or `extendApi(z.object({ ... }), { example: { some: "complex-example", ...otherOpenApiProperties }})`
96
+ * while going from openapi -> zod -> openapi
97
+ */
98
+ wrapOutput?: (arg: { output: string; schema: SchemaObject }) => string | undefined
91
99
  /**
92
100
  * Define some generators next to the zod generators
93
101
  */
@@ -107,6 +115,7 @@ type ResolvedOptions = {
107
115
  importPath: NonNullable<Options['importPath']>
108
116
  coercion: NonNullable<Options['coercion']>
109
117
  operations: NonNullable<Options['operations']>
118
+ wrapOutput: Options['wrapOutput']
110
119
  }
111
120
 
112
121
  export type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>