@orval/zod 6.19.1 → 6.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +422 -6
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,8 +1,424 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _core = require('@orval/core');var _lodashuniq = require('lodash.uniq'); var _lodashuniq2 = _interopRequireDefault(_lodashuniq);var _=[{exports:[{name:"z",alias:"zod",values:!0}],dependency:"zod"}],N= exports.getZodDependencies =()=>_,T=e=>{switch(e){case"integer":return"number";case"null":return"mixed";default:return e!=null?e:"any"}},D=(e,d,t)=>{var Z,k,x,O,q,G,W,$,g,h,z,y;if(!e)return{functions:[],consts:[]};let b=[],n=[],r=T(e.type),i=e.default!==void 0?!1:d!=null?d:!1,s=(Z=e.nullable)!=null?Z:!1,u=(q=(O=(x=(k=e.minimum)!=null?k:e.exclusiveMinimum)!=null?x:e.minLength)!=null?O:e.minItems)!=null?q:void 0,f=(g=($=(W=(G=e.maximum)!=null?G:e.exclusiveMaximum)!=null?W:e.maxLength)!=null?$:e.maxItems)!=null?g:void 0,a=(h=e.pattern)!=null?h:void 0;switch(r){case"array":let m=e.items;n.push(["array",D(m,!0,_core.camel.call(void 0, t))]);break;case"string":{if(e.enum&&r==="string")break;if(n.push([r,void 0]),e.format==="date"){n.push(["regex","new RegExp(/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/)"]);break}if(e.format==="date-time"){n.push(["datetime",void 0]);break}if(e.format==="email"){n.push(["email",void 0]);break}if(e.format==="uri"||e.format==="hostname"){n.push(["url",void 0]);break}if(e.format==="uuid"){n.push(["uuid",void 0]);break}break}case"object":default:{if(e.allOf||e.oneOf||e.anyOf){let p=e.allOf?"allOf":e.oneOf?"oneOf":"anyOf",l=(y=(z=e.allOf)!=null?z:e.oneOf)!=null?y:e.anyOf;n.push([p,l.map(P=>D(P,!0,_core.camel.call(void 0, t)))]);break}if(e.properties){n.push(["object",Object.keys(e.properties).map(p=>{var l,P;return{[p]:D((l=e.properties)==null?void 0:l[p],(P=e.required)==null?void 0:P.includes(p),_core.camel.call(void 0, `${t}-${p}`))}}).reduce((p,l)=>({...p,...l}),{})]);break}if(e.additionalProperties){n.push(["additionalProperties",_core.isBoolean.call(void 0, e.additionalProperties)?e.additionalProperties:D(e.additionalProperties,!0,t)]);break}n.push([r,void 0]);break}}if(u!==void 0&&(u===1?n.push(["min",`${u}`]):(b.push(`export const ${t}Min = ${u};`),n.push(["min",`${t}Min`]))),f!==void 0&&(b.push(`export const ${t}Max = ${f};`),n.push(["max",`${t}Max`])),a){let m=a.startsWith("/"),p=a.endsWith("/"),l=`new RegExp('${_core.jsStringEscape.call(void 0, a.slice(m?1:0,p?-1:void 0))}')`;b.push(`export const ${t}RegExp = ${l};`),n.push(["regex",`${t}RegExp`])}return e.enum&&r!=="number"&&n.push(["enum",[`[${e.enum.map(m=>_core.isString.call(void 0, m)?`'${_core.escape.call(void 0, m)}'`:`${m}`).join(", ")}]`]]),!i&&s?n.push(["nullish",void 0]):s?n.push(["nullable",void 0]):i||n.push(["optional",void 0]),{functions:n,consts:_lodashuniq2.default.call(void 0, b)}},B=e=>{if(!Object.keys(e).length)return{zod:"",consts:""};let d="",t=n=>{let[r,i=""]=n;if(r==="allOf")return i.reduce((s,{functions:u})=>{let f=u.map(t).join(""),a=`${f.startsWith(".")?"zod":""}${f}`;return s?(s+=`.and(${a})`,s):(s+=a,s)},"");if(r==="oneOf"||r==="anyOf")return i.reduce((s,{functions:u})=>{let f=u.map(t).join(""),a=`${f.startsWith(".")?"zod":""}${f}`;return s?(s+=`.or(${a})`,s):(s+=a,s)},"");if(r==="additionalProperties"){let s=i.functions.map(t).join(""),u=`${s.startsWith(".")?"zod":""}${s}`;return d+=i.consts,`zod.record(zod.string(), ${u})`}if(r==="object"){let s=B(i);return d+=s.consts,` ${s.zod}`}if(r==="array"){let s=i.functions.map(t).join("");return d+=i.consts,`.array(${s.startsWith(".")?"zod":""}${s})`}return`.${r}(${i})`};return d+=Object.entries(e).reduce((n,[r,i])=>n+i.consts.join(`
2
- `),""),{zod:`zod.object({
3
- ${Object.entries(e).map(([n,r])=>{let i=r.functions.map(t).join("");return`"${n}": ${i.startsWith(".")?"zod":""}${i}`}).join(",")}
4
- })`,consts:d}},K=(e,d)=>_core.isObject.call(void 0, e)?I(e,d):Array.isArray(e)?e.map(t=>K(t,d)):e,I=(e,d)=>{var r;let t="$ref"in e?e.$ref:void 0;if(t&&((r=d.parents)==null?void 0:r.includes(t)))return{};let b={...d,...t?{parents:[...d.parents||[],t]}:void 0},{schema:n}=_core.resolveRef.call(void 0, e,b);return Object.entries(n).reduce((i,[s,u])=>(i[s]=K(u,b),i),{})},J=({operationName:e,body:d,verb:t},{pathRoute:b,context:n})=>{var m,p,l,P,M,w,A,H,L,Q;let r=n.specs[n.specKey].paths[b],i=(m=r==null?void 0:r[t])==null?void 0:m.parameters,s=(p=r==null?void 0:r[t])==null?void 0:p.requestBody,u=(P=(l=r==null?void 0:r[t])==null?void 0:l.responses)==null?void 0:P["200"],f=u?_core.resolveRef.call(void 0, u,n).schema:void 0,a=(w=(M=f==null?void 0:f.content)==null?void 0:M["application/json"])!=null&&w.schema?_core.resolveRef.call(void 0, f.content["application/json"].schema,n).schema:void 0,Z=(A=a==null?void 0:a.properties)!=null?A:{},k=Object.entries(Z).map(([o,j])=>{var S;let c=I(j,n);return{[o]:D(c,!!((S=a==null?void 0:a.required)!=null&&S.find(R=>R===o)),_core.camel.call(void 0, `${e}-response-${o}`))}}).reduce((o,j)=>({...o,...j}),{}),x=s?_core.resolveRef.call(void 0, s,n).schema:void 0,O=(L=(H=x==null?void 0:x.content)==null?void 0:H["application/json"])!=null&&L.schema?_core.resolveRef.call(void 0, x.content["application/json"].schema,n).schema:void 0,q=(Q=O==null?void 0:O.properties)!=null?Q:{},G=Object.entries(q).map(([o,j])=>{var S;let c=I(j,n);return{[o]:D(c,!!((S=O==null?void 0:O.required)!=null&&S.find(R=>R===o)),_core.camel.call(void 0, `${e}-body-${o}`))}}).reduce((o,j)=>({...o,...j}),{}),W=(i!=null?i:[]).reduce((o,j)=>{let{schema:c}=_core.resolveRef.call(void 0, j,n);if(!c.schema)return o;let S=I(c.schema,n),R=D(S,c.required,_core.camel.call(void 0, `${e}-${c.in}-${c.name}`));return c.in==="header"?{...o,headers:{...o.headers,[c.name]:R}}:c.in==="query"?{...o,queryParams:{...o.queryParams,[c.name]:R}}:c.in==="path"?{...o,params:{...o.params,[c.name]:R}}:o},{headers:{},queryParams:{},params:{}}),$=B(W.params),g=B(W.queryParams),h=B(W.headers),z=B(G),y=B(k);return!$.zod&&!g.zod&&!h.zod&&!z.zod&&!y.zod?"":[...$.consts?[$.consts]:[],...$.zod?[`export const ${e}Params = ${$.zod}`]:[],...g.consts?[g.consts]:[],...g.zod?[`export const ${e}QueryParams = ${g.zod}`]:[],...h.consts?[h.consts]:[],...h.zod?[`export const ${e}Header = ${h.zod}`]:[],...z.consts?[z.consts]:[],...z.zod?[`export const ${e}Body = ${z.zod}`]:[],...y.consts?[y.consts]:[],...y.zod?[`export const ${e}Response = ${y.zod}`]:[]].join(`
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
5
29
 
6
- `)},ee= exports.generateZod =(e,d)=>{let t=J(e,d);return{implementation:t?`${t}
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ builder: () => builder,
34
+ default: () => src_default,
35
+ generateZod: () => generateZod,
36
+ getZodDependencies: () => getZodDependencies
37
+ });
38
+ module.exports = __toCommonJS(src_exports);
39
+ var import_core = require("@orval/core");
40
+ var import_lodash = __toESM(require("lodash.uniq"));
41
+ var ZOD_DEPENDENCIES = [
42
+ {
43
+ exports: [
44
+ {
45
+ name: "z",
46
+ alias: "zod",
47
+ values: true
48
+ }
49
+ ],
50
+ dependency: "zod"
51
+ }
52
+ ];
53
+ var getZodDependencies = () => ZOD_DEPENDENCIES;
54
+ var resolveZodType = (schemaTypeValue) => {
55
+ switch (schemaTypeValue) {
56
+ case "integer":
57
+ return "number";
58
+ case "null":
59
+ return "mixed";
60
+ default:
61
+ return schemaTypeValue != null ? schemaTypeValue : "any";
62
+ }
63
+ };
64
+ var generateZodValidationSchemaDefinition = (schema, _required, name) => {
65
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
66
+ if (!schema)
67
+ return { functions: [], consts: [] };
68
+ const consts = [];
69
+ const functions = [];
70
+ const type = resolveZodType(schema.type);
71
+ const required = schema.default !== void 0 ? false : _required != null ? _required : false;
72
+ const nullable = (_a = schema.nullable) != null ? _a : false;
73
+ const min = (_e = (_d = (_c = (_b = schema.minimum) != null ? _b : schema.exclusiveMinimum) != null ? _c : schema.minLength) != null ? _d : schema.minItems) != null ? _e : void 0;
74
+ const max = (_i = (_h = (_g = (_f = schema.maximum) != null ? _f : schema.exclusiveMaximum) != null ? _g : schema.maxLength) != null ? _h : schema.maxItems) != null ? _i : void 0;
75
+ const matches = (_j = schema.pattern) != null ? _j : void 0;
76
+ switch (type) {
77
+ case "array":
78
+ const items = schema.items;
79
+ functions.push([
80
+ "array",
81
+ generateZodValidationSchemaDefinition(items, true, (0, import_core.camel)(name))
82
+ ]);
83
+ break;
84
+ case "string": {
85
+ if (schema.enum && type === "string") {
86
+ break;
87
+ }
88
+ functions.push([type, void 0]);
89
+ if (schema.format === "date") {
90
+ functions.push(["regex", "new RegExp(/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/)"]);
91
+ break;
92
+ }
93
+ if (schema.format === "date-time") {
94
+ functions.push(["datetime", void 0]);
95
+ break;
96
+ }
97
+ if (schema.format === "email") {
98
+ functions.push(["email", void 0]);
99
+ break;
100
+ }
101
+ if (schema.format === "uri" || schema.format === "hostname") {
102
+ functions.push(["url", void 0]);
103
+ break;
104
+ }
105
+ if (schema.format === "uuid") {
106
+ functions.push(["uuid", void 0]);
107
+ break;
108
+ }
109
+ break;
110
+ }
111
+ case "object":
112
+ default: {
113
+ if (schema.allOf || schema.oneOf || schema.anyOf) {
114
+ const separator = schema.allOf ? "allOf" : schema.oneOf ? "oneOf" : "anyOf";
115
+ const schemas = (_l = (_k = schema.allOf) != null ? _k : schema.oneOf) != null ? _l : schema.anyOf;
116
+ functions.push([
117
+ separator,
118
+ schemas.map(
119
+ (schema2) => generateZodValidationSchemaDefinition(
120
+ schema2,
121
+ true,
122
+ (0, import_core.camel)(name)
123
+ )
124
+ )
125
+ ]);
126
+ break;
127
+ }
128
+ if (schema.properties) {
129
+ functions.push([
130
+ "object",
131
+ Object.keys(schema.properties).map((key) => {
132
+ var _a2, _b2;
133
+ return {
134
+ [key]: generateZodValidationSchemaDefinition(
135
+ (_a2 = schema.properties) == null ? void 0 : _a2[key],
136
+ (_b2 = schema.required) == null ? void 0 : _b2.includes(key),
137
+ (0, import_core.camel)(`${name}-${key}`)
138
+ )
139
+ };
140
+ }).reduce((acc, curr) => ({ ...acc, ...curr }), {})
141
+ ]);
142
+ break;
143
+ }
144
+ if (schema.additionalProperties) {
145
+ functions.push([
146
+ "additionalProperties",
147
+ (0, import_core.isBoolean)(schema.additionalProperties) ? schema.additionalProperties : generateZodValidationSchemaDefinition(
148
+ schema.additionalProperties,
149
+ true,
150
+ name
151
+ )
152
+ ]);
153
+ break;
154
+ }
155
+ functions.push([type, void 0]);
156
+ break;
157
+ }
158
+ }
159
+ if (min !== void 0) {
160
+ if (min === 1) {
161
+ functions.push(["min", `${min}`]);
162
+ } else {
163
+ consts.push(`export const ${name}Min = ${min};`);
164
+ functions.push(["min", `${name}Min`]);
165
+ }
166
+ }
167
+ if (max !== void 0) {
168
+ consts.push(`export const ${name}Max = ${max};`);
169
+ functions.push(["max", `${name}Max`]);
170
+ }
171
+ if (matches) {
172
+ const isStartWithSlash = matches.startsWith("/");
173
+ const isEndWithSlash = matches.endsWith("/");
174
+ const regexp = `new RegExp('${(0, import_core.jsStringEscape)(
175
+ matches.slice(isStartWithSlash ? 1 : 0, isEndWithSlash ? -1 : void 0)
176
+ )}')`;
177
+ consts.push(`export const ${name}RegExp = ${regexp};`);
178
+ functions.push(["regex", `${name}RegExp`]);
179
+ }
180
+ if (schema.enum && type !== "number") {
181
+ functions.push([
182
+ "enum",
183
+ [
184
+ `[${schema.enum.map((value) => (0, import_core.isString)(value) ? `'${(0, import_core.escape)(value)}'` : `${value}`).join(", ")}]`
185
+ ]
186
+ ]);
187
+ }
188
+ if (!required && nullable) {
189
+ functions.push(["nullish", void 0]);
190
+ } else if (nullable) {
191
+ functions.push(["nullable", void 0]);
192
+ } else if (!required) {
193
+ functions.push(["optional", void 0]);
194
+ }
195
+ return { functions, consts: (0, import_lodash.default)(consts) };
196
+ };
197
+ var parseZodValidationSchemaDefinition = (input) => {
198
+ if (!Object.keys(input).length) {
199
+ return { zod: "", consts: "" };
200
+ }
201
+ let consts = "";
202
+ const parseProperty = (property) => {
203
+ const [fn, args = ""] = property;
204
+ if (fn === "allOf") {
205
+ return args.reduce(
206
+ (acc, { functions }) => {
207
+ const value = functions.map(parseProperty).join("");
208
+ const valueWithZod = `${value.startsWith(".") ? "zod" : ""}${value}`;
209
+ if (!acc) {
210
+ acc += valueWithZod;
211
+ return acc;
212
+ }
213
+ acc += `.and(${valueWithZod})`;
214
+ return acc;
215
+ },
216
+ ""
217
+ );
218
+ }
219
+ if (fn === "oneOf" || fn === "anyOf") {
220
+ return args.reduce(
221
+ (acc, { functions }) => {
222
+ const value = functions.map(parseProperty).join("");
223
+ const valueWithZod = `${value.startsWith(".") ? "zod" : ""}${value}`;
224
+ if (!acc) {
225
+ acc += valueWithZod;
226
+ return acc;
227
+ }
228
+ acc += `.or(${valueWithZod})`;
229
+ return acc;
230
+ },
231
+ ""
232
+ );
233
+ }
234
+ if (fn === "additionalProperties") {
235
+ const value = args.functions.map(parseProperty).join("");
236
+ const valueWithZod = `${value.startsWith(".") ? "zod" : ""}${value}`;
237
+ consts += args.consts;
238
+ return `zod.record(zod.string(), ${valueWithZod})`;
239
+ }
240
+ if (fn === "object") {
241
+ const parsed = parseZodValidationSchemaDefinition(args);
242
+ consts += parsed.consts;
243
+ return ` ${parsed.zod}`;
244
+ }
245
+ if (fn === "array") {
246
+ const value = args.functions.map(parseProperty).join("");
247
+ consts += args.consts;
248
+ return `.array(${value.startsWith(".") ? "zod" : ""}${value})`;
249
+ }
250
+ return `.${fn}(${args})`;
251
+ };
252
+ consts += Object.entries(input).reduce((acc, [key, schema]) => {
253
+ return acc + schema.consts.join("\n");
254
+ }, "");
255
+ const zod = `zod.object({
256
+ ${Object.entries(input).map(([key, schema]) => {
257
+ const value = schema.functions.map(parseProperty).join("");
258
+ return `"${key}": ${value.startsWith(".") ? "zod" : ""}${value}`;
259
+ }).join(",")}
260
+ })`;
261
+ return { zod, consts };
262
+ };
263
+ var deferenceScalar = (value, context) => {
264
+ if ((0, import_core.isObject)(value)) {
265
+ return deference(value, context);
266
+ } else if (Array.isArray(value)) {
267
+ return value.map((item) => deferenceScalar(item, context));
268
+ } else {
269
+ return value;
270
+ }
271
+ };
272
+ var deference = (schema, context) => {
273
+ var _a;
274
+ const refName = "$ref" in schema ? schema.$ref : void 0;
275
+ if (refName && ((_a = context.parents) == null ? void 0 : _a.includes(refName))) {
276
+ return {};
277
+ }
278
+ const childContext = {
279
+ ...context,
280
+ ...refName ? { parents: [...context.parents || [], refName] } : void 0
281
+ };
282
+ const { schema: resolvedSchema } = (0, import_core.resolveRef)(
283
+ schema,
284
+ childContext
285
+ );
286
+ return Object.entries(resolvedSchema).reduce((acc, [key, value]) => {
287
+ acc[key] = deferenceScalar(value, childContext);
288
+ return acc;
289
+ }, {});
290
+ };
291
+ var generateZodRoute = ({ operationName, body, verb }, { pathRoute, context }) => {
292
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
293
+ const spec = context.specs[context.specKey].paths[pathRoute];
294
+ const parameters = (_a = spec == null ? void 0 : spec[verb]) == null ? void 0 : _a.parameters;
295
+ const requestBody = (_b = spec == null ? void 0 : spec[verb]) == null ? void 0 : _b.requestBody;
296
+ const response = (_d = (_c = spec == null ? void 0 : spec[verb]) == null ? void 0 : _c.responses) == null ? void 0 : _d["200"];
297
+ const resolvedResponse = response ? (0, import_core.resolveRef)(response, context).schema : void 0;
298
+ const resolvedResponseJsonSchema = ((_f = (_e = resolvedResponse == null ? void 0 : resolvedResponse.content) == null ? void 0 : _e["application/json"]) == null ? void 0 : _f.schema) ? (0, import_core.resolveRef)(
299
+ resolvedResponse.content["application/json"].schema,
300
+ context
301
+ ).schema : void 0;
302
+ const zodDefinitionsResponseProperties = (_g = resolvedResponseJsonSchema == null ? void 0 : resolvedResponseJsonSchema.properties) != null ? _g : {};
303
+ const zodDefinitionsResponse = Object.entries(
304
+ zodDefinitionsResponseProperties
305
+ ).map(([key, response2]) => {
306
+ var _a2;
307
+ const schema = deference(response2, context);
308
+ return {
309
+ [key]: generateZodValidationSchemaDefinition(
310
+ schema,
311
+ !!((_a2 = resolvedResponseJsonSchema == null ? void 0 : resolvedResponseJsonSchema.required) == null ? void 0 : _a2.find(
312
+ (requiredKey) => requiredKey === key
313
+ )),
314
+ (0, import_core.camel)(`${operationName}-response-${key}`)
315
+ )
316
+ };
317
+ }).reduce((acc, curr) => ({ ...acc, ...curr }), {});
318
+ const resolvedRequestBody = requestBody ? (0, import_core.resolveRef)(requestBody, context).schema : void 0;
319
+ const resolvedRequestBodyJsonSchema = ((_i = (_h = resolvedRequestBody == null ? void 0 : resolvedRequestBody.content) == null ? void 0 : _h["application/json"]) == null ? void 0 : _i.schema) ? (0, import_core.resolveRef)(
320
+ resolvedRequestBody.content["application/json"].schema,
321
+ context
322
+ ).schema : void 0;
323
+ const zodDefinitionsBodyProperties = (_j = resolvedRequestBodyJsonSchema == null ? void 0 : resolvedRequestBodyJsonSchema.properties) != null ? _j : {};
324
+ const zodDefinitionsBody = Object.entries(zodDefinitionsBodyProperties).map(([key, body2]) => {
325
+ var _a2;
326
+ const schema = deference(body2, context);
327
+ return {
328
+ [key]: generateZodValidationSchemaDefinition(
329
+ schema,
330
+ !!((_a2 = resolvedRequestBodyJsonSchema == null ? void 0 : resolvedRequestBodyJsonSchema.required) == null ? void 0 : _a2.find(
331
+ (requiredKey) => requiredKey === key
332
+ )),
333
+ (0, import_core.camel)(`${operationName}-body-${key}`)
334
+ )
335
+ };
336
+ }).reduce((acc, curr) => ({ ...acc, ...curr }), {});
337
+ const zodDefinitionsParameters = (parameters != null ? parameters : []).reduce(
338
+ (acc, val) => {
339
+ const { schema: parameter } = (0, import_core.resolveRef)(val, context);
340
+ if (!parameter.schema) {
341
+ return acc;
342
+ }
343
+ const schema = deference(parameter.schema, context);
344
+ const definition = generateZodValidationSchemaDefinition(
345
+ schema,
346
+ parameter.required,
347
+ (0, import_core.camel)(`${operationName}-${parameter.in}-${parameter.name}`)
348
+ );
349
+ if (parameter.in === "header") {
350
+ return {
351
+ ...acc,
352
+ headers: { ...acc.headers, [parameter.name]: definition }
353
+ };
354
+ }
355
+ if (parameter.in === "query") {
356
+ return {
357
+ ...acc,
358
+ queryParams: { ...acc.queryParams, [parameter.name]: definition }
359
+ };
360
+ }
361
+ if (parameter.in === "path") {
362
+ return {
363
+ ...acc,
364
+ params: { ...acc.params, [parameter.name]: definition }
365
+ };
366
+ }
367
+ return acc;
368
+ },
369
+ {
370
+ headers: {},
371
+ queryParams: {},
372
+ params: {}
373
+ }
374
+ );
375
+ const inputParams = parseZodValidationSchemaDefinition(
376
+ zodDefinitionsParameters.params
377
+ );
378
+ const inputQueryParams = parseZodValidationSchemaDefinition(
379
+ zodDefinitionsParameters.queryParams
380
+ );
381
+ const inputHeaders = parseZodValidationSchemaDefinition(
382
+ zodDefinitionsParameters.headers
383
+ );
384
+ const inputBody = parseZodValidationSchemaDefinition(zodDefinitionsBody);
385
+ const inputResponse = parseZodValidationSchemaDefinition(
386
+ zodDefinitionsResponse
387
+ );
388
+ if (!inputParams.zod && !inputQueryParams.zod && !inputHeaders.zod && !inputBody.zod && !inputResponse.zod) {
389
+ return "";
390
+ }
391
+ return [
392
+ ...inputParams.consts ? [inputParams.consts] : [],
393
+ ...inputParams.zod ? [`export const ${operationName}Params = ${inputParams.zod}`] : [],
394
+ ...inputQueryParams.consts ? [inputQueryParams.consts] : [],
395
+ ...inputQueryParams.zod ? [`export const ${operationName}QueryParams = ${inputQueryParams.zod}`] : [],
396
+ ...inputHeaders.consts ? [inputHeaders.consts] : [],
397
+ ...inputHeaders.zod ? [`export const ${operationName}Header = ${inputHeaders.zod}`] : [],
398
+ ...inputBody.consts ? [inputBody.consts] : [],
399
+ ...inputBody.zod ? [`export const ${operationName}Body = ${inputBody.zod}`] : [],
400
+ ...inputResponse.consts ? [inputResponse.consts] : [],
401
+ ...inputResponse.zod ? [`export const ${operationName}Response = ${inputResponse.zod}`] : []
402
+ ].join("\n\n");
403
+ };
404
+ var generateZod = (verbOptions, options) => {
405
+ const routeImplementation = generateZodRoute(verbOptions, options);
406
+ return {
407
+ implementation: routeImplementation ? `${routeImplementation}
7
408
 
8
- `:"",imports:[]}},ne={client:ee,dependencies:N},te= exports.builder =()=>()=>ne,fe= exports.default =te;exports.builder = te; exports.default = fe; exports.generateZod = ee; exports.getZodDependencies = N;
409
+ ` : "",
410
+ imports: []
411
+ };
412
+ };
413
+ var zodClientBuilder = {
414
+ client: generateZod,
415
+ dependencies: getZodDependencies
416
+ };
417
+ var builder = () => () => zodClientBuilder;
418
+ var src_default = builder;
419
+ // Annotate the CommonJS export names for ESM import in node:
420
+ 0 && (module.exports = {
421
+ builder,
422
+ generateZod,
423
+ getZodDependencies
424
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orval/zod",
3
- "version": "6.19.1",
3
+ "version": "6.20.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -8,12 +8,12 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "build": "tsup ./src/index.ts --target node12 --minify --clean --dts --splitting",
11
+ "build": "tsup ./src/index.ts --target node12 --clean --dts",
12
12
  "dev": "tsup ./src/index.ts --target node12 --clean --watch src",
13
13
  "lint": "eslint src/**/*.ts"
14
14
  },
15
15
  "dependencies": {
16
- "@orval/core": "6.19.1",
16
+ "@orval/core": "6.20.0",
17
17
  "lodash.uniq": "^4.5.0"
18
18
  },
19
19
  "devDependencies": {