@kubb/plugin-zod 3.12.1 → 3.13.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.
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/index.cjs +4 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/dist/{types-gHTd3B-E.d.cts → types-BOF1ntMm.d.cts} +6 -0
- package/dist/{types-gHTd3B-E.d.ts → types-BOF1ntMm.d.ts} +6 -0
- package/package.json +10 -10
- package/src/generators/__snapshots__/createPet.ts +1 -1
- package/src/generators/__snapshots__/createPet_wrapOutput.ts +1 -1
- package/src/generators/__snapshots__/deletePet.ts +1 -1
- package/src/generators/__snapshots__/deletePet_wrapOutput.ts +1 -1
- package/src/plugin.ts +56 -71
- package/src/types.ts +6 -0
package/dist/components.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SchemaNames } from '@kubb/plugin-oas/hooks';
|
|
2
2
|
import { Operation, SchemaObject } from '@kubb/oas';
|
|
3
3
|
import { Schema } from '@kubb/plugin-oas';
|
|
4
|
-
import { P as PluginZod } from './types-
|
|
4
|
+
import { P as PluginZod } from './types-BOF1ntMm.cjs';
|
|
5
5
|
import '@kubb/core';
|
|
6
6
|
|
|
7
7
|
type Props$1 = {
|
package/dist/components.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SchemaNames } from '@kubb/plugin-oas/hooks';
|
|
2
2
|
import { Operation, SchemaObject } from '@kubb/oas';
|
|
3
3
|
import { Schema } from '@kubb/plugin-oas';
|
|
4
|
-
import { P as PluginZod } from './types-
|
|
4
|
+
import { P as PluginZod } from './types-BOF1ntMm.js';
|
|
5
5
|
import '@kubb/core';
|
|
6
6
|
|
|
7
7
|
type Props$1 = {
|
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ var pluginZod = core.createPlugin((options) => {
|
|
|
23
23
|
transformers: transformers$1 = {},
|
|
24
24
|
dateType = "string",
|
|
25
25
|
unknownType = "any",
|
|
26
|
+
emptySchemaType = unknownType,
|
|
26
27
|
typed = false,
|
|
27
28
|
mapper = {},
|
|
28
29
|
operations = false,
|
|
@@ -30,10 +31,7 @@ var pluginZod = core.createPlugin((options) => {
|
|
|
30
31
|
importPath = version === "4" ? "zod/v4" : "zod",
|
|
31
32
|
coercion = false,
|
|
32
33
|
inferred = false,
|
|
33
|
-
generators = [
|
|
34
|
-
chunkDCHEK74F_cjs.zodGenerator,
|
|
35
|
-
operations ? chunkDCHEK74F_cjs.operationsGenerator : void 0
|
|
36
|
-
].filter(Boolean),
|
|
34
|
+
generators = [chunkDCHEK74F_cjs.zodGenerator, operations ? chunkDCHEK74F_cjs.operationsGenerator : void 0].filter(Boolean),
|
|
37
35
|
wrapOutput = void 0,
|
|
38
36
|
contentType
|
|
39
37
|
} = options;
|
|
@@ -48,6 +46,7 @@ var pluginZod = core.createPlugin((options) => {
|
|
|
48
46
|
typed,
|
|
49
47
|
dateType,
|
|
50
48
|
unknownType,
|
|
49
|
+
emptySchemaType,
|
|
51
50
|
mapper,
|
|
52
51
|
importPath,
|
|
53
52
|
coercion,
|
|
@@ -96,9 +95,7 @@ var pluginZod = core.createPlugin((options) => {
|
|
|
96
95
|
return resolvedName;
|
|
97
96
|
},
|
|
98
97
|
async buildStart() {
|
|
99
|
-
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [
|
|
100
|
-
pluginOas.pluginOasName
|
|
101
|
-
]);
|
|
98
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
102
99
|
const oas = await swaggerPlugin.context.getOas();
|
|
103
100
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
104
101
|
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
package/dist/index.cjs.map
CHANGED
|
@@ -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":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","zodGenerator","operationsGenerator","pluginOasName","pluginTsName","options","path","FileManager","camelCase","pascalCase","PluginManager","SchemaGenerator","OperationGenerator"],"mappings":";;;;;;;;;;;;;;AAWO,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,eAAkB,GAAA,WAAA;AAAA,IAClB,KAAQ,GAAA,KAAA;AAAA,IACR,SAAS,EAAC;AAAA,IACV,UAAa,GAAA,KAAA;AAAA,IACb,OAAU,GAAA,GAAA;AAAA,IACV,UAAA,GAAa,OAAY,KAAA,GAAA,GAAM,QAAW,GAAA,KAAA;AAAA,IAC1C,QAAW,GAAA,KAAA;AAAA,IACX,QAAW,GAAA,KAAA;AAAA,IACX,UAAA,GAAa,CAACC,8BAAc,EAAA,UAAA,GAAaC,wCAAsB,MAAS,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IACxF,UAAa,GAAA,MAAA;AAAA,IACb;AAAA,GACE,GAAA,OAAA;AAEJ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ACJ,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'\nimport type { Plugin } from '@kubb/core'\nimport { createPlugin, FileManager, type Group, PluginManager } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\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 emptySchemaType = unknownType,\n typed = false,\n mapper = {},\n operations = false,\n version = '3',\n importPath = version === '4' ? 'zod/v4' : '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 emptySchemaType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n wrapOutput,\n version,\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
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ var pluginZod = createPlugin((options) => {
|
|
|
17
17
|
transformers = {},
|
|
18
18
|
dateType = "string",
|
|
19
19
|
unknownType = "any",
|
|
20
|
+
emptySchemaType = unknownType,
|
|
20
21
|
typed = false,
|
|
21
22
|
mapper = {},
|
|
22
23
|
operations = false,
|
|
@@ -24,10 +25,7 @@ var pluginZod = createPlugin((options) => {
|
|
|
24
25
|
importPath = version === "4" ? "zod/v4" : "zod",
|
|
25
26
|
coercion = false,
|
|
26
27
|
inferred = false,
|
|
27
|
-
generators = [
|
|
28
|
-
zodGenerator,
|
|
29
|
-
operations ? operationsGenerator : void 0
|
|
30
|
-
].filter(Boolean),
|
|
28
|
+
generators = [zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean),
|
|
31
29
|
wrapOutput = void 0,
|
|
32
30
|
contentType
|
|
33
31
|
} = options;
|
|
@@ -42,6 +40,7 @@ var pluginZod = createPlugin((options) => {
|
|
|
42
40
|
typed,
|
|
43
41
|
dateType,
|
|
44
42
|
unknownType,
|
|
43
|
+
emptySchemaType,
|
|
45
44
|
mapper,
|
|
46
45
|
importPath,
|
|
47
46
|
coercion,
|
|
@@ -90,9 +89,7 @@ var pluginZod = createPlugin((options) => {
|
|
|
90
89
|
return resolvedName;
|
|
91
90
|
},
|
|
92
91
|
async buildStart() {
|
|
93
|
-
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [
|
|
94
|
-
pluginOasName
|
|
95
|
-
]);
|
|
92
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
96
93
|
const oas = await swaggerPlugin.context.getOas();
|
|
97
94
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
98
95
|
const mode = FileManager.getMode(path.resolve(root, output.path));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;
|
|
1
|
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,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'\nimport type { Plugin } from '@kubb/core'\nimport { createPlugin, FileManager, type Group, PluginManager } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\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 emptySchemaType = unknownType,\n typed = false,\n mapper = {},\n operations = false,\n version = '3',\n importPath = version === '4' ? 'zod/v4' : '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 emptySchemaType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\n wrapOutput,\n version,\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"]}
|
|
@@ -47,6 +47,11 @@ type Options = {
|
|
|
47
47
|
* @default 'any'
|
|
48
48
|
*/
|
|
49
49
|
unknownType?: 'any' | 'unknown' | 'void';
|
|
50
|
+
/**
|
|
51
|
+
* Which type to use for empty schema values
|
|
52
|
+
* @default `unknownType`
|
|
53
|
+
*/
|
|
54
|
+
emptySchemaType?: 'any' | 'unknown' | 'void';
|
|
50
55
|
/**
|
|
51
56
|
* Use TypeScript(`@kubb/plugin-ts`) to add type annotation.
|
|
52
57
|
*/
|
|
@@ -110,6 +115,7 @@ type ResolvedOptions = {
|
|
|
110
115
|
transformers: NonNullable<Options['transformers']>;
|
|
111
116
|
dateType: NonNullable<Options['dateType']>;
|
|
112
117
|
unknownType: NonNullable<Options['unknownType']>;
|
|
118
|
+
emptySchemaType: NonNullable<Options['emptySchemaType']>;
|
|
113
119
|
typed: NonNullable<Options['typed']>;
|
|
114
120
|
inferred: NonNullable<Options['inferred']>;
|
|
115
121
|
mapper: NonNullable<Options['mapper']>;
|
|
@@ -47,6 +47,11 @@ type Options = {
|
|
|
47
47
|
* @default 'any'
|
|
48
48
|
*/
|
|
49
49
|
unknownType?: 'any' | 'unknown' | 'void';
|
|
50
|
+
/**
|
|
51
|
+
* Which type to use for empty schema values
|
|
52
|
+
* @default `unknownType`
|
|
53
|
+
*/
|
|
54
|
+
emptySchemaType?: 'any' | 'unknown' | 'void';
|
|
50
55
|
/**
|
|
51
56
|
* Use TypeScript(`@kubb/plugin-ts`) to add type annotation.
|
|
52
57
|
*/
|
|
@@ -110,6 +115,7 @@ type ResolvedOptions = {
|
|
|
110
115
|
transformers: NonNullable<Options['transformers']>;
|
|
111
116
|
dateType: NonNullable<Options['dateType']>;
|
|
112
117
|
unknownType: NonNullable<Options['unknownType']>;
|
|
118
|
+
emptySchemaType: NonNullable<Options['emptySchemaType']>;
|
|
113
119
|
typed: NonNullable<Options['typed']>;
|
|
114
120
|
inferred: NonNullable<Options['inferred']>;
|
|
115
121
|
mapper: NonNullable<Options['mapper']>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0",
|
|
4
4
|
"description": "Generator plugin-zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -66,21 +66,21 @@
|
|
|
66
66
|
"!/**/__tests__/**"
|
|
67
67
|
],
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@kubb/core": "3.
|
|
70
|
-
"@kubb/oas": "3.
|
|
71
|
-
"@kubb/
|
|
72
|
-
"@kubb/plugin-oas": "3.
|
|
73
|
-
"@kubb/
|
|
74
|
-
"@kubb/react": "3.
|
|
69
|
+
"@kubb/core": "3.13.0",
|
|
70
|
+
"@kubb/oas": "3.13.0",
|
|
71
|
+
"@kubb/plugin-ts": "3.13.0",
|
|
72
|
+
"@kubb/plugin-oas": "3.13.0",
|
|
73
|
+
"@kubb/parser-ts": "3.13.0",
|
|
74
|
+
"@kubb/react": "3.13.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@asteasolutions/zod-to-openapi": "^7.3.4",
|
|
78
78
|
"@hono/zod-openapi": "0.19.2",
|
|
79
79
|
"tsup": "^8.5.0",
|
|
80
80
|
"zod": "~3.24.4",
|
|
81
|
-
"@kubb/config-ts": "3.
|
|
82
|
-
"@kubb/config-tsup": "3.
|
|
83
|
-
"@kubb/plugin-oas": "3.
|
|
81
|
+
"@kubb/config-ts": "3.13.0",
|
|
82
|
+
"@kubb/config-tsup": "3.13.0",
|
|
83
|
+
"@kubb/plugin-oas": "3.13.0"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"@kubb/react": "^3.0.0"
|
package/src/plugin.ts
CHANGED
|
@@ -1,49 +1,38 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import type { Plugin } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from
|
|
9
|
-
import {
|
|
10
|
-
import type {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
pluginOasName,
|
|
14
|
-
SchemaGenerator,
|
|
15
|
-
} from "@kubb/plugin-oas";
|
|
16
|
-
import { pluginTsName } from "@kubb/plugin-ts";
|
|
17
|
-
import { operationsGenerator } from "./generators";
|
|
18
|
-
import { zodGenerator } from "./generators/zodGenerator.tsx";
|
|
19
|
-
import type { PluginZod } from "./types.ts";
|
|
20
|
-
|
|
21
|
-
export const pluginZodName = "plugin-zod" satisfies PluginZod["name"];
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import type { Plugin } from '@kubb/core'
|
|
3
|
+
import { createPlugin, FileManager, type Group, PluginManager } from '@kubb/core'
|
|
4
|
+
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
5
|
+
import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
|
|
6
|
+
import { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
|
|
7
|
+
import { pluginTsName } from '@kubb/plugin-ts'
|
|
8
|
+
import { operationsGenerator } from './generators'
|
|
9
|
+
import { zodGenerator } from './generators/zodGenerator.tsx'
|
|
10
|
+
import type { PluginZod } from './types.ts'
|
|
11
|
+
|
|
12
|
+
export const pluginZodName = 'plugin-zod' satisfies PluginZod['name']
|
|
22
13
|
|
|
23
14
|
export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
24
15
|
const {
|
|
25
|
-
output = { path:
|
|
16
|
+
output = { path: 'zod', barrelType: 'named' },
|
|
26
17
|
group,
|
|
27
18
|
exclude = [],
|
|
28
19
|
include,
|
|
29
20
|
override = [],
|
|
30
21
|
transformers = {},
|
|
31
|
-
dateType =
|
|
32
|
-
unknownType =
|
|
22
|
+
dateType = 'string',
|
|
23
|
+
unknownType = 'any',
|
|
24
|
+
emptySchemaType = unknownType,
|
|
33
25
|
typed = false,
|
|
34
26
|
mapper = {},
|
|
35
27
|
operations = false,
|
|
36
|
-
version =
|
|
37
|
-
importPath = version ===
|
|
28
|
+
version = '3',
|
|
29
|
+
importPath = version === '4' ? 'zod/v4' : 'zod',
|
|
38
30
|
coercion = false,
|
|
39
31
|
inferred = false,
|
|
40
|
-
generators = [
|
|
41
|
-
zodGenerator,
|
|
42
|
-
operations ? operationsGenerator : undefined,
|
|
43
|
-
].filter(Boolean),
|
|
32
|
+
generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),
|
|
44
33
|
wrapOutput = undefined,
|
|
45
34
|
contentType,
|
|
46
|
-
} = options
|
|
35
|
+
} = options
|
|
47
36
|
|
|
48
37
|
return {
|
|
49
38
|
name: pluginZodName,
|
|
@@ -56,6 +45,7 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
|
56
45
|
typed,
|
|
57
46
|
dateType,
|
|
58
47
|
unknownType,
|
|
48
|
+
emptySchemaType,
|
|
59
49
|
mapper,
|
|
60
50
|
importPath,
|
|
61
51
|
coercion,
|
|
@@ -67,66 +57,61 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
|
67
57
|
},
|
|
68
58
|
pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),
|
|
69
59
|
resolvePath(baseName, pathMode, options) {
|
|
70
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
71
|
-
const mode =
|
|
72
|
-
pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
60
|
+
const root = path.resolve(this.config.root, this.config.output.path)
|
|
61
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
|
73
62
|
|
|
74
|
-
if (mode ===
|
|
63
|
+
if (mode === 'single') {
|
|
75
64
|
/**
|
|
76
65
|
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
77
66
|
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
78
67
|
*/
|
|
79
|
-
return path.resolve(root, output.path)
|
|
68
|
+
return path.resolve(root, output.path)
|
|
80
69
|
}
|
|
81
70
|
|
|
82
71
|
if (group && (options?.group?.path || options?.group?.tag)) {
|
|
83
|
-
const groupName: Group[
|
|
72
|
+
const groupName: Group['name'] = group?.name
|
|
84
73
|
? group.name
|
|
85
74
|
: (ctx) => {
|
|
86
|
-
if (group?.type ===
|
|
87
|
-
return `${ctx.group.split(
|
|
75
|
+
if (group?.type === 'path') {
|
|
76
|
+
return `${ctx.group.split('/')[1]}`
|
|
88
77
|
}
|
|
89
|
-
return `${camelCase(ctx.group)}Controller
|
|
90
|
-
}
|
|
78
|
+
return `${camelCase(ctx.group)}Controller`
|
|
79
|
+
}
|
|
91
80
|
|
|
92
81
|
return path.resolve(
|
|
93
82
|
root,
|
|
94
83
|
output.path,
|
|
95
84
|
groupName({
|
|
96
|
-
group:
|
|
97
|
-
group.type === "path" ? options.group.path! : options.group.tag!,
|
|
85
|
+
group: group.type === 'path' ? options.group.path! : options.group.tag!,
|
|
98
86
|
}),
|
|
99
|
-
baseName
|
|
100
|
-
)
|
|
87
|
+
baseName,
|
|
88
|
+
)
|
|
101
89
|
}
|
|
102
90
|
|
|
103
|
-
return path.resolve(root, output.path, baseName)
|
|
91
|
+
return path.resolve(root, output.path, baseName)
|
|
104
92
|
},
|
|
105
93
|
resolveName(name, type) {
|
|
106
94
|
let resolvedName = camelCase(name, {
|
|
107
|
-
suffix: type ?
|
|
108
|
-
isFile: type ===
|
|
109
|
-
})
|
|
95
|
+
suffix: type ? 'schema' : undefined,
|
|
96
|
+
isFile: type === 'file',
|
|
97
|
+
})
|
|
110
98
|
|
|
111
|
-
if (type ===
|
|
112
|
-
resolvedName = pascalCase(resolvedName)
|
|
99
|
+
if (type === 'type') {
|
|
100
|
+
resolvedName = pascalCase(resolvedName)
|
|
113
101
|
}
|
|
114
102
|
|
|
115
103
|
if (type) {
|
|
116
|
-
return transformers?.name?.(resolvedName, type) || resolvedName
|
|
104
|
+
return transformers?.name?.(resolvedName, type) || resolvedName
|
|
117
105
|
}
|
|
118
106
|
|
|
119
|
-
return resolvedName
|
|
107
|
+
return resolvedName
|
|
120
108
|
},
|
|
121
109
|
async buildStart() {
|
|
122
|
-
const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] =
|
|
123
|
-
PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [
|
|
124
|
-
pluginOasName,
|
|
125
|
-
]);
|
|
110
|
+
const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])
|
|
126
111
|
|
|
127
|
-
const oas = await swaggerPlugin.context.getOas()
|
|
128
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
129
|
-
const mode = FileManager.getMode(path.resolve(root, output.path))
|
|
112
|
+
const oas = await swaggerPlugin.context.getOas()
|
|
113
|
+
const root = path.resolve(this.config.root, this.config.output.path)
|
|
114
|
+
const mode = FileManager.getMode(path.resolve(root, output.path))
|
|
130
115
|
|
|
131
116
|
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
132
117
|
oas,
|
|
@@ -137,10 +122,10 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
|
137
122
|
override,
|
|
138
123
|
mode,
|
|
139
124
|
output: output.path,
|
|
140
|
-
})
|
|
125
|
+
})
|
|
141
126
|
|
|
142
|
-
const schemaFiles = await schemaGenerator.build(...generators)
|
|
143
|
-
await this.addFile(...schemaFiles)
|
|
127
|
+
const schemaFiles = await schemaGenerator.build(...generators)
|
|
128
|
+
await this.addFile(...schemaFiles)
|
|
144
129
|
|
|
145
130
|
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
146
131
|
oas,
|
|
@@ -151,13 +136,13 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
|
151
136
|
include,
|
|
152
137
|
override,
|
|
153
138
|
mode,
|
|
154
|
-
})
|
|
139
|
+
})
|
|
155
140
|
|
|
156
|
-
const operationFiles = await operationGenerator.build(...generators)
|
|
157
|
-
await this.addFile(...operationFiles)
|
|
141
|
+
const operationFiles = await operationGenerator.build(...generators)
|
|
142
|
+
await this.addFile(...operationFiles)
|
|
158
143
|
|
|
159
144
|
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
160
|
-
type: output.barrelType ??
|
|
145
|
+
type: output.barrelType ?? 'named',
|
|
161
146
|
root,
|
|
162
147
|
output,
|
|
163
148
|
files: this.fileManager.files,
|
|
@@ -165,9 +150,9 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
|
|
|
165
150
|
pluginKey: this.plugin.key,
|
|
166
151
|
},
|
|
167
152
|
logger: this.logger,
|
|
168
|
-
})
|
|
153
|
+
})
|
|
169
154
|
|
|
170
|
-
await this.addFile(...barrelFiles)
|
|
155
|
+
await this.addFile(...barrelFiles)
|
|
171
156
|
},
|
|
172
|
-
}
|
|
173
|
-
})
|
|
157
|
+
}
|
|
158
|
+
})
|
package/src/types.ts
CHANGED
|
@@ -48,6 +48,11 @@ export type Options = {
|
|
|
48
48
|
* @default 'any'
|
|
49
49
|
*/
|
|
50
50
|
unknownType?: 'any' | 'unknown' | 'void'
|
|
51
|
+
/**
|
|
52
|
+
* Which type to use for empty schema values
|
|
53
|
+
* @default `unknownType`
|
|
54
|
+
*/
|
|
55
|
+
emptySchemaType?: 'any' | 'unknown' | 'void'
|
|
51
56
|
/**
|
|
52
57
|
* Use TypeScript(`@kubb/plugin-ts`) to add type annotation.
|
|
53
58
|
*/
|
|
@@ -114,6 +119,7 @@ type ResolvedOptions = {
|
|
|
114
119
|
transformers: NonNullable<Options['transformers']>
|
|
115
120
|
dateType: NonNullable<Options['dateType']>
|
|
116
121
|
unknownType: NonNullable<Options['unknownType']>
|
|
122
|
+
emptySchemaType: NonNullable<Options['emptySchemaType']>
|
|
117
123
|
typed: NonNullable<Options['typed']>
|
|
118
124
|
inferred: NonNullable<Options['inferred']>
|
|
119
125
|
mapper: NonNullable<Options['mapper']>
|