@kubb/plugin-zod 5.4.8 → 5.4.10

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/index.cjs CHANGED
@@ -2,34 +2,10 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- //#region \0rolldown/runtime.js
6
- var __defProp = Object.defineProperty;
7
- var __name = (target, value) => __defProp(target, "name", {
8
- value,
9
- configurable: true
10
- });
11
5
  //#endregion
12
6
  let kubb_kit = require("kubb/kit");
13
7
  let kubb_jsx = require("kubb/jsx");
14
8
  let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
15
- //#region ../../internals/shared/src/params.ts
16
- /**
17
- * Drops parameters that share the same name, keeping the first.
18
- *
19
- * A malformed spec can declare the same parameter name twice within one `in` location. Both would
20
- * resolve to the same output property, so emitting both would yield an object type with a duplicate
21
- * member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
22
- * parameter names flow through unchanged, so no two distinct names ever collide here anymore.
23
- */
24
- function dedupeParams(params) {
25
- const seen = /* @__PURE__ */ new Set();
26
- return params.filter((param) => {
27
- if (seen.has(param.name)) return false;
28
- seen.add(param.name);
29
- return true;
30
- });
31
- }
32
- //#endregion
33
9
  //#region ../../internals/shared/src/operation.ts
34
10
  /**
35
11
  * Maps a content type to the PascalCase suffix used to name per-content-type variants
@@ -89,11 +65,19 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
89
65
  function getOperationParameters(node) {
90
66
  const cached = operationParameterGroupsByNode.get(node);
91
67
  if (cached) return cached;
68
+ const group = (location) => {
69
+ const seen = /* @__PURE__ */ new Set();
70
+ return node.parameters.filter((param) => {
71
+ if (param.in !== location || seen.has(param.name)) return false;
72
+ seen.add(param.name);
73
+ return true;
74
+ });
75
+ };
92
76
  const groups = {
93
- path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
94
- query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
95
- header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
96
- cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
77
+ path: group("path"),
78
+ query: group("query"),
79
+ header: group("header"),
80
+ cookie: group("cookie")
97
81
  };
98
82
  operationParameterGroupsByNode.set(node, groups);
99
83
  return groups;
@@ -237,7 +221,13 @@ function getSuccessResponses(responses) {
237
221
  * ```
238
222
  */
239
223
  function getOasAdapter(adapter) {
240
- if (adapter.name !== "oas") throw new Error(`Expected the OpenAPI adapter (adapterOas), but received "${adapter.name}". Configure \`adapter: adapterOas()\` in your Kubb config.`);
224
+ if (adapter.name !== "oas") throw new kubb_kit.Diagnostics.Error({
225
+ code: kubb_kit.Diagnostics.code.adapterRequired,
226
+ severity: "error",
227
+ message: `Expected the OpenAPI adapter (adapterOas), but received "${adapter.name}".`,
228
+ help: "Set `adapter: adapterOas()` in kubb.config.ts.",
229
+ location: { kind: "config" }
230
+ });
241
231
  return adapter;
242
232
  }
243
233
  //#endregion
@@ -660,20 +650,6 @@ function createCasedFile(caseLast) {
660
650
  } };
661
651
  }
662
652
  //#endregion
663
- //#region ../../internals/shared/src/refs.ts
664
- /**
665
- * Collects the resolved target name of every pointer-carrying ref in a schema tree, in
666
- * first-occurrence order. Use this for name-only checks (e.g. redeclaration detection) where
667
- * `resolver.imports` would resolve file paths that are then discarded.
668
- */
669
- function collectRefNames(schema) {
670
- return kubb_kit.ast.collectSync(schema, { schema: (node) => {
671
- const refNode = kubb_kit.ast.narrowSchema(node, "ref");
672
- if (!refNode?.ref) return null;
673
- return kubb_kit.ast.resolveRefName(refNode);
674
- } });
675
- }
676
- //#endregion
677
653
  //#region ../../internals/shared/src/group.ts
678
654
  /**
679
655
  * Builds the `group` config a Kubb plugin passes to `ctx.setOptions`, applying the
@@ -817,13 +793,6 @@ function Zod({ name, node, printer, inferTypeName, typeGuards, isName, assertNam
817
793
  ] });
818
794
  }
819
795
  //#endregion
820
- //#region src/constants.ts
821
- /**
822
- * Import paths that use a namespace import (`import * as z from '...'`).
823
- * All other import paths use a named import (`import { z } from '...'`).
824
- */
825
- const ZOD_NAMESPACE_IMPORTS = /* @__PURE__ */ new Set(["zod", "zod/mini"]);
826
- //#endregion
827
796
  //#region src/utils.ts
828
797
  /**
829
798
  * Returns `true` when the given coercion option enables coercion for the specified type.
@@ -833,8 +802,8 @@ function shouldCoerce(coercion, type) {
833
802
  if (coercion === true) return true;
834
803
  return !!coercion[type];
835
804
  }
836
- function hasPropertyNames(node) {
837
- return "propertyNames" in node && Boolean(node.propertyNames);
805
+ function propertyNamesOf(node) {
806
+ return "propertyNames" in node ? node.propertyNames : void 0;
838
807
  }
839
808
  /**
840
809
  * Whether the schema node represents a closed or finite set of keys (e.g. enum, literal,
@@ -864,7 +833,7 @@ function isPlainInlineObject(node) {
864
833
  if (node.nullable || node.optional || node.nullish) return false;
865
834
  const hasAdditionalProperties = node.additionalProperties !== void 0;
866
835
  const hasPatternProperties = Boolean(node.patternProperties);
867
- return !hasAdditionalProperties && !hasPatternProperties && !hasPropertyNames(node);
836
+ return !hasAdditionalProperties && !hasPatternProperties && !propertyNamesOf(node);
868
837
  }
869
838
  /**
870
839
  * Whether a node renders as a bare Zod object — one that accepts `.extend(…)` and can be a
@@ -879,7 +848,7 @@ function isObjectSchemaNode(node, cyclicSchemas) {
879
848
  const hasProperties = Boolean(node.properties?.length);
880
849
  const hasTypedAdditionalProperties = Boolean(node.additionalProperties && node.additionalProperties !== true);
881
850
  const hasPatternProperties = Boolean(node.patternProperties);
882
- return !(!hasProperties && (hasTypedAdditionalProperties || hasPatternProperties || hasPropertyNames(node)));
851
+ return !(!hasProperties && (hasTypedAdditionalProperties || hasPatternProperties || propertyNamesOf(node)));
883
852
  }
884
853
  if (node.type === "ref") {
885
854
  const refName = kubb_kit.ast.resolveRefName(node);
@@ -936,28 +905,20 @@ function defaultLiteral(node, value) {
936
905
  const values = enumNode.namedEnumValues?.map((member) => member.value) ?? enumNode.enumValues ?? [];
937
906
  if (values.length) {
938
907
  const match = values.find((member) => member === value || String(member) === String(value));
939
- return match != null ? formatLiteral(match) : null;
908
+ return match != null ? formatDefault(match) : null;
940
909
  }
941
910
  }
942
911
  return formatDefault(value);
943
912
  }
944
913
  /**
945
- * Format a primitive enum/literal value.
946
- * Strings are quoted; numbers and booleans are emitted raw.
947
- */
948
- function formatLiteral(v) {
949
- if (typeof v === "string") return stringify(v);
950
- return String(v);
951
- }
952
- /**
953
914
  * Build the Zod schema for a set of literal enum values.
954
915
  * `z.enum()` only accepts string members in Zod v4, so a numeric, boolean, or
955
916
  * mixed set is emitted as a single `z.literal(…)` or a `z.union([z.literal(…), …])`.
956
917
  * An all-string set keeps the more compact `z.enum([…])`.
957
918
  */
958
919
  function buildEnum(values) {
959
- if (values.every((v) => typeof v === "string")) return `z.enum([${values.map(formatLiteral).join(", ")}])`;
960
- const literals = values.map((v) => `z.literal(${formatLiteral(v)})`);
920
+ if (values.every((v) => typeof v === "string")) return `z.enum([${values.map((v) => formatDefault(v)).join(", ")}])`;
921
+ const literals = values.map((v) => `z.literal(${formatDefault(v)})`);
961
922
  if (literals.length === 1) return literals[0];
962
923
  return `z.union([${literals.join(", ")}])`;
963
924
  }
@@ -976,33 +937,26 @@ function integerFormatPattern(format) {
976
937
  if (format === "uint64") return "^\\d+$";
977
938
  }
978
939
  /**
979
- * Map a `regexType` to the `func` argument of `toRegExpString`: `'constructor'` emits
980
- * `new RegExp(...)`, while `'literal'` (the default) emits a regex literal.
940
+ * Renders a `pattern` as a regex literal, or as `new RegExp(...)` when `regexType` is `'constructor'`.
981
941
  */
982
- function regexFunc(regexType) {
983
- return regexType === "constructor" ? "RegExp" : null;
942
+ function regexSource(pattern, regexType) {
943
+ return toRegExpString(pattern, regexType === "constructor" ? "RegExp" : null);
944
+ }
945
+ function joinPatterns(patterns) {
946
+ return patterns.length === 1 ? patterns[0] : patterns.map((pattern) => `(${pattern})`).join("|");
984
947
  }
985
948
  /**
986
949
  * Builds a Zod record key schema that enforces the `patternProperties` regexes a plain
987
- * `.catchall()` would drop. Several patterns combine into one alternation (`(^a)|(^b)`).
950
+ * `.catchall()` would drop.
988
951
  */
989
952
  function patternKeySchema({ patterns, regexType }) {
990
- return `z.string().regex(${patternKeySource({
991
- patterns,
992
- regexType
993
- })})`;
953
+ return `z.string().regex(${regexSource(joinPatterns(patterns), regexType)})`;
994
954
  }
995
955
  /**
996
956
  * `zod/mini` variant of {@link patternKeySchema}, wrapping the regex in `.check(z.regex(...))`.
997
957
  */
998
958
  function patternKeySchemaMini({ patterns, regexType }) {
999
- return `z.string().check(z.regex(${patternKeySource({
1000
- patterns,
1001
- regexType
1002
- })}))`;
1003
- }
1004
- function patternKeySource({ patterns, regexType }) {
1005
- return toRegExpString(patterns.length === 1 ? patterns[0] : patterns.map((pattern) => `(${pattern})`).join("|"), regexFunc(regexType));
959
+ return `z.string().check(z.regex(${regexSource(joinPatterns(patterns), regexType)}))`;
1006
960
  }
1007
961
  /**
1008
962
  * Build `.min()` / `.max()` / `.gt()` / `.lt()` constraint chains for numbers
@@ -1025,7 +979,7 @@ function lengthConstraints({ min, max, pattern, regexType }) {
1025
979
  return [
1026
980
  min !== void 0 ? `.min(${min})` : "",
1027
981
  max !== void 0 ? `.max(${max})` : "",
1028
- pattern !== void 0 ? `.regex(${toRegExpString(pattern, regexFunc(regexType))})` : ""
982
+ pattern !== void 0 ? `.regex(${regexSource(pattern, regexType)})` : ""
1029
983
  ].join("");
1030
984
  }
1031
985
  /**
@@ -1047,7 +1001,7 @@ function lengthChecksMini({ min, max, pattern, regexType }) {
1047
1001
  const checks = [];
1048
1002
  if (min !== void 0) checks.push(`z.minLength(${min})`);
1049
1003
  if (max !== void 0) checks.push(`z.maxLength(${max})`);
1050
- if (pattern !== void 0) checks.push(`z.regex(${toRegExpString(pattern, regexFunc(regexType))})`);
1004
+ if (pattern !== void 0) checks.push(`z.regex(${regexSource(pattern, regexType)})`);
1051
1005
  return checks.length ? `.check(${checks.join(", ")})` : "";
1052
1006
  }
1053
1007
  /**
@@ -1101,63 +1055,44 @@ function applyMiniModifiers({ value, schema, nullable, optional, nullish, defaul
1101
1055
  return literal !== null ? `z._default(${withModifier}, ${literal})` : withModifier;
1102
1056
  }
1103
1057
  /**
1104
- * Builds an `object` schema node grouping the given parameter nodes.
1105
- * The `primitive: 'object'` marker ensures the Zod printer emits `z.object(…)` rather than a record.
1058
+ * Calls for string `format`s with a dedicated Zod constructor; a `Map` so `constructor` cannot hit `Object.prototype`.
1106
1059
  */
1107
- function buildGroupedParamsSchema({ params, optional }) {
1108
- return kubb_kit.ast.factory.createSchema({
1109
- type: "object",
1110
- optional,
1111
- primitive: "object",
1112
- properties: params.map((param) => kubb_kit.ast.factory.createProperty({
1113
- name: param.name,
1114
- required: param.required,
1115
- schema: param.schema
1116
- }))
1117
- });
1118
- }
1119
- //#endregion
1120
- //#region src/printers/printerZod.ts
1060
+ const STRING_FORMAT_CALLS = /* @__PURE__ */ new Map([
1061
+ ["byte", "z.base64()"],
1062
+ ["base64", "z.base64()"],
1063
+ ["base64url", "z.base64url()"],
1064
+ ["jwt", "z.jwt()"],
1065
+ ["ulid", "z.ulid()"],
1066
+ ["iban", "z.iban()"],
1067
+ ["duration", "z.iso.duration()"]
1068
+ ]);
1121
1069
  /**
1122
- * A `oneOf` member that is an inline object is exhaustive, so it prints as a strict object.
1123
- * Marking the node lets `object()` build `z.strictObject(...)` itself; appending `.strict()` to the
1124
- * printed member instead would read `.shape` eagerly and run a self-reference's deferred getter
1125
- * inside the temporal dead zone.
1070
+ * Marks an inline `oneOf` object strict, so `object()` builds `z.strictObject(...)` and no eager `.shape` read hits a deferred getter.
1126
1071
  */
1127
- function strictOneOfNode$1(node) {
1072
+ function strictOneOfNode(node) {
1128
1073
  return node.type === "object" && node.additionalProperties === void 0 ? {
1129
1074
  ...node,
1130
1075
  additionalProperties: false
1131
1076
  } : node;
1132
1077
  }
1133
- __name(strictOneOfNode$1, "strictOneOfNode");
1134
- function strictOneOfMember(member, node, cyclicSchemas) {
1135
- if (node.type === "ref") {
1136
- if (member.startsWith("z.lazy(")) return member;
1137
- const refName = kubb_kit.ast.resolveRefName(node);
1138
- if (refName && cyclicSchemas?.has(refName)) return member;
1139
- const schema = (0, kubb_kit.syncSchemaRef)(node);
1140
- if (schema.nullable || schema.optional || node.nullable || node.optional) return member;
1141
- if (schema.type === "object" && (schema.additionalProperties === void 0 || schema.additionalProperties === false)) return `${member}.strict()`;
1142
- }
1143
- return member;
1144
- }
1145
- function getMemberConstraint({ member, regexType }) {
1146
- if (member.primitive === "string") return lengthConstraints({
1078
+ /**
1079
+ * The constraint chain an `allOf` member adds to a bare string, number or array; each printer passes its own renderers.
1080
+ */
1081
+ function getMemberConstraint({ member, regexType, lengths, numbers }) {
1082
+ if (member.primitive === "string") return lengths({
1147
1083
  ...kubb_kit.ast.narrowSchema(member, "string") ?? {},
1148
1084
  regexType
1149
1085
  }) || void 0;
1150
- if (member.primitive === "number" || member.primitive === "integer") return numberConstraints(kubb_kit.ast.narrowSchema(member, "number") ?? kubb_kit.ast.narrowSchema(member, "integer") ?? {}) || void 0;
1151
- if (member.primitive === "array") return lengthConstraints({
1086
+ if (member.primitive === "number" || member.primitive === "integer") return numbers(kubb_kit.ast.narrowSchema(member, "number") ?? kubb_kit.ast.narrowSchema(member, "integer") ?? {}) || void 0;
1087
+ if (member.primitive === "array") return lengths({
1152
1088
  ...kubb_kit.ast.narrowSchema(member, "array") ?? {},
1153
1089
  regexType
1154
1090
  }) || void 0;
1155
1091
  }
1156
1092
  /**
1157
- * Builds the `{ key: value, … }` shape for an object node, shared by the `z.object(...)` and
1158
- * `.extend(...)` renderings so they stay in lockstep.
1093
+ * Builds the `{ key: value, … }` shape shared by the `z.object(...)` and `.extend(...)` renderings.
1159
1094
  */
1160
- function buildZodObjectShape(ctx, node) {
1095
+ function buildObjectShape(ctx, node, modify) {
1161
1096
  const objectNode = kubb_kit.ast.narrowSchema(node, "object");
1162
1097
  if (!objectNode) return "{}";
1163
1098
  const isCyclic = (schema) => ctx.options.cyclicSchemas != null && (0, kubb_kit.containsCircularRef)(schema, { circularSchemas: ctx.options.cyclicSchemas });
@@ -1170,17 +1105,11 @@ function buildZodObjectShape(ctx, node) {
1170
1105
  return baseOutput;
1171
1106
  }).map(({ name: propName, property, output: baseOutput }) => {
1172
1107
  const { schema } = property;
1173
- const meta = (0, kubb_kit.syncSchemaRef)(schema);
1174
- const descriptionToApply = schema.type !== "ref" && meta.type === "ref" ? void 0 : meta.description;
1175
- const value = applyModifiers({
1108
+ const value = modify({
1176
1109
  value: baseOutput,
1177
1110
  schema,
1178
- nullable: meta.nullable,
1179
- optional: schema.optional || property.required === false,
1180
- nullish: schema.nullish,
1181
- defaultValue: meta.default,
1182
- description: descriptionToApply,
1183
- examples: meta.examples
1111
+ required: property.required,
1112
+ meta: (0, kubb_kit.syncSchemaRef)(schema)
1184
1113
  });
1185
1114
  return isCyclic(schema) ? lazyGetter({
1186
1115
  name: propName,
@@ -1189,6 +1118,51 @@ function buildZodObjectShape(ctx, node) {
1189
1118
  }));
1190
1119
  }
1191
1120
  /**
1121
+ * Shared `print` body: transforms the node, applies `keysToOmit` as `.omit(...)`, then `modify` adds the modifiers.
1122
+ */
1123
+ function printWithOmit(ctx, node, modify) {
1124
+ const { keysToOmit } = ctx.options;
1125
+ const transformed = ctx.transform(node);
1126
+ if (!transformed) return null;
1127
+ const meta = (0, kubb_kit.syncSchemaRef)(node);
1128
+ return modify((() => {
1129
+ if (!keysToOmit?.length || meta.primitive !== "object" || meta.type === "union" && meta.discriminatorPropertyName) return transformed;
1130
+ const unwrap = omitUnwrapChain(node);
1131
+ const omit = `.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
1132
+ const lazyMatch = transformed.match(/^z\.lazy\(\(\)\s*=>\s*(.+)\)$/);
1133
+ if (lazyMatch) return `z.lazy(() => ${lazyMatch[1]}${unwrap}${omit})`;
1134
+ return `${transformed}${unwrap}${omit}`;
1135
+ })(), meta);
1136
+ }
1137
+ //#endregion
1138
+ //#region src/printers/printerZod.ts
1139
+ function strictOneOfMember(member, node, cyclicSchemas) {
1140
+ if (node.type === "ref") {
1141
+ if (member.startsWith("z.lazy(")) return member;
1142
+ const refName = kubb_kit.ast.resolveRefName(node);
1143
+ if (refName && cyclicSchemas?.has(refName)) return member;
1144
+ const schema = (0, kubb_kit.syncSchemaRef)(node);
1145
+ if (schema.nullable || schema.optional || node.nullable || node.optional) return member;
1146
+ if (schema.type === "object" && (schema.additionalProperties === void 0 || schema.additionalProperties === false)) return `${member}.strict()`;
1147
+ }
1148
+ return member;
1149
+ }
1150
+ /**
1151
+ * Builds the `{ key: value, … }` shape for an object node with the chainable modifiers.
1152
+ */
1153
+ function buildZodObjectShape(ctx, node) {
1154
+ return buildObjectShape(ctx, node, ({ value, schema, required, meta }) => applyModifiers({
1155
+ value,
1156
+ schema,
1157
+ nullable: meta.nullable,
1158
+ optional: schema.optional || required === false,
1159
+ nullish: schema.nullish,
1160
+ defaultValue: meta.default,
1161
+ description: schema.type !== "ref" && meta.type === "ref" ? void 0 : meta.description,
1162
+ examples: meta.examples
1163
+ }));
1164
+ }
1165
+ /**
1192
1166
  * Types the direction probe skips. They delegate to their children rather than reading
1193
1167
  * `direction` themselves, so {@link containsDirectionalNode} walks into the children instead.
1194
1168
  */
@@ -1254,7 +1228,8 @@ function containsDirectionalNode({ node, printerOptions, seen = /* @__PURE__ */
1254
1228
  if ("items" in node && node.items) children.push(...node.items);
1255
1229
  if ("members" in node && node.members) children.push(...node.members);
1256
1230
  if ("additionalProperties" in node && node.additionalProperties && node.additionalProperties !== true) children.push(node.additionalProperties);
1257
- if ("propertyNames" in node && node.propertyNames) children.push(node.propertyNames);
1231
+ const propertyNames = propertyNamesOf(node);
1232
+ if (propertyNames) children.push(propertyNames);
1258
1233
  return children.some((child) => containsDirectionalNode({
1259
1234
  node: child,
1260
1235
  printerOptions,
@@ -1289,32 +1264,11 @@ const scalarNodes = {
1289
1264
  boolean: () => "z.boolean()",
1290
1265
  null: () => "z.null()",
1291
1266
  string(node) {
1292
- if (!shouldCoerce(this.options.coercion, "strings")) {
1293
- if (node.format === "byte" || node.format === "base64") return `z.base64()${lengthConstraints({
1294
- ...node,
1295
- regexType: this.options.regexType
1296
- })}`;
1297
- if (node.format === "base64url") return `z.base64url()${lengthConstraints({
1298
- ...node,
1299
- regexType: this.options.regexType
1300
- })}`;
1301
- if (node.format === "jwt") return `z.jwt()${lengthConstraints({
1302
- ...node,
1303
- regexType: this.options.regexType
1304
- })}`;
1305
- if (node.format === "ulid") return `z.ulid()${lengthConstraints({
1306
- ...node,
1307
- regexType: this.options.regexType
1308
- })}`;
1309
- if (node.format === "iban") return `z.iban()${lengthConstraints({
1310
- ...node,
1311
- regexType: this.options.regexType
1312
- })}`;
1313
- if (node.format === "duration") return `z.iso.duration()${lengthConstraints({
1314
- ...node,
1315
- regexType: this.options.regexType
1316
- })}`;
1317
- }
1267
+ const call = shouldCoerce(this.options.coercion, "strings") ? void 0 : STRING_FORMAT_CALLS.get(node.format);
1268
+ if (call) return `${call}${lengthConstraints({
1269
+ ...node,
1270
+ regexType: this.options.regexType
1271
+ })}`;
1318
1272
  const base = shouldCoerce(this.options.coercion, "strings") ? "z.coerce.string()" : "z.string()";
1319
1273
  const pattern = node.pattern ?? integerFormatPattern(node.format);
1320
1274
  return `${base}${lengthConstraints({
@@ -1378,7 +1332,7 @@ const scalarNodes = {
1378
1332
  enum(node) {
1379
1333
  const nonNullValues = (node.namedEnumValues?.map((v) => v.value) ?? node.enumValues ?? []).filter((v) => v !== null);
1380
1334
  if (node.namedEnumValues?.length) {
1381
- const literals = nonNullValues.map((v) => `z.literal(${formatLiteral(v)})`);
1335
+ const literals = nonNullValues.map((v) => `z.literal(${formatDefault(v)})`);
1382
1336
  if (literals.length === 1) return literals[0];
1383
1337
  return `z.union([${literals.join(", ")}])`;
1384
1338
  }
@@ -1419,7 +1373,7 @@ const printerZod = kubb_kit.ast.createPrinter((options) => {
1419
1373
  object(node) {
1420
1374
  const entries = node.properties ?? [];
1421
1375
  const patterns = node.patternProperties ? Object.entries(node.patternProperties) : [];
1422
- const propertyNamesNode = "propertyNames" in node ? node.propertyNames : void 0;
1376
+ const propertyNamesNode = propertyNamesOf(node);
1423
1377
  const propertyNamesKeySchema = propertyNamesNode ? this.transform(propertyNamesNode) : null;
1424
1378
  const isStrict = node.additionalProperties === false && patterns.length === 0;
1425
1379
  const isLoose = node.additionalProperties === true;
@@ -1465,7 +1419,7 @@ const printerZod = kubb_kit.ast.createPrinter((options) => {
1465
1419
  },
1466
1420
  union(node) {
1467
1421
  const nodeMembers = node.members ?? [];
1468
- const members = mapSchemaMembers(node, (memberNode) => this.transform(node.strategy === "one" ? strictOneOfNode$1(memberNode) : memberNode)).map(({ schema, output }) => output && node.strategy === "one" ? strictOneOfMember(output, schema, cyclicSchemaNames) : output).filter(Boolean);
1422
+ const members = mapSchemaMembers(node, (memberNode) => this.transform(node.strategy === "one" ? strictOneOfNode(memberNode) : memberNode)).map(({ schema, output }) => output && node.strategy === "one" ? strictOneOfMember(output, schema, cyclicSchemaNames) : output).filter(Boolean);
1469
1423
  if (members.length === 0) return "";
1470
1424
  if (members.length === 1) return members[0];
1471
1425
  const allDiscriminable = nodeMembers.every((m) => isObjectSchemaNode(m, cyclicSchemaNames));
@@ -1483,7 +1437,9 @@ const printerZod = kubb_kit.ast.createPrinter((options) => {
1483
1437
  return rest.reduce((acc, member) => {
1484
1438
  const constraint = getMemberConstraint({
1485
1439
  member,
1486
- regexType: this.options.regexType
1440
+ regexType: this.options.regexType,
1441
+ lengths: lengthConstraints,
1442
+ numbers: numberConstraints
1487
1443
  });
1488
1444
  if (constraint) return acc + constraint;
1489
1445
  const transformed = this.transform(member);
@@ -1493,19 +1449,8 @@ const printerZod = kubb_kit.ast.createPrinter((options) => {
1493
1449
  },
1494
1450
  overrides: options.nodes,
1495
1451
  print(node) {
1496
- const { keysToOmit } = this.options;
1497
- const transformed = this.transform(node);
1498
- if (!transformed) return null;
1499
- const meta = (0, kubb_kit.syncSchemaRef)(node);
1500
- return applyModifiers({
1501
- value: (() => {
1502
- if (!keysToOmit?.length || meta.primitive !== "object" || meta.type === "union" && meta.discriminatorPropertyName) return transformed;
1503
- const unwrap = omitUnwrapChain(node);
1504
- const omit = `.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
1505
- const lazyMatch = transformed.match(/^z\.lazy\(\(\)\s*=>\s*(.+)\)$/);
1506
- if (lazyMatch) return `z.lazy(() => ${lazyMatch[1]}${unwrap}${omit})`;
1507
- return `${transformed}${unwrap}${omit}`;
1508
- })(),
1452
+ return printWithOmit(this, node, (value, meta) => applyModifiers({
1453
+ value,
1509
1454
  schema: node,
1510
1455
  nullable: meta.nullable,
1511
1456
  optional: meta.optional,
@@ -1513,63 +1458,23 @@ const printerZod = kubb_kit.ast.createPrinter((options) => {
1513
1458
  defaultValue: meta.default,
1514
1459
  description: meta.description,
1515
1460
  examples: meta.examples
1516
- });
1461
+ }));
1517
1462
  }
1518
1463
  };
1519
1464
  });
1520
1465
  //#endregion
1521
1466
  //#region src/printers/printerZodMini.ts
1522
1467
  /**
1523
- * A `oneOf` member that is an inline object is exhaustive, so it prints as a strict object.
1524
- * Marking the node lets `object()` build `z.strictObject(...)` itself, with no rewrite afterwards.
1525
- */
1526
- function strictOneOfNode(node) {
1527
- return node.type === "object" && node.additionalProperties === void 0 ? {
1528
- ...node,
1529
- additionalProperties: false
1530
- } : node;
1531
- }
1532
- function getMemberConstraintMini({ member, regexType }) {
1533
- if (member.primitive === "string") return lengthChecksMini({
1534
- ...kubb_kit.ast.narrowSchema(member, "string") ?? {},
1535
- regexType
1536
- }) || void 0;
1537
- if (member.primitive === "number" || member.primitive === "integer") return numberChecksMini(kubb_kit.ast.narrowSchema(member, "number") ?? kubb_kit.ast.narrowSchema(member, "integer") ?? {}) || void 0;
1538
- if (member.primitive === "array") return lengthChecksMini({
1539
- ...kubb_kit.ast.narrowSchema(member, "array") ?? {},
1540
- regexType
1541
- }) || void 0;
1542
- }
1543
- /**
1544
- * Builds the `{ key: value, … }` shape for an object node with the functional `zod/mini` modifiers,
1545
- * shared by the `z.object(...)` and `z.extend(...)` renderings so they stay in lockstep.
1468
+ * Builds the `{ key: value, … }` shape for an object node with the functional `zod/mini` modifiers.
1546
1469
  */
1547
1470
  function buildZodMiniObjectShape(ctx, node) {
1548
- const objectNode = kubb_kit.ast.narrowSchema(node, "object");
1549
- if (!objectNode) return "{}";
1550
- const isCyclic = (schema) => ctx.options.cyclicSchemas != null && (0, kubb_kit.containsCircularRef)(schema, { circularSchemas: ctx.options.cyclicSchemas });
1551
- return buildObject(mapSchemaProperties(objectNode, (schema) => {
1552
- const hasSelfRef = isCyclic(schema);
1553
- const savedCyclicSchemas = ctx.options.cyclicSchemas;
1554
- if (hasSelfRef) ctx.options.cyclicSchemas = void 0;
1555
- const baseOutput = ctx.transform(schema) ?? ctx.transform(kubb_kit.ast.factory.createSchema({ type: "unknown" }));
1556
- if (hasSelfRef) ctx.options.cyclicSchemas = savedCyclicSchemas;
1557
- return baseOutput;
1558
- }).map(({ name: propName, property, output: baseOutput }) => {
1559
- const { schema } = property;
1560
- const meta = (0, kubb_kit.syncSchemaRef)(schema);
1561
- const value = applyMiniModifiers({
1562
- value: baseOutput,
1563
- schema,
1564
- nullable: meta.nullable,
1565
- optional: schema.optional || property.required === false,
1566
- nullish: schema.nullish,
1567
- defaultValue: meta.default
1568
- });
1569
- return isCyclic(schema) ? lazyGetter({
1570
- name: propName,
1571
- body: value
1572
- }) : `${objectKey(propName)}: ${value}`;
1471
+ return buildObjectShape(ctx, node, ({ value, schema, required, meta }) => applyMiniModifiers({
1472
+ value,
1473
+ schema,
1474
+ nullable: meta.nullable,
1475
+ optional: schema.optional || required === false,
1476
+ nullish: schema.nullish,
1477
+ defaultValue: meta.default
1573
1478
  }));
1574
1479
  }
1575
1480
  /**
@@ -1598,32 +1503,11 @@ const printerZodMini = kubb_kit.ast.createPrinter((options) => {
1598
1503
  null: () => "z.null()",
1599
1504
  string(node) {
1600
1505
  const coerce = shouldCoerce(this.options.coercion, "strings");
1601
- if (!coerce) {
1602
- if (node.format === "byte" || node.format === "base64") return `z.base64()${lengthChecksMini({
1603
- ...node,
1604
- regexType: this.options.regexType
1605
- })}`;
1606
- if (node.format === "base64url") return `z.base64url()${lengthChecksMini({
1607
- ...node,
1608
- regexType: this.options.regexType
1609
- })}`;
1610
- if (node.format === "jwt") return `z.jwt()${lengthChecksMini({
1611
- ...node,
1612
- regexType: this.options.regexType
1613
- })}`;
1614
- if (node.format === "ulid") return `z.ulid()${lengthChecksMini({
1615
- ...node,
1616
- regexType: this.options.regexType
1617
- })}`;
1618
- if (node.format === "iban") return `z.iban()${lengthChecksMini({
1619
- ...node,
1620
- regexType: this.options.regexType
1621
- })}`;
1622
- if (node.format === "duration") return `z.iso.duration()${lengthChecksMini({
1623
- ...node,
1624
- regexType: this.options.regexType
1625
- })}`;
1626
- }
1506
+ const call = coerce ? void 0 : STRING_FORMAT_CALLS.get(node.format);
1507
+ if (call) return `${call}${lengthChecksMini({
1508
+ ...node,
1509
+ regexType: this.options.regexType
1510
+ })}`;
1627
1511
  const base = coerce ? "z.coerce.string()" : "z.string()";
1628
1512
  const pattern = node.pattern ?? integerFormatPattern(node.format);
1629
1513
  return `${base}${lengthChecksMini({
@@ -1679,7 +1563,7 @@ const printerZodMini = kubb_kit.ast.createPrinter((options) => {
1679
1563
  enum(node) {
1680
1564
  const nonNullValues = (node.namedEnumValues?.map((v) => v.value) ?? node.enumValues ?? []).filter((v) => v !== null);
1681
1565
  if (node.namedEnumValues?.length) {
1682
- const literals = nonNullValues.map((v) => `z.literal(${formatLiteral(v)})`);
1566
+ const literals = nonNullValues.map((v) => `z.literal(${formatDefault(v)})`);
1683
1567
  if (literals.length === 1) return literals[0];
1684
1568
  return `z.union([${literals.join(", ")}])`;
1685
1569
  }
@@ -1696,7 +1580,7 @@ const printerZodMini = kubb_kit.ast.createPrinter((options) => {
1696
1580
  object(node) {
1697
1581
  const entries = node.properties ?? [];
1698
1582
  const patterns = node.patternProperties ? Object.entries(node.patternProperties) : [];
1699
- const propertyNamesNode = "propertyNames" in node ? node.propertyNames : void 0;
1583
+ const propertyNamesNode = propertyNamesOf(node);
1700
1584
  const propertyNamesKeySchema = propertyNamesNode ? this.transform(propertyNamesNode) : null;
1701
1585
  const isStrict = node.additionalProperties === false && patterns.length === 0;
1702
1586
  const isLoose = node.additionalProperties === true;
@@ -1753,9 +1637,11 @@ const printerZodMini = kubb_kit.ast.createPrinter((options) => {
1753
1637
  if (!firstBase) return "";
1754
1638
  if (rest.length > 0 && isObjectComposableIntersection(node, cyclicSchemaNames)) return rest.reduce((acc, member) => `z.extend(${acc}, ${buildZodMiniObjectShape(this, member)})`, firstBase);
1755
1639
  return rest.reduce((acc, member) => {
1756
- const constraint = getMemberConstraintMini({
1640
+ const constraint = getMemberConstraint({
1757
1641
  member,
1758
- regexType: this.options.regexType
1642
+ regexType: this.options.regexType,
1643
+ lengths: lengthChecksMini,
1644
+ numbers: numberChecksMini
1759
1645
  });
1760
1646
  if (constraint) return acc + constraint;
1761
1647
  const transformed = this.transform(member);
@@ -1765,25 +1651,14 @@ const printerZodMini = kubb_kit.ast.createPrinter((options) => {
1765
1651
  },
1766
1652
  overrides: options.nodes,
1767
1653
  print(node) {
1768
- const { keysToOmit } = this.options;
1769
- const transformed = this.transform(node);
1770
- if (!transformed) return null;
1771
- const meta = (0, kubb_kit.syncSchemaRef)(node);
1772
- return applyMiniModifiers({
1773
- value: (() => {
1774
- if (!keysToOmit?.length || meta.primitive !== "object" || meta.type === "union" && meta.discriminatorPropertyName) return transformed;
1775
- const unwrap = omitUnwrapChain(node);
1776
- const omit = `.omit({ ${keysToOmit.map((k) => `"${k}": true`).join(", ")} })`;
1777
- const lazyMatch = transformed.match(/^z\.lazy\(\(\)\s*=>\s*(.+)\)$/);
1778
- if (lazyMatch) return `z.lazy(() => ${lazyMatch[1]}${unwrap}${omit})`;
1779
- return `${transformed}${unwrap}${omit}`;
1780
- })(),
1654
+ return printWithOmit(this, node, (value, meta) => applyMiniModifiers({
1655
+ value,
1781
1656
  schema: node,
1782
1657
  nullable: meta.nullable,
1783
1658
  optional: meta.optional,
1784
1659
  nullish: meta.nullish,
1785
1660
  defaultValue: meta.default
1786
- });
1661
+ }));
1787
1662
  }
1788
1663
  };
1789
1664
  });
@@ -1855,7 +1730,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
1855
1730
  const { output, coercion, guidType, regexType, compile, mini, inferred, typeGuards, importPath, group, printer } = ctx.options;
1856
1731
  const dateType = getOasAdapter(adapter).options.dateType;
1857
1732
  if (!node.name) return;
1858
- const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
1733
+ const isZodImport = importPath === "zod" || importPath === "zod/mini";
1859
1734
  const cyclicSchemas = new Set(ctx.meta.circularNames);
1860
1735
  const printerOptions = {
1861
1736
  coercion,
@@ -1890,13 +1765,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
1890
1765
  group: group ?? void 0
1891
1766
  }).path
1892
1767
  })) : [];
1893
- const seenImports = /* @__PURE__ */ new Set();
1894
- const imports = [...importEntries, ...inputImportEntries].filter((imp) => {
1895
- const key = `${Array.isArray(imp.name) ? imp.name.join(",") : imp.name}|${imp.path}`;
1896
- if (seenImports.has(key)) return false;
1897
- seenImports.add(key);
1898
- return true;
1899
- });
1768
+ const imports = [...new Map([...importEntries, ...inputImportEntries].map((imp) => [`${Array.isArray(imp.name) ? imp.name.join(",") : imp.name}|${imp.path}`, imp])).values()];
1900
1769
  const meta = {
1901
1770
  name: resolver.name(node.name),
1902
1771
  file: resolver.file({
@@ -1992,7 +1861,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
1992
1861
  const { adapter, config, resolver, root } = ctx;
1993
1862
  const { output, coercion, guidType, regexType, compile, mini, inferred, importPath, group, printer } = ctx.options;
1994
1863
  const dateType = getOasAdapter(adapter).options.dateType;
1995
- const isZodImport = ZOD_NAMESPACE_IMPORTS.has(importPath);
1864
+ const isZodImport = importPath === "zod" || importPath === "zod/mini";
1996
1865
  const meta = { file: resolver.file({
1997
1866
  name: node.operationId,
1998
1867
  extname: ".ts",
@@ -2096,7 +1965,7 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
2096
1965
  })] });
2097
1966
  }
2098
1967
  function buildResponseUnion({ responses, name, fallbackUnknown }) {
2099
- if (new Set(responses.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ? collectRefNames(entry.schema).map((refName) => resolver.name(refName)) : []))).has(name)) return null;
1968
+ if (new Set(responses.flatMap((res) => (res.content ?? []).flatMap((entry) => entry.schema ? kubb_kit.ast.collectImportedRefNames(entry.schema).map((refName) => resolver.name(refName)) : []))).has(name)) return null;
2100
1969
  const members = responses.map((res) => kubb_kit.ast.factory.createSchema({
2101
1970
  type: "ref",
2102
1971
  name: resolver.response.status(node, res.statusCode)
@@ -2177,7 +2046,15 @@ const zodGenerator = (0, kubb_kit.defineGenerator)({
2177
2046
  params: header
2178
2047
  }
2179
2048
  ].filter(({ params }) => params.length > 0).map(({ kind, params }) => renderSchemaEntry({
2180
- schema: buildGroupedParamsSchema({ params }),
2049
+ schema: kubb_kit.ast.factory.createSchema({
2050
+ type: "object",
2051
+ primitive: "object",
2052
+ properties: params.map((param) => kubb_kit.ast.factory.createProperty({
2053
+ name: param.name,
2054
+ required: param.required,
2055
+ schema: param.schema
2056
+ }))
2057
+ }),
2181
2058
  name: resolver.param[kind](node, params[0]),
2182
2059
  direction: "encode"
2183
2060
  })) : [];
@@ -2236,7 +2113,7 @@ var compatibility = {
2236
2113
  };
2237
2114
  //#endregion
2238
2115
  //#region package.json
2239
- var version = "5.4.8";
2116
+ var version = "5.4.10";
2240
2117
  //#endregion
2241
2118
  //#region src/resolvers/resolverZod.ts
2242
2119
  /**
@@ -2336,6 +2213,18 @@ const pluginZod = (0, kubb_kit.defineExtension)({
2336
2213
  path: "zod",
2337
2214
  barrel: { type: "named" }
2338
2215
  }, group, exclude = [], include, override = [], compile = false, mini = false, guidType = "uuid", regexType = "literal", importPath = mini ? "zod/mini" : "zod", coercion = false, inferred = false, typeGuards = false, printer, resolver: userResolver, macros: userMacros } = options;
2216
+ (0, kubb_kit.assertPluginOption)({
2217
+ plugin: pluginZodName,
2218
+ option: "guidType",
2219
+ value: guidType,
2220
+ allowed: ["uuid", "guid"]
2221
+ });
2222
+ (0, kubb_kit.assertPluginOption)({
2223
+ plugin: pluginZodName,
2224
+ option: "regexType",
2225
+ value: regexType,
2226
+ allowed: ["literal", "constructor"]
2227
+ });
2339
2228
  (0, kubb_kit.setResolver)(userResolver ? kubb_kit.Resolver.merge(resolverZod, userResolver) : resolverZod);
2340
2229
  if (userMacros?.length) (0, kubb_kit.setMacros)(userMacros);
2341
2230
  (0, kubb_kit.addGenerator)(zodGenerator);