@kubb/plugin-zod 3.16.2 → 3.16.4

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 (53) hide show
  1. package/dist/components-CJ6RN1R2.js +414 -0
  2. package/dist/components-CJ6RN1R2.js.map +1 -0
  3. package/dist/components-GvkeO2ig.cjs +454 -0
  4. package/dist/components-GvkeO2ig.cjs.map +1 -0
  5. package/dist/components.cjs +3 -15
  6. package/dist/components.d.cts +56 -26
  7. package/dist/components.d.ts +56 -26
  8. package/dist/components.js +3 -3
  9. package/dist/generators-C3ALr3ph.js +254 -0
  10. package/dist/generators-C3ALr3ph.js.map +1 -0
  11. package/dist/generators-D3uH7-vO.cjs +265 -0
  12. package/dist/generators-D3uH7-vO.cjs.map +1 -0
  13. package/dist/generators.cjs +4 -16
  14. package/dist/generators.d.cts +8 -8
  15. package/dist/generators.d.ts +8 -8
  16. package/dist/generators.js +4 -4
  17. package/dist/index.cjs +103 -137
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +6 -7
  20. package/dist/index.d.ts +6 -7
  21. package/dist/index.js +103 -131
  22. package/dist/index.js.map +1 -1
  23. package/dist/types-B0UqdcbG.d.cts +1237 -0
  24. package/dist/types-YpNWeJUW.d.ts +1237 -0
  25. package/dist/utils/v4.cjs +0 -0
  26. package/dist/utils/v4.d.cts +38 -0
  27. package/dist/utils/v4.d.ts +38 -0
  28. package/dist/utils/v4.js +1 -0
  29. package/dist/utils.cjs +0 -4
  30. package/dist/utils.d.cts +18 -24
  31. package/dist/utils.d.ts +18 -24
  32. package/dist/utils.js +1 -3
  33. package/package.json +32 -31
  34. package/src/generators/zodGenerator.tsx +2 -2
  35. package/src/plugin.ts +2 -3
  36. package/src/utils/v4/ToZod.ts +61 -0
  37. package/src/utils/v4/index.ts +1 -0
  38. package/dist/chunk-4QMHDKCS.js +0 -453
  39. package/dist/chunk-4QMHDKCS.js.map +0 -1
  40. package/dist/chunk-6LDDO2JJ.cjs +0 -184
  41. package/dist/chunk-6LDDO2JJ.cjs.map +0 -1
  42. package/dist/chunk-FYI4GRXP.cjs +0 -460
  43. package/dist/chunk-FYI4GRXP.cjs.map +0 -1
  44. package/dist/chunk-I74P26CO.js +0 -181
  45. package/dist/chunk-I74P26CO.js.map +0 -1
  46. package/dist/components.cjs.map +0 -1
  47. package/dist/components.js.map +0 -1
  48. package/dist/generators.cjs.map +0 -1
  49. package/dist/generators.js.map +0 -1
  50. package/dist/types-BOF1ntMm.d.cts +0 -130
  51. package/dist/types-BOF1ntMm.d.ts +0 -130
  52. package/dist/utils.cjs.map +0 -1
  53. package/dist/utils.js.map +0 -1
@@ -1,184 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkFYI4GRXP_cjs = require('./chunk-FYI4GRXP.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
- chunkFYI4GRXP_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
- chunkFYI4GRXP_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(chunkFYI4GRXP_cjs.Operations, { name, operations: transformedOperations })
175
- ]
176
- }
177
- );
178
- }
179
- });
180
-
181
- exports.operationsGenerator = operationsGenerator;
182
- exports.zodGenerator = zodGenerator;
183
- //# sourceMappingURL=chunk-6LDDO2JJ.cjs.map
184
- //# sourceMappingURL=chunk-6LDDO2JJ.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,GAAqB,CAAC,EAAE,IAAM,EAAA,MAAA,EAA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AA,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-6LDDO2JJ.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"]}
@@ -1,460 +0,0 @@
1
- 'use strict';
2
-
3
- var react = require('@kubb/react');
4
- var transformers2 = require('@kubb/core/transformers');
5
- var jsxRuntime = require('@kubb/react/jsx-runtime');
6
- var pluginOas = require('@kubb/plugin-oas');
7
-
8
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
-
10
- var transformers2__default = /*#__PURE__*/_interopDefault(transformers2);
11
-
12
- // src/components/Operations.tsx
13
- function Operations({ name, operations }) {
14
- const operationsJSON = operations.reduce(
15
- (prev, acc) => {
16
- prev[`"${acc.operation.getOperationId()}"`] = acc.data;
17
- return prev;
18
- },
19
- {}
20
- );
21
- const pathsJSON = operations.reduce(
22
- (prev, acc) => {
23
- prev[`"${acc.operation.path}"`] = {
24
- ...prev[`"${acc.operation.path}"`] || {},
25
- [acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
26
- };
27
- return prev;
28
- },
29
- {}
30
- );
31
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
32
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Const, { export: true, name, asConst: true, children: `{${transformers2__default.default.stringifyObject(operationsJSON)}}` }) }),
33
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: "paths", isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Const, { export: true, name: "paths", asConst: true, children: `{${transformers2__default.default.stringifyObject(pathsJSON)}}` }) })
34
- ] });
35
- }
36
- var zodKeywordMapper = {
37
- any: () => "z.any()",
38
- unknown: () => "z.unknown()",
39
- void: () => "z.void()",
40
- number: (coercion, min, max) => {
41
- return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
42
- },
43
- integer: (coercion, min, max, version = "3") => {
44
- return [
45
- coercion ? "z.coerce.number().int()" : version === "4" ? "z.int()" : "z.number().int()",
46
- min !== void 0 ? `.min(${min})` : void 0,
47
- max !== void 0 ? `.max(${max})` : void 0
48
- ].filter(Boolean).join("");
49
- },
50
- interface: (value, strict) => {
51
- if (strict) {
52
- return `z.strictInterface({
53
- ${value}
54
- })`;
55
- }
56
- return `z.interface({
57
- ${value}
58
- })`;
59
- },
60
- object: (value, strict, version = "3") => {
61
- if (version === "4" && strict) {
62
- return `z.strictObject({
63
- ${value}
64
- })`;
65
- }
66
- if (strict) {
67
- return `z.object({
68
- ${value}
69
- }).strict()`;
70
- }
71
- return `z.object({
72
- ${value}
73
- })`;
74
- },
75
- string: (coercion, min, max) => {
76
- return [coercion ? "z.coerce.string()" : "z.string()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
77
- },
78
- //support for discriminatedUnion
79
- boolean: () => "z.boolean()",
80
- undefined: () => "z.undefined()",
81
- nullable: () => ".nullable()",
82
- null: () => "z.null()",
83
- nullish: () => ".nullish()",
84
- array: (items = [], min, max, unique) => {
85
- return [
86
- `z.array(${items?.join("")})`,
87
- min !== void 0 ? `.min(${min})` : void 0,
88
- max !== void 0 ? `.max(${max})` : void 0,
89
- unique ? `.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })` : void 0
90
- ].filter(Boolean).join("");
91
- },
92
- tuple: (items = []) => `z.tuple([${items?.join(", ")}])`,
93
- enum: (items = []) => `z.enum([${items?.join(", ")}])`,
94
- union: (items = []) => `z.union([${items?.join(", ")}])`,
95
- const: (value) => `z.literal(${value ?? ""})`,
96
- /**
97
- * ISO 8601
98
- */
99
- datetime: (offset = false, local = false, version = "3") => {
100
- if (offset) {
101
- return version === "4" ? `z.iso.datetime({ offset: ${offset} })` : `z.string().datetime({ offset: ${offset} })`;
102
- }
103
- if (local) {
104
- return version === "4" ? `z.iso.datetime({ local: ${local} })` : `z.string().datetime({ local: ${local} })`;
105
- }
106
- return "z.string().datetime()";
107
- },
108
- /**
109
- * Type `'date'` Date
110
- * Type `'string'` ISO date format (YYYY-MM-DD)
111
- * @default ISO date format (YYYY-MM-DD)
112
- */
113
- date: (type = "string", coercion, version = "3") => {
114
- if (type === "string") {
115
- return version === "4" ? "z.iso.date()" : "z.string().date()";
116
- }
117
- if (coercion) {
118
- return "z.coerce.date()";
119
- }
120
- return "z.date()";
121
- },
122
- /**
123
- * Type `'date'` Date
124
- * Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])
125
- * @default ISO time format (HH:mm:ss[.SSSSSS])
126
- */
127
- time: (type = "string", coercion, version = "3") => {
128
- if (type === "string") {
129
- return version === "4" ? "z.iso.time()" : "z.string().time()";
130
- }
131
- if (coercion) {
132
- return "z.coerce.date()";
133
- }
134
- return "z.date()";
135
- },
136
- uuid: (coercion, version = "3") => version === "4" ? coercion ? "z.coerce.string().uuid()" : "z.uuid()" : coercion ? "z.coerce.string().uuid()" : "z.string().uuid()",
137
- url: (coercion, version = "3") => version === "4" ? coercion ? "z.coerce.string().url()" : "z.url()" : coercion ? "z.coerce.string().url()" : "z.string().url()",
138
- default: (value) => {
139
- if (typeof value === "object") {
140
- return ".default({})";
141
- }
142
- return `.default(${value ?? ""})`;
143
- },
144
- and: (items = []) => items?.map((item) => `.and(${item})`).join(""),
145
- describe: (value = "") => `.describe(${value})`,
146
- min: (value) => `.min(${value ?? ""})`,
147
- max: (value) => `.max(${value ?? ""})`,
148
- optional: () => ".optional()",
149
- matches: (value = "", coercion) => coercion ? `z.coerce.string().regex(${value})` : `z.string().regex(${value})`,
150
- email: (coercion, version = "3") => version === "4" ? coercion ? "z.coerce.string().email()" : "z.email()" : coercion ? "z.coerce.string().email()" : "z.string().email()",
151
- firstName: void 0,
152
- lastName: void 0,
153
- password: void 0,
154
- phone: void 0,
155
- readOnly: void 0,
156
- writeOnly: void 0,
157
- ref: (value, version = "3") => {
158
- if (!value) {
159
- return void 0;
160
- }
161
- return version === "4" ? value : `z.lazy(() => ${value})`;
162
- },
163
- blob: () => "z.instanceof(File)",
164
- deprecated: void 0,
165
- example: void 0,
166
- schema: void 0,
167
- catchall: (value) => value ? `.catchall(${value})` : void 0,
168
- name: void 0
169
- };
170
- function sort(items) {
171
- const order = [
172
- pluginOas.schemaKeywords.string,
173
- pluginOas.schemaKeywords.datetime,
174
- pluginOas.schemaKeywords.date,
175
- pluginOas.schemaKeywords.time,
176
- pluginOas.schemaKeywords.tuple,
177
- pluginOas.schemaKeywords.number,
178
- pluginOas.schemaKeywords.object,
179
- pluginOas.schemaKeywords.enum,
180
- pluginOas.schemaKeywords.url,
181
- pluginOas.schemaKeywords.email,
182
- pluginOas.schemaKeywords.firstName,
183
- pluginOas.schemaKeywords.lastName,
184
- pluginOas.schemaKeywords.password,
185
- pluginOas.schemaKeywords.matches,
186
- pluginOas.schemaKeywords.uuid,
187
- pluginOas.schemaKeywords.null,
188
- pluginOas.schemaKeywords.min,
189
- pluginOas.schemaKeywords.max,
190
- pluginOas.schemaKeywords.default,
191
- pluginOas.schemaKeywords.describe,
192
- pluginOas.schemaKeywords.optional,
193
- pluginOas.schemaKeywords.nullable,
194
- pluginOas.schemaKeywords.nullish
195
- ];
196
- if (!items) {
197
- return [];
198
- }
199
- return transformers2__default.default.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
200
- }
201
- var shouldCoerce = (coercion, type) => {
202
- if (coercion === void 0) {
203
- return false;
204
- }
205
- if (typeof coercion === "boolean") {
206
- return coercion;
207
- }
208
- return !!coercion[type];
209
- };
210
- function parse({ parent, current, name, siblings }, options) {
211
- const value = zodKeywordMapper[current.keyword];
212
- const hasMatches = siblings.some((it) => pluginOas.isKeyword(it, pluginOas.schemaKeywords.matches));
213
- const hasRef = siblings.some((it) => pluginOas.isKeyword(it, pluginOas.schemaKeywords.ref));
214
- if (hasMatches && hasRef && pluginOas.isKeyword(current, pluginOas.schemaKeywords.matches)) {
215
- return void 0;
216
- }
217
- if (!value) {
218
- return void 0;
219
- }
220
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.union)) {
221
- if (Array.isArray(current.args) && current.args.length === 1) {
222
- return parse({ parent, name, current: current.args[0], siblings }, options);
223
- }
224
- if (Array.isArray(current.args) && !current.args.length) {
225
- return "";
226
- }
227
- return zodKeywordMapper.union(
228
- sort(current.args).map((schema, _index, siblings2) => parse({ parent: current, name, current: schema, siblings: siblings2 }, options)).filter(Boolean)
229
- );
230
- }
231
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.and)) {
232
- const items = sort(current.args).filter((schema) => {
233
- return ![pluginOas.schemaKeywords.optional, pluginOas.schemaKeywords.describe].includes(schema.keyword);
234
- }).map((schema, _index, siblings2) => parse({ parent: current, name, current: schema, siblings: siblings2 }, options)).filter(Boolean);
235
- return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`;
236
- }
237
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.array)) {
238
- return zodKeywordMapper.array(
239
- sort(current.args.items).map((schemas, _index, siblings2) => parse({ parent: current, name, current: schemas, siblings: siblings2 }, options)).filter(Boolean),
240
- current.args.min,
241
- current.args.max,
242
- current.args.unique
243
- );
244
- }
245
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.enum)) {
246
- if (current.args.asConst) {
247
- if (current.args.items.length === 1) {
248
- const child = {
249
- keyword: pluginOas.schemaKeywords.const,
250
- args: current.args.items[0]
251
- };
252
- return parse({ parent: current, name, current: child, siblings: [child] }, options);
253
- }
254
- return zodKeywordMapper.union(
255
- current.args.items.map((schema) => ({
256
- keyword: pluginOas.schemaKeywords.const,
257
- args: schema
258
- })).map((schema, _index, siblings2) => {
259
- return parse({ parent: current, name, current: schema, siblings: siblings2 }, options);
260
- }).filter(Boolean)
261
- );
262
- }
263
- return zodKeywordMapper.enum(
264
- current.args.items.map((schema) => {
265
- if (schema.format === "boolean") {
266
- return transformers2__default.default.stringify(schema.value);
267
- }
268
- if (schema.format === "number") {
269
- return transformers2__default.default.stringify(schema.value);
270
- }
271
- return transformers2__default.default.stringify(schema.value);
272
- })
273
- );
274
- }
275
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.ref)) {
276
- return zodKeywordMapper.ref(current.args?.name, options.version);
277
- }
278
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.object)) {
279
- const propertyEntries = Object.entries(current.args?.properties || {}).filter((item) => {
280
- const schema = item[1];
281
- return schema && typeof schema.map === "function";
282
- });
283
- const properties = propertyEntries.map(([name2, schemas]) => {
284
- const nameSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.name);
285
- const mappedName = nameSchema?.args || name2;
286
- if (options.mapper?.[mappedName]) {
287
- return `"${name2}": ${options.mapper?.[mappedName]}`;
288
- }
289
- const baseSchemaOutput = sort(schemas).map((schema) => parse({ parent: current, name: name2, current: schema, siblings: schemas }, options)).filter(Boolean).join("");
290
- const objectValue = options.wrapOutput ? options.wrapOutput({ output: baseSchemaOutput, schema: options.rawSchema?.properties?.[name2] }) || baseSchemaOutput : baseSchemaOutput;
291
- if (options.version === "4" && pluginOas.SchemaGenerator.find(schemas, pluginOas.schemaKeywords.ref)) {
292
- return `get ${name2}(){
293
- return ${objectValue}
294
- }`;
295
- }
296
- return `"${name2}": ${objectValue}`;
297
- }).join(",\n");
298
- const additionalProperties = current.args?.additionalProperties?.length ? current.args.additionalProperties.map((schema, _index, siblings2) => parse({ parent: current, name, current: schema, siblings: siblings2 }, options)).filter(Boolean).join("") : void 0;
299
- const text = [
300
- zodKeywordMapper.object(properties, current.args?.strict, options.version),
301
- additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : void 0
302
- ].filter(Boolean);
303
- return text.join("");
304
- }
305
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.tuple)) {
306
- return zodKeywordMapper.tuple(
307
- current.args.items.map((schema, _index, siblings2) => parse({ parent: current, name, current: schema, siblings: siblings2 }, options)).filter(Boolean)
308
- );
309
- }
310
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.const)) {
311
- if (current.args.format === "number" && current.args.value !== void 0) {
312
- return zodKeywordMapper.const(Number(current.args.value));
313
- }
314
- if (current.args.format === "boolean" && current.args.value !== void 0) {
315
- return zodKeywordMapper.const(current.args.value);
316
- }
317
- return zodKeywordMapper.const(transformers2__default.default.stringify(current.args.value));
318
- }
319
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.matches)) {
320
- if (current.args) {
321
- return zodKeywordMapper.matches(transformers2__default.default.toRegExpString(current.args, null), shouldCoerce(options.coercion, "strings"));
322
- }
323
- }
324
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.default)) {
325
- if (current.args) {
326
- return zodKeywordMapper.default(current.args);
327
- }
328
- }
329
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.describe)) {
330
- if (current.args) {
331
- return zodKeywordMapper.describe(transformers2__default.default.stringify(current.args.toString()));
332
- }
333
- }
334
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.string)) {
335
- return zodKeywordMapper.string(shouldCoerce(options.coercion, "strings"));
336
- }
337
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.uuid)) {
338
- return zodKeywordMapper.uuid(shouldCoerce(options.coercion, "strings"), options.version);
339
- }
340
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.email)) {
341
- return zodKeywordMapper.email(shouldCoerce(options.coercion, "strings"), options.version);
342
- }
343
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.url)) {
344
- return zodKeywordMapper.url(shouldCoerce(options.coercion, "strings"), options.version);
345
- }
346
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.number)) {
347
- return zodKeywordMapper.number(shouldCoerce(options.coercion, "numbers"));
348
- }
349
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.integer)) {
350
- return zodKeywordMapper.integer(shouldCoerce(options.coercion, "numbers"), void 0, void 0, options.version);
351
- }
352
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.min)) {
353
- return zodKeywordMapper.min(current.args);
354
- }
355
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.max)) {
356
- return zodKeywordMapper.max(current.args);
357
- }
358
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.datetime)) {
359
- return zodKeywordMapper.datetime(current.args.offset, current.args.local, options.version);
360
- }
361
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.date)) {
362
- return zodKeywordMapper.date(current.args.type, shouldCoerce(options.coercion, "dates"), options.version);
363
- }
364
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.time)) {
365
- return zodKeywordMapper.time(current.args.type, shouldCoerce(options.coercion, "dates"), options.version);
366
- }
367
- if (current.keyword in zodKeywordMapper && "args" in current) {
368
- const value2 = zodKeywordMapper[current.keyword];
369
- return value2(current.args);
370
- }
371
- if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.optional)) {
372
- if (siblings.some((schema) => pluginOas.isKeyword(schema, pluginOas.schemaKeywords.default))) return "";
373
- return value();
374
- }
375
- if (current.keyword in zodKeywordMapper) {
376
- return value();
377
- }
378
- return void 0;
379
- }
380
- function Zod({
381
- name,
382
- typeName,
383
- tree,
384
- rawSchema,
385
- inferTypeName,
386
- mapper,
387
- coercion,
388
- keysToOmit,
389
- description,
390
- wrapOutput,
391
- version,
392
- emptySchemaType
393
- }) {
394
- const hasTuple = !!pluginOas.SchemaGenerator.deepSearch(tree, pluginOas.schemaKeywords.tuple);
395
- const schemas = sort(tree).filter((item) => {
396
- if (hasTuple && (pluginOas.isKeyword(item, pluginOas.schemaKeywords.min) || pluginOas.isKeyword(item, pluginOas.schemaKeywords.max))) {
397
- return false;
398
- }
399
- return true;
400
- });
401
- const output = schemas.map(
402
- (schema, _index, siblings) => parse(
403
- { parent: void 0, current: schema, siblings },
404
- { name, keysToOmit, typeName, description, mapper, coercion, wrapOutput, rawSchema, version }
405
- )
406
- ).filter(Boolean).join("");
407
- let suffix = "";
408
- const firstSchema = schemas.at(0);
409
- const lastSchema = schemas.at(-1);
410
- if (lastSchema && pluginOas.isKeyword(lastSchema, pluginOas.schemaKeywords.nullable)) {
411
- if (firstSchema && pluginOas.isKeyword(firstSchema, pluginOas.schemaKeywords.ref)) {
412
- if (version === "3") {
413
- suffix = ".unwrap().schema.unwrap()";
414
- } else {
415
- suffix = ".unwrap().unwrap()";
416
- }
417
- } else {
418
- suffix = ".unwrap()";
419
- }
420
- } else {
421
- if (firstSchema && pluginOas.isKeyword(firstSchema, pluginOas.schemaKeywords.ref) && version === "3") {
422
- suffix = ".schema";
423
- }
424
- }
425
- const emptyValue = parse(
426
- {
427
- parent: void 0,
428
- current: {
429
- keyword: pluginOas.schemaKeywords[emptySchemaType]
430
- },
431
- siblings: []
432
- },
433
- { name, keysToOmit, typeName, description, mapper, coercion, wrapOutput, rawSchema, version }
434
- );
435
- const baseSchemaOutput = [output, keysToOmit?.length ? `${suffix}.omit({ ${keysToOmit.map((key) => `${key}: true`).join(",")} })` : void 0].filter(Boolean).join("") || emptyValue || "";
436
- const wrappedSchemaOutput = wrapOutput ? wrapOutput({ output: baseSchemaOutput, schema: rawSchema }) || baseSchemaOutput : baseSchemaOutput;
437
- const finalOutput = typeName ? `${wrappedSchemaOutput} as unknown as ToZod<${typeName}>` : wrappedSchemaOutput;
438
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
439
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
440
- react.Const,
441
- {
442
- export: true,
443
- name,
444
- JSDoc: {
445
- comments: [description ? `@description ${transformers2__default.default.jsStringEscape(description)}` : void 0].filter(Boolean)
446
- },
447
- children: finalOutput
448
- }
449
- ) }),
450
- inferTypeName && /* @__PURE__ */ jsxRuntime.jsxs(react.File.Source, { name: inferTypeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: [
451
- typeName && /* @__PURE__ */ jsxRuntime.jsx(react.Type, { export: true, name: inferTypeName, children: typeName }),
452
- !typeName && /* @__PURE__ */ jsxRuntime.jsx(react.Type, { export: true, name: inferTypeName, children: `z.infer<typeof ${name}>` })
453
- ] })
454
- ] });
455
- }
456
-
457
- exports.Operations = Operations;
458
- exports.Zod = Zod;
459
- //# sourceMappingURL=chunk-FYI4GRXP.cjs.map
460
- //# sourceMappingURL=chunk-FYI4GRXP.cjs.map