zod-nest 1.5.1 → 1.6.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/README.md CHANGED
@@ -431,7 +431,7 @@ A compact, link-out index. Type signatures and detailed semantics live in the co
431
431
  - `ZodNestModule.forRoot(options?)`, `ZodNestModuleOptions`, `DEFAULT_REDACT_KEYS`, `DEFAULT_MAX_LOGGED_VALUE_BYTES`, `ZOD_NEST_OPTIONS`
432
432
 
433
433
  **Schema engine** — single-schema mode and extension points
434
- - `toOpenApi(schema, opts)`, `createRegistry()`, `defaultRegistry`, `ZodNestRegistry`, `Override`, `OverrideContext`, `overrideJSONSchema(schema, fragment | { input?, output? })`, `OverrideJSONSchemaArg`, `ZodNestError`, `ZodNestUnrepresentableError`, `extend`, `getLineage`, `LineageEntry`
434
+ - `toOpenApi(schema, opts)`, `createRegistry()`, `defaultRegistry`, `registerSchema(schema, registry?, options?)`, `ZodNestRegistry`, `RegisterSchemaOptions`, `Override`, `OverrideContext`, `overrideJSONSchema(schema, fragment | { input?, output? })`, `OverrideJSONSchemaArg`, `ZodNestError`, `ZodNestUnrepresentableError`, `extend`, `getLineage`, `LineageEntry`
435
435
 
436
436
  **Helpers** (subpath: `zod-nest/helpers`) — common JSON Schema fragments + presets for assembling overrides
437
437
  - **Fragment catalog** (frozen consts): `dateTimeFragment`, `dateFragment`, `timeFragment`, `uuidFragment`, `emailFragment`, `uriFragment`, `hostnameFragment`, `ipv4Fragment`, `ipv6Fragment`, `binaryFragment`, `byteFragment`, `int32Fragment`, `int64Fragment`, `floatFragment`, `doubleFragment`, `opaqueFragment`
package/dist/index.d.mts CHANGED
@@ -46,6 +46,25 @@ interface ZodNestRegistry {
46
46
  declare const createRegistry: () => ZodNestRegistry;
47
47
  /** Process-wide default registry, used when no explicit `options.registry` is passed. */
48
48
  declare const defaultRegistry: ZodNestRegistry;
49
+ interface RegisterSchemaOptions {
50
+ /** Forces this id, overriding any `.meta({ id })` already on the schema. */
51
+ readonly id?: string;
52
+ }
53
+ /**
54
+ * Register a schema with the given registry, resolving its id from (in order):
55
+ * an explicit `options.id`, then `.meta({ id })` on the schema. Returns the
56
+ * resolved id, or `undefined` when neither source yields one (the call is then
57
+ * a no-op — callers with their own fallback path handle that case).
58
+ *
59
+ * Shared by `createZodDto` and `extend` so a schema named via `.meta({ id })`
60
+ * gets its body emitted into `components.schemas` even when it never flows
61
+ * through `createZodDto` (e.g. used only as an `extend()` parent — Zod's
62
+ * `.extend()` produces a flat object, so the parent isn't a transitive
63
+ * descendant of the child and would otherwise be missed by `discoverDependents`).
64
+ *
65
+ * Idempotent — `registry.register` already deduplicates repeat calls.
66
+ */
67
+ declare const registerSchema: (schema: z.ZodType, registry?: ZodNestRegistry, options?: RegisterSchemaOptions) => string | undefined;
49
68
 
50
69
  /**
51
70
  * Composition layer — emits OpenAPI `allOf` for schemas derived via `extend`.
@@ -600,4 +619,4 @@ declare class ZodNestDocumentError extends ZodNestError {
600
619
  constructor(code: ZodNestDocumentErrorCode, message: string, details?: Record<string, unknown>);
601
620
  }
602
621
 
603
- export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type OverrideJSONSchemaArg, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, overrideJSONSchema, resolveEffectiveStatus, toOpenApi };
622
+ export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type OverrideJSONSchemaArg, type RegisterSchemaOptions, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, overrideJSONSchema, registerSchema, resolveEffectiveStatus, toOpenApi };
package/dist/index.d.ts CHANGED
@@ -46,6 +46,25 @@ interface ZodNestRegistry {
46
46
  declare const createRegistry: () => ZodNestRegistry;
47
47
  /** Process-wide default registry, used when no explicit `options.registry` is passed. */
48
48
  declare const defaultRegistry: ZodNestRegistry;
49
+ interface RegisterSchemaOptions {
50
+ /** Forces this id, overriding any `.meta({ id })` already on the schema. */
51
+ readonly id?: string;
52
+ }
53
+ /**
54
+ * Register a schema with the given registry, resolving its id from (in order):
55
+ * an explicit `options.id`, then `.meta({ id })` on the schema. Returns the
56
+ * resolved id, or `undefined` when neither source yields one (the call is then
57
+ * a no-op — callers with their own fallback path handle that case).
58
+ *
59
+ * Shared by `createZodDto` and `extend` so a schema named via `.meta({ id })`
60
+ * gets its body emitted into `components.schemas` even when it never flows
61
+ * through `createZodDto` (e.g. used only as an `extend()` parent — Zod's
62
+ * `.extend()` produces a flat object, so the parent isn't a transitive
63
+ * descendant of the child and would otherwise be missed by `discoverDependents`).
64
+ *
65
+ * Idempotent — `registry.register` already deduplicates repeat calls.
66
+ */
67
+ declare const registerSchema: (schema: z.ZodType, registry?: ZodNestRegistry, options?: RegisterSchemaOptions) => string | undefined;
49
68
 
50
69
  /**
51
70
  * Composition layer — emits OpenAPI `allOf` for schemas derived via `extend`.
@@ -600,4 +619,4 @@ declare class ZodNestDocumentError extends ZodNestError {
600
619
  constructor(code: ZodNestDocumentErrorCode, message: string, details?: Record<string, unknown>);
601
620
  }
602
621
 
603
- export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type OverrideJSONSchemaArg, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, overrideJSONSchema, resolveEffectiveStatus, toOpenApi };
622
+ export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type OverrideJSONSchemaArg, type RegisterSchemaOptions, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, overrideJSONSchema, registerSchema, resolveEffectiveStatus, toOpenApi };
package/dist/index.js CHANGED
@@ -22,6 +22,191 @@ var DEFS_PREFIX = "#/$defs/";
22
22
  var ZOD_NEST_ERROR_EXTENSION = "x-zod-nest-error";
23
23
  var ZOD_NEST_ERROR_DUPLICATE_ID = "duplicate-id";
24
24
  var ZOD_NEST_DTO_EXTENSION = "x-zod-nest-dto";
25
+ var INNER_TYPE_WRAPPERS = /* @__PURE__ */ new Set([
26
+ "optional",
27
+ "nullable",
28
+ "default",
29
+ "prefault",
30
+ "catch",
31
+ "nonoptional",
32
+ "success",
33
+ "readonly",
34
+ "promise"
35
+ ]);
36
+ var readId = /* @__PURE__ */ __name((schema) => {
37
+ const meta = zod.z.globalRegistry.get(schema);
38
+ if (meta === void 0) {
39
+ return void 0;
40
+ }
41
+ const id = meta.id;
42
+ return typeof id === "string" ? id : void 0;
43
+ }, "readId");
44
+ var collectChildren = /* @__PURE__ */ __name((schema) => {
45
+ const def = schema._zod.def;
46
+ if (def.type === "object") {
47
+ const out = [];
48
+ const shape = def.shape;
49
+ if (shape !== void 0) {
50
+ for (const value of Object.values(shape)) {
51
+ out.push(value);
52
+ }
53
+ }
54
+ if (def.catchall !== void 0) {
55
+ out.push(def.catchall);
56
+ }
57
+ return out;
58
+ }
59
+ if (def.type === "array") {
60
+ return [
61
+ def.element
62
+ ];
63
+ }
64
+ if (def.type === "union") {
65
+ return def.options.map((opt) => opt);
66
+ }
67
+ if (def.type === "intersection") {
68
+ return [
69
+ def.left,
70
+ def.right
71
+ ];
72
+ }
73
+ if (def.type === "tuple") {
74
+ const out = def.items.map((it) => it);
75
+ if (def.rest !== null) {
76
+ out.push(def.rest);
77
+ }
78
+ return out;
79
+ }
80
+ if (def.type === "record" || def.type === "map") {
81
+ return [
82
+ def.keyType,
83
+ def.valueType
84
+ ];
85
+ }
86
+ if (def.type === "set") {
87
+ return [
88
+ def.valueType
89
+ ];
90
+ }
91
+ if (def.type === "pipe") {
92
+ return [
93
+ def.in,
94
+ def.out
95
+ ];
96
+ }
97
+ if (def.type === "lazy") {
98
+ return [
99
+ def.getter()
100
+ ];
101
+ }
102
+ if (INNER_TYPE_WRAPPERS.has(def.type)) {
103
+ return [
104
+ def.innerType
105
+ ];
106
+ }
107
+ return [];
108
+ }, "collectChildren");
109
+ var discoverDependents = /* @__PURE__ */ __name((schema) => {
110
+ const visited = /* @__PURE__ */ new WeakSet();
111
+ const out = [];
112
+ const stack = [
113
+ schema
114
+ ];
115
+ while (stack.length > 0) {
116
+ const current = stack.pop();
117
+ if (visited.has(current)) {
118
+ continue;
119
+ }
120
+ visited.add(current);
121
+ for (const child of collectChildren(current)) {
122
+ if (child === void 0 || visited.has(child)) {
123
+ continue;
124
+ }
125
+ const id = readId(child);
126
+ if (id !== void 0) {
127
+ out.push([
128
+ child,
129
+ id
130
+ ]);
131
+ }
132
+ stack.push(child);
133
+ }
134
+ }
135
+ return out;
136
+ }, "discoverDependents");
137
+
138
+ // src/schema/registry.ts
139
+ var createRegistry = /* @__PURE__ */ __name(() => {
140
+ const seen = /* @__PURE__ */ new Map();
141
+ const recordOnce = /* @__PURE__ */ __name((schema, id) => {
142
+ let set = seen.get(id);
143
+ if (set === void 0) {
144
+ set = /* @__PURE__ */ new Set();
145
+ seen.set(id, set);
146
+ }
147
+ if (set.has(schema)) {
148
+ return false;
149
+ }
150
+ set.add(schema);
151
+ return true;
152
+ }, "recordOnce");
153
+ return {
154
+ zodRegistry: zod.z.globalRegistry,
155
+ register: /* @__PURE__ */ __name((schema, id) => {
156
+ if (zod.z.globalRegistry.has(schema)) {
157
+ const existing = zod.z.globalRegistry.get(schema);
158
+ if (existing?.id !== id) {
159
+ zod.z.globalRegistry.add(schema, {
160
+ ...existing ?? {},
161
+ id
162
+ });
163
+ }
164
+ } else {
165
+ zod.z.globalRegistry.add(schema, {
166
+ id
167
+ });
168
+ }
169
+ if (!recordOnce(schema, id)) {
170
+ return;
171
+ }
172
+ for (const [child, childId] of discoverDependents(schema)) {
173
+ recordOnce(child, childId);
174
+ }
175
+ }, "register"),
176
+ hasCollision: /* @__PURE__ */ __name((id) => {
177
+ const set = seen.get(id);
178
+ return set !== void 0 && set.size > 1;
179
+ }, "hasCollision"),
180
+ getCollisions: /* @__PURE__ */ __name(() => {
181
+ const out = /* @__PURE__ */ new Map();
182
+ for (const [id, set] of seen) {
183
+ if (set.size <= 1) {
184
+ continue;
185
+ }
186
+ out.set(id, set);
187
+ }
188
+ return out;
189
+ }, "getCollisions"),
190
+ ids: /* @__PURE__ */ __name(() => [
191
+ ...seen.keys()
192
+ ], "ids")
193
+ };
194
+ }, "createRegistry");
195
+ var defaultRegistry = createRegistry();
196
+ var registerSchema = /* @__PURE__ */ __name((schema, registry = defaultRegistry, options) => {
197
+ const explicit = options?.id;
198
+ if (typeof explicit === "string" && explicit !== "") {
199
+ registry.register(schema, explicit);
200
+ return explicit;
201
+ }
202
+ const meta = registry.zodRegistry.get(schema);
203
+ const metaId = meta === void 0 ? void 0 : meta.id;
204
+ if (typeof metaId !== "string" || metaId === "") {
205
+ return void 0;
206
+ }
207
+ registry.register(schema, metaId);
208
+ return metaId;
209
+ }, "registerSchema");
25
210
 
26
211
  // src/schema/composition.ts
27
212
  var lineageMap = /* @__PURE__ */ new WeakMap();
@@ -52,6 +237,8 @@ var extend = /* @__PURE__ */ __name((parent, build) => {
52
237
  if (!propsMap.has(parent)) {
53
238
  propsMap.set(parent, computeShapeKeys(parent));
54
239
  }
240
+ registerSchema(parent);
241
+ registerSchema(result);
55
242
  return result;
56
243
  }, "extend");
57
244
  var getLineage = /* @__PURE__ */ __name((schema) => lineageMap.get(schema), "getLineage");
@@ -72,6 +259,7 @@ var createCompositionOverride = /* @__PURE__ */ __name((opts) => {
72
259
  if (parentId === void 0) {
73
260
  return;
74
261
  }
262
+ registerSchema(entry.parent, registry);
75
263
  const childProps = jsonSchema.properties ?? {};
76
264
  const childRequired = jsonSchema.required ?? [];
77
265
  const parentPropSet = new Set(parentCache.properties);
@@ -350,167 +538,6 @@ var toOpenApi = /* @__PURE__ */ __name((schema, opts) => {
350
538
  }
351
539
  return result;
352
540
  }, "toOpenApi");
353
- var INNER_TYPE_WRAPPERS = /* @__PURE__ */ new Set([
354
- "optional",
355
- "nullable",
356
- "default",
357
- "prefault",
358
- "catch",
359
- "nonoptional",
360
- "success",
361
- "readonly",
362
- "promise"
363
- ]);
364
- var readId = /* @__PURE__ */ __name((schema) => {
365
- const meta = zod.z.globalRegistry.get(schema);
366
- if (meta === void 0) {
367
- return void 0;
368
- }
369
- const id = meta.id;
370
- return typeof id === "string" ? id : void 0;
371
- }, "readId");
372
- var collectChildren = /* @__PURE__ */ __name((schema) => {
373
- const def = schema._zod.def;
374
- if (def.type === "object") {
375
- const out = [];
376
- const shape = def.shape;
377
- if (shape !== void 0) {
378
- for (const value of Object.values(shape)) {
379
- out.push(value);
380
- }
381
- }
382
- if (def.catchall !== void 0) {
383
- out.push(def.catchall);
384
- }
385
- return out;
386
- }
387
- if (def.type === "array") {
388
- return [
389
- def.element
390
- ];
391
- }
392
- if (def.type === "union") {
393
- return def.options.map((opt) => opt);
394
- }
395
- if (def.type === "intersection") {
396
- return [
397
- def.left,
398
- def.right
399
- ];
400
- }
401
- if (def.type === "tuple") {
402
- const out = def.items.map((it) => it);
403
- if (def.rest !== null) {
404
- out.push(def.rest);
405
- }
406
- return out;
407
- }
408
- if (def.type === "record" || def.type === "map") {
409
- return [
410
- def.keyType,
411
- def.valueType
412
- ];
413
- }
414
- if (def.type === "set") {
415
- return [
416
- def.valueType
417
- ];
418
- }
419
- if (def.type === "pipe") {
420
- return [
421
- def.in,
422
- def.out
423
- ];
424
- }
425
- if (def.type === "lazy") {
426
- return [
427
- def.getter()
428
- ];
429
- }
430
- if (INNER_TYPE_WRAPPERS.has(def.type)) {
431
- return [
432
- def.innerType
433
- ];
434
- }
435
- return [];
436
- }, "collectChildren");
437
- var discoverDependents = /* @__PURE__ */ __name((schema) => {
438
- const visited = /* @__PURE__ */ new WeakSet();
439
- const out = [];
440
- const stack = [
441
- schema
442
- ];
443
- while (stack.length > 0) {
444
- const current = stack.pop();
445
- if (visited.has(current)) {
446
- continue;
447
- }
448
- visited.add(current);
449
- for (const child of collectChildren(current)) {
450
- if (visited.has(child)) {
451
- continue;
452
- }
453
- const id = readId(child);
454
- if (id !== void 0) {
455
- out.push([
456
- child,
457
- id
458
- ]);
459
- }
460
- stack.push(child);
461
- }
462
- }
463
- return out;
464
- }, "discoverDependents");
465
-
466
- // src/schema/registry.ts
467
- var createRegistry = /* @__PURE__ */ __name(() => {
468
- const seen = /* @__PURE__ */ new Map();
469
- const recordOnce = /* @__PURE__ */ __name((schema, id) => {
470
- let set = seen.get(id);
471
- if (set === void 0) {
472
- set = /* @__PURE__ */ new Set();
473
- seen.set(id, set);
474
- }
475
- if (set.has(schema)) {
476
- return false;
477
- }
478
- set.add(schema);
479
- return true;
480
- }, "recordOnce");
481
- return {
482
- zodRegistry: zod.z.globalRegistry,
483
- register: /* @__PURE__ */ __name((schema, id) => {
484
- zod.z.globalRegistry.add(schema, {
485
- id
486
- });
487
- if (!recordOnce(schema, id)) {
488
- return;
489
- }
490
- for (const [child, childId] of discoverDependents(schema)) {
491
- recordOnce(child, childId);
492
- }
493
- }, "register"),
494
- hasCollision: /* @__PURE__ */ __name((id) => {
495
- const set = seen.get(id);
496
- return set !== void 0 && set.size > 1;
497
- }, "hasCollision"),
498
- getCollisions: /* @__PURE__ */ __name(() => {
499
- const out = /* @__PURE__ */ new Map();
500
- for (const [id, set] of seen) {
501
- if (set.size <= 1) {
502
- continue;
503
- }
504
- out.set(id, set);
505
- }
506
- return out;
507
- }, "getCollisions"),
508
- ids: /* @__PURE__ */ __name(() => [
509
- ...seen.keys()
510
- ], "ids")
511
- };
512
- }, "createRegistry");
513
- var defaultRegistry = createRegistry();
514
541
 
515
542
  // src/dto/marker.ts
516
543
  var makeZodDtoMarker = /* @__PURE__ */ __name((dtoId, io) => ({
@@ -573,14 +600,7 @@ var resolveOutput = /* @__PURE__ */ __name((parent, schema) => {
573
600
  // src/dto/create-zod-dto.ts
574
601
  var anonCounter = 0;
575
602
  var warnedOnAnonymous = false;
576
- var resolveId = /* @__PURE__ */ __name((registry, schema, providedId, className) => {
577
- if (providedId !== void 0 && providedId !== "") {
578
- return providedId;
579
- }
580
- const meta = registry.zodRegistry.get(schema);
581
- if (meta && typeof meta.id === "string" && meta.id !== "") {
582
- return meta.id;
583
- }
603
+ var resolveFallbackId = /* @__PURE__ */ __name((className) => {
584
604
  if (className !== "" && className.length > 1) {
585
605
  return className;
586
606
  }
@@ -591,7 +611,7 @@ var resolveId = /* @__PURE__ */ __name((registry, schema, providedId, className)
591
611
  console.warn(`[zod-nest] Could not resolve a DTO id from class name (got "${className}"). Using "${fallback}". Set an explicit id via \`schema.meta({ id: 'Foo' })\` (preferred) or \`createZodDto(schema, { id: 'Foo' })\` \u2014 important under minification, where class names become single mangled characters.`);
592
612
  }
593
613
  return fallback;
594
- }, "resolveId");
614
+ }, "resolveFallbackId");
595
615
  var createZodDto = /* @__PURE__ */ __name((schema, options) => {
596
616
  const registry = options?.registry ?? defaultRegistry;
597
617
  const io = "input";
@@ -600,7 +620,14 @@ var createZodDto = /* @__PURE__ */ __name((schema, options) => {
600
620
  if (cachedId !== void 0) {
601
621
  return cachedId;
602
622
  }
603
- cachedId = resolveId(registry, schema, options?.id, className);
623
+ const named = registerSchema(schema, registry, {
624
+ id: options?.id
625
+ });
626
+ if (named !== void 0) {
627
+ cachedId = named;
628
+ return cachedId;
629
+ }
630
+ cachedId = resolveFallbackId(className);
604
631
  registry.register(schema, cachedId);
605
632
  return cachedId;
606
633
  }, "ensureRegistered");
@@ -1946,6 +1973,7 @@ exports.isZodDto = isZodDto;
1946
1973
  exports.isZodDtoMarker = isZodDtoMarker;
1947
1974
  exports.makeZodDtoMarker = makeZodDtoMarker;
1948
1975
  exports.overrideJSONSchema = overrideJSONSchema;
1976
+ exports.registerSchema = registerSchema;
1949
1977
  exports.resolveEffectiveStatus = resolveEffectiveStatus;
1950
1978
  exports.toOpenApi = toOpenApi;
1951
1979
  //# sourceMappingURL=index.js.map