zod-nest 3.2.6 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1037,6 +1037,101 @@ var ZodNestModule = class _ZodNestModule {
1037
1037
  };
1038
1038
  }
1039
1039
  };
1040
+
1041
+ // src/document/http-methods.ts
1042
+ var OPENAPI_OPERATION_KEYS = [
1043
+ "get",
1044
+ "put",
1045
+ "post",
1046
+ "delete",
1047
+ "options",
1048
+ "head",
1049
+ "patch",
1050
+ "trace",
1051
+ "query"
1052
+ ];
1053
+ var EXTENSION_OPERATION_KEYS = [
1054
+ "search",
1055
+ "propfind",
1056
+ "proppatch",
1057
+ "mkcol",
1058
+ "copy",
1059
+ "move",
1060
+ "lock",
1061
+ "unlock"
1062
+ ];
1063
+ var HTTP_METHODS = [
1064
+ ...OPENAPI_OPERATION_KEYS,
1065
+ ...EXTENSION_OPERATION_KEYS
1066
+ ];
1067
+ var ADDITIONAL_OPERATIONS_KEY = "additionalOperations";
1068
+ var isRecord = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object", "isRecord");
1069
+ var operationsOfPathItem = /* @__PURE__ */ __name((pathItem) => {
1070
+ const operations = [];
1071
+ for (const method of HTTP_METHODS) {
1072
+ const operation = pathItem[method];
1073
+ if (isRecord(operation)) {
1074
+ operations.push(operation);
1075
+ }
1076
+ }
1077
+ const additional = pathItem[ADDITIONAL_OPERATIONS_KEY];
1078
+ if (isRecord(additional)) {
1079
+ for (const operation of Object.values(additional)) {
1080
+ if (isRecord(operation)) {
1081
+ operations.push(operation);
1082
+ }
1083
+ }
1084
+ }
1085
+ return operations;
1086
+ }, "operationsOfPathItem");
1087
+ var forEachOperation = /* @__PURE__ */ __name((doc, fn) => {
1088
+ const paths = doc.paths;
1089
+ if (!isRecord(paths)) {
1090
+ return;
1091
+ }
1092
+ for (const pathItem of Object.values(paths)) {
1093
+ if (!isRecord(pathItem)) {
1094
+ continue;
1095
+ }
1096
+ for (const operation of operationsOfPathItem(pathItem)) {
1097
+ fn(operation);
1098
+ }
1099
+ }
1100
+ }, "forEachOperation");
1101
+
1102
+ // src/document/additional-operations.ts
1103
+ var isRecord2 = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object", "isRecord");
1104
+ var relocateExtensionOperations = /* @__PURE__ */ __name((doc) => {
1105
+ const paths = doc.paths;
1106
+ if (!isRecord2(paths)) {
1107
+ return;
1108
+ }
1109
+ for (const pathItem of Object.values(paths)) {
1110
+ if (!isRecord2(pathItem)) {
1111
+ continue;
1112
+ }
1113
+ relocateInPathItem(pathItem);
1114
+ }
1115
+ }, "relocateExtensionOperations");
1116
+ var relocateInPathItem = /* @__PURE__ */ __name((pathItem) => {
1117
+ const relocated = {};
1118
+ for (const method of EXTENSION_OPERATION_KEYS) {
1119
+ const operation = pathItem[method];
1120
+ if (!isRecord2(operation)) {
1121
+ continue;
1122
+ }
1123
+ relocated[method.toUpperCase()] = operation;
1124
+ delete pathItem[method];
1125
+ }
1126
+ if (Object.keys(relocated).length === 0) {
1127
+ return;
1128
+ }
1129
+ const existing = pathItem[ADDITIONAL_OPERATIONS_KEY];
1130
+ pathItem[ADDITIONAL_OPERATIONS_KEY] = isRecord2(existing) ? {
1131
+ ...relocated,
1132
+ ...existing
1133
+ } : relocated;
1134
+ }, "relocateInPathItem");
1040
1135
  var URI = /* @__PURE__ */ __name((id) => `#/components/schemas/${id}`, "URI");
1041
1136
  var bulkEmit = /* @__PURE__ */ __name((opts) => {
1042
1137
  const knownIds = new Set(opts.registry.ids());
@@ -1076,46 +1171,6 @@ var runPass = /* @__PURE__ */ __name((opts, io, knownIds) => {
1076
1171
  return filtered;
1077
1172
  }, "runPass");
1078
1173
 
1079
- // src/document/http-methods.ts
1080
- var HTTP_METHODS = [
1081
- "get",
1082
- "put",
1083
- "post",
1084
- "delete",
1085
- "options",
1086
- "head",
1087
- "patch",
1088
- "trace",
1089
- "query",
1090
- "search",
1091
- "propfind",
1092
- "proppatch",
1093
- "mkcol",
1094
- "copy",
1095
- "move",
1096
- "lock",
1097
- "unlock"
1098
- ];
1099
- var forEachOperation = /* @__PURE__ */ __name((doc, fn) => {
1100
- const paths = doc.paths;
1101
- if (paths === null || typeof paths !== "object") {
1102
- return;
1103
- }
1104
- for (const pathItem of Object.values(paths)) {
1105
- if (pathItem === null || typeof pathItem !== "object") {
1106
- continue;
1107
- }
1108
- const pathRecord = pathItem;
1109
- for (const method of HTTP_METHODS) {
1110
- const op = pathRecord[method];
1111
- if (op === null || typeof op !== "object") {
1112
- continue;
1113
- }
1114
- fn(op);
1115
- }
1116
- }
1117
- }, "forEachOperation");
1118
-
1119
1174
  // src/document/walk-refs.ts
1120
1175
  var walkRefs = /* @__PURE__ */ __name((node, visit) => {
1121
1176
  if (node === null || typeof node !== "object") {
@@ -1188,22 +1243,12 @@ var collectInputExposedIds = /* @__PURE__ */ __name((doc, classToDtoId, knownIds
1188
1243
  if (!isPlainRecord2(pathItem)) {
1189
1244
  continue;
1190
1245
  }
1191
- for (const operation of operationsOf(pathItem)) {
1246
+ for (const operation of operationsOfPathItem(pathItem)) {
1192
1247
  collectRefsFromOperation(operation, classToDtoId, knownIds, ids);
1193
1248
  }
1194
1249
  }
1195
1250
  return ids;
1196
1251
  }, "collectInputExposedIds");
1197
- var operationsOf = /* @__PURE__ */ __name((pathItem) => {
1198
- const out = [];
1199
- for (const method of HTTP_METHODS) {
1200
- const op = pathItem[method];
1201
- if (isPlainRecord2(op)) {
1202
- out.push(op);
1203
- }
1204
- }
1205
- return out;
1206
- }, "operationsOf");
1207
1252
  var collectRefsFromOperation = /* @__PURE__ */ __name((operation, classToDtoId, knownIds, ids) => {
1208
1253
  if (isPlainRecord2(operation.requestBody)) {
1209
1254
  collectRefsFromContent(operation.requestBody.content, classToDtoId, knownIds, ids);
@@ -1265,7 +1310,7 @@ var collectOutputExposedIds = /* @__PURE__ */ __name((doc, classToDtoId, knownId
1265
1310
  if (!isPlainRecord2(pathItem)) {
1266
1311
  continue;
1267
1312
  }
1268
- for (const operation of operationsOf(pathItem)) {
1313
+ for (const operation of operationsOfPathItem(pathItem)) {
1269
1314
  collectRefsFromResponses(operation.responses, classToDtoId, knownIds, ids);
1270
1315
  }
1271
1316
  }
@@ -1724,6 +1769,25 @@ var decorateIfPresent = /* @__PURE__ */ __name((schemas, key) => {
1724
1769
  };
1725
1770
  }, "decorateIfPresent");
1726
1771
 
1772
+ // src/document/openapi-version.ts
1773
+ var SUPPORTED_OPENAPI_SERIES = [
1774
+ "3.1",
1775
+ "3.2"
1776
+ ];
1777
+ var DEFAULT_OPENAPI_VERSION = "3.1.0";
1778
+ var SUPPORTED_VERSION_PATTERN = /^3\.[12]\.\d+(?:-.+)?$/;
1779
+ var resolveOpenApiVersion = /* @__PURE__ */ __name((doc) => {
1780
+ const declared = doc.openapi;
1781
+ if (typeof declared !== "string" || declared === "") {
1782
+ return DEFAULT_OPENAPI_VERSION;
1783
+ }
1784
+ if (SUPPORTED_VERSION_PATTERN.test(declared)) {
1785
+ return declared;
1786
+ }
1787
+ console.warn(`[zod-nest] Document declares OpenAPI \`${declared}\`, which zod-nest does not emit; emitting \`${DEFAULT_OPENAPI_VERSION}\` instead. Supported: ${SUPPORTED_OPENAPI_SERIES.map((series) => `${series}.x`).join(", ")}. Set one via \`DocumentBuilder.setOpenAPIVersion()\` to silence this.`);
1788
+ return DEFAULT_OPENAPI_VERSION;
1789
+ }, "resolveOpenApiVersion");
1790
+
1727
1791
  // src/document/ref-titles.ts
1728
1792
  var applyRefTitles = /* @__PURE__ */ __name((doc) => {
1729
1793
  const schemas = doc.components?.schemas;
@@ -1793,11 +1857,7 @@ var rewriteRefs = /* @__PURE__ */ __name((params) => {
1793
1857
  }
1794
1858
  }, "rewriteRefs");
1795
1859
  var rewriteResponseSubtree = /* @__PURE__ */ __name((pathItem, divergentOutputIds) => {
1796
- for (const method of HTTP_METHODS) {
1797
- const op = pathItem[method];
1798
- if (op === null || typeof op !== "object") {
1799
- continue;
1800
- }
1860
+ for (const op of operationsOfPathItem(pathItem)) {
1801
1861
  const responses = op.responses;
1802
1862
  if (responses === null || typeof responses !== "object") {
1803
1863
  continue;
@@ -1876,7 +1936,6 @@ var withForcedExposure = /* @__PURE__ */ __name((collected, registry) => {
1876
1936
  classToDtoId: collected.classToDtoId
1877
1937
  };
1878
1938
  }, "withForcedExposure");
1879
- var OPENAPI_VERSION = "3.1.0";
1880
1939
  var applyZodNest = /* @__PURE__ */ __name((doc, opts = {}) => {
1881
1940
  const registry = opts.registry ?? defaultRegistry;
1882
1941
  const collected = collectUsage(doc, registry);
@@ -1917,7 +1976,11 @@ var applyZodNest = /* @__PURE__ */ __name((doc, opts = {}) => {
1917
1976
  doc,
1918
1977
  collected: extended
1919
1978
  });
1920
- doc.openapi = OPENAPI_VERSION;
1979
+ const openApiVersion = resolveOpenApiVersion(doc);
1980
+ if (openApiVersion.startsWith("3.2.")) {
1981
+ relocateExtensionOperations(doc);
1982
+ }
1983
+ doc.openapi = openApiVersion;
1921
1984
  return doc;
1922
1985
  }, "applyZodNest");
1923
1986