zod-nest 3.5.0 → 3.6.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.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +53 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -300,10 +300,12 @@ type ResponseStatusWildcard = '1XX' | '2XX' | '3XX' | '4XX' | '5XX';
|
|
|
300
300
|
* Description payload accepted by `@ZodResponse(...)` and passed through to
|
|
301
301
|
* `applyZodNest`'s `@ApiResponse(...)` emitter. String form is shorthand for
|
|
302
302
|
* `{ description }`; the object form lets users declare OpenAPI response
|
|
303
|
-
* `headers` / `links` alongside the description.
|
|
303
|
+
* `summary` / `headers` / `links` alongside the description.
|
|
304
304
|
*/
|
|
305
305
|
type ZodResponseDescription = string | {
|
|
306
306
|
description: string;
|
|
307
|
+
/** 3.2-only. `applyZodNest` drops it, with a warning, when emitting 3.1. */
|
|
308
|
+
summary?: string;
|
|
307
309
|
headers?: Record<string, unknown>;
|
|
308
310
|
links?: Record<string, unknown>;
|
|
309
311
|
};
|
|
@@ -818,6 +820,8 @@ interface ApplyZodNestOptions {
|
|
|
818
820
|
* `additionalOperations`, the only place that version accepts them, and
|
|
819
821
|
* rewrites `schema` to `itemSchema` on sequential media types (SSE, NDJSON, …)
|
|
820
822
|
* so a streamed body documents one item rather than the whole sequence.
|
|
823
|
+
* - Response Object `summary` survives only under 3.2; emitting 3.1 drops each
|
|
824
|
+
* one with a warning naming the operation, since 3.1 forbids the field.
|
|
821
825
|
*
|
|
822
826
|
* Composable with other doc-transform passes — apply other mutations before
|
|
823
827
|
* or after this function.
|
package/dist/index.d.ts
CHANGED
|
@@ -300,10 +300,12 @@ type ResponseStatusWildcard = '1XX' | '2XX' | '3XX' | '4XX' | '5XX';
|
|
|
300
300
|
* Description payload accepted by `@ZodResponse(...)` and passed through to
|
|
301
301
|
* `applyZodNest`'s `@ApiResponse(...)` emitter. String form is shorthand for
|
|
302
302
|
* `{ description }`; the object form lets users declare OpenAPI response
|
|
303
|
-
* `headers` / `links` alongside the description.
|
|
303
|
+
* `summary` / `headers` / `links` alongside the description.
|
|
304
304
|
*/
|
|
305
305
|
type ZodResponseDescription = string | {
|
|
306
306
|
description: string;
|
|
307
|
+
/** 3.2-only. `applyZodNest` drops it, with a warning, when emitting 3.1. */
|
|
308
|
+
summary?: string;
|
|
307
309
|
headers?: Record<string, unknown>;
|
|
308
310
|
links?: Record<string, unknown>;
|
|
309
311
|
};
|
|
@@ -818,6 +820,8 @@ interface ApplyZodNestOptions {
|
|
|
818
820
|
* `additionalOperations`, the only place that version accepts them, and
|
|
819
821
|
* rewrites `schema` to `itemSchema` on sequential media types (SSE, NDJSON, …)
|
|
820
822
|
* so a streamed body documents one item rather than the whole sequence.
|
|
823
|
+
* - Response Object `summary` survives only under 3.2; emitting 3.1 drops each
|
|
824
|
+
* one with a warning naming the operation, since 3.1 forbids the field.
|
|
821
825
|
*
|
|
822
826
|
* Composable with other doc-transform passes — apply other mutations before
|
|
823
827
|
* or after this function.
|
package/dist/index.js
CHANGED
|
@@ -624,6 +624,9 @@ var extractDescriptionFields = /* @__PURE__ */ chunkEV5I5HGT_js.__name((desc) =>
|
|
|
624
624
|
const out = {
|
|
625
625
|
description: desc.description
|
|
626
626
|
};
|
|
627
|
+
if (desc.summary !== void 0) {
|
|
628
|
+
out.summary = desc.summary;
|
|
629
|
+
}
|
|
627
630
|
if (desc.headers !== void 0) {
|
|
628
631
|
out.headers = desc.headers;
|
|
629
632
|
}
|
|
@@ -1100,35 +1103,45 @@ var HTTP_METHODS = [
|
|
|
1100
1103
|
];
|
|
1101
1104
|
var ADDITIONAL_OPERATIONS_KEY = "additionalOperations";
|
|
1102
1105
|
var isRecord = /* @__PURE__ */ chunkEV5I5HGT_js.__name((value) => value !== null && typeof value === "object", "isRecord");
|
|
1103
|
-
var
|
|
1104
|
-
const
|
|
1106
|
+
var operationEntriesOfPathItem = /* @__PURE__ */ chunkEV5I5HGT_js.__name((pathItem) => {
|
|
1107
|
+
const entries = [];
|
|
1105
1108
|
for (const method of HTTP_METHODS) {
|
|
1106
1109
|
const operation = pathItem[method];
|
|
1107
1110
|
if (isRecord(operation)) {
|
|
1108
|
-
|
|
1111
|
+
entries.push({
|
|
1112
|
+
method,
|
|
1113
|
+
operation
|
|
1114
|
+
});
|
|
1109
1115
|
}
|
|
1110
1116
|
}
|
|
1111
1117
|
const additional = pathItem[ADDITIONAL_OPERATIONS_KEY];
|
|
1112
1118
|
if (isRecord(additional)) {
|
|
1113
|
-
for (const operation of Object.
|
|
1119
|
+
for (const [method, operation] of Object.entries(additional)) {
|
|
1114
1120
|
if (isRecord(operation)) {
|
|
1115
|
-
|
|
1121
|
+
entries.push({
|
|
1122
|
+
method,
|
|
1123
|
+
operation
|
|
1124
|
+
});
|
|
1116
1125
|
}
|
|
1117
1126
|
}
|
|
1118
1127
|
}
|
|
1119
|
-
return
|
|
1120
|
-
}, "
|
|
1128
|
+
return entries;
|
|
1129
|
+
}, "operationEntriesOfPathItem");
|
|
1130
|
+
var operationsOfPathItem = /* @__PURE__ */ chunkEV5I5HGT_js.__name((pathItem) => operationEntriesOfPathItem(pathItem).map((entry) => entry.operation), "operationsOfPathItem");
|
|
1121
1131
|
var forEachOperation = /* @__PURE__ */ chunkEV5I5HGT_js.__name((doc, fn) => {
|
|
1122
1132
|
const paths = doc.paths;
|
|
1123
1133
|
if (!isRecord(paths)) {
|
|
1124
1134
|
return;
|
|
1125
1135
|
}
|
|
1126
|
-
for (const pathItem of Object.
|
|
1136
|
+
for (const [path, pathItem] of Object.entries(paths)) {
|
|
1127
1137
|
if (!isRecord(pathItem)) {
|
|
1128
1138
|
continue;
|
|
1129
1139
|
}
|
|
1130
|
-
for (const operation of
|
|
1131
|
-
fn(operation
|
|
1140
|
+
for (const { method, operation } of operationEntriesOfPathItem(pathItem)) {
|
|
1141
|
+
fn(operation, {
|
|
1142
|
+
path,
|
|
1143
|
+
method
|
|
1144
|
+
});
|
|
1132
1145
|
}
|
|
1133
1146
|
}
|
|
1134
1147
|
}, "forEachOperation");
|
|
@@ -1921,6 +1934,30 @@ var addRefTitles = /* @__PURE__ */ chunkEV5I5HGT_js.__name((node, titleById) =>
|
|
|
1921
1934
|
}
|
|
1922
1935
|
}, "addRefTitles");
|
|
1923
1936
|
|
|
1937
|
+
// src/document/response-summary.ts
|
|
1938
|
+
var isRecord4 = /* @__PURE__ */ chunkEV5I5HGT_js.__name((value) => value !== null && typeof value === "object", "isRecord");
|
|
1939
|
+
var applyResponseSummary = /* @__PURE__ */ chunkEV5I5HGT_js.__name((doc, opts) => {
|
|
1940
|
+
if (opts.emit) {
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
forEachOperation(doc, (operation, { path, method }) => {
|
|
1944
|
+
const responses = operation.responses;
|
|
1945
|
+
if (!isRecord4(responses)) {
|
|
1946
|
+
return;
|
|
1947
|
+
}
|
|
1948
|
+
for (const [status, response] of Object.entries(responses)) {
|
|
1949
|
+
if (!isRecord4(response) || response.summary === void 0) {
|
|
1950
|
+
continue;
|
|
1951
|
+
}
|
|
1952
|
+
delete response.summary;
|
|
1953
|
+
warnDropped(method, path, status);
|
|
1954
|
+
}
|
|
1955
|
+
});
|
|
1956
|
+
}, "applyResponseSummary");
|
|
1957
|
+
var warnDropped = /* @__PURE__ */ chunkEV5I5HGT_js.__name((method, path, status) => {
|
|
1958
|
+
console.warn(`[zod-nest] Dropped \`summary\` from \`${method.toUpperCase()} ${path}\` response \`${status}\`: OpenAPI 3.1 has no Response Object \`summary\` field. Declare 3.2 via \`DocumentBuilder.setOpenAPIVersion('3.2.0')\` to emit it.`);
|
|
1959
|
+
}, "warnDropped");
|
|
1960
|
+
|
|
1924
1961
|
// src/document/rewrite-refs.ts
|
|
1925
1962
|
var rewriteRefs = /* @__PURE__ */ chunkEV5I5HGT_js.__name((params) => {
|
|
1926
1963
|
const { doc, renames, divergentOutputIds } = params;
|
|
@@ -2069,11 +2106,15 @@ var applyZodNest = /* @__PURE__ */ chunkEV5I5HGT_js.__name((doc, opts = {}) => {
|
|
|
2069
2106
|
collected: extended
|
|
2070
2107
|
});
|
|
2071
2108
|
const openApiVersion = resolveOpenApiVersion(doc);
|
|
2072
|
-
|
|
2109
|
+
const emitThirtyTwo = openApiVersion.startsWith("3.2.");
|
|
2110
|
+
if (emitThirtyTwo) {
|
|
2073
2111
|
relocateExtensionOperations(doc);
|
|
2074
2112
|
}
|
|
2075
2113
|
applyItemSchema(doc, {
|
|
2076
|
-
emit:
|
|
2114
|
+
emit: emitThirtyTwo
|
|
2115
|
+
});
|
|
2116
|
+
applyResponseSummary(doc, {
|
|
2117
|
+
emit: emitThirtyTwo
|
|
2077
2118
|
});
|
|
2078
2119
|
doc.openapi = openApiVersion;
|
|
2079
2120
|
return doc;
|