@kubb/plugin-zod 3.16.1 → 3.16.3
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-CJ6RN1R2.js +414 -0
- package/dist/components-CJ6RN1R2.js.map +1 -0
- package/dist/components-GvkeO2ig.cjs +454 -0
- package/dist/components-GvkeO2ig.cjs.map +1 -0
- package/dist/components.cjs +3 -15
- package/dist/components.d.cts +56 -26
- package/dist/components.d.ts +56 -26
- package/dist/components.js +3 -3
- package/dist/generators-B13NknOz.cjs +265 -0
- package/dist/generators-B13NknOz.cjs.map +1 -0
- package/dist/generators-DcUZYcq0.js +254 -0
- package/dist/generators-DcUZYcq0.js.map +1 -0
- package/dist/generators.cjs +4 -16
- package/dist/generators.d.cts +8 -8
- package/dist/generators.d.ts +8 -8
- package/dist/generators.js +4 -4
- package/dist/index.cjs +103 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.js +103 -131
- package/dist/index.js.map +1 -1
- package/dist/types-B0UqdcbG.d.cts +1237 -0
- package/dist/types-YpNWeJUW.d.ts +1237 -0
- package/dist/utils.cjs +0 -4
- package/dist/utils.d.cts +18 -24
- package/dist/utils.d.ts +18 -24
- package/dist/utils.js +1 -3
- package/package.json +24 -30
- package/src/components/Zod.tsx +3 -2
- package/src/parser.ts +8 -0
- package/dist/chunk-AHCG4FYY.js +0 -448
- package/dist/chunk-AHCG4FYY.js.map +0 -1
- package/dist/chunk-QNMY34G2.cjs +0 -455
- package/dist/chunk-QNMY34G2.cjs.map +0 -1
- package/dist/chunk-RQAEGENA.cjs +0 -184
- package/dist/chunk-RQAEGENA.cjs.map +0 -1
- package/dist/chunk-Z6ERLJH7.js +0 -181
- package/dist/chunk-Z6ERLJH7.js.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
- package/dist/types-BOF1ntMm.d.cts +0 -130
- package/dist/types-BOF1ntMm.d.ts +0 -130
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.js.map +0 -1
package/dist/chunk-RQAEGENA.cjs
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkQNMY34G2_cjs = require('./chunk-QNMY34G2.cjs');
|
|
4
|
-
var pluginOas = require('@kubb/plugin-oas');
|
|
5
|
-
var components = require('@kubb/plugin-oas/components');
|
|
6
|
-
var hooks = require('@kubb/plugin-oas/hooks');
|
|
7
|
-
var utils = require('@kubb/plugin-oas/utils');
|
|
8
|
-
var pluginTs = require('@kubb/plugin-ts');
|
|
9
|
-
var react = require('@kubb/react');
|
|
10
|
-
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
11
|
-
|
|
12
|
-
var zodGenerator = pluginOas.createReactGenerator({
|
|
13
|
-
name: "zod",
|
|
14
|
-
Operation({ operation, options }) {
|
|
15
|
-
const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options;
|
|
16
|
-
const { plugin, pluginManager, mode } = react.useApp();
|
|
17
|
-
const oas = hooks.useOas();
|
|
18
|
-
const { getSchemas, getFile, getGroup } = hooks.useOperationManager();
|
|
19
|
-
const schemaManager = hooks.useSchemaManager();
|
|
20
|
-
const file = getFile(operation);
|
|
21
|
-
const schemas = getSchemas(operation);
|
|
22
|
-
const schemaGenerator = new pluginOas.SchemaGenerator(options, {
|
|
23
|
-
oas,
|
|
24
|
-
plugin,
|
|
25
|
-
pluginManager,
|
|
26
|
-
mode,
|
|
27
|
-
override: options.override
|
|
28
|
-
});
|
|
29
|
-
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
30
|
-
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options2 }, i) => {
|
|
31
|
-
const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required;
|
|
32
|
-
const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, "default") && property.default !== void 0);
|
|
33
|
-
const optional = !required && !someDefaults && name.includes("Params");
|
|
34
|
-
const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: pluginOas.schemaKeywords.optional } : void 0].filter(Boolean);
|
|
35
|
-
const imports = schemaManager.getImports(tree);
|
|
36
|
-
const group = options2.operation ? getGroup(options2.operation) : void 0;
|
|
37
|
-
const coercion = name.includes("Params") ? { numbers: true, strings: false, dates: true } : globalCoercion;
|
|
38
|
-
const zod = {
|
|
39
|
-
name: schemaManager.getName(name, { type: "function" }),
|
|
40
|
-
inferTypeName: schemaManager.getName(name, { type: "type" }),
|
|
41
|
-
file: schemaManager.getFile(name)
|
|
42
|
-
};
|
|
43
|
-
const type = {
|
|
44
|
-
name: schemaManager.getName(name, {
|
|
45
|
-
type: "type",
|
|
46
|
-
pluginKey: [pluginTs.pluginTsName]
|
|
47
|
-
}),
|
|
48
|
-
file: schemaManager.getFile(options2.operationName || name, {
|
|
49
|
-
pluginKey: [pluginTs.pluginTsName],
|
|
50
|
-
group
|
|
51
|
-
})
|
|
52
|
-
};
|
|
53
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, schemaObject, tree, children: [
|
|
54
|
-
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: file.path, path: type.file.path, name: [type.name] }),
|
|
55
|
-
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, path: "@kubb/plugin-zod/utils", name: ["ToZod"] }),
|
|
56
|
-
imports.map((imp) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: file.path, path: imp.path, name: imp.name }, [imp.path, imp.name, imp.isTypeOnly].join("-"))),
|
|
57
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
58
|
-
chunkQNMY34G2_cjs.Zod,
|
|
59
|
-
{
|
|
60
|
-
name: zod.name,
|
|
61
|
-
typeName: typed ? type.name : void 0,
|
|
62
|
-
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
63
|
-
description,
|
|
64
|
-
tree,
|
|
65
|
-
rawSchema: schemaObject,
|
|
66
|
-
mapper,
|
|
67
|
-
coercion,
|
|
68
|
-
keysToOmit,
|
|
69
|
-
wrapOutput,
|
|
70
|
-
version: plugin.options.version,
|
|
71
|
-
emptySchemaType: plugin.options.emptySchemaType
|
|
72
|
-
}
|
|
73
|
-
)
|
|
74
|
-
] }, i);
|
|
75
|
-
};
|
|
76
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
77
|
-
react.File,
|
|
78
|
-
{
|
|
79
|
-
baseName: file.baseName,
|
|
80
|
-
path: file.path,
|
|
81
|
-
meta: file.meta,
|
|
82
|
-
banner: utils.getBanner({ oas, output: plugin.options.output, config: pluginManager.config }),
|
|
83
|
-
footer: utils.getFooter({ oas, output: plugin.options.output }),
|
|
84
|
-
children: [
|
|
85
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
86
|
-
operationSchemas.map(mapOperationSchema)
|
|
87
|
-
]
|
|
88
|
-
}
|
|
89
|
-
);
|
|
90
|
-
},
|
|
91
|
-
Schema({ schema, options }) {
|
|
92
|
-
const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options;
|
|
93
|
-
const { getName, getFile, getImports } = hooks.useSchemaManager();
|
|
94
|
-
const {
|
|
95
|
-
pluginManager,
|
|
96
|
-
plugin: {
|
|
97
|
-
options: { output, emptySchemaType }
|
|
98
|
-
}
|
|
99
|
-
} = react.useApp();
|
|
100
|
-
const oas = hooks.useOas();
|
|
101
|
-
const imports = getImports(schema.tree);
|
|
102
|
-
const zod = {
|
|
103
|
-
name: getName(schema.name, { type: "function" }),
|
|
104
|
-
inferTypeName: getName(schema.name, { type: "type" }),
|
|
105
|
-
file: getFile(schema.name)
|
|
106
|
-
};
|
|
107
|
-
const type = {
|
|
108
|
-
name: getName(schema.name, { type: "type", pluginKey: [pluginTs.pluginTsName] }),
|
|
109
|
-
file: getFile(schema.name, { pluginKey: [pluginTs.pluginTsName] })
|
|
110
|
-
};
|
|
111
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
112
|
-
react.File,
|
|
113
|
-
{
|
|
114
|
-
baseName: zod.file.baseName,
|
|
115
|
-
path: zod.file.path,
|
|
116
|
-
meta: zod.file.meta,
|
|
117
|
-
banner: utils.getBanner({ oas, output, config: pluginManager.config }),
|
|
118
|
-
footer: utils.getFooter({ oas, output }),
|
|
119
|
-
children: [
|
|
120
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: importPath }),
|
|
121
|
-
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: zod.file.path, path: type.file.path, name: [type.name] }),
|
|
122
|
-
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, path: "@kubb/plugin-zod/utils", name: ["ToZod"] }),
|
|
123
|
-
imports.map((imp) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: zod.file.path, path: imp.path, name: imp.name }, [imp.path, imp.name, imp.isTypeOnly].join("-"))),
|
|
124
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
125
|
-
chunkQNMY34G2_cjs.Zod,
|
|
126
|
-
{
|
|
127
|
-
name: zod.name,
|
|
128
|
-
typeName: typed ? type.name : void 0,
|
|
129
|
-
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
130
|
-
description: schema.value.description,
|
|
131
|
-
tree: schema.tree,
|
|
132
|
-
rawSchema: schema.value,
|
|
133
|
-
mapper,
|
|
134
|
-
coercion,
|
|
135
|
-
wrapOutput,
|
|
136
|
-
version,
|
|
137
|
-
emptySchemaType
|
|
138
|
-
}
|
|
139
|
-
)
|
|
140
|
-
]
|
|
141
|
-
}
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
var operationsGenerator = pluginOas.createReactGenerator({
|
|
146
|
-
name: "operations",
|
|
147
|
-
Operations({ operations }) {
|
|
148
|
-
const {
|
|
149
|
-
pluginManager,
|
|
150
|
-
plugin: {
|
|
151
|
-
key: pluginKey,
|
|
152
|
-
options: { output }
|
|
153
|
-
}
|
|
154
|
-
} = react.useApp();
|
|
155
|
-
const oas = hooks.useOas();
|
|
156
|
-
const { getFile, groupSchemasByName } = hooks.useOperationManager();
|
|
157
|
-
const name = "operations";
|
|
158
|
-
const file = pluginManager.getFile({ name, extname: ".ts", pluginKey });
|
|
159
|
-
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
160
|
-
const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
|
|
161
|
-
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
162
|
-
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
163
|
-
}).filter(Boolean);
|
|
164
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
165
|
-
react.File,
|
|
166
|
-
{
|
|
167
|
-
baseName: file.baseName,
|
|
168
|
-
path: file.path,
|
|
169
|
-
meta: file.meta,
|
|
170
|
-
banner: utils.getBanner({ oas, output, config: pluginManager.config }),
|
|
171
|
-
footer: utils.getFooter({ oas, output }),
|
|
172
|
-
children: [
|
|
173
|
-
imports,
|
|
174
|
-
/* @__PURE__ */ jsxRuntime.jsx(chunkQNMY34G2_cjs.Operations, { name, operations: transformedOperations })
|
|
175
|
-
]
|
|
176
|
-
}
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
exports.operationsGenerator = operationsGenerator;
|
|
182
|
-
exports.zodGenerator = zodGenerator;
|
|
183
|
-
//# sourceMappingURL=chunk-RQAEGENA.cjs.map
|
|
184
|
-
//# sourceMappingURL=chunk-RQAEGENA.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","useSchemaManager","SchemaGenerator","options","schemaKeywords","pluginTsName","Oas","File","jsx","Zod","jsxs","getBanner","getFooter","Operations"],"mappings":";;;;;;;;;;;AASO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAU,EAAA,cAAA,EAAgB,UAAU,KAAO,EAAA,MAAA,EAAQ,YAAe,GAAA,OAAA;AAE1E,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAASC,YAAkB,EAAA;AAC1D,IAAA,MAAM,MAAMC,YAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,QAAA,KAAaC,yBAAoB,EAAA;AAC9D,IAAA,MAAM,gBAAgBC,sBAAiB,EAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA;AACpC,IAAM,MAAA,eAAA,GAAkB,IAAIC,yBAAA,CAAgB,OAAS,EAAA;AAAA,MACnD,GAAA;AAAA,MACA,MAAA;AAAA,MACA,aAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAU,OAAQ,CAAA;AAAA,KACnB,CAAA;AAED,IAAA,MAAM,mBAAmB,CAAC,OAAA,CAAQ,YAAY,OAAQ,CAAA,WAAA,EAAa,QAAQ,YAAc,EAAA,OAAA,CAAQ,WAAa,EAAA,OAAA,CAAQ,SAAS,OAAQ,CAAA,QAAQ,EAC5I,IAAK,EAAA,CACL,OAAO,OAAO,CAAA;AAEjB,IAAM,MAAA,kBAAA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AAA,uBAAOQ,cAAAA,CAACD,UAAK,CAAA,MAAA,EAAL,EAAsB,IAAM,EAAA,KAAA,EAAO,IAAM,EAAA,IAAA,CAAK,MAAM,IAAM,EAAA,OAAA,CAAQ,SAAS,CAAA,CAAE,QAA5D,GAAkE,CAAA;AAAA,KAC5F,CACA,CAAA,MAAA,CAAO,OAAO,CAAA;AAEjB,IAAA,uBACEG,eAAAA;AAAA,MAACH,UAAAA;AAAA,MAAA;AAAA,QACC,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAA,EAAQI,gBAAU,EAAE,GAAA,EAAK,QAAQ,MAAQ,EAAA,aAAA,CAAc,QAAQ,CAAA;AAAA,QAC/D,MAAQC,EAAAA,eAAAA,CAAU,EAAE,GAAA,EAAK,QAAQ,CAAA;AAAA,QAEhC,QAAA,EAAA;AAAA,UAAA,OAAA;AAAA,0BACDJ,cAAAA,CAACK,4BAAW,EAAA,EAAA,IAAA,EAAY,YAAY,qBAAuB,EAAA;AAAA;AAAA;AAAA,KAC7D;AAAA;AAGN,CAAC","file":"chunk-RQAEGENA.cjs","sourcesContent":["import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output, emptySchemaType },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}
|
package/dist/chunk-Z6ERLJH7.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { Zod, Operations } from './chunk-AHCG4FYY.js';
|
|
2
|
-
import { createReactGenerator, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas';
|
|
3
|
-
import { Oas } from '@kubb/plugin-oas/components';
|
|
4
|
-
import { useSchemaManager, useOas, useOperationManager } from '@kubb/plugin-oas/hooks';
|
|
5
|
-
import { getFooter, getBanner } from '@kubb/plugin-oas/utils';
|
|
6
|
-
import { pluginTsName } from '@kubb/plugin-ts';
|
|
7
|
-
import { useApp, File } from '@kubb/react';
|
|
8
|
-
import { jsxs, jsx } from '@kubb/react/jsx-runtime';
|
|
9
|
-
|
|
10
|
-
var zodGenerator = createReactGenerator({
|
|
11
|
-
name: "zod",
|
|
12
|
-
Operation({ operation, options }) {
|
|
13
|
-
const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options;
|
|
14
|
-
const { plugin, pluginManager, mode } = useApp();
|
|
15
|
-
const oas = useOas();
|
|
16
|
-
const { getSchemas, getFile, getGroup } = useOperationManager();
|
|
17
|
-
const schemaManager = useSchemaManager();
|
|
18
|
-
const file = getFile(operation);
|
|
19
|
-
const schemas = getSchemas(operation);
|
|
20
|
-
const schemaGenerator = new SchemaGenerator(options, {
|
|
21
|
-
oas,
|
|
22
|
-
plugin,
|
|
23
|
-
pluginManager,
|
|
24
|
-
mode,
|
|
25
|
-
override: options.override
|
|
26
|
-
});
|
|
27
|
-
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
28
|
-
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options2 }, i) => {
|
|
29
|
-
const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required;
|
|
30
|
-
const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, "default") && property.default !== void 0);
|
|
31
|
-
const optional = !required && !someDefaults && name.includes("Params");
|
|
32
|
-
const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : void 0].filter(Boolean);
|
|
33
|
-
const imports = schemaManager.getImports(tree);
|
|
34
|
-
const group = options2.operation ? getGroup(options2.operation) : void 0;
|
|
35
|
-
const coercion = name.includes("Params") ? { numbers: true, strings: false, dates: true } : globalCoercion;
|
|
36
|
-
const zod = {
|
|
37
|
-
name: schemaManager.getName(name, { type: "function" }),
|
|
38
|
-
inferTypeName: schemaManager.getName(name, { type: "type" }),
|
|
39
|
-
file: schemaManager.getFile(name)
|
|
40
|
-
};
|
|
41
|
-
const type = {
|
|
42
|
-
name: schemaManager.getName(name, {
|
|
43
|
-
type: "type",
|
|
44
|
-
pluginKey: [pluginTsName]
|
|
45
|
-
}),
|
|
46
|
-
file: schemaManager.getFile(options2.operationName || name, {
|
|
47
|
-
pluginKey: [pluginTsName],
|
|
48
|
-
group
|
|
49
|
-
})
|
|
50
|
-
};
|
|
51
|
-
return /* @__PURE__ */ jsxs(Oas.Schema, { name, schemaObject, tree, children: [
|
|
52
|
-
typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, root: file.path, path: type.file.path, name: [type.name] }),
|
|
53
|
-
typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, path: "@kubb/plugin-zod/utils", name: ["ToZod"] }),
|
|
54
|
-
imports.map((imp) => /* @__PURE__ */ jsx(File.Import, { root: file.path, path: imp.path, name: imp.name }, [imp.path, imp.name, imp.isTypeOnly].join("-"))),
|
|
55
|
-
/* @__PURE__ */ jsx(
|
|
56
|
-
Zod,
|
|
57
|
-
{
|
|
58
|
-
name: zod.name,
|
|
59
|
-
typeName: typed ? type.name : void 0,
|
|
60
|
-
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
61
|
-
description,
|
|
62
|
-
tree,
|
|
63
|
-
rawSchema: schemaObject,
|
|
64
|
-
mapper,
|
|
65
|
-
coercion,
|
|
66
|
-
keysToOmit,
|
|
67
|
-
wrapOutput,
|
|
68
|
-
version: plugin.options.version,
|
|
69
|
-
emptySchemaType: plugin.options.emptySchemaType
|
|
70
|
-
}
|
|
71
|
-
)
|
|
72
|
-
] }, i);
|
|
73
|
-
};
|
|
74
|
-
return /* @__PURE__ */ jsxs(
|
|
75
|
-
File,
|
|
76
|
-
{
|
|
77
|
-
baseName: file.baseName,
|
|
78
|
-
path: file.path,
|
|
79
|
-
meta: file.meta,
|
|
80
|
-
banner: getBanner({ oas, output: plugin.options.output, config: pluginManager.config }),
|
|
81
|
-
footer: getFooter({ oas, output: plugin.options.output }),
|
|
82
|
-
children: [
|
|
83
|
-
/* @__PURE__ */ jsx(File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
84
|
-
operationSchemas.map(mapOperationSchema)
|
|
85
|
-
]
|
|
86
|
-
}
|
|
87
|
-
);
|
|
88
|
-
},
|
|
89
|
-
Schema({ schema, options }) {
|
|
90
|
-
const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options;
|
|
91
|
-
const { getName, getFile, getImports } = useSchemaManager();
|
|
92
|
-
const {
|
|
93
|
-
pluginManager,
|
|
94
|
-
plugin: {
|
|
95
|
-
options: { output, emptySchemaType }
|
|
96
|
-
}
|
|
97
|
-
} = useApp();
|
|
98
|
-
const oas = useOas();
|
|
99
|
-
const imports = getImports(schema.tree);
|
|
100
|
-
const zod = {
|
|
101
|
-
name: getName(schema.name, { type: "function" }),
|
|
102
|
-
inferTypeName: getName(schema.name, { type: "type" }),
|
|
103
|
-
file: getFile(schema.name)
|
|
104
|
-
};
|
|
105
|
-
const type = {
|
|
106
|
-
name: getName(schema.name, { type: "type", pluginKey: [pluginTsName] }),
|
|
107
|
-
file: getFile(schema.name, { pluginKey: [pluginTsName] })
|
|
108
|
-
};
|
|
109
|
-
return /* @__PURE__ */ jsxs(
|
|
110
|
-
File,
|
|
111
|
-
{
|
|
112
|
-
baseName: zod.file.baseName,
|
|
113
|
-
path: zod.file.path,
|
|
114
|
-
meta: zod.file.meta,
|
|
115
|
-
banner: getBanner({ oas, output, config: pluginManager.config }),
|
|
116
|
-
footer: getFooter({ oas, output }),
|
|
117
|
-
children: [
|
|
118
|
-
/* @__PURE__ */ jsx(File.Import, { name: ["z"], path: importPath }),
|
|
119
|
-
typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, root: zod.file.path, path: type.file.path, name: [type.name] }),
|
|
120
|
-
typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, path: "@kubb/plugin-zod/utils", name: ["ToZod"] }),
|
|
121
|
-
imports.map((imp) => /* @__PURE__ */ jsx(File.Import, { root: zod.file.path, path: imp.path, name: imp.name }, [imp.path, imp.name, imp.isTypeOnly].join("-"))),
|
|
122
|
-
/* @__PURE__ */ jsx(
|
|
123
|
-
Zod,
|
|
124
|
-
{
|
|
125
|
-
name: zod.name,
|
|
126
|
-
typeName: typed ? type.name : void 0,
|
|
127
|
-
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
128
|
-
description: schema.value.description,
|
|
129
|
-
tree: schema.tree,
|
|
130
|
-
rawSchema: schema.value,
|
|
131
|
-
mapper,
|
|
132
|
-
coercion,
|
|
133
|
-
wrapOutput,
|
|
134
|
-
version,
|
|
135
|
-
emptySchemaType
|
|
136
|
-
}
|
|
137
|
-
)
|
|
138
|
-
]
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
var operationsGenerator = createReactGenerator({
|
|
144
|
-
name: "operations",
|
|
145
|
-
Operations({ operations }) {
|
|
146
|
-
const {
|
|
147
|
-
pluginManager,
|
|
148
|
-
plugin: {
|
|
149
|
-
key: pluginKey,
|
|
150
|
-
options: { output }
|
|
151
|
-
}
|
|
152
|
-
} = useApp();
|
|
153
|
-
const oas = useOas();
|
|
154
|
-
const { getFile, groupSchemasByName } = useOperationManager();
|
|
155
|
-
const name = "operations";
|
|
156
|
-
const file = pluginManager.getFile({ name, extname: ".ts", pluginKey });
|
|
157
|
-
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
158
|
-
const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
|
|
159
|
-
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
160
|
-
return /* @__PURE__ */ jsx(File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
161
|
-
}).filter(Boolean);
|
|
162
|
-
return /* @__PURE__ */ jsxs(
|
|
163
|
-
File,
|
|
164
|
-
{
|
|
165
|
-
baseName: file.baseName,
|
|
166
|
-
path: file.path,
|
|
167
|
-
meta: file.meta,
|
|
168
|
-
banner: getBanner({ oas, output, config: pluginManager.config }),
|
|
169
|
-
footer: getFooter({ oas, output }),
|
|
170
|
-
children: [
|
|
171
|
-
imports,
|
|
172
|
-
/* @__PURE__ */ jsx(Operations, { name, operations: transformedOperations })
|
|
173
|
-
]
|
|
174
|
-
}
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
export { operationsGenerator, zodGenerator };
|
|
180
|
-
//# sourceMappingURL=chunk-Z6ERLJH7.js.map
|
|
181
|
-
//# sourceMappingURL=chunk-Z6ERLJH7.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"names":["options","createReactGenerator","useApp","useOas","useOperationManager","jsx","File","jsxs","getBanner","getFooter"],"mappings":";;;;;;;;;AASO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAU,EAAA,cAAA,EAAgB,UAAU,KAAO,EAAA,MAAA,EAAQ,YAAe,GAAA,OAAA;AAE1E,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAAS,MAAkB,EAAA;AAC1D,IAAA,MAAM,MAAM,MAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,QAAA,KAAa,mBAAoB,EAAA;AAC9D,IAAA,MAAM,gBAAgB,gBAAiB,EAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA;AACpC,IAAM,MAAA,eAAA,GAAkB,IAAI,eAAA,CAAgB,OAAS,EAAA;AAAA,MACnD,GAAA;AAAA,MACA,MAAA;AAAA,MACA,aAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAU,OAAQ,CAAA;AAAA,KACn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KAAA;AACnC,MAAA,MAAM,QAAQ,CAAC,IAAA,CAAK,SAAS,GAAG,MAAA,CAAO,OAAO,IAAK,CAAA,SAAS,CAAG,EAAA,GAAG,OAAO,MAAO,CAAA,IAAA,CAAK,UAAU,CAAC,CAAA,CAAE,OAAO,OAAO,CAAA;AAEhH,MAAA,uBAAOC,GAAAA,CAACC,IAAK,CAAA,MAAA,EAAL,EAAsB,IAAM,EAAA,KAAA,EAAO,IAAM,EAAA,IAAA,CAAK,MAAM,IAAM,EAAA,OAAA,CAAQ,SAAS,CAAA,CAAE,QAA5D,GAAkE,CAAA;AAAA,KAC5F,CACA,CAAA,MAAA,CAAO,OAAO,CAAA;AAEjB,IAAA,uBACEC,IAAAA;AAAA,MAACD,IAAAA;AAAA,MAAA;AAAA,QACC,UAAU,IAAK,CAAA,QAAA;AAAA,QACf,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAM,IAAK,CAAA,IAAA;AAAA,QACX,MAAA,EAAQE,UAAU,EAAE,GAAA,EAAK,QAAQ,MAAQ,EAAA,aAAA,CAAc,QAAQ,CAAA;AAAA,QAC/D,MAAQC,EAAAA,SAAAA,CAAU,EAAE,GAAA,EAAK,QAAQ,CAAA;AAAA,QAEhC,QAAA,EAAA;AAAA,UAAA,OAAA;AAAA,0BACDJ,GAAAA,CAAC,UAAW,EAAA,EAAA,IAAA,EAAY,YAAY,qBAAuB,EAAA;AAAA;AAAA;AAAA,KAC7D;AAAA;AAGN,CAAC","file":"chunk-Z6ERLJH7.js","sourcesContent":["import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output, emptySchemaType },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}
|
package/dist/components.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"components.cjs"}
|
package/dist/components.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"components.js"}
|
package/dist/generators.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.cjs"}
|
package/dist/generators.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.js"}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { Output, Group, ResolveNameParams, PluginFactoryOptions } from '@kubb/core';
|
|
2
|
-
import { Oas, contentType, SchemaObject } from '@kubb/oas';
|
|
3
|
-
import { Exclude, Include, Override, Schema, Generator, ResolvePathOptions } from '@kubb/plugin-oas';
|
|
4
|
-
|
|
5
|
-
type Options = {
|
|
6
|
-
/**
|
|
7
|
-
* @default 'zod'
|
|
8
|
-
*/
|
|
9
|
-
output?: Output<Oas>;
|
|
10
|
-
/**
|
|
11
|
-
* Define which contentType should be used.
|
|
12
|
-
* By default, the first JSON valid mediaType will be used
|
|
13
|
-
*/
|
|
14
|
-
contentType?: contentType;
|
|
15
|
-
/**
|
|
16
|
-
* Group the Zod schemas based on the provided name.
|
|
17
|
-
*/
|
|
18
|
-
group?: Group;
|
|
19
|
-
/**
|
|
20
|
-
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
21
|
-
*/
|
|
22
|
-
exclude?: Array<Exclude>;
|
|
23
|
-
/**
|
|
24
|
-
* Array containing include parameters to include tags/operations/methods/paths.
|
|
25
|
-
*/
|
|
26
|
-
include?: Array<Include>;
|
|
27
|
-
/**
|
|
28
|
-
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
29
|
-
*/
|
|
30
|
-
override?: Array<Override<ResolvedOptions>>;
|
|
31
|
-
/**
|
|
32
|
-
* Path to Zod
|
|
33
|
-
* It will be used as `import { z } from '${importPath}'`.
|
|
34
|
-
* It allows both relative and absolute path.
|
|
35
|
-
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
36
|
-
* @default 'zod'
|
|
37
|
-
*/
|
|
38
|
-
importPath?: string;
|
|
39
|
-
/**
|
|
40
|
-
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
|
41
|
-
* False will fallback on a simple z.string() format
|
|
42
|
-
* @default 'string' 'stringOffset' will become the default in Kubb v3
|
|
43
|
-
*/
|
|
44
|
-
dateType?: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
45
|
-
/**
|
|
46
|
-
* Which type to use when the Swagger/OpenAPI file is not providing more information
|
|
47
|
-
* @default 'any'
|
|
48
|
-
*/
|
|
49
|
-
unknownType?: 'any' | 'unknown' | 'void';
|
|
50
|
-
/**
|
|
51
|
-
* Which type to use for empty schema values
|
|
52
|
-
* @default `unknownType`
|
|
53
|
-
*/
|
|
54
|
-
emptySchemaType?: 'any' | 'unknown' | 'void';
|
|
55
|
-
/**
|
|
56
|
-
* Use TypeScript(`@kubb/plugin-ts`) to add type annotation.
|
|
57
|
-
*/
|
|
58
|
-
typed?: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Return Zod generated schema as type with z.infer<TYPE>
|
|
61
|
-
*/
|
|
62
|
-
inferred?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Use of z.coerce.string() instead of z.string()
|
|
65
|
-
* can also be an object to enable coercion for dates, strings, and numbers
|
|
66
|
-
*/
|
|
67
|
-
coercion?: boolean | {
|
|
68
|
-
dates?: boolean;
|
|
69
|
-
strings?: boolean;
|
|
70
|
-
numbers?: boolean;
|
|
71
|
-
};
|
|
72
|
-
operations?: boolean;
|
|
73
|
-
mapper?: Record<string, string>;
|
|
74
|
-
transformers?: {
|
|
75
|
-
/**
|
|
76
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
77
|
-
*/
|
|
78
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
79
|
-
/**
|
|
80
|
-
* Receive schema and baseName(propertName) and return FakerMeta array
|
|
81
|
-
* TODO TODO add docs
|
|
82
|
-
* @beta
|
|
83
|
-
*/
|
|
84
|
-
schema?: (props: {
|
|
85
|
-
schema?: SchemaObject;
|
|
86
|
-
name?: string;
|
|
87
|
-
parentName?: string;
|
|
88
|
-
}, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Which version of Zod should be used
|
|
92
|
-
* @default '3
|
|
93
|
-
*/
|
|
94
|
-
version?: '3' | '4';
|
|
95
|
-
/**
|
|
96
|
-
* Callback function to wrap the output of the generated zod schema
|
|
97
|
-
*
|
|
98
|
-
* This is useful for edge case scenarios where you might leverage something like `z.object({ ... }).openapi({ example: { some: "complex-example" }})`
|
|
99
|
-
* or `extendApi(z.object({ ... }), { example: { some: "complex-example", ...otherOpenApiProperties }})`
|
|
100
|
-
* while going from openapi -> zod -> openapi
|
|
101
|
-
*/
|
|
102
|
-
wrapOutput?: (arg: {
|
|
103
|
-
output: string;
|
|
104
|
-
schema: SchemaObject;
|
|
105
|
-
}) => string | undefined;
|
|
106
|
-
/**
|
|
107
|
-
* Define some generators next to the zod generators
|
|
108
|
-
*/
|
|
109
|
-
generators?: Array<Generator<PluginZod>>;
|
|
110
|
-
};
|
|
111
|
-
type ResolvedOptions = {
|
|
112
|
-
output: Output<Oas>;
|
|
113
|
-
group: Options['group'];
|
|
114
|
-
override: NonNullable<Options['override']>;
|
|
115
|
-
transformers: NonNullable<Options['transformers']>;
|
|
116
|
-
dateType: NonNullable<Options['dateType']>;
|
|
117
|
-
unknownType: NonNullable<Options['unknownType']>;
|
|
118
|
-
emptySchemaType: NonNullable<Options['emptySchemaType']>;
|
|
119
|
-
typed: NonNullable<Options['typed']>;
|
|
120
|
-
inferred: NonNullable<Options['inferred']>;
|
|
121
|
-
mapper: NonNullable<Options['mapper']>;
|
|
122
|
-
importPath: NonNullable<Options['importPath']>;
|
|
123
|
-
coercion: NonNullable<Options['coercion']>;
|
|
124
|
-
operations: NonNullable<Options['operations']>;
|
|
125
|
-
wrapOutput: Options['wrapOutput'];
|
|
126
|
-
version: NonNullable<Options['version']>;
|
|
127
|
-
};
|
|
128
|
-
type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
129
|
-
|
|
130
|
-
export type { Options as O, PluginZod as P };
|