zod-openapi 5.4.5 → 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) => {
@@ -239,7 +255,12 @@ const override = (ctx) => {
239
255
  break;
240
256
  }
241
257
  };
242
- const validate = (ctx, opts) => {
258
+ const validate = (ctx, opts, previousContext) => {
259
+ if (previousContext.context && ctx.zodSchema._zod.parent !== previousContext.context.zodSchema) {
260
+ if (previousContext.context.zodSchema._zod.def.type === "pipe") throw new Error(`Zod transform found at ${previousContext.context.path.join(" > ")} are not supported in output schemas. Please use \`.overwrite()\` or wrap the schema in a \`.pipe()\` or assign it manual metadata with \`.meta()\``);
261
+ throw new Error(`Zod schema of type \`${previousContext.context.zodSchema._zod.def.type}\` at ${previousContext.context?.path.join(" > ")} cannot be represented in OpenAPI. Please assign it metadata with \`.meta()\``);
262
+ }
263
+ previousContext.context = void 0;
243
264
  if (Object.keys(ctx.jsonSchema).length) return;
244
265
  const def = ctx.zodSchema._zod.def;
245
266
  const allowEmptySchema = opts.allowEmptySchema?.[def.type];
@@ -249,12 +270,17 @@ const validate = (ctx, opts) => {
249
270
  validate({
250
271
  ...ctx,
251
272
  zodSchema: def.innerType
252
- }, opts);
273
+ }, opts, previousContext);
253
274
  return;
254
275
  case "any": return;
255
276
  case "unknown": return;
256
277
  case "pipe":
257
- if (ctx.io === "output") throw new Error(`Zod transform found at ${ctx.path.join(" > ")} are not supported in output schemas. Please use \`.overwrite()\` or wrap the schema in a \`.pipe()\` or assign it manual metadata with \`.meta()\``);
278
+ if (ctx.io === "output") {
279
+ if (!ctx.zodSchema._zod.parent) {
280
+ previousContext.context = ctx;
281
+ return;
282
+ }
283
+ }
258
284
  return;
259
285
  case "transform":
260
286
  if (ctx.io === "output") return;
@@ -262,10 +288,13 @@ const validate = (ctx, opts) => {
262
288
  case "literal":
263
289
  if (def.values.includes(void 0)) throw new Error(`Zod literal at ${ctx.path.join(" > ")} cannot include \`undefined\` as a value. Please use \`z.undefined()\` or \`.optional()\` instead.`);
264
290
  return;
291
+ case "custom": if (!ctx.zodSchema._zod.parent) {
292
+ previousContext.context = ctx;
293
+ return;
294
+ }
265
295
  }
266
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()\``);
267
297
  };
268
-
269
298
  //#endregion
270
299
  //#region src/create/schema/rename.ts
271
300
  const renameComponents = (components, outputIds, ctx, refPath) => {
@@ -295,22 +324,21 @@ const renameComponents = (components, outputIds, ctx, refPath) => {
295
324
  }
296
325
  return componentsToRename;
297
326
  };
298
- const isDependencyPure = (componentDependencies, stringifiedComponents, registry$1, key, visited = /* @__PURE__ */ new Set()) => {
327
+ const isDependencyPure = (componentDependencies, stringifiedComponents, registry, key, visited = /* @__PURE__ */ new Set()) => {
299
328
  if (visited.has(key)) return true;
300
329
  const dependencies = componentDependencies.get(key);
301
330
  if (dependencies.pure !== void 0) return dependencies.pure;
302
331
  const stringified = stringifiedComponents.get(key);
303
- const component = registry$1.components.schemas.ids.get(key);
332
+ const component = registry.components.schemas.ids.get(key);
304
333
  if (component && stringified !== JSON.stringify(component)) {
305
334
  dependencies.pure = false;
306
335
  return false;
307
336
  }
308
337
  visited.add(key);
309
- 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)));
310
339
  dependencies.pure = result;
311
340
  return result;
312
341
  };
313
-
314
342
  //#endregion
315
343
  //#region src/create/schema/schema.ts
316
344
  const createSchema = (schema, ctx = {}) => {
@@ -360,6 +388,7 @@ const createSchemas = (schemas, ctx) => {
360
388
  for (const [id, { zodType }] of ctx.registry.components.schemas.manual) zodRegistry.add(zodType, { id });
361
389
  const outputIds = /* @__PURE__ */ new Map();
362
390
  const defsName = satisfiesVersion(ctx.openapiVersion ?? "3.1.0", "3.1.0") ? "$defs" : "definitions";
391
+ const previousContext = {};
363
392
  const jsonSchema = (0, zod_v4.toJSONSchema)(zodRegistry, {
364
393
  override(context) {
365
394
  const meta = zod_v4.globalRegistry.get(context.zodSchema);
@@ -381,7 +410,7 @@ const createSchemas = (schemas, ctx) => {
381
410
  }
382
411
  deleteInvalidJsonSchemaFields(context.jsonSchema);
383
412
  deleteZodOpenApiMeta(context.jsonSchema);
384
- validate(enrichedContext, ctx.opts);
413
+ validate(enrichedContext, ctx.opts, previousContext);
385
414
  },
386
415
  io: ctx.io,
387
416
  unrepresentable: "any",
@@ -452,11 +481,10 @@ const createSchemas = (schemas, ctx) => {
452
481
  manual: renamedJsonSchema.schemas
453
482
  };
454
483
  };
455
-
456
484
  //#endregion
457
485
  //#region src/create/components.ts
458
486
  const createRegistry = (components) => {
459
- const registry$1 = {
487
+ const registry = {
460
488
  components: {
461
489
  schemas: {
462
490
  dynamicSchemaCount: 0,
@@ -504,7 +532,7 @@ const createRegistry = (components) => {
504
532
  },
505
533
  addSchema: (schema, path, opts) => {
506
534
  const schemaObject = {};
507
- registry$1.components.schemas[opts.io].set(path.join(" > "), {
535
+ registry.components.schemas[opts.io].set(path.join(" > "), {
508
536
  schemaObject,
509
537
  zodType: schema,
510
538
  source: {
@@ -515,14 +543,14 @@ const createRegistry = (components) => {
515
543
  return schemaObject;
516
544
  },
517
545
  addParameter: (parameter, path, opts) => {
518
- const seenParameter = registry$1.components.parameters.seen.get(parameter);
546
+ const seenParameter = registry.components.parameters.seen.get(parameter);
519
547
  if (seenParameter) return seenParameter;
520
548
  const meta = zod_v4_core.globalRegistry.get(parameter);
521
549
  const name = opts?.location?.name ?? meta?.param?.name;
522
550
  const inLocation = opts?.location?.in ?? meta?.param?.in;
523
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`);
524
552
  if (!name || !inLocation) throw new Error(`Parameter at ${path.join(" > ")} is missing \`.meta({ param: { name, in } })\` information`);
525
- const schemaObject = registry$1.addSchema(parameter, [
553
+ const schemaObject = registry.addSchema(parameter, [
526
554
  ...path,
527
555
  inLocation,
528
556
  name,
@@ -544,7 +572,7 @@ const createRegistry = (components) => {
544
572
  schema: schemaObject,
545
573
  ...rest
546
574
  };
547
- const examplesObject = createExamples(examples, registry$1, [
575
+ const examplesObject = createExamples(examples, registry, [
548
576
  ...path,
549
577
  inLocation,
550
578
  name,
@@ -555,19 +583,19 @@ const createRegistry = (components) => {
555
583
  if (!parameterObject.description && meta?.description) parameterObject.description = meta.description;
556
584
  const id = metaId ?? opts?.manualId;
557
585
  if (id) {
558
- 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`);
559
587
  const ref = { $ref: `#/components/parameters/${id}` };
560
- registry$1.components.parameters.seen.set(parameter, ref);
561
- registry$1.components.parameters.ids.set(id, parameterObject);
588
+ registry.components.parameters.seen.set(parameter, ref);
589
+ registry.components.parameters.ids.set(id, parameterObject);
562
590
  if (opts?.manualId) return parameterObject;
563
591
  return ref;
564
592
  }
565
593
  if (opts?.location?.name || opts?.location?.in) return parameterObject;
566
- registry$1.components.parameters.seen.set(parameter, parameterObject);
594
+ registry.components.parameters.seen.set(parameter, parameterObject);
567
595
  return parameterObject;
568
596
  },
569
597
  addHeader: (header, path, opts) => {
570
- const seenHeader = registry$1.components.headers.seen.get(header);
598
+ const seenHeader = registry.components.headers.seen.get(header);
571
599
  if (seenHeader) return seenHeader;
572
600
  const meta = zod_v4_core.globalRegistry.get(header);
573
601
  const { id: metaId, ...rest } = meta?.header ?? {};
@@ -575,46 +603,46 @@ const createRegistry = (components) => {
575
603
  const headerObject = rest;
576
604
  if (isRequired(header, "output")) headerObject.required = true;
577
605
  if (!headerObject.description && meta?.description) headerObject.description = meta.description;
578
- headerObject.schema = registry$1.addSchema(header, [...path, "schema"], {
606
+ headerObject.schema = registry.addSchema(header, [...path, "schema"], {
579
607
  io: "output",
580
608
  source: { type: "header" }
581
609
  });
582
610
  if (id) {
583
- 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`);
584
612
  const ref = { $ref: `#/components/headers/${id}` };
585
- registry$1.components.headers.ids.set(id, headerObject);
586
- registry$1.components.headers.seen.set(header, ref);
613
+ registry.components.headers.ids.set(id, headerObject);
614
+ registry.components.headers.seen.set(header, ref);
587
615
  if (opts?.manualId) return headerObject;
588
616
  return ref;
589
617
  }
590
- registry$1.components.headers.seen.set(header, headerObject);
618
+ registry.components.headers.seen.set(header, headerObject);
591
619
  return headerObject;
592
620
  },
593
621
  addRequestBody: (requestBody, path, opts) => {
594
- const seenRequestBody = registry$1.components.requestBodies.seen.get(requestBody);
622
+ const seenRequestBody = registry.components.requestBodies.seen.get(requestBody);
595
623
  if (seenRequestBody) return seenRequestBody;
596
624
  const { content, id: metaId, ...rest } = requestBody;
597
625
  const requestBodyObject = {
598
626
  ...rest,
599
627
  content: createContent(content, {
600
- registry: registry$1,
628
+ registry,
601
629
  io: "input"
602
630
  }, [...path, "content"])
603
631
  };
604
632
  const id = metaId ?? opts?.manualId;
605
633
  if (id) {
606
- 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`);
607
635
  const ref = { $ref: `#/components/requestBodies/${id}` };
608
- registry$1.components.requestBodies.ids.set(id, requestBodyObject);
609
- registry$1.components.requestBodies.seen.set(requestBody, ref);
636
+ registry.components.requestBodies.ids.set(id, requestBodyObject);
637
+ registry.components.requestBodies.seen.set(requestBody, ref);
610
638
  if (opts?.manualId) return requestBodyObject;
611
639
  return ref;
612
640
  }
613
- registry$1.components.requestBodies.seen.set(requestBody, requestBodyObject);
641
+ registry.components.requestBodies.seen.set(requestBody, requestBodyObject);
614
642
  return requestBodyObject;
615
643
  },
616
644
  addPathItem: (pathItem, path, opts) => {
617
- const seenPathItem = registry$1.components.pathItems.seen.get(pathItem);
645
+ const seenPathItem = registry.components.pathItems.seen.get(pathItem);
618
646
  if (seenPathItem) return seenPathItem;
619
647
  const pathItemObject = {};
620
648
  const { id: metaId, ...rest } = pathItem;
@@ -624,53 +652,63 @@ const createRegistry = (components) => {
624
652
  pathItemObject[key] = value;
625
653
  continue;
626
654
  }
627
- if (key === "get" || key === "put" || key === "post" || key === "delete" || key === "options" || key === "head" || key === "patch" || key === "trace") {
628
- 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]);
629
657
  continue;
630
658
  }
631
659
  if (key === "parameters") {
632
- 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;
633
671
  continue;
634
672
  }
635
673
  pathItemObject[key] = value;
636
674
  }
637
675
  if (id) {
638
- 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`);
639
677
  const ref = { $ref: `#/components/pathItems/${id}` };
640
- registry$1.components.pathItems.ids.set(id, pathItemObject);
641
- registry$1.components.pathItems.seen.set(pathItem, ref);
678
+ registry.components.pathItems.ids.set(id, pathItemObject);
679
+ registry.components.pathItems.seen.set(pathItem, ref);
642
680
  if (opts?.manualId) return pathItemObject;
643
681
  return ref;
644
682
  }
645
- registry$1.components.pathItems.seen.set(pathItem, pathItemObject);
683
+ registry.components.pathItems.seen.set(pathItem, pathItemObject);
646
684
  return pathItemObject;
647
685
  },
648
686
  addResponse: (response, path, opts) => {
649
- const seenResponse = registry$1.components.responses.seen.get(response);
687
+ const seenResponse = registry.components.responses.seen.get(response);
650
688
  if (seenResponse) return seenResponse;
651
689
  const { content, headers, links, id: metaId, ...rest } = response;
652
690
  const responseObject = rest;
653
- const maybeHeaders = createHeaders(headers, registry$1, [...path, "headers"]);
691
+ const maybeHeaders = createHeaders(headers, registry, [...path, "headers"]);
654
692
  if (maybeHeaders) responseObject.headers = maybeHeaders;
655
693
  if (content) responseObject.content = createContent(content, {
656
- registry: registry$1,
694
+ registry,
657
695
  io: "output"
658
696
  }, [...path, "content"]);
659
- if (links) responseObject.links = createLinks(links, registry$1, [...path, "links"]);
697
+ if (links) responseObject.links = createLinks(links, registry, [...path, "links"]);
660
698
  const id = metaId ?? opts?.manualId;
661
699
  if (id) {
662
- 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`);
663
701
  const ref = { $ref: `#/components/responses/${id}` };
664
- registry$1.components.responses.ids.set(id, responseObject);
665
- registry$1.components.responses.seen.set(response, ref);
702
+ registry.components.responses.ids.set(id, responseObject);
703
+ registry.components.responses.seen.set(response, ref);
666
704
  if (opts?.manualId) return responseObject;
667
705
  return ref;
668
706
  }
669
- registry$1.components.responses.seen.set(response, responseObject);
707
+ registry.components.responses.seen.set(response, responseObject);
670
708
  return responseObject;
671
709
  },
672
710
  addCallback: (callback, path, opts) => {
673
- const seenCallback = registry$1.components.callbacks.seen.get(callback);
711
+ const seenCallback = registry.components.callbacks.seen.get(callback);
674
712
  if (seenCallback) return seenCallback;
675
713
  const { id: metaId, ...rest } = callback;
676
714
  const callbackObject = {};
@@ -679,100 +717,100 @@ const createRegistry = (components) => {
679
717
  callbackObject[name] = pathItem;
680
718
  continue;
681
719
  }
682
- callbackObject[name] = registry$1.addPathItem(pathItem, [...path, name]);
720
+ callbackObject[name] = registry.addPathItem(pathItem, [...path, name]);
683
721
  }
684
722
  const id = metaId ?? opts?.manualId;
685
723
  if (id) {
686
- 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`);
687
725
  const ref = { $ref: `#/components/callbacks/${id}` };
688
- registry$1.components.callbacks.ids.set(id, callbackObject);
689
- registry$1.components.callbacks.seen.set(callback, ref);
726
+ registry.components.callbacks.ids.set(id, callbackObject);
727
+ registry.components.callbacks.seen.set(callback, ref);
690
728
  if (opts?.manualId) return callbackObject;
691
729
  return ref;
692
730
  }
693
- registry$1.components.callbacks.seen.set(callback, callbackObject);
731
+ registry.components.callbacks.seen.set(callback, callbackObject);
694
732
  return callbackObject;
695
733
  },
696
734
  addSecurityScheme: (securityScheme, path, opts) => {
697
- const seenSecurityScheme = registry$1.components.securitySchemes.seen.get(securityScheme);
735
+ const seenSecurityScheme = registry.components.securitySchemes.seen.get(securityScheme);
698
736
  if (seenSecurityScheme) return seenSecurityScheme;
699
737
  const { id: metaId, ...rest } = securityScheme;
700
738
  const securitySchemeObject = rest;
701
739
  const id = metaId ?? opts?.manualId;
702
740
  if (id) {
703
- 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`);
704
742
  const ref = { $ref: `#/components/securitySchemes/${id}` };
705
- registry$1.components.securitySchemes.ids.set(id, securitySchemeObject);
706
- registry$1.components.securitySchemes.seen.set(securityScheme, ref);
743
+ registry.components.securitySchemes.ids.set(id, securitySchemeObject);
744
+ registry.components.securitySchemes.seen.set(securityScheme, ref);
707
745
  if (opts?.manualId) return securitySchemeObject;
708
746
  return ref;
709
747
  }
710
- registry$1.components.securitySchemes.seen.set(securityScheme, securitySchemeObject);
748
+ registry.components.securitySchemes.seen.set(securityScheme, securitySchemeObject);
711
749
  return securitySchemeObject;
712
750
  },
713
751
  addLink: (link, path, opts) => {
714
- const seenLink = registry$1.components.links.seen.get(link);
752
+ const seenLink = registry.components.links.seen.get(link);
715
753
  if (seenLink) return seenLink;
716
754
  const { id: metaId, ...rest } = link;
717
755
  const linkObject = rest;
718
756
  const id = metaId ?? opts?.manualId;
719
757
  if (id) {
720
- 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`);
721
759
  const ref = { $ref: `#/components/links/${id}` };
722
- registry$1.components.links.ids.set(id, linkObject);
723
- registry$1.components.links.seen.set(link, ref);
760
+ registry.components.links.ids.set(id, linkObject);
761
+ registry.components.links.seen.set(link, ref);
724
762
  if (opts?.manualId) return linkObject;
725
763
  return ref;
726
764
  }
727
- registry$1.components.links.seen.set(link, linkObject);
765
+ registry.components.links.seen.set(link, linkObject);
728
766
  return linkObject;
729
767
  },
730
768
  addExample: (example, path, opts) => {
731
- const seenExample = registry$1.components.examples.seen.get(example);
769
+ const seenExample = registry.components.examples.seen.get(example);
732
770
  if (seenExample) return seenExample;
733
771
  const { id: metaId, ...rest } = example;
734
772
  const exampleObject = rest;
735
773
  const id = metaId ?? opts?.manualId;
736
774
  if (id) {
737
- 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`);
738
776
  const ref = { $ref: `#/components/examples/${id}` };
739
- registry$1.components.examples.ids.set(id, exampleObject);
740
- registry$1.components.examples.seen.set(example, ref);
777
+ registry.components.examples.ids.set(id, exampleObject);
778
+ registry.components.examples.seen.set(example, ref);
741
779
  if (opts?.manualId) return exampleObject;
742
780
  return ref;
743
781
  }
744
- registry$1.components.examples.seen.set(example, exampleObject);
782
+ registry.components.examples.seen.set(example, exampleObject);
745
783
  return exampleObject;
746
784
  }
747
785
  };
748
- registerSchemas(components?.schemas, registry$1);
749
- registerParameters(components?.parameters, registry$1);
750
- registerHeaders(components?.headers, registry$1);
751
- registerResponses(components?.responses, registry$1);
752
- registerPathItems(components?.pathItems, registry$1);
753
- registerRequestBodies(components?.requestBodies, registry$1);
754
- registerCallbacks(components?.callbacks, registry$1);
755
- registerSecuritySchemes(components?.securitySchemes, registry$1);
756
- registerLinks(components?.links, registry$1);
757
- registerExamples(components?.examples, registry$1);
758
- return registry$1;
759
- };
760
- 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) => {
761
799
  if (!schemas) return;
762
800
  for (const [key, schema] of Object.entries(schemas)) {
763
801
  if (isAnyZodType(schema)) {
764
802
  const id = zod_v4_core.globalRegistry.get(schema)?.id ?? key;
765
- registry$1.components.schemas.manual.set(id, {
803
+ registry.components.schemas.manual.set(id, {
766
804
  input: { schemaObject: {} },
767
805
  output: { schemaObject: {} },
768
806
  zodType: schema
769
807
  });
770
808
  continue;
771
809
  }
772
- registry$1.components.schemas.ids.set(key, schema);
810
+ registry.components.schemas.ids.set(key, schema);
773
811
  }
774
812
  };
775
- const registerParameters = (parameters, registry$1) => {
813
+ const registerParameters = (parameters, registry) => {
776
814
  if (!parameters) return;
777
815
  for (const [key, schema] of Object.entries(parameters)) {
778
816
  if (isAnyZodType(schema)) {
@@ -781,13 +819,13 @@ const registerParameters = (parameters, registry$1) => {
781
819
  "parameters",
782
820
  key
783
821
  ];
784
- registry$1.addParameter(schema, path, { manualId: key });
822
+ registry.addParameter(schema, path, { manualId: key });
785
823
  continue;
786
824
  }
787
- registry$1.components.parameters.ids.set(key, schema);
825
+ registry.components.parameters.ids.set(key, schema);
788
826
  }
789
827
  };
790
- const registerHeaders = (headers, registry$1) => {
828
+ const registerHeaders = (headers, registry) => {
791
829
  if (!headers) return;
792
830
  for (const [key, schema] of Object.entries(headers)) {
793
831
  if (isAnyZodType(schema)) {
@@ -796,73 +834,73 @@ const registerHeaders = (headers, registry$1) => {
796
834
  "headers",
797
835
  key
798
836
  ];
799
- registry$1.addHeader(schema, path, { manualId: key });
837
+ registry.addHeader(schema, path, { manualId: key });
800
838
  continue;
801
839
  }
802
- registry$1.components.headers.ids.set(key, schema);
840
+ registry.components.headers.ids.set(key, schema);
803
841
  }
804
842
  };
805
- const registerResponses = (responses, registry$1) => {
843
+ const registerResponses = (responses, registry) => {
806
844
  if (!responses) return;
807
845
  for (const [key, schema] of Object.entries(responses)) {
808
- const responseObject = registry$1.addResponse(schema, [
846
+ const responseObject = registry.addResponse(schema, [
809
847
  "components",
810
848
  "responses",
811
849
  key
812
850
  ], { manualId: key });
813
- registry$1.components.responses.ids.set(key, responseObject);
814
- registry$1.components.responses.seen.set(schema, responseObject);
851
+ registry.components.responses.ids.set(key, responseObject);
852
+ registry.components.responses.seen.set(schema, responseObject);
815
853
  }
816
854
  };
817
- const registerRequestBodies = (requestBodies, registry$1) => {
855
+ const registerRequestBodies = (requestBodies, registry) => {
818
856
  if (!requestBodies) return;
819
857
  for (const [key, schema] of Object.entries(requestBodies)) {
820
858
  if (isAnyZodType(schema)) {
821
- registry$1.addRequestBody(schema, [
859
+ registry.addRequestBody(schema, [
822
860
  "components",
823
861
  "requestBodies",
824
862
  key
825
863
  ], { manualId: key });
826
864
  continue;
827
865
  }
828
- registry$1.components.requestBodies.ids.set(key, schema);
866
+ registry.components.requestBodies.ids.set(key, schema);
829
867
  }
830
868
  };
831
- const registerCallbacks = (callbacks, registry$1) => {
869
+ const registerCallbacks = (callbacks, registry) => {
832
870
  if (!callbacks) return;
833
- for (const [key, schema] of Object.entries(callbacks)) registry$1.addCallback(schema, [
871
+ for (const [key, schema] of Object.entries(callbacks)) registry.addCallback(schema, [
834
872
  "components",
835
873
  "callbacks",
836
874
  key
837
875
  ], { manualId: key });
838
876
  };
839
- const registerPathItems = (pathItems, registry$1) => {
877
+ const registerPathItems = (pathItems, registry) => {
840
878
  if (!pathItems) return;
841
- for (const [key, schema] of Object.entries(pathItems)) registry$1.addPathItem(schema, [
879
+ for (const [key, schema] of Object.entries(pathItems)) registry.addPathItem(schema, [
842
880
  "components",
843
881
  "pathItems",
844
882
  key
845
883
  ], { manualId: key });
846
884
  };
847
- const registerSecuritySchemes = (securitySchemes, registry$1) => {
885
+ const registerSecuritySchemes = (securitySchemes, registry) => {
848
886
  if (!securitySchemes) return;
849
- for (const [key, schema] of Object.entries(securitySchemes)) registry$1.addSecurityScheme(schema, [
887
+ for (const [key, schema] of Object.entries(securitySchemes)) registry.addSecurityScheme(schema, [
850
888
  "components",
851
889
  "securitySchemes",
852
890
  key
853
891
  ], { manualId: key });
854
892
  };
855
- const registerLinks = (links, registry$1) => {
893
+ const registerLinks = (links, registry) => {
856
894
  if (!links) return;
857
- for (const [key, schema] of Object.entries(links)) registry$1.addLink(schema, [
895
+ for (const [key, schema] of Object.entries(links)) registry.addLink(schema, [
858
896
  "components",
859
897
  "links",
860
898
  key
861
899
  ], { manualId: key });
862
900
  };
863
- const registerExamples = (examples, registry$1) => {
901
+ const registerExamples = (examples, registry) => {
864
902
  if (!examples) return;
865
- 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);
866
904
  };
867
905
  const createIOSchemas = (ctx) => {
868
906
  const { schemas, components, manual } = createSchemas(Object.fromEntries(ctx.registry.components.schemas[ctx.io]), ctx);
@@ -878,74 +916,73 @@ const createIOSchemas = (ctx) => {
878
916
  Object.assign(manualSchema[ctx.io].schemaObject, value);
879
917
  }
880
918
  };
881
- const createManualSchemas = (registry$1) => {
882
- 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) {
883
921
  const schema = value[zod_v4_core.globalRegistry.get(value.zodType)?.unusedIO ?? "output"].schemaObject;
884
- registry$1.components.schemas.ids.set(key, schema);
922
+ registry.components.schemas.ids.set(key, schema);
885
923
  }
886
924
  };
887
- const createComponents = (registry$1, opts, openapiVersion) => {
925
+ const createComponents = (registry, opts, openapiVersion) => {
888
926
  createIOSchemas({
889
- registry: registry$1,
927
+ registry,
890
928
  io: "input",
891
929
  opts,
892
930
  openapiVersion
893
931
  });
894
932
  createIOSchemas({
895
- registry: registry$1,
933
+ registry,
896
934
  io: "output",
897
935
  opts,
898
936
  openapiVersion
899
937
  });
900
- createManualSchemas(registry$1);
938
+ createManualSchemas(registry);
901
939
  const components = {};
902
- if (registry$1.components.schemas.ids.size > 0) components.schemas = Object.fromEntries(registry$1.components.schemas.ids);
903
- if (registry$1.components.headers.ids.size > 0) components.headers = Object.fromEntries(registry$1.components.headers.ids);
904
- if (registry$1.components.requestBodies.ids.size > 0) components.requestBodies = Object.fromEntries(registry$1.components.requestBodies.ids);
905
- if (registry$1.components.responses.ids.size > 0) components.responses = Object.fromEntries(registry$1.components.responses.ids);
906
- if (registry$1.components.parameters.ids.size > 0) components.parameters = Object.fromEntries(registry$1.components.parameters.ids);
907
- if (registry$1.components.callbacks.ids.size > 0) components.callbacks = Object.fromEntries(registry$1.components.callbacks.ids);
908
- if (registry$1.components.pathItems.ids.size > 0) components.pathItems = Object.fromEntries(registry$1.components.pathItems.ids);
909
- if (registry$1.components.securitySchemes.ids.size > 0) components.securitySchemes = Object.fromEntries(registry$1.components.securitySchemes.ids);
910
- if (registry$1.components.links.ids.size > 0) components.links = Object.fromEntries(registry$1.components.links.ids);
911
- 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);
912
950
  return components;
913
951
  };
914
-
915
952
  //#endregion
916
- Object.defineProperty(exports, 'createComponents', {
917
- enumerable: true,
918
- get: function () {
919
- return createComponents;
920
- }
953
+ Object.defineProperty(exports, "createComponents", {
954
+ enumerable: true,
955
+ get: function() {
956
+ return createComponents;
957
+ }
921
958
  });
922
- Object.defineProperty(exports, 'createPaths', {
923
- enumerable: true,
924
- get: function () {
925
- return createPaths;
926
- }
959
+ Object.defineProperty(exports, "createPaths", {
960
+ enumerable: true,
961
+ get: function() {
962
+ return createPaths;
963
+ }
927
964
  });
928
- Object.defineProperty(exports, 'createRegistry', {
929
- enumerable: true,
930
- get: function () {
931
- return createRegistry;
932
- }
965
+ Object.defineProperty(exports, "createRegistry", {
966
+ enumerable: true,
967
+ get: function() {
968
+ return createRegistry;
969
+ }
933
970
  });
934
- Object.defineProperty(exports, 'createSchema', {
935
- enumerable: true,
936
- get: function () {
937
- return createSchema;
938
- }
971
+ Object.defineProperty(exports, "createSchema", {
972
+ enumerable: true,
973
+ get: function() {
974
+ return createSchema;
975
+ }
939
976
  });
940
- Object.defineProperty(exports, 'isAnyZodType', {
941
- enumerable: true,
942
- get: function () {
943
- return isAnyZodType;
944
- }
977
+ Object.defineProperty(exports, "isAnyZodType", {
978
+ enumerable: true,
979
+ get: function() {
980
+ return isAnyZodType;
981
+ }
982
+ });
983
+ Object.defineProperty(exports, "unwrapZodObject", {
984
+ enumerable: true,
985
+ get: function() {
986
+ return unwrapZodObject;
987
+ }
945
988
  });
946
- Object.defineProperty(exports, 'unwrapZodObject', {
947
- enumerable: true,
948
- get: function () {
949
- return unwrapZodObject;
950
- }
951
- });