zod-openapi 3.0.1 → 3.1.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.
@@ -55,12 +55,15 @@ const createBooleanSchema = (_zodBoolean) => ({
55
55
  });
56
56
  const createBrandedSchema = (zodBranded, state) => createSchemaObject(zodBranded._def.type, state, ["brand"]);
57
57
  const createCatchSchema = (zodCatch, state) => createSchemaObject(zodCatch._def.innerType, state, ["catch"]);
58
- const createDateSchema = (_zodDate) => ({
59
- type: "schema",
60
- schema: {
61
- type: "string"
62
- }
63
- });
58
+ const createDateSchema = (_zodDate, state) => {
59
+ var _a;
60
+ return {
61
+ type: "schema",
62
+ schema: ((_a = state.documentOptions) == null ? void 0 : _a.defaultDateSchema) ?? {
63
+ type: "string"
64
+ }
65
+ };
66
+ };
64
67
  const createDefaultSchema = (zodDefault, state) => {
65
68
  const schemaObject = createSchemaObject(zodDefault._def.innerType, state, [
66
69
  "default"
@@ -81,7 +84,7 @@ const createNativeEnumSchema = (zodEnum, state) => {
81
84
  const enumValues = getValidEnumValues(zodEnum._def.values);
82
85
  const { numbers, strings } = sortStringsAndNumbers(enumValues);
83
86
  if (strings.length && numbers.length) {
84
- if (satisfiesVersion(state.components.openapi, "3.1.0"))
87
+ if (satisfiesVersion(state.components.openapi, "3.1.0")) {
85
88
  return {
86
89
  type: "schema",
87
90
  schema: {
@@ -89,6 +92,7 @@ const createNativeEnumSchema = (zodEnum, state) => {
89
92
  enum: [...strings, ...numbers]
90
93
  }
91
94
  };
95
+ }
92
96
  return {
93
97
  type: "schema",
94
98
  schema: {
@@ -1128,11 +1132,11 @@ const mapPrefixItems = (items, state) => {
1128
1132
  return void 0;
1129
1133
  };
1130
1134
  const createUnionSchema = (zodUnion, state) => {
1131
- var _a;
1135
+ var _a, _b;
1132
1136
  const schemas = zodUnion.options.map(
1133
1137
  (option, index) => createSchemaObject(option, state, [`union option ${index}`])
1134
1138
  );
1135
- if ((_a = zodUnion._def.openapi) == null ? void 0 : _a.unionOneOf) {
1139
+ if (((_a = zodUnion._def.openapi) == null ? void 0 : _a.unionOneOf) ?? ((_b = state.documentOptions) == null ? void 0 : _b.unionOneOf)) {
1136
1140
  return {
1137
1141
  type: "schema",
1138
1142
  schema: {
@@ -1210,7 +1214,7 @@ const createSchemaSwitch = (zodSchema, state) => {
1210
1214
  return createTupleSchema(zodSchema, state);
1211
1215
  }
1212
1216
  if (isZodType(zodSchema, "ZodDate")) {
1213
- return createDateSchema();
1217
+ return createDateSchema(zodSchema, state);
1214
1218
  }
1215
1219
  if (isZodType(zodSchema, "ZodPipeline")) {
1216
1220
  return createPipelineSchema(zodSchema, state);
@@ -1360,7 +1364,7 @@ const createSchema = (zodSchema, state, subpath) => {
1360
1364
  }
1361
1365
  return schema.schema;
1362
1366
  };
1363
- const createMediaTypeSchema = (schemaObject, components, type, subpath) => {
1367
+ const createMediaTypeSchema = (schemaObject, components, type, subpath, documentOptions) => {
1364
1368
  if (!schemaObject) {
1365
1369
  return void 0;
1366
1370
  }
@@ -1373,30 +1377,35 @@ const createMediaTypeSchema = (schemaObject, components, type, subpath) => {
1373
1377
  components,
1374
1378
  type,
1375
1379
  path: [],
1376
- visited: /* @__PURE__ */ new Set()
1380
+ visited: /* @__PURE__ */ new Set(),
1381
+ documentOptions
1377
1382
  },
1378
1383
  subpath
1379
1384
  );
1380
1385
  };
1381
- const createMediaTypeObject = (mediaTypeObject, components, type, subpath) => {
1386
+ const createMediaTypeObject = (mediaTypeObject, components, type, subpath, documentOptions) => {
1382
1387
  if (!mediaTypeObject) {
1383
1388
  return void 0;
1384
1389
  }
1385
1390
  return {
1386
1391
  ...mediaTypeObject,
1387
- schema: createMediaTypeSchema(mediaTypeObject.schema, components, type, [
1388
- ...subpath,
1389
- "schema"
1390
- ])
1392
+ schema: createMediaTypeSchema(
1393
+ mediaTypeObject.schema,
1394
+ components,
1395
+ type,
1396
+ [...subpath, "schema"],
1397
+ documentOptions
1398
+ )
1391
1399
  };
1392
1400
  };
1393
- const createContent = (contentObject, components, type, subpath) => Object.entries(contentObject).reduce(
1401
+ const createContent = (contentObject, components, type, subpath, documentOptions) => Object.entries(contentObject).reduce(
1394
1402
  (acc, [mediaType, zodOpenApiMediaTypeObject]) => {
1395
1403
  const mediaTypeObject = createMediaTypeObject(
1396
1404
  zodOpenApiMediaTypeObject,
1397
1405
  components,
1398
1406
  type,
1399
- [...subpath, mediaType]
1407
+ [...subpath, mediaType],
1408
+ documentOptions
1400
1409
  );
1401
1410
  if (mediaTypeObject) {
1402
1411
  acc[mediaType] = mediaTypeObject;
@@ -1406,14 +1415,15 @@ const createContent = (contentObject, components, type, subpath) => Object.entri
1406
1415
  {}
1407
1416
  );
1408
1417
  const createComponentParamRef = (ref) => `#/components/parameters/${ref}`;
1409
- const createBaseParameter = (schema, components, subpath) => {
1418
+ const createBaseParameter = (schema, components, subpath, documentOptions) => {
1410
1419
  var _a, _b, _c;
1411
1420
  const { ref, ...rest } = ((_a = schema._def.openapi) == null ? void 0 : _a.param) ?? {};
1412
1421
  const state = {
1413
1422
  components,
1414
1423
  type: "input",
1415
1424
  path: [],
1416
- visited: /* @__PURE__ */ new Set()
1425
+ visited: /* @__PURE__ */ new Set(),
1426
+ documentOptions
1417
1427
  };
1418
1428
  const schemaObject = createSchema(schema, state, [...subpath, "schema"]);
1419
1429
  const required = !((_b = isOptionalSchema(schema, state)) == null ? void 0 : _b.optional);
@@ -1425,7 +1435,7 @@ const createBaseParameter = (schema, components, subpath) => {
1425
1435
  ...required && { required }
1426
1436
  };
1427
1437
  };
1428
- const createParamOrRef = (zodSchema, components, subpath, type, name) => {
1438
+ const createParamOrRef = (zodSchema, components, subpath, type, name, documentOptions) => {
1429
1439
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1430
1440
  const component = components.parameters.get(zodSchema);
1431
1441
  const paramType = ((_c = (_b = (_a = zodSchema._def) == null ? void 0 : _a.openapi) == null ? void 0 : _b.param) == null ? void 0 : _c.in) ?? (component == null ? void 0 : component.in) ?? type;
@@ -1444,7 +1454,12 @@ const createParamOrRef = (zodSchema, components, subpath, type, name) => {
1444
1454
  $ref: createComponentParamRef(component.ref)
1445
1455
  };
1446
1456
  }
1447
- const baseParamOrRef = createBaseParameter(zodSchema, components, subpath);
1457
+ const baseParamOrRef = createBaseParameter(
1458
+ zodSchema,
1459
+ components,
1460
+ subpath,
1461
+ documentOptions
1462
+ );
1448
1463
  if ("$ref" in baseParamOrRef) {
1449
1464
  throw new Error("Unexpected Error: received a reference object");
1450
1465
  }
@@ -1468,59 +1483,82 @@ const createParamOrRef = (zodSchema, components, subpath, type, name) => {
1468
1483
  }
1469
1484
  return paramObject;
1470
1485
  };
1471
- const createParameters = (type, zodObjectType, components, subpath) => {
1486
+ const createParameters = (type, zodObjectType, components, subpath, documentOptions) => {
1472
1487
  if (!zodObjectType) {
1473
1488
  return [];
1474
1489
  }
1475
1490
  const zodObject = getZodObject(zodObjectType).shape;
1476
1491
  return Object.entries(zodObject).map(
1477
- ([key, zodSchema]) => createParamOrRef(zodSchema, components, [...subpath, key], type, key)
1492
+ ([key, zodSchema]) => createParamOrRef(
1493
+ zodSchema,
1494
+ components,
1495
+ [...subpath, key],
1496
+ type,
1497
+ key,
1498
+ documentOptions
1499
+ )
1478
1500
  );
1479
1501
  };
1480
- const createRequestParams = (requestParams, components, subpath) => {
1502
+ const createRequestParams = (requestParams, components, subpath, documentOptions) => {
1481
1503
  if (!requestParams) {
1482
1504
  return [];
1483
1505
  }
1484
- const pathParams = createParameters("path", requestParams.path, components, [
1485
- ...subpath,
1486
- "path"
1487
- ]);
1506
+ const pathParams = createParameters(
1507
+ "path",
1508
+ requestParams.path,
1509
+ components,
1510
+ [...subpath, "path"],
1511
+ documentOptions
1512
+ );
1488
1513
  const queryParams = createParameters(
1489
1514
  "query",
1490
1515
  requestParams.query,
1491
1516
  components,
1492
- [...subpath, "query"]
1517
+ [...subpath, "query"],
1518
+ documentOptions
1493
1519
  );
1494
1520
  const cookieParams = createParameters(
1495
1521
  "cookie",
1496
1522
  requestParams.cookie,
1497
1523
  components,
1498
- [...subpath, "cookie"]
1524
+ [...subpath, "cookie"],
1525
+ documentOptions
1499
1526
  );
1500
1527
  const headerParams = createParameters(
1501
1528
  "header",
1502
1529
  requestParams.header,
1503
1530
  components,
1504
- [...subpath, "header"]
1531
+ [...subpath, "header"],
1532
+ documentOptions
1505
1533
  );
1506
1534
  return [...pathParams, ...queryParams, ...cookieParams, ...headerParams];
1507
1535
  };
1508
- const createManualParameters = (parameters, components, subpath) => (parameters == null ? void 0 : parameters.map((param, index) => {
1536
+ const createManualParameters = (parameters, components, subpath, documentOptions) => (parameters == null ? void 0 : parameters.map((param, index) => {
1509
1537
  if (isAnyZodType(param)) {
1510
- return createParamOrRef(param, components, [
1511
- ...subpath,
1512
- `param index ${index}`
1513
- ]);
1538
+ return createParamOrRef(
1539
+ param,
1540
+ components,
1541
+ [...subpath, `param index ${index}`],
1542
+ void 0,
1543
+ void 0,
1544
+ documentOptions
1545
+ );
1514
1546
  }
1515
1547
  return param;
1516
1548
  })) ?? [];
1517
- const createParametersObject = (parameters, requestParams, components, subpath) => {
1549
+ const createParametersObject = (parameters, requestParams, components, subpath, documentOptions) => {
1518
1550
  const manualParameters = createManualParameters(
1519
1551
  parameters,
1520
1552
  components,
1521
- subpath
1553
+ subpath,
1554
+ documentOptions
1555
+ );
1556
+ const createdParams = createRequestParams(
1557
+ requestParams,
1558
+ components,
1559
+ subpath,
1560
+ documentOptions
1522
1561
  );
1523
- const createdParams = createRequestParams(requestParams, components, subpath);
1524
1562
  const combinedParameters = [
1525
1563
  ...manualParameters,
1526
1564
  ...createdParams
@@ -1548,19 +1586,19 @@ const getZodObject = (schema, type) => {
1548
1586
  throw new Error("failed to find ZodObject in schema");
1549
1587
  };
1550
1588
  const isISpecificationExtension = (key) => key.startsWith("x-");
1551
- const createResponseHeaders = (responseHeaders, components) => {
1589
+ const createResponseHeaders = (responseHeaders, components, documentOptions) => {
1552
1590
  if (!responseHeaders) {
1553
1591
  return void 0;
1554
1592
  }
1555
1593
  if (isAnyZodType(responseHeaders)) {
1556
1594
  return Object.entries(responseHeaders.shape).reduce((acc, [key, zodSchema]) => {
1557
- acc[key] = createHeaderOrRef(zodSchema, components);
1595
+ acc[key] = createHeaderOrRef(zodSchema, components, documentOptions);
1558
1596
  return acc;
1559
1597
  }, {});
1560
1598
  }
1561
1599
  return responseHeaders;
1562
1600
  };
1563
- const createHeaderOrRef = (schema, components) => {
1601
+ const createHeaderOrRef = (schema, components, documentOptions) => {
1564
1602
  var _a, _b, _c;
1565
1603
  const component = components.headers.get(schema);
1566
1604
  if (component && component.type === "complete") {
@@ -1568,7 +1606,7 @@ const createHeaderOrRef = (schema, components) => {
1568
1606
  $ref: createComponentHeaderRef(component.ref)
1569
1607
  };
1570
1608
  }
1571
- const baseHeader = createBaseHeader(schema, components);
1609
+ const baseHeader = createBaseHeader(schema, components, documentOptions);
1572
1610
  if ("$ref" in baseHeader) {
1573
1611
  throw new Error("Unexpected Error: received a reference object");
1574
1612
  }
@@ -1585,14 +1623,15 @@ const createHeaderOrRef = (schema, components) => {
1585
1623
  }
1586
1624
  return baseHeader;
1587
1625
  };
1588
- const createBaseHeader = (schema, components) => {
1626
+ const createBaseHeader = (schema, components, documentOptions) => {
1589
1627
  var _a, _b;
1590
1628
  const { ref, ...rest } = ((_a = schema._def.openapi) == null ? void 0 : _a.header) ?? {};
1591
1629
  const state = {
1592
1630
  components,
1593
1631
  type: "output",
1594
1632
  path: [],
1595
- visited: /* @__PURE__ */ new Set()
1633
+ visited: /* @__PURE__ */ new Set(),
1634
+ documentOptions
1596
1635
  };
1597
1636
  const schemaObject = createSchema(schema, state, ["header"]);
1598
1637
  const required = !((_b = isOptionalSchema(schema, state)) == null ? void 0 : _b.optional);
@@ -1603,7 +1642,7 @@ const createBaseHeader = (schema, components) => {
1603
1642
  };
1604
1643
  };
1605
1644
  const createComponentHeaderRef = (ref) => `#/components/headers/${ref}`;
1606
- const createResponse = (responseObject, components, subpath) => {
1645
+ const createResponse = (responseObject, components, subpath, documentOptions) => {
1607
1646
  if ("$ref" in responseObject) {
1608
1647
  return responseObject;
1609
1648
  }
@@ -1612,15 +1651,22 @@ const createResponse = (responseObject, components, subpath) => {
1612
1651
  return { $ref: createComponentResponseRef(component.ref) };
1613
1652
  }
1614
1653
  const { content, headers, ref, ...rest } = responseObject;
1615
- const maybeHeaders = createResponseHeaders(headers, components);
1654
+ const maybeHeaders = createResponseHeaders(
1655
+ headers,
1656
+ components,
1657
+ documentOptions
1658
+ );
1616
1659
  const response = {
1617
1660
  ...rest,
1618
1661
  ...maybeHeaders && { headers: maybeHeaders },
1619
1662
  ...content && {
1620
- content: createContent(content, components, "output", [
1621
- ...subpath,
1622
- "content"
1623
- ])
1663
+ content: createContent(
1664
+ content,
1665
+ components,
1666
+ "output",
1667
+ [...subpath, "content"],
1668
+ documentOptions
1669
+ )
1624
1670
  }
1625
1671
  };
1626
1672
  const responseRef = ref ?? (component == null ? void 0 : component.ref);
@@ -1636,21 +1682,23 @@ const createResponse = (responseObject, components, subpath) => {
1636
1682
  }
1637
1683
  return response;
1638
1684
  };
1639
- const createResponses = (responsesObject, components, subpath) => Object.entries(responsesObject).reduce(
1685
+ const createResponses = (responsesObject, components, subpath, documentOptions) => Object.entries(responsesObject).reduce(
1640
1686
  (acc, [statusCode, responseObject]) => {
1641
1687
  if (isISpecificationExtension(statusCode)) {
1642
1688
  acc[statusCode] = responseObject;
1643
1689
  return acc;
1644
1690
  }
1645
- acc[statusCode] = createResponse(responseObject, components, [
1646
- ...subpath,
1647
- statusCode
1648
- ]);
1691
+ acc[statusCode] = createResponse(
1692
+ responseObject,
1693
+ components,
1694
+ [...subpath, statusCode],
1695
+ documentOptions
1696
+ );
1649
1697
  return acc;
1650
1698
  },
1651
1699
  {}
1652
1700
  );
1653
- const createRequestBody = (requestBodyObject, components, subpath) => {
1701
+ const createRequestBody = (requestBodyObject, components, subpath, documentOptions) => {
1654
1702
  if (!requestBodyObject) {
1655
1703
  return void 0;
1656
1704
  }
@@ -1663,10 +1711,13 @@ const createRequestBody = (requestBodyObject, components, subpath) => {
1663
1711
  const ref = requestBodyObject.ref ?? (component == null ? void 0 : component.ref);
1664
1712
  const requestBody = {
1665
1713
  ...requestBodyObject,
1666
- content: createContent(requestBodyObject.content, components, "input", [
1667
- ...subpath,
1668
- "content"
1669
- ])
1714
+ content: createContent(
1715
+ requestBodyObject.content,
1716
+ components,
1717
+ "input",
1718
+ [...subpath, "content"],
1719
+ documentOptions
1720
+ )
1670
1721
  };
1671
1722
  if (ref) {
1672
1723
  components.requestBodies.set(requestBodyObject, {
@@ -1680,28 +1731,32 @@ const createRequestBody = (requestBodyObject, components, subpath) => {
1680
1731
  }
1681
1732
  return requestBody;
1682
1733
  };
1683
- const createOperation = (operationObject, components, subpath) => {
1734
+ const createOperation = (operationObject, components, subpath, documentOptions) => {
1684
1735
  const { parameters, requestParams, requestBody, responses, ...rest } = operationObject;
1685
1736
  const maybeParameters = createParametersObject(
1686
1737
  parameters,
1687
1738
  requestParams,
1688
1739
  components,
1689
- [...subpath, "parameters"]
1740
+ [...subpath, "parameters"],
1741
+ documentOptions
1690
1742
  );
1691
1743
  const maybeRequestBody = createRequestBody(
1692
1744
  operationObject.requestBody,
1693
1745
  components,
1694
- [...subpath, "request body"]
1746
+ [...subpath, "request body"],
1747
+ documentOptions
1695
1748
  );
1696
1749
  const maybeResponses = createResponses(
1697
1750
  operationObject.responses,
1698
1751
  components,
1699
- [...subpath, "responses"]
1752
+ [...subpath, "responses"],
1753
+ documentOptions
1700
1754
  );
1701
1755
  const maybeCallbacks = createCallbacks(
1702
1756
  operationObject.callbacks,
1703
1757
  components,
1704
- [...subpath, "callbacks"]
1758
+ [...subpath, "callbacks"],
1759
+ documentOptions
1705
1760
  );
1706
1761
  return {
1707
1762
  ...rest,
@@ -1711,7 +1766,7 @@ const createOperation = (operationObject, components, subpath) => {
1711
1766
  ...maybeCallbacks && { callbacks: maybeCallbacks }
1712
1767
  };
1713
1768
  };
1714
- const createPathItem = (pathObject, components, path) => Object.entries(pathObject).reduce(
1769
+ const createPathItem = (pathObject, components, path, documentOptions) => Object.entries(pathObject).reduce(
1715
1770
  (acc, [key, value]) => {
1716
1771
  if (!value) {
1717
1772
  return acc;
@@ -1720,7 +1775,8 @@ const createPathItem = (pathObject, components, path) => Object.entries(pathObje
1720
1775
  acc[key] = createOperation(
1721
1776
  value,
1722
1777
  components,
1723
- [...path, key]
1778
+ [...path, key],
1779
+ documentOptions
1724
1780
  );
1725
1781
  return acc;
1726
1782
  }
@@ -1729,7 +1785,7 @@ const createPathItem = (pathObject, components, path) => Object.entries(pathObje
1729
1785
  },
1730
1786
  {}
1731
1787
  );
1732
- const createPaths = (pathsObject, components) => {
1788
+ const createPaths = (pathsObject, components, documentOptions) => {
1733
1789
  if (!pathsObject) {
1734
1790
  return void 0;
1735
1791
  }
@@ -1739,13 +1795,18 @@ const createPaths = (pathsObject, components) => {
1739
1795
  acc[path] = pathItemObject;
1740
1796
  return acc;
1741
1797
  }
1742
- acc[path] = createPathItem(pathItemObject, components, [path]);
1798
+ acc[path] = createPathItem(
1799
+ pathItemObject,
1800
+ components,
1801
+ [path],
1802
+ documentOptions
1803
+ );
1743
1804
  return acc;
1744
1805
  },
1745
1806
  {}
1746
1807
  );
1747
1808
  };
1748
- const createCallback = (callbackObject, components, subpath) => {
1809
+ const createCallback = (callbackObject, components, subpath, documentOptions) => {
1749
1810
  const { ref, ...callbacks } = callbackObject;
1750
1811
  const callback = Object.entries(
1751
1812
  callbacks
@@ -1754,10 +1815,13 @@ const createCallback = (callbackObject, components, subpath) => {
1754
1815
  acc[callbackName] = pathItemObject;
1755
1816
  return acc;
1756
1817
  }
1757
- acc[callbackName] = createPathItem(pathItemObject, components, [
1758
- ...subpath,
1759
- callbackName
1760
- ]);
1818
+ acc[callbackName] = createPathItem(
1819
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1820
+ pathItemObject,
1821
+ components,
1822
+ [...subpath, callbackName],
1823
+ documentOptions
1824
+ );
1761
1825
  return acc;
1762
1826
  }, {});
1763
1827
  if (ref) {
@@ -1772,7 +1836,7 @@ const createCallback = (callbackObject, components, subpath) => {
1772
1836
  }
1773
1837
  return callback;
1774
1838
  };
1775
- const createCallbacks = (callbacksObject, components, subpath) => {
1839
+ const createCallbacks = (callbacksObject, components, subpath, documentOptions) => {
1776
1840
  if (!callbacksObject) {
1777
1841
  return void 0;
1778
1842
  }
@@ -1782,10 +1846,13 @@ const createCallbacks = (callbacksObject, components, subpath) => {
1782
1846
  acc[callbackName] = callbackObject;
1783
1847
  return acc;
1784
1848
  }
1785
- acc[callbackName] = createCallback(callbackObject, components, [
1786
- ...subpath,
1787
- callbackName
1788
- ]);
1849
+ acc[callbackName] = createCallback(
1850
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
1851
+ callbackObject,
1852
+ components,
1853
+ [...subpath, callbackName],
1854
+ documentOptions
1855
+ );
1789
1856
  return acc;
1790
1857
  },
1791
1858
  {}
@@ -1934,16 +2001,34 @@ const createComponentSchemaRef = (schemaRef) => `#/components/schemas/${schemaRe
1934
2001
  const createComponentResponseRef = (responseRef) => `#/components/responses/${responseRef}`;
1935
2002
  const createComponentRequestBodyRef = (requestBodyRef) => `#/components/requestBodies/${requestBodyRef}`;
1936
2003
  const createComponentCallbackRef = (callbackRef) => `#/components/callbacks/${callbackRef}`;
1937
- const createComponents = (componentsObject, components) => {
1938
- const combinedSchemas = createSchemaComponents(componentsObject, components);
2004
+ const createComponents = (componentsObject, components, documentOptions) => {
2005
+ const combinedSchemas = createSchemaComponents(
2006
+ componentsObject,
2007
+ components,
2008
+ documentOptions
2009
+ );
1939
2010
  const combinedParameters = createParamComponents(
1940
2011
  componentsObject,
1941
- components
2012
+ components,
2013
+ documentOptions
2014
+ );
2015
+ const combinedHeaders = createHeaderComponents(
2016
+ componentsObject,
2017
+ components,
2018
+ documentOptions
2019
+ );
2020
+ const combinedResponses = createResponseComponents(
2021
+ components,
2022
+ documentOptions
2023
+ );
2024
+ const combinedRequestBodies = createRequestBodiesComponents(
2025
+ components,
2026
+ documentOptions
2027
+ );
2028
+ const combinedCallbacks = createCallbackComponents(
2029
+ components,
2030
+ documentOptions
1942
2031
  );
1943
- const combinedHeaders = createHeaderComponents(componentsObject, components);
1944
- const combinedResponses = createResponseComponents(components);
1945
- const combinedRequestBodies = createRequestBodiesComponents(components);
1946
- const combinedCallbacks = createCallbackComponents(components);
1947
2032
  const { schemas, parameters, headers, responses, requestBodies, ...rest } = componentsObject;
1948
2033
  const finalComponents = {
1949
2034
  ...rest,
@@ -1956,7 +2041,7 @@ const createComponents = (componentsObject, components) => {
1956
2041
  };
1957
2042
  return Object.keys(finalComponents).length ? finalComponents : void 0;
1958
2043
  };
1959
- const createSchemaComponents = (componentsObject, components) => {
2044
+ const createSchemaComponents = (componentsObject, components, documentOptions) => {
1960
2045
  Array.from(components.schemas).forEach(([schema, { type }], index) => {
1961
2046
  var _a;
1962
2047
  if (type === "manual") {
@@ -1964,7 +2049,8 @@ const createSchemaComponents = (componentsObject, components) => {
1964
2049
  components,
1965
2050
  type: ((_a = schema._def.openapi) == null ? void 0 : _a.refType) ?? "output",
1966
2051
  path: [],
1967
- visited: /* @__PURE__ */ new Set()
2052
+ visited: /* @__PURE__ */ new Set(),
2053
+ documentOptions
1968
2054
  };
1969
2055
  createSchema(schema, state, [`component schema index ${index}`]);
1970
2056
  }
@@ -1995,7 +2081,7 @@ const createSchemaComponents = (componentsObject, components) => {
1995
2081
  }, customComponents);
1996
2082
  return Object.keys(finalComponents).length ? finalComponents : void 0;
1997
2083
  };
1998
- const createParamComponents = (componentsObject, components) => {
2084
+ const createParamComponents = (componentsObject, components, documentOptions) => {
1999
2085
  Array.from(components.parameters).forEach(([schema, component], index) => {
2000
2086
  if (component.type === "manual") {
2001
2087
  createParamOrRef(
@@ -2003,7 +2089,8 @@ const createParamComponents = (componentsObject, components) => {
2003
2089
  components,
2004
2090
  [`component parameter index ${index}`],
2005
2091
  component.in,
2006
- component.ref
2092
+ component.ref,
2093
+ documentOptions
2007
2094
  );
2008
2095
  }
2009
2096
  });
@@ -2032,10 +2119,10 @@ const createParamComponents = (componentsObject, components) => {
2032
2119
  }, customComponents);
2033
2120
  return Object.keys(finalComponents).length ? finalComponents : void 0;
2034
2121
  };
2035
- const createHeaderComponents = (componentsObject, components) => {
2122
+ const createHeaderComponents = (componentsObject, components, documentOptions) => {
2036
2123
  Array.from(components.headers).forEach(([schema, component]) => {
2037
2124
  if (component.type === "manual") {
2038
- createHeaderOrRef(schema, components);
2125
+ createHeaderOrRef(schema, components, documentOptions);
2039
2126
  }
2040
2127
  });
2041
2128
  const headers = componentsObject.headers ?? {};
@@ -2059,10 +2146,15 @@ const createHeaderComponents = (componentsObject, components) => {
2059
2146
  }, customComponents);
2060
2147
  return Object.keys(finalComponents).length ? finalComponents : void 0;
2061
2148
  };
2062
- const createResponseComponents = (components) => {
2149
+ const createResponseComponents = (components, documentOptions) => {
2063
2150
  Array.from(components.responses).forEach(([schema, component], index) => {
2064
2151
  if (component.type === "manual") {
2065
- createResponse(schema, components, [`component response index ${index}`]);
2152
+ createResponse(
2153
+ schema,
2154
+ components,
2155
+ [`component response index ${index}`],
2156
+ documentOptions
2157
+ );
2066
2158
  }
2067
2159
  });
2068
2160
  const finalComponents = Array.from(components.responses).reduce((acc, [_zodType, component]) => {
@@ -2076,12 +2168,15 @@ const createResponseComponents = (components) => {
2076
2168
  }, {});
2077
2169
  return Object.keys(finalComponents).length ? finalComponents : void 0;
2078
2170
  };
2079
- const createRequestBodiesComponents = (components) => {
2171
+ const createRequestBodiesComponents = (components, documentOptions) => {
2080
2172
  Array.from(components.requestBodies).forEach(([schema, component], index) => {
2081
2173
  if (component.type === "manual") {
2082
- createRequestBody(schema, components, [
2083
- `component request body ${index}`
2084
- ]);
2174
+ createRequestBody(
2175
+ schema,
2176
+ components,
2177
+ [`component request body ${index}`],
2178
+ documentOptions
2179
+ );
2085
2180
  }
2086
2181
  });
2087
2182
  const finalComponents = Array.from(components.requestBodies).reduce((acc, [_zodType, component]) => {
@@ -2095,10 +2190,15 @@ const createRequestBodiesComponents = (components) => {
2095
2190
  }, {});
2096
2191
  return Object.keys(finalComponents).length ? finalComponents : void 0;
2097
2192
  };
2098
- const createCallbackComponents = (components) => {
2193
+ const createCallbackComponents = (components, documentOptions) => {
2099
2194
  Array.from(components.callbacks).forEach(([schema, component], index) => {
2100
2195
  if (component.type === "manual") {
2101
- createCallback(schema, components, [`component callback ${index}`]);
2196
+ createCallback(
2197
+ schema,
2198
+ components,
2199
+ [`component callback ${index}`],
2200
+ documentOptions
2201
+ );
2102
2202
  }
2103
2203
  });
2104
2204
  const finalComponents = Array.from(components.callbacks).reduce((acc, [_zodType, component]) => {
@@ -2117,5 +2217,7 @@ export {
2117
2217
  createMediaTypeSchema,
2118
2218
  createParamOrRef,
2119
2219
  createPaths,
2220
+ createSchema,
2221
+ createSchemaComponents,
2120
2222
  getDefaultComponents
2121
2223
  };
@@ -1,7 +1,7 @@
1
1
  import { ZodType } from 'zod';
2
2
  import { SchemaObject as SchemaObject$1, ReferenceObject as ReferenceObject$1, ParameterObject as ParameterObject$1, HeaderObject as HeaderObject$1, ResponseObject as ResponseObject$1, RequestBodyObject as RequestBodyObject$1, CallbackObject as CallbackObject$1 } from '../openapi3-ts/dist/model/openapi30.js';
3
3
  import { ComponentsObject as ComponentsObject$1, SchemaObject, ReferenceObject, ParameterObject, ParameterLocation, HeaderObject, ResponseObject, RequestBodyObject, CallbackObject } from '../openapi3-ts/dist/model/openapi31.js';
4
- import { ZodOpenApiVersion, ZodOpenApiComponentsObject, ZodOpenApiResponseObject, ZodOpenApiRequestBodyObject, ZodOpenApiCallbackObject } from './document.js';
4
+ import { ZodOpenApiVersion, ZodOpenApiComponentsObject, CreateDocumentOptions, ZodOpenApiResponseObject, ZodOpenApiRequestBodyObject, ZodOpenApiCallbackObject } from './document.js';
5
5
 
6
6
  type CreationType = 'input' | 'output';
7
7
  type BaseEffect = {
@@ -119,6 +119,6 @@ interface ComponentsObject {
119
119
  openapi: ZodOpenApiVersion;
120
120
  }
121
121
  declare const getDefaultComponents: (componentsObject?: ZodOpenApiComponentsObject, openapi?: ZodOpenApiVersion) => ComponentsObject;
122
- declare const createComponents: (componentsObject: ZodOpenApiComponentsObject, components: ComponentsObject) => ComponentsObject$1 | undefined;
122
+ declare const createComponents: (componentsObject: ZodOpenApiComponentsObject, components: ComponentsObject, documentOptions?: CreateDocumentOptions) => ComponentsObject$1 | undefined;
123
123
 
124
124
  export { type BaseCallbackComponent, type CallbackComponent, type CallbackComponentMap, type CompleteCallbackComponent, type CompleteHeaderComponent, type CompleteParameterComponent, type CompleteRequestBodyComponent, type CompleteResponseComponent, type CompleteSchemaComponent, type ComponentEffect, type ComponentsObject, type CreationType, type Effect, type HeaderComponent, type HeaderComponentMap, type InProgressSchemaComponent, type ManualSchemaComponent, type ParameterComponent, type ParameterComponentMap, type PartialCallbackComponent, type PartialHeaderComponent, type PartialParameterComponent, type PartialRequestBodyComponent, type PartialResponseComponent, type RequestBodyComponent, type RequestBodyComponentMap, type ResolvedEffect, type ResponseComponent, type ResponseComponentMap, type SchemaComponent, type SchemaComponentMap, type SchemaEffect, createComponents, getDefaultComponents };