zod-openapi 3.0.1 → 3.1.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/README.md +92 -11
- package/dist/components.chunk.cjs +202 -102
- package/dist/components.chunk.mjs +202 -102
- package/dist/create/components.d.ts +2 -2
- package/dist/create/content.d.ts +2 -1
- package/dist/create/document.d.ts +12 -2
- package/dist/create/parameters.d.ts +2 -2
- package/dist/create/schema/single.d.ts +28 -0
- package/dist/extendZodTypes.d.ts +1 -1
- package/dist/index.cjs +34 -4
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +35 -5
- package/package.json +6 -6
|
@@ -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
|
-
|
|
60
|
-
|
|
61
|
-
type: "
|
|
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(
|
|
1388
|
-
|
|
1389
|
-
|
|
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, documentOptions, type, name) => {
|
|
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(
|
|
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,80 @@ 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(
|
|
1492
|
+
([key, zodSchema]) => createParamOrRef(
|
|
1493
|
+
zodSchema,
|
|
1494
|
+
components,
|
|
1495
|
+
[...subpath, key],
|
|
1496
|
+
documentOptions,
|
|
1497
|
+
type,
|
|
1498
|
+
key
|
|
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(
|
|
1485
|
-
|
|
1486
|
-
|
|
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(
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1538
|
+
return createParamOrRef(
|
|
1539
|
+
param,
|
|
1540
|
+
components,
|
|
1541
|
+
[...subpath, `param index ${index}`],
|
|
1542
|
+
documentOptions
|
|
1543
|
+
);
|
|
1514
1544
|
}
|
|
1515
1545
|
return param;
|
|
1516
1546
|
})) ?? [];
|
|
1517
|
-
const createParametersObject = (parameters, requestParams, components, subpath) => {
|
|
1547
|
+
const createParametersObject = (parameters, requestParams, components, subpath, documentOptions) => {
|
|
1518
1548
|
const manualParameters = createManualParameters(
|
|
1519
1549
|
parameters,
|
|
1520
1550
|
components,
|
|
1521
|
-
subpath
|
|
1551
|
+
subpath,
|
|
1552
|
+
documentOptions
|
|
1553
|
+
);
|
|
1554
|
+
const createdParams = createRequestParams(
|
|
1555
|
+
requestParams,
|
|
1556
|
+
components,
|
|
1557
|
+
subpath,
|
|
1558
|
+
documentOptions
|
|
1522
1559
|
);
|
|
1523
|
-
const createdParams = createRequestParams(requestParams, components, subpath);
|
|
1524
1560
|
const combinedParameters = [
|
|
1525
1561
|
...manualParameters,
|
|
1526
1562
|
...createdParams
|
|
@@ -1548,19 +1584,19 @@ const getZodObject = (schema, type) => {
|
|
|
1548
1584
|
throw new Error("failed to find ZodObject in schema");
|
|
1549
1585
|
};
|
|
1550
1586
|
const isISpecificationExtension = (key) => key.startsWith("x-");
|
|
1551
|
-
const createResponseHeaders = (responseHeaders, components) => {
|
|
1587
|
+
const createResponseHeaders = (responseHeaders, components, documentOptions) => {
|
|
1552
1588
|
if (!responseHeaders) {
|
|
1553
1589
|
return void 0;
|
|
1554
1590
|
}
|
|
1555
1591
|
if (isAnyZodType(responseHeaders)) {
|
|
1556
1592
|
return Object.entries(responseHeaders.shape).reduce((acc, [key, zodSchema]) => {
|
|
1557
|
-
acc[key] = createHeaderOrRef(zodSchema, components);
|
|
1593
|
+
acc[key] = createHeaderOrRef(zodSchema, components, documentOptions);
|
|
1558
1594
|
return acc;
|
|
1559
1595
|
}, {});
|
|
1560
1596
|
}
|
|
1561
1597
|
return responseHeaders;
|
|
1562
1598
|
};
|
|
1563
|
-
const createHeaderOrRef = (schema, components) => {
|
|
1599
|
+
const createHeaderOrRef = (schema, components, documentOptions) => {
|
|
1564
1600
|
var _a, _b, _c;
|
|
1565
1601
|
const component = components.headers.get(schema);
|
|
1566
1602
|
if (component && component.type === "complete") {
|
|
@@ -1568,7 +1604,7 @@ const createHeaderOrRef = (schema, components) => {
|
|
|
1568
1604
|
$ref: createComponentHeaderRef(component.ref)
|
|
1569
1605
|
};
|
|
1570
1606
|
}
|
|
1571
|
-
const baseHeader = createBaseHeader(schema, components);
|
|
1607
|
+
const baseHeader = createBaseHeader(schema, components, documentOptions);
|
|
1572
1608
|
if ("$ref" in baseHeader) {
|
|
1573
1609
|
throw new Error("Unexpected Error: received a reference object");
|
|
1574
1610
|
}
|
|
@@ -1585,14 +1621,15 @@ const createHeaderOrRef = (schema, components) => {
|
|
|
1585
1621
|
}
|
|
1586
1622
|
return baseHeader;
|
|
1587
1623
|
};
|
|
1588
|
-
const createBaseHeader = (schema, components) => {
|
|
1624
|
+
const createBaseHeader = (schema, components, documentOptions) => {
|
|
1589
1625
|
var _a, _b;
|
|
1590
1626
|
const { ref, ...rest } = ((_a = schema._def.openapi) == null ? void 0 : _a.header) ?? {};
|
|
1591
1627
|
const state = {
|
|
1592
1628
|
components,
|
|
1593
1629
|
type: "output",
|
|
1594
1630
|
path: [],
|
|
1595
|
-
visited: /* @__PURE__ */ new Set()
|
|
1631
|
+
visited: /* @__PURE__ */ new Set(),
|
|
1632
|
+
documentOptions
|
|
1596
1633
|
};
|
|
1597
1634
|
const schemaObject = createSchema(schema, state, ["header"]);
|
|
1598
1635
|
const required = !((_b = isOptionalSchema(schema, state)) == null ? void 0 : _b.optional);
|
|
@@ -1603,7 +1640,7 @@ const createBaseHeader = (schema, components) => {
|
|
|
1603
1640
|
};
|
|
1604
1641
|
};
|
|
1605
1642
|
const createComponentHeaderRef = (ref) => `#/components/headers/${ref}`;
|
|
1606
|
-
const createResponse = (responseObject, components, subpath) => {
|
|
1643
|
+
const createResponse = (responseObject, components, subpath, documentOptions) => {
|
|
1607
1644
|
if ("$ref" in responseObject) {
|
|
1608
1645
|
return responseObject;
|
|
1609
1646
|
}
|
|
@@ -1612,15 +1649,22 @@ const createResponse = (responseObject, components, subpath) => {
|
|
|
1612
1649
|
return { $ref: createComponentResponseRef(component.ref) };
|
|
1613
1650
|
}
|
|
1614
1651
|
const { content, headers, ref, ...rest } = responseObject;
|
|
1615
|
-
const maybeHeaders = createResponseHeaders(
|
|
1652
|
+
const maybeHeaders = createResponseHeaders(
|
|
1653
|
+
headers,
|
|
1654
|
+
components,
|
|
1655
|
+
documentOptions
|
|
1656
|
+
);
|
|
1616
1657
|
const response = {
|
|
1617
1658
|
...rest,
|
|
1618
1659
|
...maybeHeaders && { headers: maybeHeaders },
|
|
1619
1660
|
...content && {
|
|
1620
|
-
content: createContent(
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1661
|
+
content: createContent(
|
|
1662
|
+
content,
|
|
1663
|
+
components,
|
|
1664
|
+
"output",
|
|
1665
|
+
[...subpath, "content"],
|
|
1666
|
+
documentOptions
|
|
1667
|
+
)
|
|
1624
1668
|
}
|
|
1625
1669
|
};
|
|
1626
1670
|
const responseRef = ref ?? (component == null ? void 0 : component.ref);
|
|
@@ -1636,21 +1680,23 @@ const createResponse = (responseObject, components, subpath) => {
|
|
|
1636
1680
|
}
|
|
1637
1681
|
return response;
|
|
1638
1682
|
};
|
|
1639
|
-
const createResponses = (responsesObject, components, subpath) => Object.entries(responsesObject).reduce(
|
|
1683
|
+
const createResponses = (responsesObject, components, subpath, documentOptions) => Object.entries(responsesObject).reduce(
|
|
1640
1684
|
(acc, [statusCode, responseObject]) => {
|
|
1641
1685
|
if (isISpecificationExtension(statusCode)) {
|
|
1642
1686
|
acc[statusCode] = responseObject;
|
|
1643
1687
|
return acc;
|
|
1644
1688
|
}
|
|
1645
|
-
acc[statusCode] = createResponse(
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1689
|
+
acc[statusCode] = createResponse(
|
|
1690
|
+
responseObject,
|
|
1691
|
+
components,
|
|
1692
|
+
[...subpath, statusCode],
|
|
1693
|
+
documentOptions
|
|
1694
|
+
);
|
|
1649
1695
|
return acc;
|
|
1650
1696
|
},
|
|
1651
1697
|
{}
|
|
1652
1698
|
);
|
|
1653
|
-
const createRequestBody = (requestBodyObject, components, subpath) => {
|
|
1699
|
+
const createRequestBody = (requestBodyObject, components, subpath, documentOptions) => {
|
|
1654
1700
|
if (!requestBodyObject) {
|
|
1655
1701
|
return void 0;
|
|
1656
1702
|
}
|
|
@@ -1663,10 +1709,13 @@ const createRequestBody = (requestBodyObject, components, subpath) => {
|
|
|
1663
1709
|
const ref = requestBodyObject.ref ?? (component == null ? void 0 : component.ref);
|
|
1664
1710
|
const requestBody = {
|
|
1665
1711
|
...requestBodyObject,
|
|
1666
|
-
content: createContent(
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1712
|
+
content: createContent(
|
|
1713
|
+
requestBodyObject.content,
|
|
1714
|
+
components,
|
|
1715
|
+
"input",
|
|
1716
|
+
[...subpath, "content"],
|
|
1717
|
+
documentOptions
|
|
1718
|
+
)
|
|
1670
1719
|
};
|
|
1671
1720
|
if (ref) {
|
|
1672
1721
|
components.requestBodies.set(requestBodyObject, {
|
|
@@ -1680,28 +1729,32 @@ const createRequestBody = (requestBodyObject, components, subpath) => {
|
|
|
1680
1729
|
}
|
|
1681
1730
|
return requestBody;
|
|
1682
1731
|
};
|
|
1683
|
-
const createOperation = (operationObject, components, subpath) => {
|
|
1732
|
+
const createOperation = (operationObject, components, subpath, documentOptions) => {
|
|
1684
1733
|
const { parameters, requestParams, requestBody, responses, ...rest } = operationObject;
|
|
1685
1734
|
const maybeParameters = createParametersObject(
|
|
1686
1735
|
parameters,
|
|
1687
1736
|
requestParams,
|
|
1688
1737
|
components,
|
|
1689
|
-
[...subpath, "parameters"]
|
|
1738
|
+
[...subpath, "parameters"],
|
|
1739
|
+
documentOptions
|
|
1690
1740
|
);
|
|
1691
1741
|
const maybeRequestBody = createRequestBody(
|
|
1692
1742
|
operationObject.requestBody,
|
|
1693
1743
|
components,
|
|
1694
|
-
[...subpath, "request body"]
|
|
1744
|
+
[...subpath, "request body"],
|
|
1745
|
+
documentOptions
|
|
1695
1746
|
);
|
|
1696
1747
|
const maybeResponses = createResponses(
|
|
1697
1748
|
operationObject.responses,
|
|
1698
1749
|
components,
|
|
1699
|
-
[...subpath, "responses"]
|
|
1750
|
+
[...subpath, "responses"],
|
|
1751
|
+
documentOptions
|
|
1700
1752
|
);
|
|
1701
1753
|
const maybeCallbacks = createCallbacks(
|
|
1702
1754
|
operationObject.callbacks,
|
|
1703
1755
|
components,
|
|
1704
|
-
[...subpath, "callbacks"]
|
|
1756
|
+
[...subpath, "callbacks"],
|
|
1757
|
+
documentOptions
|
|
1705
1758
|
);
|
|
1706
1759
|
return {
|
|
1707
1760
|
...rest,
|
|
@@ -1711,7 +1764,7 @@ const createOperation = (operationObject, components, subpath) => {
|
|
|
1711
1764
|
...maybeCallbacks && { callbacks: maybeCallbacks }
|
|
1712
1765
|
};
|
|
1713
1766
|
};
|
|
1714
|
-
const createPathItem = (pathObject, components, path) => Object.entries(pathObject).reduce(
|
|
1767
|
+
const createPathItem = (pathObject, components, path, documentOptions) => Object.entries(pathObject).reduce(
|
|
1715
1768
|
(acc, [key, value]) => {
|
|
1716
1769
|
if (!value) {
|
|
1717
1770
|
return acc;
|
|
@@ -1720,7 +1773,8 @@ const createPathItem = (pathObject, components, path) => Object.entries(pathObje
|
|
|
1720
1773
|
acc[key] = createOperation(
|
|
1721
1774
|
value,
|
|
1722
1775
|
components,
|
|
1723
|
-
[...path, key]
|
|
1776
|
+
[...path, key],
|
|
1777
|
+
documentOptions
|
|
1724
1778
|
);
|
|
1725
1779
|
return acc;
|
|
1726
1780
|
}
|
|
@@ -1729,7 +1783,7 @@ const createPathItem = (pathObject, components, path) => Object.entries(pathObje
|
|
|
1729
1783
|
},
|
|
1730
1784
|
{}
|
|
1731
1785
|
);
|
|
1732
|
-
const createPaths = (pathsObject, components) => {
|
|
1786
|
+
const createPaths = (pathsObject, components, documentOptions) => {
|
|
1733
1787
|
if (!pathsObject) {
|
|
1734
1788
|
return void 0;
|
|
1735
1789
|
}
|
|
@@ -1739,13 +1793,18 @@ const createPaths = (pathsObject, components) => {
|
|
|
1739
1793
|
acc[path] = pathItemObject;
|
|
1740
1794
|
return acc;
|
|
1741
1795
|
}
|
|
1742
|
-
acc[path] = createPathItem(
|
|
1796
|
+
acc[path] = createPathItem(
|
|
1797
|
+
pathItemObject,
|
|
1798
|
+
components,
|
|
1799
|
+
[path],
|
|
1800
|
+
documentOptions
|
|
1801
|
+
);
|
|
1743
1802
|
return acc;
|
|
1744
1803
|
},
|
|
1745
1804
|
{}
|
|
1746
1805
|
);
|
|
1747
1806
|
};
|
|
1748
|
-
const createCallback = (callbackObject, components, subpath) => {
|
|
1807
|
+
const createCallback = (callbackObject, components, subpath, documentOptions) => {
|
|
1749
1808
|
const { ref, ...callbacks } = callbackObject;
|
|
1750
1809
|
const callback = Object.entries(
|
|
1751
1810
|
callbacks
|
|
@@ -1754,10 +1813,13 @@ const createCallback = (callbackObject, components, subpath) => {
|
|
|
1754
1813
|
acc[callbackName] = pathItemObject;
|
|
1755
1814
|
return acc;
|
|
1756
1815
|
}
|
|
1757
|
-
acc[callbackName] = createPathItem(
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1816
|
+
acc[callbackName] = createPathItem(
|
|
1817
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1818
|
+
pathItemObject,
|
|
1819
|
+
components,
|
|
1820
|
+
[...subpath, callbackName],
|
|
1821
|
+
documentOptions
|
|
1822
|
+
);
|
|
1761
1823
|
return acc;
|
|
1762
1824
|
}, {});
|
|
1763
1825
|
if (ref) {
|
|
@@ -1772,7 +1834,7 @@ const createCallback = (callbackObject, components, subpath) => {
|
|
|
1772
1834
|
}
|
|
1773
1835
|
return callback;
|
|
1774
1836
|
};
|
|
1775
|
-
const createCallbacks = (callbacksObject, components, subpath) => {
|
|
1837
|
+
const createCallbacks = (callbacksObject, components, subpath, documentOptions) => {
|
|
1776
1838
|
if (!callbacksObject) {
|
|
1777
1839
|
return void 0;
|
|
1778
1840
|
}
|
|
@@ -1782,10 +1844,13 @@ const createCallbacks = (callbacksObject, components, subpath) => {
|
|
|
1782
1844
|
acc[callbackName] = callbackObject;
|
|
1783
1845
|
return acc;
|
|
1784
1846
|
}
|
|
1785
|
-
acc[callbackName] = createCallback(
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1847
|
+
acc[callbackName] = createCallback(
|
|
1848
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
1849
|
+
callbackObject,
|
|
1850
|
+
components,
|
|
1851
|
+
[...subpath, callbackName],
|
|
1852
|
+
documentOptions
|
|
1853
|
+
);
|
|
1789
1854
|
return acc;
|
|
1790
1855
|
},
|
|
1791
1856
|
{}
|
|
@@ -1934,16 +1999,34 @@ const createComponentSchemaRef = (schemaRef) => `#/components/schemas/${schemaRe
|
|
|
1934
1999
|
const createComponentResponseRef = (responseRef) => `#/components/responses/${responseRef}`;
|
|
1935
2000
|
const createComponentRequestBodyRef = (requestBodyRef) => `#/components/requestBodies/${requestBodyRef}`;
|
|
1936
2001
|
const createComponentCallbackRef = (callbackRef) => `#/components/callbacks/${callbackRef}`;
|
|
1937
|
-
const createComponents = (componentsObject, components) => {
|
|
1938
|
-
const combinedSchemas = createSchemaComponents(
|
|
2002
|
+
const createComponents = (componentsObject, components, documentOptions) => {
|
|
2003
|
+
const combinedSchemas = createSchemaComponents(
|
|
2004
|
+
componentsObject,
|
|
2005
|
+
components,
|
|
2006
|
+
documentOptions
|
|
2007
|
+
);
|
|
1939
2008
|
const combinedParameters = createParamComponents(
|
|
1940
2009
|
componentsObject,
|
|
1941
|
-
components
|
|
2010
|
+
components,
|
|
2011
|
+
documentOptions
|
|
2012
|
+
);
|
|
2013
|
+
const combinedHeaders = createHeaderComponents(
|
|
2014
|
+
componentsObject,
|
|
2015
|
+
components,
|
|
2016
|
+
documentOptions
|
|
2017
|
+
);
|
|
2018
|
+
const combinedResponses = createResponseComponents(
|
|
2019
|
+
components,
|
|
2020
|
+
documentOptions
|
|
2021
|
+
);
|
|
2022
|
+
const combinedRequestBodies = createRequestBodiesComponents(
|
|
2023
|
+
components,
|
|
2024
|
+
documentOptions
|
|
2025
|
+
);
|
|
2026
|
+
const combinedCallbacks = createCallbackComponents(
|
|
2027
|
+
components,
|
|
2028
|
+
documentOptions
|
|
1942
2029
|
);
|
|
1943
|
-
const combinedHeaders = createHeaderComponents(componentsObject, components);
|
|
1944
|
-
const combinedResponses = createResponseComponents(components);
|
|
1945
|
-
const combinedRequestBodies = createRequestBodiesComponents(components);
|
|
1946
|
-
const combinedCallbacks = createCallbackComponents(components);
|
|
1947
2030
|
const { schemas, parameters, headers, responses, requestBodies, ...rest } = componentsObject;
|
|
1948
2031
|
const finalComponents = {
|
|
1949
2032
|
...rest,
|
|
@@ -1956,7 +2039,7 @@ const createComponents = (componentsObject, components) => {
|
|
|
1956
2039
|
};
|
|
1957
2040
|
return Object.keys(finalComponents).length ? finalComponents : void 0;
|
|
1958
2041
|
};
|
|
1959
|
-
const createSchemaComponents = (componentsObject, components) => {
|
|
2042
|
+
const createSchemaComponents = (componentsObject, components, documentOptions) => {
|
|
1960
2043
|
Array.from(components.schemas).forEach(([schema, { type }], index) => {
|
|
1961
2044
|
var _a;
|
|
1962
2045
|
if (type === "manual") {
|
|
@@ -1964,7 +2047,8 @@ const createSchemaComponents = (componentsObject, components) => {
|
|
|
1964
2047
|
components,
|
|
1965
2048
|
type: ((_a = schema._def.openapi) == null ? void 0 : _a.refType) ?? "output",
|
|
1966
2049
|
path: [],
|
|
1967
|
-
visited: /* @__PURE__ */ new Set()
|
|
2050
|
+
visited: /* @__PURE__ */ new Set(),
|
|
2051
|
+
documentOptions
|
|
1968
2052
|
};
|
|
1969
2053
|
createSchema(schema, state, [`component schema index ${index}`]);
|
|
1970
2054
|
}
|
|
@@ -1995,13 +2079,14 @@ const createSchemaComponents = (componentsObject, components) => {
|
|
|
1995
2079
|
}, customComponents);
|
|
1996
2080
|
return Object.keys(finalComponents).length ? finalComponents : void 0;
|
|
1997
2081
|
};
|
|
1998
|
-
const createParamComponents = (componentsObject, components) => {
|
|
2082
|
+
const createParamComponents = (componentsObject, components, documentOptions) => {
|
|
1999
2083
|
Array.from(components.parameters).forEach(([schema, component], index) => {
|
|
2000
2084
|
if (component.type === "manual") {
|
|
2001
2085
|
createParamOrRef(
|
|
2002
2086
|
schema,
|
|
2003
2087
|
components,
|
|
2004
2088
|
[`component parameter index ${index}`],
|
|
2089
|
+
documentOptions,
|
|
2005
2090
|
component.in,
|
|
2006
2091
|
component.ref
|
|
2007
2092
|
);
|
|
@@ -2032,10 +2117,10 @@ const createParamComponents = (componentsObject, components) => {
|
|
|
2032
2117
|
}, customComponents);
|
|
2033
2118
|
return Object.keys(finalComponents).length ? finalComponents : void 0;
|
|
2034
2119
|
};
|
|
2035
|
-
const createHeaderComponents = (componentsObject, components) => {
|
|
2120
|
+
const createHeaderComponents = (componentsObject, components, documentOptions) => {
|
|
2036
2121
|
Array.from(components.headers).forEach(([schema, component]) => {
|
|
2037
2122
|
if (component.type === "manual") {
|
|
2038
|
-
createHeaderOrRef(schema, components);
|
|
2123
|
+
createHeaderOrRef(schema, components, documentOptions);
|
|
2039
2124
|
}
|
|
2040
2125
|
});
|
|
2041
2126
|
const headers = componentsObject.headers ?? {};
|
|
@@ -2059,10 +2144,15 @@ const createHeaderComponents = (componentsObject, components) => {
|
|
|
2059
2144
|
}, customComponents);
|
|
2060
2145
|
return Object.keys(finalComponents).length ? finalComponents : void 0;
|
|
2061
2146
|
};
|
|
2062
|
-
const createResponseComponents = (components) => {
|
|
2147
|
+
const createResponseComponents = (components, documentOptions) => {
|
|
2063
2148
|
Array.from(components.responses).forEach(([schema, component], index) => {
|
|
2064
2149
|
if (component.type === "manual") {
|
|
2065
|
-
createResponse(
|
|
2150
|
+
createResponse(
|
|
2151
|
+
schema,
|
|
2152
|
+
components,
|
|
2153
|
+
[`component response index ${index}`],
|
|
2154
|
+
documentOptions
|
|
2155
|
+
);
|
|
2066
2156
|
}
|
|
2067
2157
|
});
|
|
2068
2158
|
const finalComponents = Array.from(components.responses).reduce((acc, [_zodType, component]) => {
|
|
@@ -2076,12 +2166,15 @@ const createResponseComponents = (components) => {
|
|
|
2076
2166
|
}, {});
|
|
2077
2167
|
return Object.keys(finalComponents).length ? finalComponents : void 0;
|
|
2078
2168
|
};
|
|
2079
|
-
const createRequestBodiesComponents = (components) => {
|
|
2169
|
+
const createRequestBodiesComponents = (components, documentOptions) => {
|
|
2080
2170
|
Array.from(components.requestBodies).forEach(([schema, component], index) => {
|
|
2081
2171
|
if (component.type === "manual") {
|
|
2082
|
-
createRequestBody(
|
|
2083
|
-
|
|
2084
|
-
|
|
2172
|
+
createRequestBody(
|
|
2173
|
+
schema,
|
|
2174
|
+
components,
|
|
2175
|
+
[`component request body ${index}`],
|
|
2176
|
+
documentOptions
|
|
2177
|
+
);
|
|
2085
2178
|
}
|
|
2086
2179
|
});
|
|
2087
2180
|
const finalComponents = Array.from(components.requestBodies).reduce((acc, [_zodType, component]) => {
|
|
@@ -2095,10 +2188,15 @@ const createRequestBodiesComponents = (components) => {
|
|
|
2095
2188
|
}, {});
|
|
2096
2189
|
return Object.keys(finalComponents).length ? finalComponents : void 0;
|
|
2097
2190
|
};
|
|
2098
|
-
const createCallbackComponents = (components) => {
|
|
2191
|
+
const createCallbackComponents = (components, documentOptions) => {
|
|
2099
2192
|
Array.from(components.callbacks).forEach(([schema, component], index) => {
|
|
2100
2193
|
if (component.type === "manual") {
|
|
2101
|
-
createCallback(
|
|
2194
|
+
createCallback(
|
|
2195
|
+
schema,
|
|
2196
|
+
components,
|
|
2197
|
+
[`component callback ${index}`],
|
|
2198
|
+
documentOptions
|
|
2199
|
+
);
|
|
2102
2200
|
}
|
|
2103
2201
|
});
|
|
2104
2202
|
const finalComponents = Array.from(components.callbacks).reduce((acc, [_zodType, component]) => {
|
|
@@ -2117,5 +2215,7 @@ export {
|
|
|
2117
2215
|
createMediaTypeSchema,
|
|
2118
2216
|
createParamOrRef,
|
|
2119
2217
|
createPaths,
|
|
2218
|
+
createSchema,
|
|
2219
|
+
createSchemaComponents,
|
|
2120
2220
|
getDefaultComponents
|
|
2121
2221
|
};
|
|
@@ -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 };
|