zod-nest 1.3.0 → 1.3.1

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.js CHANGED
@@ -1199,6 +1199,25 @@ var HTTP_METHODS = [
1199
1199
  "patch",
1200
1200
  "trace"
1201
1201
  ];
1202
+ var forEachOperation = /* @__PURE__ */ __name((doc, fn) => {
1203
+ const paths = doc.paths;
1204
+ if (paths === null || typeof paths !== "object") {
1205
+ return;
1206
+ }
1207
+ for (const pathItem of Object.values(paths)) {
1208
+ if (pathItem === null || typeof pathItem !== "object") {
1209
+ continue;
1210
+ }
1211
+ const pathRecord = pathItem;
1212
+ for (const method of HTTP_METHODS) {
1213
+ const op = pathRecord[method];
1214
+ if (op === null || typeof op !== "object") {
1215
+ continue;
1216
+ }
1217
+ fn(op);
1218
+ }
1219
+ }
1220
+ }, "forEachOperation");
1202
1221
 
1203
1222
  // src/document/collect-usage.ts
1204
1223
  var isPlainRecord2 = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !Array.isArray(value), "isPlainRecord");
@@ -1441,41 +1460,39 @@ var hintFor = /* @__PURE__ */ __name((ref, collected) => {
1441
1460
  var isPlainRecord3 = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !Array.isArray(value), "isPlainRecord");
1442
1461
  var expandParamMarkers = /* @__PURE__ */ __name((params) => {
1443
1462
  const { doc, inputSchemas, outputSchemas } = params;
1444
- const paths = doc.paths;
1445
- if (!isPlainRecord3(paths)) {
1446
- return;
1447
- }
1448
- for (const pathItem of Object.values(paths)) {
1449
- if (!isPlainRecord3(pathItem)) {
1450
- continue;
1463
+ let expandedAny = false;
1464
+ forEachOperation(doc, (op) => {
1465
+ const parameters = op.parameters;
1466
+ if (!Array.isArray(parameters)) {
1467
+ return;
1451
1468
  }
1452
- for (const method of HTTP_METHODS) {
1453
- const op = pathItem[method];
1454
- if (!isPlainRecord3(op)) {
1455
- continue;
1456
- }
1457
- const parameters = op.parameters;
1458
- if (!Array.isArray(parameters)) {
1459
- continue;
1460
- }
1461
- op.parameters = expandParameterList(parameters, inputSchemas, outputSchemas);
1469
+ const next = expandParameterList(parameters, inputSchemas, outputSchemas);
1470
+ if (next !== parameters) {
1471
+ op.parameters = next;
1472
+ expandedAny = true;
1462
1473
  }
1474
+ });
1475
+ if (expandedAny) {
1476
+ pruneOrphanObjectSchema(doc);
1463
1477
  }
1464
- pruneOrphanObjectSchema(doc);
1465
1478
  }, "expandParamMarkers");
1466
1479
  var expandParameterList = /* @__PURE__ */ __name((parameters, inputSchemas, outputSchemas) => {
1467
- const result = [];
1468
- for (const param of parameters) {
1480
+ let result;
1481
+ for (let i = 0; i < parameters.length; i++) {
1482
+ const param = parameters[i];
1469
1483
  const marker = readMarker2(param);
1470
1484
  if (marker === void 0) {
1471
- result.push(param);
1485
+ result?.push(param);
1472
1486
  continue;
1473
1487
  }
1488
+ if (result === void 0) {
1489
+ result = parameters.slice(0, i);
1490
+ }
1474
1491
  const map = marker.io === "output" ? outputSchemas : inputSchemas;
1475
1492
  const body = map.get(marker.dtoId);
1476
1493
  result.push(...expandOne(marker, body));
1477
1494
  }
1478
- return result;
1495
+ return result ?? parameters;
1479
1496
  }, "expandParameterList");
1480
1497
  var readMarker2 = /* @__PURE__ */ __name((value) => {
1481
1498
  if (!isPlainRecord3(value)) {
@@ -1532,16 +1549,12 @@ var buildParameter = /* @__PURE__ */ __name((marker, name, schema, required) =>
1532
1549
  console.warn(`[zod-nest] Path parameter \`${name}\` on DTO \`${marker.dtoId}\` is marked optional in the Zod schema; OpenAPI 3.1 requires path parameters to be required. Coercing \`required: true\` so the emitted document is spec-valid. Fix by removing \`.optional()\` / \`.nullish()\` from the field, or by switching the decorator to @Query() / @Headers() if the field is genuinely optional.`);
1533
1550
  effectiveRequired = true;
1534
1551
  }
1535
- const entry = {
1552
+ return {
1536
1553
  name,
1537
1554
  in: marker.in,
1538
1555
  required: effectiveRequired,
1539
1556
  schema
1540
1557
  };
1541
- if (typeof schema.description === "string") {
1542
- entry.description = schema.description;
1543
- }
1544
- return entry;
1545
1558
  }, "buildParameter");
1546
1559
  var capitalize = /* @__PURE__ */ __name((value) => value.charAt(0).toUpperCase() + value.slice(1), "capitalize");
1547
1560
  var pruneOrphanObjectSchema = /* @__PURE__ */ __name((doc) => {
@@ -1755,40 +1768,28 @@ var stripMarkers = /* @__PURE__ */ __name((doc) => {
1755
1768
  if (schemas !== void 0) {
1756
1769
  for (const schema of Object.values(schemas)) {
1757
1770
  stripMarkerFromSchema(schema);
1771
+ dropJsonSchemaMetadata(schema);
1758
1772
  }
1759
1773
  }
1760
1774
  stripMarkerParameters(doc);
1761
1775
  }, "stripMarkers");
1762
- var stripMarkerParameters = /* @__PURE__ */ __name((doc) => {
1763
- const paths = doc.paths;
1764
- if (paths === null || typeof paths !== "object") {
1776
+ var dropJsonSchemaMetadata = /* @__PURE__ */ __name((schema) => {
1777
+ if (schema === null || typeof schema !== "object") {
1765
1778
  return;
1766
1779
  }
1767
- for (const pathItem of Object.values(paths)) {
1768
- if (pathItem === null || typeof pathItem !== "object") {
1769
- continue;
1770
- }
1771
- const pathRecord = pathItem;
1772
- for (const method of HTTP_METHODS) {
1773
- const op = pathRecord[method];
1774
- if (op === null || typeof op !== "object") {
1775
- continue;
1776
- }
1777
- const opRecord = op;
1778
- const parameters = opRecord.parameters;
1779
- if (!Array.isArray(parameters)) {
1780
- continue;
1781
- }
1782
- opRecord.parameters = parameters.filter((param) => !isMarkerParam(param));
1780
+ const body = schema;
1781
+ delete body.$schema;
1782
+ delete body.$id;
1783
+ }, "dropJsonSchemaMetadata");
1784
+ var stripMarkerParameters = /* @__PURE__ */ __name((doc) => {
1785
+ forEachOperation(doc, (op) => {
1786
+ const parameters = op.parameters;
1787
+ if (!Array.isArray(parameters)) {
1788
+ return;
1783
1789
  }
1784
- }
1790
+ op.parameters = parameters.filter((param) => !isZodDtoMarker(param));
1791
+ });
1785
1792
  }, "stripMarkerParameters");
1786
- var isMarkerParam = /* @__PURE__ */ __name((value) => {
1787
- if (value === null || typeof value !== "object") {
1788
- return false;
1789
- }
1790
- return value.__zodNestDto === true;
1791
- }, "isMarkerParam");
1792
1793
  var stripMarkerFromSchema = /* @__PURE__ */ __name((schema) => {
1793
1794
  if (schema === null || typeof schema !== "object") {
1794
1795
  return;