zod-openapi 5.0.0-beta.7 → 5.0.0-beta.9

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
@@ -48,7 +48,7 @@ Generates an OpenAPI documentation object.
48
48
 
49
49
  ```typescript
50
50
  import 'zod-openapi/extend';
51
- import { z } from 'zod';
51
+ import { z } from 'zod/v4';
52
52
  import { createDocument } from 'zod-openapi';
53
53
 
54
54
  const jobId = z.string().openapi({
@@ -191,7 +191,7 @@ Creates an OpenAPI Schema Object along with any registered components. OpenAPI 3
191
191
 
192
192
  ```typescript
193
193
  import 'zod-openapi/extend';
194
- import { z } from 'zod';
194
+ import { z } from 'zod/v4';
195
195
  import { createSchema } from 'zod-openapi';
196
196
 
197
197
  const jobId = z.string().openapi({
package/dist/api.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { ComponentRegistry, Override, ParameterLocation, ParameterObject, ReferenceObject, createComponents, createRegistry, isAnyZodType } from "./components-DAYTA1Um.mjs";
1
+ import { ComponentRegistry, Override, ParameterLocation, ParameterObject, ReferenceObject, createComponents, createRegistry } from "./components-26wns3Hd.mjs";
2
2
  import { $ZodObject, $ZodType, $ZodTypes } from "zod/v4/core";
3
+ import { core } from "zod/v4";
3
4
 
4
5
  //#region src/create/parameters.d.ts
5
6
  declare const createParameter: (parameter: $ZodType, location: {
@@ -13,4 +14,7 @@ declare const createParameter: (parameter: $ZodType, location: {
13
14
  //#region src/create/object.d.ts
14
15
  declare const unwrapZodObject: (zodType: $ZodTypes, io: "input" | "output", path: string[]) => $ZodObject;
15
16
  //#endregion
16
- export { Override, createComponents, createParameter, createRegistry, isAnyZodType, unwrapZodObject };
17
+ //#region src/zod.d.ts
18
+ declare const isAnyZodType: (schema: unknown) => schema is core.$ZodTypes;
19
+ //#endregion
20
+ export { ComponentRegistry, Override, createComponents, createParameter, createRegistry, isAnyZodType, unwrapZodObject };
package/dist/api.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { ComponentRegistry, Override, ParameterLocation, ParameterObject, ReferenceObject, createComponents, createRegistry, isAnyZodType } from "./components-5_CJdR73.js";
1
+ import { ComponentRegistry, Override, ParameterLocation, ParameterObject, ReferenceObject, createComponents, createRegistry } from "./components-CokUEQbL.js";
2
2
  import { $ZodObject, $ZodType, $ZodTypes } from "zod/v4/core";
3
+ import { core } from "zod/v4";
3
4
 
4
5
  //#region src/create/parameters.d.ts
5
6
  declare const createParameter: (parameter: $ZodType, location: {
@@ -13,4 +14,7 @@ declare const createParameter: (parameter: $ZodType, location: {
13
14
  //#region src/create/object.d.ts
14
15
  declare const unwrapZodObject: (zodType: $ZodTypes, io: "input" | "output", path: string[]) => $ZodObject;
15
16
  //#endregion
16
- export { Override, createComponents, createParameter, createRegistry, isAnyZodType, unwrapZodObject };
17
+ //#region src/zod.d.ts
18
+ declare const isAnyZodType: (schema: unknown) => schema is core.$ZodTypes;
19
+ //#endregion
20
+ export { ComponentRegistry, Override, createComponents, createParameter, createRegistry, isAnyZodType, unwrapZodObject };
package/dist/api.js CHANGED
@@ -1,8 +1,7 @@
1
- const require_zod = require('./zod-i2t01GF0.js');
2
- const require_components = require('./components-BaA49bb2.js');
1
+ const require_components = require('./components-CB3cj8u3.js');
3
2
 
4
3
  exports.createComponents = require_components.createComponents;
5
4
  exports.createParameter = require_components.createParameter;
6
5
  exports.createRegistry = require_components.createRegistry;
7
- exports.isAnyZodType = require_zod.isAnyZodType;
6
+ exports.isAnyZodType = require_components.isAnyZodType;
8
7
  exports.unwrapZodObject = require_components.unwrapZodObject;
package/dist/api.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import { isAnyZodType } from "./zod-BvA30wad.mjs";
2
- import { createComponents, createParameter, createRegistry, unwrapZodObject } from "./components-DMRr6ft0.mjs";
1
+ import { createComponents, createParameter, createRegistry, isAnyZodType, unwrapZodObject } from "./components-0QHfGwg0.mjs";
3
2
 
4
3
  export { createComponents, createParameter, createRegistry, isAnyZodType, unwrapZodObject };
@@ -1,8 +1,10 @@
1
- import { isAnyZodType } from "./zod-BvA30wad.mjs";
2
1
  import { globalRegistry } from "zod/v4/core";
3
- import { globalRegistry as globalRegistry$1, object, toJSONSchema } from "zod/v4";
4
- import { registerSchemas } from "./create/componentsSideEffects";
2
+ import { globalRegistry as globalRegistry$1, object, registry, toJSONSchema } from "zod/v4";
5
3
 
4
+ //#region src/zod.ts
5
+ const isAnyZodType = (schema) => typeof schema === "object" && schema !== null && "_zod" in schema;
6
+
7
+ //#endregion
6
8
  //#region src/create/object.ts
7
9
  const unwrapZodObject = (zodType, io, path) => {
8
10
  const def = zodType._zod.def;
@@ -217,43 +219,43 @@ const createResponses = (responses, ctx, path) => {
217
219
 
218
220
  //#endregion
219
221
  //#region src/create/paths.ts
220
- const createOperation = (operationObject, registry, path) => {
222
+ const createOperation = (operationObject, registry$1, path) => {
221
223
  const { parameters, requestParams, requestBody, responses, callbacks,...rest } = operationObject;
222
224
  const operation = rest;
223
225
  const maybeManualParameters = createManualParameters(parameters, {
224
- registry,
226
+ registry: registry$1,
225
227
  io: "input"
226
228
  }, [...path, "parameters"]);
227
229
  const maybeRequestParams = createParameters(requestParams, {
228
- registry,
230
+ registry: registry$1,
229
231
  io: "input"
230
232
  }, [...path, "requestParams"]);
231
233
  if (maybeRequestParams || maybeManualParameters) operation.parameters = [...maybeRequestParams ?? [], ...maybeManualParameters ?? []];
232
234
  const maybeRequestBody = createRequestBody(requestBody, {
233
- registry,
235
+ registry: registry$1,
234
236
  io: "input"
235
237
  }, [...path, "requestBody"]);
236
238
  if (maybeRequestBody) operation.requestBody = maybeRequestBody;
237
239
  const maybeResponses = createResponses(responses, {
238
- registry,
240
+ registry: registry$1,
239
241
  io: "output"
240
242
  }, [...path, "responses"]);
241
243
  if (maybeResponses) operation.responses = maybeResponses;
242
- const maybeCallbacks = createCallbacks(callbacks, registry, [...path, "callbacks"]);
244
+ const maybeCallbacks = createCallbacks(callbacks, registry$1, [...path, "callbacks"]);
243
245
  if (maybeCallbacks) operation.callbacks = maybeCallbacks;
244
246
  return operation;
245
247
  };
246
- const createPathItem = (pathItem, registry, path) => {
248
+ const createPathItem = (pathItem, registry$1, path) => {
247
249
  const pathItemObject = {};
248
250
  const { id,...rest } = pathItem;
249
251
  for (const [key, value] of Object.entries(rest)) {
250
252
  if (key === "get" || key === "put" || key === "post" || key === "delete" || key === "options" || key === "head" || key === "patch" || key === "trace") {
251
- pathItemObject[key] = createOperation(value, registry, [...path, key]);
253
+ pathItemObject[key] = createOperation(value, registry$1, [...path, key]);
252
254
  continue;
253
255
  }
254
256
  if (key === "parameters") {
255
257
  pathItemObject[key] = createManualParameters(value, {
256
- registry,
258
+ registry: registry$1,
257
259
  io: "input"
258
260
  }, [...path, key]);
259
261
  continue;
@@ -262,14 +264,14 @@ const createPathItem = (pathItem, registry, path) => {
262
264
  }
263
265
  if (id) {
264
266
  const ref = { $ref: `#/components/pathItems/${id}` };
265
- registry.pathItems.ids.set(id, pathItemObject);
266
- registry.pathItems.seen.set(pathItem, ref);
267
+ registry$1.pathItems.ids.set(id, pathItemObject);
268
+ registry$1.pathItems.seen.set(pathItem, ref);
267
269
  return ref;
268
270
  }
269
- registry.pathItems.seen.set(pathItem, pathItemObject);
271
+ registry$1.pathItems.seen.set(pathItem, pathItemObject);
270
272
  return pathItemObject;
271
273
  };
272
- const createPaths = (paths, registry, path) => {
274
+ const createPaths = (paths, registry$1, path) => {
273
275
  if (!paths) return void 0;
274
276
  const pathsObject = {};
275
277
  for (const [singlePath, pathItemObject] of Object.entries(paths)) {
@@ -277,15 +279,15 @@ const createPaths = (paths, registry, path) => {
277
279
  pathsObject[singlePath] = pathItemObject;
278
280
  continue;
279
281
  }
280
- pathsObject[singlePath] = createPathItem(pathItemObject, registry, [...path, singlePath]);
282
+ pathsObject[singlePath] = createPathItem(pathItemObject, registry$1, [...path, singlePath]);
281
283
  }
282
284
  return pathsObject;
283
285
  };
284
286
 
285
287
  //#endregion
286
288
  //#region src/create/callbacks.ts
287
- const createCallback = (callbackObject, registry, path) => {
288
- const seenCallback = registry.callbacks.seen.get(callbackObject);
289
+ const createCallback = (callbackObject, registry$1, path) => {
290
+ const seenCallback = registry$1.callbacks.seen.get(callbackObject);
289
291
  if (seenCallback) return seenCallback;
290
292
  const { id,...rest } = callbackObject;
291
293
  const callback = {};
@@ -294,18 +296,18 @@ const createCallback = (callbackObject, registry, path) => {
294
296
  callback[name] = pathItem;
295
297
  continue;
296
298
  }
297
- callback[name] = createPathItem(pathItem, registry, [...path, name]);
299
+ callback[name] = createPathItem(pathItem, registry$1, [...path, name]);
298
300
  }
299
301
  if (id) {
300
302
  const ref = { $ref: `#/components/callbacks/${id}` };
301
- registry.callbacks.ids.set(id, callback);
302
- registry.callbacks.seen.set(callbackObject, ref);
303
+ registry$1.callbacks.ids.set(id, callback);
304
+ registry$1.callbacks.seen.set(callbackObject, ref);
303
305
  return ref;
304
306
  }
305
- registry.callbacks.seen.set(callbackObject, callback);
307
+ registry$1.callbacks.seen.set(callbackObject, callback);
306
308
  return callback;
307
309
  };
308
- const createCallbacks = (callbacks, registry, path) => {
310
+ const createCallbacks = (callbacks, registry$1, path) => {
309
311
  if (!callbacks) return void 0;
310
312
  const callbacksObject = {};
311
313
  for (const [name, value] of Object.entries(callbacks)) {
@@ -313,7 +315,7 @@ const createCallbacks = (callbacks, registry, path) => {
313
315
  callbacksObject[name] = value;
314
316
  continue;
315
317
  }
316
- callbacksObject[name] = createCallback(value, registry, [...path, name]);
318
+ callbacksObject[name] = createCallback(value, registry$1, [...path, name]);
317
319
  }
318
320
  return callbacksObject;
319
321
  };
@@ -395,6 +397,7 @@ const validate = (ctx, opts) => {
395
397
  //#region src/create/schema/rename.ts
396
398
  const renameComponents = (components, outputIds, ctx) => {
397
399
  const componentsToRename = /* @__PURE__ */ new Map();
400
+ if (ctx.io === "input") return componentsToRename;
398
401
  const componentDependencies = /* @__PURE__ */ new Map();
399
402
  const stringifiedComponents = /* @__PURE__ */ new Map();
400
403
  for (const [key, value] of Object.entries(components)) {
@@ -420,18 +423,18 @@ const renameComponents = (components, outputIds, ctx) => {
420
423
  }
421
424
  return componentsToRename;
422
425
  };
423
- const isDependencyPure = (componentDependencies, stringifiedComponents, registry, key, visited = /* @__PURE__ */ new Set()) => {
426
+ const isDependencyPure = (componentDependencies, stringifiedComponents, registry$1, key, visited = /* @__PURE__ */ new Set()) => {
424
427
  if (visited.has(key)) return true;
425
428
  const dependencies = componentDependencies.get(key);
426
429
  if (dependencies.pure !== void 0) return dependencies.pure;
427
430
  const stringified = stringifiedComponents.get(key);
428
- const component = registry.schemas.ids.get(key);
431
+ const component = registry$1.schemas.ids.get(key);
429
432
  if (component && stringified !== JSON.stringify(component)) {
430
433
  dependencies.pure = false;
431
434
  return false;
432
435
  }
433
436
  visited.add(key);
434
- const result = [...dependencies.dependencies].every((dep) => isDependencyPure(componentDependencies, stringifiedComponents, registry, dep, new Set(visited)));
437
+ const result = [...dependencies.dependencies].every((dep) => isDependencyPure(componentDependencies, stringifiedComponents, registry$1, dep, new Set(visited)));
435
438
  dependencies.pure = result;
436
439
  return result;
437
440
  };
@@ -469,9 +472,11 @@ const createSchema = (schema, ctx = {
469
472
  const createSchemas = (schemas, ctx) => {
470
473
  const entries = {};
471
474
  for (const [name, { zodType }] of Object.entries(schemas)) entries[name] = zodType;
472
- const schemaRegistry = object(entries);
475
+ const zodRegistry = registry();
476
+ zodRegistry.add(object(entries), { id: "zodOpenApiCreateSchema" });
477
+ for (const [id, { zodType }] of ctx.registry.schemas.manual) zodRegistry.add(zodType, { id });
473
478
  const outputIds = /* @__PURE__ */ new Map();
474
- const jsonSchema = toJSONSchema(schemaRegistry, {
479
+ const jsonSchema = toJSONSchema(zodRegistry, {
475
480
  override(context) {
476
481
  const meta = context.zodSchema.meta();
477
482
  if (meta?.outputId && meta?.id) outputIds.set(meta.id, meta.outputId);
@@ -498,11 +503,13 @@ const createSchemas = (schemas, ctx) => {
498
503
  io: ctx.io,
499
504
  unrepresentable: "any",
500
505
  reused: ctx.opts.reused,
501
- cycles: ctx.opts.cycles
506
+ cycles: ctx.opts.cycles,
507
+ uri: (id) => id === "__shared" ? `#ZOD_OPENAPI/${id}` : `#ZOD_OPENAPI/__shared#/$defs/${id}`
502
508
  });
503
- const components = jsonSchema.$defs ?? {};
509
+ const components = jsonSchema.schemas.__shared?.$defs ?? {};
510
+ jsonSchema.schemas.__shared ??= { $defs: components };
504
511
  const dynamicComponents = /* @__PURE__ */ new Map();
505
- for (const [key, value] of Object.entries(components)) if (/^__schema\d+$/.test(key)) {
512
+ for (const [key, value] of Object.entries(components)) if (/^schema\d+$/.test(key)) {
506
513
  const newName = `__schema${ctx.registry.schemas.dynamicSchemaCount++}`;
507
514
  dynamicComponents.set(key, `"#/components/schemas/${newName}"`);
508
515
  if (newName !== key) {
@@ -510,38 +517,59 @@ const createSchemas = (schemas, ctx) => {
510
517
  delete components[key];
511
518
  }
512
519
  }
513
- const parsedJsonSchema = JSON.parse(JSON.stringify(jsonSchema).replace(/"#\/\$defs\/([^"]+)"/g, (_, match) => {
520
+ const manualUsed = {};
521
+ const parsedJsonSchema = JSON.parse(JSON.stringify(jsonSchema).replace(/"#ZOD_OPENAPI\/__shared#\/\$defs\/([^"]+)"/g, (_, match) => {
514
522
  const dynamic = dynamicComponents.get(match);
515
523
  if (dynamic) return dynamic;
516
524
  const manualComponent = ctx.registry.schemas.manual.get(match);
517
- if (manualComponent) manualComponent.io[ctx.io].used++;
525
+ if (manualComponent) manualUsed[match] = true;
518
526
  return `"#/components/schemas/${match}"`;
519
527
  }));
520
- for (const [key, value] of ctx.registry.schemas.manual) if (value.io[ctx.io].used === 1 && parsedJsonSchema.properties?.[value.identifier] && parsedJsonSchema.$defs?.[key]) {
521
- parsedJsonSchema.properties[value.identifier] = parsedJsonSchema.$defs[key];
522
- delete parsedJsonSchema.$defs[key];
523
- continue;
528
+ const parsedComponents = parsedJsonSchema.schemas.__shared?.$defs ?? {};
529
+ parsedJsonSchema.schemas.__shared ??= { $defs: parsedComponents };
530
+ for (const [key] of ctx.registry.schemas.manual) {
531
+ const manualComponent = parsedJsonSchema.schemas[key];
532
+ if (!manualComponent) continue;
533
+ delete manualComponent.$schema;
534
+ delete manualComponent.id;
535
+ if (manualUsed[key]) {
536
+ delete manualComponent.$schema;
537
+ delete manualComponent.id;
538
+ if (parsedComponents[key]) throw new Error(`Component "${key}" is already registered as a component in the registry`);
539
+ parsedComponents[key] = manualComponent;
540
+ }
541
+ }
542
+ const componentsToRename = renameComponents(parsedComponents, outputIds, ctx);
543
+ if (!componentsToRename.size) {
544
+ const parsedSchemas = parsedJsonSchema.schemas.zodOpenApiCreateSchema?.properties;
545
+ delete parsedJsonSchema.schemas.zodOpenApiCreateSchema;
546
+ delete parsedJsonSchema.schemas.__shared;
547
+ return {
548
+ schemas: parsedSchemas,
549
+ components: parsedComponents,
550
+ manual: parsedJsonSchema.schemas
551
+ };
524
552
  }
525
- const renamedComponents = renameComponents(parsedJsonSchema.$defs ?? {}, outputIds, ctx);
526
- if (!renamedComponents.size) return {
527
- schemas: parsedJsonSchema.properties,
528
- components: parsedJsonSchema.$defs ?? {}
529
- };
530
553
  const renamedJsonSchema = JSON.parse(JSON.stringify(parsedJsonSchema).replace(/"#\/components\/schemas\/([^"]+)"/g, (_, match) => {
531
- const replacement = renamedComponents.get(match);
554
+ const replacement = componentsToRename.get(match);
532
555
  if (replacement) return `"#/components/schemas/${replacement}"`;
533
556
  return `"#/components/schemas/${match}"`;
534
557
  }));
558
+ const renamedSchemas = renamedJsonSchema.schemas.zodOpenApiCreateSchema?.properties;
559
+ const renamedComponents = renamedJsonSchema.schemas.__shared?.$defs ?? {};
560
+ delete renamedJsonSchema.schemas.zodOpenApiCreateSchema;
561
+ delete renamedJsonSchema.schemas.__shared;
535
562
  return {
536
- schemas: renamedJsonSchema.properties,
537
- components: renamedJsonSchema.$defs ?? {}
563
+ schemas: renamedSchemas,
564
+ components: renamedComponents,
565
+ manual: renamedJsonSchema.schemas
538
566
  };
539
567
  };
540
568
 
541
569
  //#endregion
542
570
  //#region src/create/components.ts
543
571
  const createRegistry = (components) => {
544
- const registry = {
572
+ const registry$1 = {
545
573
  schemas: {
546
574
  dynamicSchemaCount: 0,
547
575
  input: /* @__PURE__ */ new Map(),
@@ -550,7 +578,7 @@ const createRegistry = (components) => {
550
578
  manual: /* @__PURE__ */ new Map(),
551
579
  setSchema: (key, schema, io) => {
552
580
  const schemaObject = {};
553
- registry.schemas[io].set(key, {
581
+ registry$1.schemas[io].set(key, {
554
582
  schemaObject,
555
583
  zodType: schema
556
584
  });
@@ -582,19 +610,35 @@ const createRegistry = (components) => {
582
610
  seen: /* @__PURE__ */ new WeakMap()
583
611
  }
584
612
  };
585
- registerSchemas(components?.schemas, registry);
586
- registerParameters(components?.parameters, registry);
587
- registerHeaders(components?.headers, registry);
588
- registerResponses(components?.responses, registry);
589
- registerPathItems(components?.pathItems, registry);
590
- registerRequestBodies(components?.requestBodies, registry);
591
- registerCallbacks(components?.callbacks, registry);
592
- return registry;
593
- };
594
- const registerParameters = (parameters, registry) => {
613
+ registerSchemas(components?.schemas, registry$1);
614
+ registerParameters(components?.parameters, registry$1);
615
+ registerHeaders(components?.headers, registry$1);
616
+ registerResponses(components?.responses, registry$1);
617
+ registerPathItems(components?.pathItems, registry$1);
618
+ registerRequestBodies(components?.requestBodies, registry$1);
619
+ registerCallbacks(components?.callbacks, registry$1);
620
+ return registry$1;
621
+ };
622
+ const registerSchemas = (schemas, registry$1) => {
623
+ if (!schemas) return;
624
+ for (const [key, schema] of Object.entries(schemas)) {
625
+ if (registry$1.schemas.ids.has(key)) throw new Error(`Schema "${key}" is already registered`);
626
+ if (isAnyZodType(schema)) {
627
+ const id = globalRegistry.get(schema)?.id ?? key;
628
+ registry$1.schemas.manual.set(id, {
629
+ input: { schemaObject: {} },
630
+ output: { schemaObject: {} },
631
+ zodType: schema
632
+ });
633
+ continue;
634
+ }
635
+ registry$1.schemas.ids.set(key, schema);
636
+ }
637
+ };
638
+ const registerParameters = (parameters, registry$1) => {
595
639
  if (!parameters) return;
596
640
  for (const [key, schema] of Object.entries(parameters)) {
597
- if (registry.parameters.ids.has(key)) throw new Error(`Parameter "${key}" is already registered`);
641
+ if (registry$1.parameters.ids.has(key)) throw new Error(`Parameter "${key}" is already registered`);
598
642
  if (isAnyZodType(schema)) {
599
643
  const path = [
600
644
  "components",
@@ -602,20 +646,20 @@ const registerParameters = (parameters, registry) => {
602
646
  key
603
647
  ];
604
648
  const paramObject = createParameter(schema, void 0, {
605
- registry,
649
+ registry: registry$1,
606
650
  io: "input"
607
651
  }, path);
608
- registry.parameters.ids.set(key, paramObject);
609
- registry.parameters.seen.set(schema, paramObject);
652
+ registry$1.parameters.ids.set(key, paramObject);
653
+ registry$1.parameters.seen.set(schema, paramObject);
610
654
  continue;
611
655
  }
612
- registry.parameters.ids.set(key, schema);
656
+ registry$1.parameters.ids.set(key, schema);
613
657
  }
614
658
  };
615
- const registerHeaders = (headers, registry) => {
659
+ const registerHeaders = (headers, registry$1) => {
616
660
  if (!headers) return;
617
661
  for (const [key, schema] of Object.entries(headers)) {
618
- if (registry.headers.ids.has(key)) throw new Error(`Header "${key}" is already registered`);
662
+ if (registry$1.headers.ids.has(key)) throw new Error(`Header "${key}" is already registered`);
619
663
  if (isAnyZodType(schema)) {
620
664
  const path = [
621
665
  "components",
@@ -623,17 +667,17 @@ const registerHeaders = (headers, registry) => {
623
667
  key
624
668
  ];
625
669
  const headerObject = createHeader(schema, {
626
- registry,
670
+ registry: registry$1,
627
671
  io: "output"
628
672
  }, path);
629
- registry.headers.ids.set(key, headerObject);
630
- registry.headers.seen.set(schema, headerObject);
673
+ registry$1.headers.ids.set(key, headerObject);
674
+ registry$1.headers.seen.set(schema, headerObject);
631
675
  continue;
632
676
  }
633
- registry.headers.ids.set(key, schema);
677
+ registry$1.headers.ids.set(key, schema);
634
678
  }
635
679
  };
636
- const registerResponses = (responses, registry) => {
680
+ const registerResponses = (responses, registry$1) => {
637
681
  if (!responses) return;
638
682
  for (const [key, schema] of Object.entries(responses)) {
639
683
  const path = [
@@ -641,19 +685,19 @@ const registerResponses = (responses, registry) => {
641
685
  "responses",
642
686
  key
643
687
  ];
644
- if (registry.responses.ids.has(key)) throw new Error(`Response "${key}" is already registered`);
688
+ if (registry$1.responses.ids.has(key)) throw new Error(`Response "${key}" is already registered`);
645
689
  const responseObject = createResponse(schema, {
646
- registry,
690
+ registry: registry$1,
647
691
  io: "output"
648
692
  }, path);
649
- registry.responses.ids.set(key, responseObject);
650
- registry.responses.seen.set(schema, responseObject);
693
+ registry$1.responses.ids.set(key, responseObject);
694
+ registry$1.responses.seen.set(schema, responseObject);
651
695
  }
652
696
  };
653
- const registerRequestBodies = (requestBodies, registry) => {
697
+ const registerRequestBodies = (requestBodies, registry$1) => {
654
698
  if (!requestBodies) return;
655
699
  for (const [key, schema] of Object.entries(requestBodies)) {
656
- if (registry.requestBodies.ids.has(key)) throw new Error(`RequestBody "${key}" is already registered`);
700
+ if (registry$1.requestBodies.ids.has(key)) throw new Error(`RequestBody "${key}" is already registered`);
657
701
  if (isAnyZodType(schema)) {
658
702
  const path = [
659
703
  "components",
@@ -661,81 +705,87 @@ const registerRequestBodies = (requestBodies, registry) => {
661
705
  key
662
706
  ];
663
707
  const requestBodyObject = createRequestBody(schema, {
664
- registry,
708
+ registry: registry$1,
665
709
  io: "input"
666
710
  }, path);
667
- registry.requestBodies.ids.set(key, requestBodyObject);
711
+ registry$1.requestBodies.ids.set(key, requestBodyObject);
668
712
  continue;
669
713
  }
670
- registry.requestBodies.ids.set(key, schema);
714
+ registry$1.requestBodies.ids.set(key, schema);
671
715
  }
672
716
  };
673
- const registerCallbacks = (callbacks, registry) => {
717
+ const registerCallbacks = (callbacks, registry$1) => {
674
718
  if (!callbacks) return;
675
719
  for (const [key, schema] of Object.entries(callbacks)) {
676
- if (registry.callbacks.ids.has(key)) throw new Error(`Callback "${key}" is already registered`);
720
+ if (registry$1.callbacks.ids.has(key)) throw new Error(`Callback "${key}" is already registered`);
677
721
  const path = [
678
722
  "components",
679
723
  "callbacks",
680
724
  key
681
725
  ];
682
- const callbackObject = createCallback(schema, registry, path);
683
- registry.callbacks.ids.set(key, callbackObject);
684
- registry.callbacks.seen.set(schema, callbackObject);
726
+ const callbackObject = createCallback(schema, registry$1, path);
727
+ registry$1.callbacks.ids.set(key, callbackObject);
728
+ registry$1.callbacks.seen.set(schema, callbackObject);
685
729
  }
686
730
  };
687
- const registerPathItems = (pathItems, registry) => {
731
+ const registerPathItems = (pathItems, registry$1) => {
688
732
  if (!pathItems) return;
689
733
  for (const [key, schema] of Object.entries(pathItems)) {
690
- if (registry.pathItems.ids.has(key)) throw new Error(`PathItem "${key}" is already registered`);
734
+ if (registry$1.pathItems.ids.has(key)) throw new Error(`PathItem "${key}" is already registered`);
691
735
  const path = [
692
736
  "components",
693
737
  "pathItems",
694
738
  key
695
739
  ];
696
- const pathItemObject = createPathItem(schema, registry, path);
697
- registry.pathItems.ids.set(key, pathItemObject);
698
- registry.pathItems.seen.set(schema, pathItemObject);
740
+ const pathItemObject = createPathItem(schema, registry$1, path);
741
+ registry$1.pathItems.ids.set(key, pathItemObject);
742
+ registry$1.pathItems.seen.set(schema, pathItemObject);
699
743
  continue;
700
744
  }
701
745
  };
702
746
  const createIOSchemas = (ctx) => {
703
- const { schemas, components } = createSchemas(Object.fromEntries(ctx.registry.schemas[ctx.io]), ctx);
747
+ const { schemas, components, manual } = createSchemas(Object.fromEntries(ctx.registry.schemas[ctx.io]), ctx);
704
748
  for (const [key, schema] of Object.entries(components)) ctx.registry.schemas.ids.set(key, schema);
705
749
  for (const [key, schema] of Object.entries(schemas)) {
706
750
  const ioSchema = ctx.registry.schemas[ctx.io].get(key);
707
751
  if (ioSchema) Object.assign(ioSchema.schemaObject, schema);
708
752
  }
753
+ for (const [key, value] of Object.entries(manual)) {
754
+ const manualSchema = ctx.registry.schemas.manual.get(key);
755
+ if (!manualSchema) continue;
756
+ if (components[key]) manualSchema[ctx.io].used = true;
757
+ Object.assign(manualSchema[ctx.io].schemaObject, value);
758
+ }
709
759
  };
710
- const createManualSchemas = (registry) => {
711
- for (const [key, value] of registry.schemas.manual) if (value.io.input.used === 1) {
760
+ const createManualSchemas = (registry$1) => {
761
+ for (const [key, value] of registry$1.schemas.manual) if (!value.input.used) {
712
762
  const io = globalRegistry.get(value.zodType)?.unusedIO ?? "output";
713
- const schema = value.io[io].schemaObject;
714
- registry.schemas.ids.set(key, schema);
763
+ const schema = value[io].schemaObject;
764
+ registry$1.schemas.ids.set(key, schema);
715
765
  }
716
766
  };
717
- const createComponents = (registry, opts) => {
767
+ const createComponents = (registry$1, opts) => {
718
768
  createIOSchemas({
719
- registry,
769
+ registry: registry$1,
720
770
  io: "input",
721
771
  opts
722
772
  });
723
773
  createIOSchemas({
724
- registry,
774
+ registry: registry$1,
725
775
  io: "output",
726
776
  opts
727
777
  });
728
- createManualSchemas(registry);
778
+ createManualSchemas(registry$1);
729
779
  const components = {};
730
- if (registry.schemas.ids.size > 0) components.schemas = Object.fromEntries(registry.schemas.ids);
731
- if (registry.headers.ids.size > 0) components.headers = Object.fromEntries(registry.headers.ids);
732
- if (registry.requestBodies.ids.size > 0) components.requestBodies = Object.fromEntries(registry.requestBodies.ids);
733
- if (registry.responses.ids.size > 0) components.responses = Object.fromEntries(registry.responses.ids);
734
- if (registry.parameters.ids.size > 0) components.parameters = Object.fromEntries(registry.parameters.ids);
735
- if (registry.callbacks.ids.size > 0) components.callbacks = Object.fromEntries(registry.callbacks.ids);
736
- if (registry.pathItems.ids.size > 0) components.pathItems = Object.fromEntries(registry.pathItems.ids);
780
+ if (registry$1.schemas.ids.size > 0) components.schemas = Object.fromEntries(registry$1.schemas.ids);
781
+ if (registry$1.headers.ids.size > 0) components.headers = Object.fromEntries(registry$1.headers.ids);
782
+ if (registry$1.requestBodies.ids.size > 0) components.requestBodies = Object.fromEntries(registry$1.requestBodies.ids);
783
+ if (registry$1.responses.ids.size > 0) components.responses = Object.fromEntries(registry$1.responses.ids);
784
+ if (registry$1.parameters.ids.size > 0) components.parameters = Object.fromEntries(registry$1.parameters.ids);
785
+ if (registry$1.callbacks.ids.size > 0) components.callbacks = Object.fromEntries(registry$1.callbacks.ids);
786
+ if (registry$1.pathItems.ids.size > 0) components.pathItems = Object.fromEntries(registry$1.pathItems.ids);
737
787
  return components;
738
788
  };
739
789
 
740
790
  //#endregion
741
- export { createComponents, createParameter, createPaths, createRegistry, createSchema, unwrapZodObject };
791
+ export { createComponents, createParameter, createPaths, createRegistry, createSchema, isAnyZodType, unwrapZodObject };
@@ -1,5 +1,4 @@
1
1
  import { $ZodType, $ZodTypes } from "zod/v4/core";
2
- import { ZodType, ZodTypeDef } from "zod";
3
2
  import { core } from "zod/v4";
4
3
 
5
4
  //#region src/openapi3-ts/dist/model/specification-extension.d.ts
@@ -324,13 +323,12 @@ interface SecurityRequirementObject {
324
323
  declare const openApiVersions: readonly ["3.1.0", "3.1.1"];
325
324
  type OpenApiVersion = (typeof openApiVersions)[number];
326
325
  //#endregion
327
- //#region src/zod.d.ts
326
+ //#region src/types.d.ts
328
327
  type Override = (ctx: {
329
328
  zodSchema: core.$ZodTypes;
330
329
  jsonSchema: core.JSONSchema.BaseSchema;
331
330
  io: 'input' | 'output';
332
331
  }) => void;
333
- declare const isAnyZodType: (schema: unknown) => schema is core.$ZodTypes;
334
332
  declare module 'zod/v4' {
335
333
  interface GlobalMeta {
336
334
  /**
@@ -446,7 +444,6 @@ interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'we
446
444
  webhooks?: ZodOpenApiPathsObject;
447
445
  components?: ZodOpenApiComponentsObject;
448
446
  }
449
- type ZodObjectInputType<Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Record<string, unknown>> = ZodType<Output, Def, Input>;
450
447
  type ZodObjectInput = $ZodType<unknown, Record<string, unknown>>;
451
448
  type OverrideType = $ZodTypes['_zod']['def']['type'];
452
449
  interface CreateDocumentOptions {
@@ -497,16 +494,13 @@ interface ComponentRegistry {
497
494
  }>;
498
495
  ids: Map<string, SchemaObject | ReferenceObject>;
499
496
  manual: Map<string, {
500
- identifier: string;
501
- io: {
502
- input: {
503
- used: number;
504
- schemaObject: SchemaObject;
505
- };
506
- output: {
507
- used: number;
508
- schemaObject: SchemaObject;
509
- };
497
+ input: {
498
+ used?: true;
499
+ schemaObject: SchemaObject;
500
+ };
501
+ output: {
502
+ used?: true;
503
+ schemaObject: SchemaObject;
510
504
  };
511
505
  zodType: $ZodType;
512
506
  }>;
@@ -540,4 +534,4 @@ interface ComponentRegistry {
540
534
  declare const createRegistry: (components?: ZodOpenApiComponentsObject) => ComponentRegistry;
541
535
  declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions) => ComponentsObject;
542
536
  //#endregion
543
- export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodObjectInputType, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBody, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry, isAnyZodType };
537
+ export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBody, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };