zod-openapi 5.4.6 → 6.0.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.
@@ -1,37 +1,15 @@
1
1
  let zod_v4_core = require("zod/v4/core");
2
2
  let zod_v4 = require("zod/v4");
3
-
4
3
  //#region src/zod.ts
5
4
  const isAnyZodType = (schema) => typeof schema === "object" && schema !== null && "_zod" in schema;
6
-
7
5
  //#endregion
8
6
  //#region src/create/examples.ts
9
- const createExamples = (examples, registry$1, path) => {
7
+ const createExamples = (examples, registry, path) => {
10
8
  if (!examples) return;
11
9
  const examplesObject = {};
12
- for (const [name, example] of Object.entries(examples)) examplesObject[name] = registry$1.addExample(example, [...path, name]);
10
+ for (const [name, example] of Object.entries(examples)) examplesObject[name] = registry.addExample(example, [...path, name]);
13
11
  return examplesObject;
14
12
  };
15
-
16
- //#endregion
17
- //#region src/create/content.ts
18
- const createMediaTypeObject = (mediaType, ctx, path) => {
19
- const { schema, examples, ...rest } = mediaType;
20
- const mediaTypeObject = rest;
21
- if (isAnyZodType(schema)) mediaTypeObject.schema = ctx.registry.addSchema(schema, [...path, "schema"], {
22
- io: ctx.io,
23
- source: { type: "mediaType" }
24
- });
25
- else mediaTypeObject.schema = schema;
26
- if (examples) mediaTypeObject.examples = createExamples(examples, ctx.registry, [...path, "examples"]);
27
- return mediaTypeObject;
28
- };
29
- const createContent = (content, ctx, path) => {
30
- const contentObject = {};
31
- for (const [mediaType, mediaTypeObject] of Object.entries(content)) if (mediaTypeObject) contentObject[mediaType] = createMediaTypeObject(mediaTypeObject, ctx, [...path, mediaType]);
32
- return contentObject;
33
- };
34
-
35
13
  //#endregion
36
14
  //#region src/create/object.ts
37
15
  const unwrapZodObject = (zodType, io, path) => {
@@ -49,37 +27,83 @@ const isRequired = (zodType, io) => {
49
27
  if (io === "input") return zodType._zod.optin === void 0;
50
28
  return zodType._zod.optout === void 0;
51
29
  };
52
-
53
30
  //#endregion
54
31
  //#region src/create/headers.ts
55
- const createHeaders = (headers, registry$1, path) => {
32
+ const createHeaders = (headers, registry, path) => {
56
33
  if (!headers) return;
57
34
  if (isAnyZodType(headers)) {
58
35
  const zodObject = unwrapZodObject(headers, "output", path);
59
36
  const headersObject = {};
60
- for (const [key, zodSchema] of Object.entries(zodObject._zod.def.shape)) headersObject[key] = registry$1.addHeader(zodSchema, [...path, key]);
37
+ for (const [key, zodSchema] of Object.entries(zodObject._zod.def.shape)) headersObject[key] = registry.addHeader(zodSchema, [...path, key]);
61
38
  return headersObject;
62
39
  }
63
40
  return headers;
64
41
  };
65
-
42
+ //#endregion
43
+ //#region src/create/specificationExtension.ts
44
+ const isISpecificationExtension = (key) => key.startsWith("x-");
45
+ //#endregion
46
+ //#region src/create/content.ts
47
+ const createMediaTypeObject = (mediaType, ctx, path) => {
48
+ const { schema, itemSchema, examples, encoding, itemEncoding, prefixEncoding, ...rest } = mediaType;
49
+ const mediaTypeObject = rest;
50
+ if (isAnyZodType(schema)) mediaTypeObject.schema = ctx.registry.addSchema(schema, [...path, "schema"], {
51
+ io: ctx.io,
52
+ source: { type: "mediaType" }
53
+ });
54
+ else if (schema) mediaTypeObject.schema = schema;
55
+ if (isAnyZodType(itemSchema)) mediaTypeObject.itemSchema = ctx.registry.addSchema(itemSchema, [...path, "itemSchema"], {
56
+ io: ctx.io,
57
+ source: { type: "mediaType" }
58
+ });
59
+ else if (itemSchema) mediaTypeObject.itemSchema = itemSchema;
60
+ if (examples) mediaTypeObject.examples = createExamples(examples, ctx.registry, [...path, "examples"]);
61
+ if (encoding) mediaTypeObject.encoding = createEncodingObject(encoding, ctx, [...path, "encoding"]);
62
+ if (itemEncoding) mediaTypeObject.itemEncoding = createEncodingProperty(itemEncoding, ctx, [...path, "itemEncoding"]);
63
+ if (prefixEncoding) mediaTypeObject.prefixEncoding = prefixEncoding.map((encodingPrefix) => createEncodingProperty(encodingPrefix, ctx, [...path, "prefixEncoding"]));
64
+ return mediaTypeObject;
65
+ };
66
+ const createContent = (content, ctx, path) => {
67
+ const contentObject = {};
68
+ for (const [mediaType, mediaTypeObject] of Object.entries(content)) if (mediaTypeObject) contentObject[mediaType] = createMediaTypeObject(mediaTypeObject, ctx, [...path, mediaType]);
69
+ return contentObject;
70
+ };
71
+ const createEncodingObject = (encoding, ctx, path) => {
72
+ const encodingObject = {};
73
+ for (const [property, encodingProperty] of Object.entries(encoding)) {
74
+ if (isISpecificationExtension(property)) {
75
+ encodingObject[property] = encodingProperty;
76
+ continue;
77
+ }
78
+ encodingObject[property] = createEncodingProperty(encodingProperty, ctx, [...path, property]);
79
+ }
80
+ return encodingObject;
81
+ };
82
+ const createEncodingProperty = (encodingProperty, ctx, path) => {
83
+ const { headers, encoding, prefixEncoding, itemEncoding, ...rest } = encodingProperty;
84
+ const encodingPropertyObject = rest;
85
+ if (headers) encodingPropertyObject.headers = createHeaders(headers, ctx.registry, [...path, "headers"]);
86
+ if (encoding) encodingPropertyObject.encoding = createEncodingObject(encoding, ctx, [...path, "encoding"]);
87
+ if (prefixEncoding) encodingPropertyObject.prefixEncoding = prefixEncoding.map((encodingPrefix) => createEncodingProperty(encodingPrefix, ctx, [...path, "prefixEncoding"]));
88
+ if (itemEncoding) encodingPropertyObject.itemEncoding = createEncodingProperty(itemEncoding, ctx, [...path, "itemEncoding"]);
89
+ return encodingPropertyObject;
90
+ };
66
91
  //#endregion
67
92
  //#region src/create/links.ts
68
- const createLinks = (links, registry$1, path) => {
93
+ const createLinks = (links, registry, path) => {
69
94
  if (!links) return;
70
95
  const linksObject = {};
71
- for (const [name, link] of Object.entries(links)) linksObject[name] = registry$1.addLink(link, [...path, name]);
96
+ for (const [name, link] of Object.entries(links)) linksObject[name] = registry.addLink(link, [...path, name]);
72
97
  return linksObject;
73
98
  };
74
-
75
99
  //#endregion
76
100
  //#region src/create/parameters.ts
77
- const createManualParameters = (parameters, registry$1, path) => {
101
+ const createManualParameters = (parameters, registry, path) => {
78
102
  if (!parameters) return;
79
103
  const parameterObjects = [];
80
104
  for (const parameter of parameters) {
81
105
  if (isAnyZodType(parameter)) {
82
- const paramObject = registry$1.addParameter(parameter, [...path, "parameters"]);
106
+ const paramObject = registry.addParameter(parameter, [...path, "parameters"]);
83
107
  parameterObjects.push(paramObject);
84
108
  continue;
85
109
  }
@@ -87,13 +111,13 @@ const createManualParameters = (parameters, registry$1, path) => {
87
111
  }
88
112
  return parameterObjects;
89
113
  };
90
- const createParameters = (requestParams, registry$1, path) => {
114
+ const createParameters = (requestParams, registry, path) => {
91
115
  if (!requestParams) return;
92
116
  const parameterObjects = [];
93
117
  for (const [location, schema] of Object.entries(requestParams ?? {})) {
94
118
  const zodObject = unwrapZodObject(schema, "input", path);
95
119
  for (const [name, zodSchema] of Object.entries(zodObject._zod.def.shape)) {
96
- const paramObject = registry$1.addParameter(zodSchema, [
120
+ const paramObject = registry.addParameter(zodSchema, [
97
121
  ...path,
98
122
  location,
99
123
  name
@@ -106,14 +130,9 @@ const createParameters = (requestParams, registry$1, path) => {
106
130
  }
107
131
  return parameterObjects;
108
132
  };
109
-
110
- //#endregion
111
- //#region src/create/specificationExtension.ts
112
- const isISpecificationExtension = (key) => key.startsWith("x-");
113
-
114
133
  //#endregion
115
134
  //#region src/create/callbacks.ts
116
- const createCallbacks = (callbacks, registry$1, path) => {
135
+ const createCallbacks = (callbacks, registry, path) => {
117
136
  if (!callbacks) return;
118
137
  const callbacksObject = {};
119
138
  for (const [name, value] of Object.entries(callbacks)) {
@@ -121,14 +140,13 @@ const createCallbacks = (callbacks, registry$1, path) => {
121
140
  callbacksObject[name] = value;
122
141
  continue;
123
142
  }
124
- callbacksObject[name] = registry$1.addCallback(value, [...path, name]);
143
+ callbacksObject[name] = registry.addCallback(value, [...path, name]);
125
144
  }
126
145
  return callbacksObject;
127
146
  };
128
-
129
147
  //#endregion
130
148
  //#region src/create/responses.ts
131
- const createResponses = (responses, registry$1, path) => {
149
+ const createResponses = (responses, registry, path) => {
132
150
  if (!responses) return;
133
151
  const responsesObject = {};
134
152
  for (const [statusCode, response] of Object.entries(responses)) {
@@ -141,28 +159,27 @@ const createResponses = (responses, registry$1, path) => {
141
159
  responsesObject[statusCode] = response;
142
160
  continue;
143
161
  }
144
- responsesObject[statusCode] = registry$1.addResponse(response, [...path, statusCode]);
162
+ responsesObject[statusCode] = registry.addResponse(response, [...path, statusCode]);
145
163
  }
146
164
  return responsesObject;
147
165
  };
148
-
149
166
  //#endregion
150
167
  //#region src/create/paths.ts
151
- const createOperation = (operation, registry$1, path) => {
168
+ const createOperation = (operation, registry, path) => {
152
169
  const { parameters, requestParams, requestBody, responses, callbacks, ...rest } = operation;
153
170
  const operationObject = rest;
154
- const maybeManualParameters = createManualParameters(parameters, registry$1, [...path, "parameters"]);
155
- const maybeRequestParams = createParameters(requestParams, registry$1, [...path, "requestParams"]);
171
+ const maybeManualParameters = createManualParameters(parameters, registry, [...path, "parameters"]);
172
+ const maybeRequestParams = createParameters(requestParams, registry, [...path, "requestParams"]);
156
173
  if (maybeRequestParams || maybeManualParameters) operationObject.parameters = [...maybeRequestParams ?? [], ...maybeManualParameters ?? []];
157
- const maybeRequestBody = requestBody && registry$1.addRequestBody(requestBody, path);
174
+ const maybeRequestBody = requestBody && registry.addRequestBody(requestBody, path);
158
175
  if (maybeRequestBody) operationObject.requestBody = maybeRequestBody;
159
- const maybeResponses = createResponses(responses, registry$1, [...path, "responses"]);
176
+ const maybeResponses = createResponses(responses, registry, [...path, "responses"]);
160
177
  if (maybeResponses) operationObject.responses = maybeResponses;
161
- const maybeCallbacks = createCallbacks(callbacks, registry$1, [...path, "callbacks"]);
178
+ const maybeCallbacks = createCallbacks(callbacks, registry, [...path, "callbacks"]);
162
179
  if (maybeCallbacks) operationObject.callbacks = maybeCallbacks;
163
180
  return operationObject;
164
181
  };
165
- const createPaths = (paths, registry$1, path) => {
182
+ const createPaths = (paths, registry, path) => {
166
183
  if (!paths) return;
167
184
  const pathsObject = {};
168
185
  for (const [singlePath, pathItemObject] of Object.entries(paths)) {
@@ -170,11 +187,10 @@ const createPaths = (paths, registry$1, path) => {
170
187
  pathsObject[singlePath] = pathItemObject;
171
188
  continue;
172
189
  }
173
- pathsObject[singlePath] = registry$1.addPathItem(pathItemObject, [...path, singlePath]);
190
+ pathsObject[singlePath] = registry.addPathItem(pathItemObject, [...path, singlePath]);
174
191
  }
175
192
  return pathsObject;
176
193
  };
177
-
178
194
  //#endregion
179
195
  //#region src/openapi.ts
180
196
  const openApiVersions = [
@@ -183,10 +199,10 @@ const openApiVersions = [
183
199
  "3.0.2",
184
200
  "3.0.3",
185
201
  "3.1.0",
186
- "3.1.1"
202
+ "3.1.1",
203
+ "3.2.0"
187
204
  ];
188
205
  const satisfiesVersion = (test, against) => openApiVersions.indexOf(test) >= openApiVersions.indexOf(against);
189
-
190
206
  //#endregion
191
207
  //#region src/create/schema/override.ts
192
208
  const override = (ctx) => {
@@ -279,7 +295,6 @@ const validate = (ctx, opts, previousContext) => {
279
295
  }
280
296
  throw new Error(`Zod schema of type \`${def.type}\` at ${ctx.path.join(" > ")} cannot be represented in OpenAPI. Please assign it metadata with \`.meta()\``);
281
297
  };
282
-
283
298
  //#endregion
284
299
  //#region src/create/schema/rename.ts
285
300
  const renameComponents = (components, outputIds, ctx, refPath) => {
@@ -309,22 +324,21 @@ const renameComponents = (components, outputIds, ctx, refPath) => {
309
324
  }
310
325
  return componentsToRename;
311
326
  };
312
- const isDependencyPure = (componentDependencies, stringifiedComponents, registry$1, key, visited = /* @__PURE__ */ new Set()) => {
327
+ const isDependencyPure = (componentDependencies, stringifiedComponents, registry, key, visited = /* @__PURE__ */ new Set()) => {
313
328
  if (visited.has(key)) return true;
314
329
  const dependencies = componentDependencies.get(key);
315
330
  if (dependencies.pure !== void 0) return dependencies.pure;
316
331
  const stringified = stringifiedComponents.get(key);
317
- const component = registry$1.components.schemas.ids.get(key);
332
+ const component = registry.components.schemas.ids.get(key);
318
333
  if (component && stringified !== JSON.stringify(component)) {
319
334
  dependencies.pure = false;
320
335
  return false;
321
336
  }
322
337
  visited.add(key);
323
- const result = [...dependencies.dependencies].every((dep) => isDependencyPure(componentDependencies, stringifiedComponents, registry$1, dep, new Set(visited)));
338
+ const result = [...dependencies.dependencies].every((dep) => isDependencyPure(componentDependencies, stringifiedComponents, registry, dep, new Set(visited)));
324
339
  dependencies.pure = result;
325
340
  return result;
326
341
  };
327
-
328
342
  //#endregion
329
343
  //#region src/create/schema/schema.ts
330
344
  const createSchema = (schema, ctx = {}) => {
@@ -467,11 +481,10 @@ const createSchemas = (schemas, ctx) => {
467
481
  manual: renamedJsonSchema.schemas
468
482
  };
469
483
  };
470
-
471
484
  //#endregion
472
485
  //#region src/create/components.ts
473
486
  const createRegistry = (components) => {
474
- const registry$1 = {
487
+ const registry = {
475
488
  components: {
476
489
  schemas: {
477
490
  dynamicSchemaCount: 0,
@@ -519,7 +532,7 @@ const createRegistry = (components) => {
519
532
  },
520
533
  addSchema: (schema, path, opts) => {
521
534
  const schemaObject = {};
522
- registry$1.components.schemas[opts.io].set(path.join(" > "), {
535
+ registry.components.schemas[opts.io].set(path.join(" > "), {
523
536
  schemaObject,
524
537
  zodType: schema,
525
538
  source: {
@@ -530,14 +543,14 @@ const createRegistry = (components) => {
530
543
  return schemaObject;
531
544
  },
532
545
  addParameter: (parameter, path, opts) => {
533
- const seenParameter = registry$1.components.parameters.seen.get(parameter);
546
+ const seenParameter = registry.components.parameters.seen.get(parameter);
534
547
  if (seenParameter) return seenParameter;
535
548
  const meta = zod_v4_core.globalRegistry.get(parameter);
536
549
  const name = opts?.location?.name ?? meta?.param?.name;
537
550
  const inLocation = opts?.location?.in ?? meta?.param?.in;
538
551
  if (opts?.location?.name && meta?.param?.name || opts?.location?.in && meta?.param?.in) throw new Error(`Parameter at ${path.join(" > ")} has both \`.meta({ param: { name, in } })\` and \`.meta({ param: { location: { in, name } } })\` information`);
539
552
  if (!name || !inLocation) throw new Error(`Parameter at ${path.join(" > ")} is missing \`.meta({ param: { name, in } })\` information`);
540
- const schemaObject = registry$1.addSchema(parameter, [
553
+ const schemaObject = registry.addSchema(parameter, [
541
554
  ...path,
542
555
  inLocation,
543
556
  name,
@@ -559,7 +572,7 @@ const createRegistry = (components) => {
559
572
  schema: schemaObject,
560
573
  ...rest
561
574
  };
562
- const examplesObject = createExamples(examples, registry$1, [
575
+ const examplesObject = createExamples(examples, registry, [
563
576
  ...path,
564
577
  inLocation,
565
578
  name,
@@ -570,19 +583,19 @@ const createRegistry = (components) => {
570
583
  if (!parameterObject.description && meta?.description) parameterObject.description = meta.description;
571
584
  const id = metaId ?? opts?.manualId;
572
585
  if (id) {
573
- if (registry$1.components.parameters.ids.has(id)) throw new Error(`Schema "${id}" at ${path.join(" > ")} is already registered`);
586
+ if (registry.components.parameters.ids.has(id)) throw new Error(`Schema "${id}" at ${path.join(" > ")} is already registered`);
574
587
  const ref = { $ref: `#/components/parameters/${id}` };
575
- registry$1.components.parameters.seen.set(parameter, ref);
576
- registry$1.components.parameters.ids.set(id, parameterObject);
588
+ registry.components.parameters.seen.set(parameter, ref);
589
+ registry.components.parameters.ids.set(id, parameterObject);
577
590
  if (opts?.manualId) return parameterObject;
578
591
  return ref;
579
592
  }
580
593
  if (opts?.location?.name || opts?.location?.in) return parameterObject;
581
- registry$1.components.parameters.seen.set(parameter, parameterObject);
594
+ registry.components.parameters.seen.set(parameter, parameterObject);
582
595
  return parameterObject;
583
596
  },
584
597
  addHeader: (header, path, opts) => {
585
- const seenHeader = registry$1.components.headers.seen.get(header);
598
+ const seenHeader = registry.components.headers.seen.get(header);
586
599
  if (seenHeader) return seenHeader;
587
600
  const meta = zod_v4_core.globalRegistry.get(header);
588
601
  const { id: metaId, ...rest } = meta?.header ?? {};
@@ -590,46 +603,46 @@ const createRegistry = (components) => {
590
603
  const headerObject = rest;
591
604
  if (isRequired(header, "output")) headerObject.required = true;
592
605
  if (!headerObject.description && meta?.description) headerObject.description = meta.description;
593
- headerObject.schema = registry$1.addSchema(header, [...path, "schema"], {
606
+ headerObject.schema = registry.addSchema(header, [...path, "schema"], {
594
607
  io: "output",
595
608
  source: { type: "header" }
596
609
  });
597
610
  if (id) {
598
- if (registry$1.components.schemas.ids.has(id)) throw new Error(`Schema "${id}" at ${path.join(" > ")} is already registered`);
611
+ if (registry.components.schemas.ids.has(id)) throw new Error(`Schema "${id}" at ${path.join(" > ")} is already registered`);
599
612
  const ref = { $ref: `#/components/headers/${id}` };
600
- registry$1.components.headers.ids.set(id, headerObject);
601
- registry$1.components.headers.seen.set(header, ref);
613
+ registry.components.headers.ids.set(id, headerObject);
614
+ registry.components.headers.seen.set(header, ref);
602
615
  if (opts?.manualId) return headerObject;
603
616
  return ref;
604
617
  }
605
- registry$1.components.headers.seen.set(header, headerObject);
618
+ registry.components.headers.seen.set(header, headerObject);
606
619
  return headerObject;
607
620
  },
608
621
  addRequestBody: (requestBody, path, opts) => {
609
- const seenRequestBody = registry$1.components.requestBodies.seen.get(requestBody);
622
+ const seenRequestBody = registry.components.requestBodies.seen.get(requestBody);
610
623
  if (seenRequestBody) return seenRequestBody;
611
624
  const { content, id: metaId, ...rest } = requestBody;
612
625
  const requestBodyObject = {
613
626
  ...rest,
614
627
  content: createContent(content, {
615
- registry: registry$1,
628
+ registry,
616
629
  io: "input"
617
630
  }, [...path, "content"])
618
631
  };
619
632
  const id = metaId ?? opts?.manualId;
620
633
  if (id) {
621
- if (registry$1.components.requestBodies.ids.has(id)) throw new Error(`RequestBody "${id}" at ${path.join(" > ")} is already registered`);
634
+ if (registry.components.requestBodies.ids.has(id)) throw new Error(`RequestBody "${id}" at ${path.join(" > ")} is already registered`);
622
635
  const ref = { $ref: `#/components/requestBodies/${id}` };
623
- registry$1.components.requestBodies.ids.set(id, requestBodyObject);
624
- registry$1.components.requestBodies.seen.set(requestBody, ref);
636
+ registry.components.requestBodies.ids.set(id, requestBodyObject);
637
+ registry.components.requestBodies.seen.set(requestBody, ref);
625
638
  if (opts?.manualId) return requestBodyObject;
626
639
  return ref;
627
640
  }
628
- registry$1.components.requestBodies.seen.set(requestBody, requestBodyObject);
641
+ registry.components.requestBodies.seen.set(requestBody, requestBodyObject);
629
642
  return requestBodyObject;
630
643
  },
631
644
  addPathItem: (pathItem, path, opts) => {
632
- const seenPathItem = registry$1.components.pathItems.seen.get(pathItem);
645
+ const seenPathItem = registry.components.pathItems.seen.get(pathItem);
633
646
  if (seenPathItem) return seenPathItem;
634
647
  const pathItemObject = {};
635
648
  const { id: metaId, ...rest } = pathItem;
@@ -639,53 +652,63 @@ const createRegistry = (components) => {
639
652
  pathItemObject[key] = value;
640
653
  continue;
641
654
  }
642
- if (key === "get" || key === "put" || key === "post" || key === "delete" || key === "options" || key === "head" || key === "patch" || key === "trace") {
643
- pathItemObject[key] = createOperation(value, registry$1, [...path, key]);
655
+ if (key === "get" || key === "put" || key === "post" || key === "delete" || key === "options" || key === "head" || key === "patch" || key === "trace" || key === "query") {
656
+ pathItemObject[key] = createOperation(value, registry, [...path, key]);
644
657
  continue;
645
658
  }
646
659
  if (key === "parameters") {
647
- pathItemObject[key] = createManualParameters(value, registry$1, [...path, key]);
660
+ pathItemObject[key] = createManualParameters(value, registry, [...path, key]);
661
+ continue;
662
+ }
663
+ if (key === "additionalOperations") {
664
+ const additionalOperations = {};
665
+ for (const [method, operation] of Object.entries(value)) additionalOperations[method] = createOperation(operation, registry, [
666
+ ...path,
667
+ key,
668
+ method
669
+ ]);
670
+ pathItemObject.additionalOperations = additionalOperations;
648
671
  continue;
649
672
  }
650
673
  pathItemObject[key] = value;
651
674
  }
652
675
  if (id) {
653
- if (registry$1.components.pathItems.ids.has(id)) throw new Error(`PathItem "${id}" at ${path.join(" > ")} is already registered`);
676
+ if (registry.components.pathItems.ids.has(id)) throw new Error(`PathItem "${id}" at ${path.join(" > ")} is already registered`);
654
677
  const ref = { $ref: `#/components/pathItems/${id}` };
655
- registry$1.components.pathItems.ids.set(id, pathItemObject);
656
- registry$1.components.pathItems.seen.set(pathItem, ref);
678
+ registry.components.pathItems.ids.set(id, pathItemObject);
679
+ registry.components.pathItems.seen.set(pathItem, ref);
657
680
  if (opts?.manualId) return pathItemObject;
658
681
  return ref;
659
682
  }
660
- registry$1.components.pathItems.seen.set(pathItem, pathItemObject);
683
+ registry.components.pathItems.seen.set(pathItem, pathItemObject);
661
684
  return pathItemObject;
662
685
  },
663
686
  addResponse: (response, path, opts) => {
664
- const seenResponse = registry$1.components.responses.seen.get(response);
687
+ const seenResponse = registry.components.responses.seen.get(response);
665
688
  if (seenResponse) return seenResponse;
666
689
  const { content, headers, links, id: metaId, ...rest } = response;
667
690
  const responseObject = rest;
668
- const maybeHeaders = createHeaders(headers, registry$1, [...path, "headers"]);
691
+ const maybeHeaders = createHeaders(headers, registry, [...path, "headers"]);
669
692
  if (maybeHeaders) responseObject.headers = maybeHeaders;
670
693
  if (content) responseObject.content = createContent(content, {
671
- registry: registry$1,
694
+ registry,
672
695
  io: "output"
673
696
  }, [...path, "content"]);
674
- if (links) responseObject.links = createLinks(links, registry$1, [...path, "links"]);
697
+ if (links) responseObject.links = createLinks(links, registry, [...path, "links"]);
675
698
  const id = metaId ?? opts?.manualId;
676
699
  if (id) {
677
- if (registry$1.components.responses.ids.has(id)) throw new Error(`Response "${id}" at ${path.join(" > ")} is already registered`);
700
+ if (registry.components.responses.ids.has(id)) throw new Error(`Response "${id}" at ${path.join(" > ")} is already registered`);
678
701
  const ref = { $ref: `#/components/responses/${id}` };
679
- registry$1.components.responses.ids.set(id, responseObject);
680
- registry$1.components.responses.seen.set(response, ref);
702
+ registry.components.responses.ids.set(id, responseObject);
703
+ registry.components.responses.seen.set(response, ref);
681
704
  if (opts?.manualId) return responseObject;
682
705
  return ref;
683
706
  }
684
- registry$1.components.responses.seen.set(response, responseObject);
707
+ registry.components.responses.seen.set(response, responseObject);
685
708
  return responseObject;
686
709
  },
687
710
  addCallback: (callback, path, opts) => {
688
- const seenCallback = registry$1.components.callbacks.seen.get(callback);
711
+ const seenCallback = registry.components.callbacks.seen.get(callback);
689
712
  if (seenCallback) return seenCallback;
690
713
  const { id: metaId, ...rest } = callback;
691
714
  const callbackObject = {};
@@ -694,100 +717,100 @@ const createRegistry = (components) => {
694
717
  callbackObject[name] = pathItem;
695
718
  continue;
696
719
  }
697
- callbackObject[name] = registry$1.addPathItem(pathItem, [...path, name]);
720
+ callbackObject[name] = registry.addPathItem(pathItem, [...path, name]);
698
721
  }
699
722
  const id = metaId ?? opts?.manualId;
700
723
  if (id) {
701
- if (registry$1.components.callbacks.ids.has(id)) throw new Error(`Callback "${id}" at ${path.join(" > ")} is already registered`);
724
+ if (registry.components.callbacks.ids.has(id)) throw new Error(`Callback "${id}" at ${path.join(" > ")} is already registered`);
702
725
  const ref = { $ref: `#/components/callbacks/${id}` };
703
- registry$1.components.callbacks.ids.set(id, callbackObject);
704
- registry$1.components.callbacks.seen.set(callback, ref);
726
+ registry.components.callbacks.ids.set(id, callbackObject);
727
+ registry.components.callbacks.seen.set(callback, ref);
705
728
  if (opts?.manualId) return callbackObject;
706
729
  return ref;
707
730
  }
708
- registry$1.components.callbacks.seen.set(callback, callbackObject);
731
+ registry.components.callbacks.seen.set(callback, callbackObject);
709
732
  return callbackObject;
710
733
  },
711
734
  addSecurityScheme: (securityScheme, path, opts) => {
712
- const seenSecurityScheme = registry$1.components.securitySchemes.seen.get(securityScheme);
735
+ const seenSecurityScheme = registry.components.securitySchemes.seen.get(securityScheme);
713
736
  if (seenSecurityScheme) return seenSecurityScheme;
714
737
  const { id: metaId, ...rest } = securityScheme;
715
738
  const securitySchemeObject = rest;
716
739
  const id = metaId ?? opts?.manualId;
717
740
  if (id) {
718
- if (registry$1.components.securitySchemes.ids.has(id)) throw new Error(`SecurityScheme "${id}" at ${path.join(" > ")} is already registered`);
741
+ if (registry.components.securitySchemes.ids.has(id)) throw new Error(`SecurityScheme "${id}" at ${path.join(" > ")} is already registered`);
719
742
  const ref = { $ref: `#/components/securitySchemes/${id}` };
720
- registry$1.components.securitySchemes.ids.set(id, securitySchemeObject);
721
- registry$1.components.securitySchemes.seen.set(securityScheme, ref);
743
+ registry.components.securitySchemes.ids.set(id, securitySchemeObject);
744
+ registry.components.securitySchemes.seen.set(securityScheme, ref);
722
745
  if (opts?.manualId) return securitySchemeObject;
723
746
  return ref;
724
747
  }
725
- registry$1.components.securitySchemes.seen.set(securityScheme, securitySchemeObject);
748
+ registry.components.securitySchemes.seen.set(securityScheme, securitySchemeObject);
726
749
  return securitySchemeObject;
727
750
  },
728
751
  addLink: (link, path, opts) => {
729
- const seenLink = registry$1.components.links.seen.get(link);
752
+ const seenLink = registry.components.links.seen.get(link);
730
753
  if (seenLink) return seenLink;
731
754
  const { id: metaId, ...rest } = link;
732
755
  const linkObject = rest;
733
756
  const id = metaId ?? opts?.manualId;
734
757
  if (id) {
735
- if (registry$1.components.links.ids.has(id)) throw new Error(`Link "${id}" at ${path.join(" > ")} is already registered`);
758
+ if (registry.components.links.ids.has(id)) throw new Error(`Link "${id}" at ${path.join(" > ")} is already registered`);
736
759
  const ref = { $ref: `#/components/links/${id}` };
737
- registry$1.components.links.ids.set(id, linkObject);
738
- registry$1.components.links.seen.set(link, ref);
760
+ registry.components.links.ids.set(id, linkObject);
761
+ registry.components.links.seen.set(link, ref);
739
762
  if (opts?.manualId) return linkObject;
740
763
  return ref;
741
764
  }
742
- registry$1.components.links.seen.set(link, linkObject);
765
+ registry.components.links.seen.set(link, linkObject);
743
766
  return linkObject;
744
767
  },
745
768
  addExample: (example, path, opts) => {
746
- const seenExample = registry$1.components.examples.seen.get(example);
769
+ const seenExample = registry.components.examples.seen.get(example);
747
770
  if (seenExample) return seenExample;
748
771
  const { id: metaId, ...rest } = example;
749
772
  const exampleObject = rest;
750
773
  const id = metaId ?? opts?.manualId;
751
774
  if (id) {
752
- if (registry$1.components.examples.ids.has(id)) throw new Error(`Example "${id}" at ${path.join(" > ")} is already registered`);
775
+ if (registry.components.examples.ids.has(id)) throw new Error(`Example "${id}" at ${path.join(" > ")} is already registered`);
753
776
  const ref = { $ref: `#/components/examples/${id}` };
754
- registry$1.components.examples.ids.set(id, exampleObject);
755
- registry$1.components.examples.seen.set(example, ref);
777
+ registry.components.examples.ids.set(id, exampleObject);
778
+ registry.components.examples.seen.set(example, ref);
756
779
  if (opts?.manualId) return exampleObject;
757
780
  return ref;
758
781
  }
759
- registry$1.components.examples.seen.set(example, exampleObject);
782
+ registry.components.examples.seen.set(example, exampleObject);
760
783
  return exampleObject;
761
784
  }
762
785
  };
763
- registerSchemas(components?.schemas, registry$1);
764
- registerParameters(components?.parameters, registry$1);
765
- registerHeaders(components?.headers, registry$1);
766
- registerResponses(components?.responses, registry$1);
767
- registerPathItems(components?.pathItems, registry$1);
768
- registerRequestBodies(components?.requestBodies, registry$1);
769
- registerCallbacks(components?.callbacks, registry$1);
770
- registerSecuritySchemes(components?.securitySchemes, registry$1);
771
- registerLinks(components?.links, registry$1);
772
- registerExamples(components?.examples, registry$1);
773
- return registry$1;
774
- };
775
- const registerSchemas = (schemas, registry$1) => {
786
+ registerSchemas(components?.schemas, registry);
787
+ registerParameters(components?.parameters, registry);
788
+ registerHeaders(components?.headers, registry);
789
+ registerResponses(components?.responses, registry);
790
+ registerPathItems(components?.pathItems, registry);
791
+ registerRequestBodies(components?.requestBodies, registry);
792
+ registerCallbacks(components?.callbacks, registry);
793
+ registerSecuritySchemes(components?.securitySchemes, registry);
794
+ registerLinks(components?.links, registry);
795
+ registerExamples(components?.examples, registry);
796
+ return registry;
797
+ };
798
+ const registerSchemas = (schemas, registry) => {
776
799
  if (!schemas) return;
777
800
  for (const [key, schema] of Object.entries(schemas)) {
778
801
  if (isAnyZodType(schema)) {
779
802
  const id = zod_v4_core.globalRegistry.get(schema)?.id ?? key;
780
- registry$1.components.schemas.manual.set(id, {
803
+ registry.components.schemas.manual.set(id, {
781
804
  input: { schemaObject: {} },
782
805
  output: { schemaObject: {} },
783
806
  zodType: schema
784
807
  });
785
808
  continue;
786
809
  }
787
- registry$1.components.schemas.ids.set(key, schema);
810
+ registry.components.schemas.ids.set(key, schema);
788
811
  }
789
812
  };
790
- const registerParameters = (parameters, registry$1) => {
813
+ const registerParameters = (parameters, registry) => {
791
814
  if (!parameters) return;
792
815
  for (const [key, schema] of Object.entries(parameters)) {
793
816
  if (isAnyZodType(schema)) {
@@ -796,13 +819,13 @@ const registerParameters = (parameters, registry$1) => {
796
819
  "parameters",
797
820
  key
798
821
  ];
799
- registry$1.addParameter(schema, path, { manualId: key });
822
+ registry.addParameter(schema, path, { manualId: key });
800
823
  continue;
801
824
  }
802
- registry$1.components.parameters.ids.set(key, schema);
825
+ registry.components.parameters.ids.set(key, schema);
803
826
  }
804
827
  };
805
- const registerHeaders = (headers, registry$1) => {
828
+ const registerHeaders = (headers, registry) => {
806
829
  if (!headers) return;
807
830
  for (const [key, schema] of Object.entries(headers)) {
808
831
  if (isAnyZodType(schema)) {
@@ -811,73 +834,73 @@ const registerHeaders = (headers, registry$1) => {
811
834
  "headers",
812
835
  key
813
836
  ];
814
- registry$1.addHeader(schema, path, { manualId: key });
837
+ registry.addHeader(schema, path, { manualId: key });
815
838
  continue;
816
839
  }
817
- registry$1.components.headers.ids.set(key, schema);
840
+ registry.components.headers.ids.set(key, schema);
818
841
  }
819
842
  };
820
- const registerResponses = (responses, registry$1) => {
843
+ const registerResponses = (responses, registry) => {
821
844
  if (!responses) return;
822
845
  for (const [key, schema] of Object.entries(responses)) {
823
- const responseObject = registry$1.addResponse(schema, [
846
+ const responseObject = registry.addResponse(schema, [
824
847
  "components",
825
848
  "responses",
826
849
  key
827
850
  ], { manualId: key });
828
- registry$1.components.responses.ids.set(key, responseObject);
829
- registry$1.components.responses.seen.set(schema, responseObject);
851
+ registry.components.responses.ids.set(key, responseObject);
852
+ registry.components.responses.seen.set(schema, responseObject);
830
853
  }
831
854
  };
832
- const registerRequestBodies = (requestBodies, registry$1) => {
855
+ const registerRequestBodies = (requestBodies, registry) => {
833
856
  if (!requestBodies) return;
834
857
  for (const [key, schema] of Object.entries(requestBodies)) {
835
858
  if (isAnyZodType(schema)) {
836
- registry$1.addRequestBody(schema, [
859
+ registry.addRequestBody(schema, [
837
860
  "components",
838
861
  "requestBodies",
839
862
  key
840
863
  ], { manualId: key });
841
864
  continue;
842
865
  }
843
- registry$1.components.requestBodies.ids.set(key, schema);
866
+ registry.components.requestBodies.ids.set(key, schema);
844
867
  }
845
868
  };
846
- const registerCallbacks = (callbacks, registry$1) => {
869
+ const registerCallbacks = (callbacks, registry) => {
847
870
  if (!callbacks) return;
848
- for (const [key, schema] of Object.entries(callbacks)) registry$1.addCallback(schema, [
871
+ for (const [key, schema] of Object.entries(callbacks)) registry.addCallback(schema, [
849
872
  "components",
850
873
  "callbacks",
851
874
  key
852
875
  ], { manualId: key });
853
876
  };
854
- const registerPathItems = (pathItems, registry$1) => {
877
+ const registerPathItems = (pathItems, registry) => {
855
878
  if (!pathItems) return;
856
- for (const [key, schema] of Object.entries(pathItems)) registry$1.addPathItem(schema, [
879
+ for (const [key, schema] of Object.entries(pathItems)) registry.addPathItem(schema, [
857
880
  "components",
858
881
  "pathItems",
859
882
  key
860
883
  ], { manualId: key });
861
884
  };
862
- const registerSecuritySchemes = (securitySchemes, registry$1) => {
885
+ const registerSecuritySchemes = (securitySchemes, registry) => {
863
886
  if (!securitySchemes) return;
864
- for (const [key, schema] of Object.entries(securitySchemes)) registry$1.addSecurityScheme(schema, [
887
+ for (const [key, schema] of Object.entries(securitySchemes)) registry.addSecurityScheme(schema, [
865
888
  "components",
866
889
  "securitySchemes",
867
890
  key
868
891
  ], { manualId: key });
869
892
  };
870
- const registerLinks = (links, registry$1) => {
893
+ const registerLinks = (links, registry) => {
871
894
  if (!links) return;
872
- for (const [key, schema] of Object.entries(links)) registry$1.addLink(schema, [
895
+ for (const [key, schema] of Object.entries(links)) registry.addLink(schema, [
873
896
  "components",
874
897
  "links",
875
898
  key
876
899
  ], { manualId: key });
877
900
  };
878
- const registerExamples = (examples, registry$1) => {
901
+ const registerExamples = (examples, registry) => {
879
902
  if (!examples) return;
880
- for (const [key, schema] of Object.entries(examples)) registry$1.components.examples.ids.set(key, schema);
903
+ for (const [key, schema] of Object.entries(examples)) registry.components.examples.ids.set(key, schema);
881
904
  };
882
905
  const createIOSchemas = (ctx) => {
883
906
  const { schemas, components, manual } = createSchemas(Object.fromEntries(ctx.registry.components.schemas[ctx.io]), ctx);
@@ -893,74 +916,73 @@ const createIOSchemas = (ctx) => {
893
916
  Object.assign(manualSchema[ctx.io].schemaObject, value);
894
917
  }
895
918
  };
896
- const createManualSchemas = (registry$1) => {
897
- for (const [key, value] of registry$1.components.schemas.manual) if (!value.input.used) {
919
+ const createManualSchemas = (registry) => {
920
+ for (const [key, value] of registry.components.schemas.manual) if (!value.input.used) {
898
921
  const schema = value[zod_v4_core.globalRegistry.get(value.zodType)?.unusedIO ?? "output"].schemaObject;
899
- registry$1.components.schemas.ids.set(key, schema);
922
+ registry.components.schemas.ids.set(key, schema);
900
923
  }
901
924
  };
902
- const createComponents = (registry$1, opts, openapiVersion) => {
925
+ const createComponents = (registry, opts, openapiVersion) => {
903
926
  createIOSchemas({
904
- registry: registry$1,
927
+ registry,
905
928
  io: "input",
906
929
  opts,
907
930
  openapiVersion
908
931
  });
909
932
  createIOSchemas({
910
- registry: registry$1,
933
+ registry,
911
934
  io: "output",
912
935
  opts,
913
936
  openapiVersion
914
937
  });
915
- createManualSchemas(registry$1);
938
+ createManualSchemas(registry);
916
939
  const components = {};
917
- if (registry$1.components.schemas.ids.size > 0) components.schemas = Object.fromEntries(registry$1.components.schemas.ids);
918
- if (registry$1.components.headers.ids.size > 0) components.headers = Object.fromEntries(registry$1.components.headers.ids);
919
- if (registry$1.components.requestBodies.ids.size > 0) components.requestBodies = Object.fromEntries(registry$1.components.requestBodies.ids);
920
- if (registry$1.components.responses.ids.size > 0) components.responses = Object.fromEntries(registry$1.components.responses.ids);
921
- if (registry$1.components.parameters.ids.size > 0) components.parameters = Object.fromEntries(registry$1.components.parameters.ids);
922
- if (registry$1.components.callbacks.ids.size > 0) components.callbacks = Object.fromEntries(registry$1.components.callbacks.ids);
923
- if (registry$1.components.pathItems.ids.size > 0) components.pathItems = Object.fromEntries(registry$1.components.pathItems.ids);
924
- if (registry$1.components.securitySchemes.ids.size > 0) components.securitySchemes = Object.fromEntries(registry$1.components.securitySchemes.ids);
925
- if (registry$1.components.links.ids.size > 0) components.links = Object.fromEntries(registry$1.components.links.ids);
926
- if (registry$1.components.examples.ids.size > 0) components.examples = Object.fromEntries(registry$1.components.examples.ids);
940
+ if (registry.components.schemas.ids.size > 0) components.schemas = Object.fromEntries(registry.components.schemas.ids);
941
+ if (registry.components.headers.ids.size > 0) components.headers = Object.fromEntries(registry.components.headers.ids);
942
+ if (registry.components.requestBodies.ids.size > 0) components.requestBodies = Object.fromEntries(registry.components.requestBodies.ids);
943
+ if (registry.components.responses.ids.size > 0) components.responses = Object.fromEntries(registry.components.responses.ids);
944
+ if (registry.components.parameters.ids.size > 0) components.parameters = Object.fromEntries(registry.components.parameters.ids);
945
+ if (registry.components.callbacks.ids.size > 0) components.callbacks = Object.fromEntries(registry.components.callbacks.ids);
946
+ if (registry.components.pathItems.ids.size > 0) components.pathItems = Object.fromEntries(registry.components.pathItems.ids);
947
+ if (registry.components.securitySchemes.ids.size > 0) components.securitySchemes = Object.fromEntries(registry.components.securitySchemes.ids);
948
+ if (registry.components.links.ids.size > 0) components.links = Object.fromEntries(registry.components.links.ids);
949
+ if (registry.components.examples.ids.size > 0) components.examples = Object.fromEntries(registry.components.examples.ids);
927
950
  return components;
928
951
  };
929
-
930
952
  //#endregion
931
- Object.defineProperty(exports, 'createComponents', {
932
- enumerable: true,
933
- get: function () {
934
- return createComponents;
935
- }
953
+ Object.defineProperty(exports, "createComponents", {
954
+ enumerable: true,
955
+ get: function() {
956
+ return createComponents;
957
+ }
936
958
  });
937
- Object.defineProperty(exports, 'createPaths', {
938
- enumerable: true,
939
- get: function () {
940
- return createPaths;
941
- }
959
+ Object.defineProperty(exports, "createPaths", {
960
+ enumerable: true,
961
+ get: function() {
962
+ return createPaths;
963
+ }
964
+ });
965
+ Object.defineProperty(exports, "createRegistry", {
966
+ enumerable: true,
967
+ get: function() {
968
+ return createRegistry;
969
+ }
942
970
  });
943
- Object.defineProperty(exports, 'createRegistry', {
944
- enumerable: true,
945
- get: function () {
946
- return createRegistry;
947
- }
971
+ Object.defineProperty(exports, "createSchema", {
972
+ enumerable: true,
973
+ get: function() {
974
+ return createSchema;
975
+ }
948
976
  });
949
- Object.defineProperty(exports, 'createSchema', {
950
- enumerable: true,
951
- get: function () {
952
- return createSchema;
953
- }
977
+ Object.defineProperty(exports, "isAnyZodType", {
978
+ enumerable: true,
979
+ get: function() {
980
+ return isAnyZodType;
981
+ }
954
982
  });
955
- Object.defineProperty(exports, 'isAnyZodType', {
956
- enumerable: true,
957
- get: function () {
958
- return isAnyZodType;
959
- }
983
+ Object.defineProperty(exports, "unwrapZodObject", {
984
+ enumerable: true,
985
+ get: function() {
986
+ return unwrapZodObject;
987
+ }
960
988
  });
961
- Object.defineProperty(exports, 'unwrapZodObject', {
962
- enumerable: true,
963
- get: function () {
964
- return unwrapZodObject;
965
- }
966
- });