zod-nest 2.0.0 → 2.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/dist/index.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +50 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +50 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -291,10 +291,10 @@ var createCompositionOverride = /* @__PURE__ */ __name((opts) => {
|
|
|
291
291
|
if (deltaRequired.length > 0) {
|
|
292
292
|
delta.required = deltaRequired;
|
|
293
293
|
}
|
|
294
|
-
delete jsonSchema.type;
|
|
295
294
|
delete jsonSchema.properties;
|
|
296
295
|
delete jsonSchema.required;
|
|
297
296
|
delete jsonSchema.additionalProperties;
|
|
297
|
+
jsonSchema.type = "object";
|
|
298
298
|
jsonSchema.allOf = [
|
|
299
299
|
{
|
|
300
300
|
$ref: buildRef(parentId)
|
|
@@ -1328,7 +1328,7 @@ var ZodResponse = /* @__PURE__ */ __name((opts) => {
|
|
|
1328
1328
|
}, "ZodResponse");
|
|
1329
1329
|
|
|
1330
1330
|
// src/decorators/internal/zod-schema-ref.ts
|
|
1331
|
-
|
|
1331
|
+
function resolveSchemaRef(schema, options) {
|
|
1332
1332
|
const registry = options?.registry ?? defaultRegistry;
|
|
1333
1333
|
const id = registerSchema(schema, registry, {
|
|
1334
1334
|
id: options?.id
|
|
@@ -1365,7 +1365,8 @@ var resolveSchemaRef = /* @__PURE__ */ __name((schema, options) => {
|
|
|
1365
1365
|
kind: "inline",
|
|
1366
1366
|
schema: body
|
|
1367
1367
|
};
|
|
1368
|
-
}
|
|
1368
|
+
}
|
|
1369
|
+
__name(resolveSchemaRef, "resolveSchemaRef");
|
|
1369
1370
|
|
|
1370
1371
|
// src/decorators/internal/zod-param-expand.ts
|
|
1371
1372
|
var isZodObject = /* @__PURE__ */ __name((schema) => schema._zod.def.type === "object", "isZodObject");
|
|
@@ -1499,12 +1500,11 @@ var resolveBodySchema = /* @__PURE__ */ __name((schema, options) => {
|
|
|
1499
1500
|
if (options?.flatten === true) {
|
|
1500
1501
|
return flattenObjectIntersection(schema, options.registry ?? defaultRegistry, "@ZodBody");
|
|
1501
1502
|
}
|
|
1502
|
-
|
|
1503
|
+
return resolveSchemaRef(schema, {
|
|
1503
1504
|
id: options?.id,
|
|
1504
1505
|
registry: options?.registry,
|
|
1505
1506
|
deferAnonInline: true
|
|
1506
|
-
});
|
|
1507
|
-
return resolution.kind === "ref" ? resolution.ref : resolution.schema;
|
|
1507
|
+
}).ref;
|
|
1508
1508
|
}, "resolveBodySchema");
|
|
1509
1509
|
|
|
1510
1510
|
// src/decorators/internal/query-marker.ts
|
|
@@ -2376,6 +2376,47 @@ var decorateIfPresent = /* @__PURE__ */ __name((schemas, key) => {
|
|
|
2376
2376
|
};
|
|
2377
2377
|
}, "decorateIfPresent");
|
|
2378
2378
|
|
|
2379
|
+
// src/document/ref-titles.ts
|
|
2380
|
+
var applyRefTitles = /* @__PURE__ */ __name((doc) => {
|
|
2381
|
+
const schemas = doc.components?.schemas;
|
|
2382
|
+
if (schemas === void 0) {
|
|
2383
|
+
return;
|
|
2384
|
+
}
|
|
2385
|
+
const titleById = /* @__PURE__ */ new Map();
|
|
2386
|
+
for (const [id, body] of Object.entries(schemas)) {
|
|
2387
|
+
if (isPlainRecord5(body) && typeof body.title === "string" && body.title !== "") {
|
|
2388
|
+
titleById.set(id, body.title);
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
if (titleById.size === 0) {
|
|
2392
|
+
return;
|
|
2393
|
+
}
|
|
2394
|
+
addRefTitles(doc.paths, titleById);
|
|
2395
|
+
addRefTitles(schemas, titleById);
|
|
2396
|
+
}, "applyRefTitles");
|
|
2397
|
+
var isPlainRecord5 = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && !Array.isArray(value), "isPlainRecord");
|
|
2398
|
+
var addRefTitles = /* @__PURE__ */ __name((node, titleById) => {
|
|
2399
|
+
if (Array.isArray(node)) {
|
|
2400
|
+
for (const item of node) {
|
|
2401
|
+
addRefTitles(item, titleById);
|
|
2402
|
+
}
|
|
2403
|
+
return;
|
|
2404
|
+
}
|
|
2405
|
+
if (!isPlainRecord5(node)) {
|
|
2406
|
+
return;
|
|
2407
|
+
}
|
|
2408
|
+
const ref = node.$ref;
|
|
2409
|
+
if (typeof ref === "string" && ref.startsWith(COMPONENTS_SCHEMAS_PREFIX) && node.title === void 0) {
|
|
2410
|
+
const title = titleById.get(ref.slice(COMPONENTS_SCHEMAS_PREFIX.length));
|
|
2411
|
+
if (title !== void 0) {
|
|
2412
|
+
node.title = title;
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
for (const value of Object.values(node)) {
|
|
2416
|
+
addRefTitles(value, titleById);
|
|
2417
|
+
}
|
|
2418
|
+
}, "addRefTitles");
|
|
2419
|
+
|
|
2379
2420
|
// src/document/rewrite-refs.ts
|
|
2380
2421
|
var rewriteRefs2 = /* @__PURE__ */ __name((params) => {
|
|
2381
2422
|
const { doc, renames, divergentOutputIds } = params;
|
|
@@ -2521,6 +2562,9 @@ var applyZodNest = /* @__PURE__ */ __name((doc, opts = {}) => {
|
|
|
2521
2562
|
doc,
|
|
2522
2563
|
registry
|
|
2523
2564
|
});
|
|
2565
|
+
if (opts.refTitles !== false) {
|
|
2566
|
+
applyRefTitles(doc);
|
|
2567
|
+
}
|
|
2524
2568
|
assertNoDanglingRefs({
|
|
2525
2569
|
doc,
|
|
2526
2570
|
collected: extended
|