zod-openapi 5.3.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <h1 align="center">zod-openapi</h1>
4
4
  </p>
5
5
  <p align="center">
6
- A TypeScript library which uses <a href="https://github.com/colinhacks/zod">Zod</a> schemas to generate OpenAPI v3.1x documentation.
6
+ A TypeScript library which uses <a href="https://github.com/colinhacks/zod">Zod</a> schemas to generate OpenAPI v3.x documentation.
7
7
  </p>
8
8
  <div align="center">
9
9
  <a href="https://www.npmjs.com/package/zod-openapi"><img src="https://img.shields.io/npm/v/zod-openapi"/></a>
@@ -31,7 +31,9 @@ pnpm install zod zod-openapi
31
31
 
32
32
  ### `.meta()`
33
33
 
34
- Use the `.meta()` method to add OpenAPI metadata to a Zod schema. It accepts an object with the following options:
34
+ Use Zod's native `.meta()` method to add OpenAPI metadata to your schemas. This library leverages Zod's built-in metadata functionality - no monkey patching or additional setup is required. Simply call `.meta()` on any Zod schema and it accepts an object with the following options:
35
+
36
+ > **Note:** To get full TypeScript support for the OpenAPI-specific properties in `.meta()`, you need to import `zod-openapi` somewhere in your project. This import provides TypeScript type definitions that extend Zod's `.meta()` interface at compile-time (no runtime changes), enabling your IDE and TypeScript compiler to recognize the additional properties (like `id`, `param`, `header`, etc.). In most cases this will be done where you call `createDocument` or other zod-openapi functions.
35
37
 
36
38
  | Option | Description |
37
39
  | ---------- | ---------------------------------------------------------------------------------------------------------------- |
@@ -42,7 +44,7 @@ Use the `.meta()` method to add OpenAPI metadata to a Zod schema. It accepts an
42
44
  | `outputId` | Allows you to set a different ID for the output schema. This is useful when the input and output schemas differ. |
43
45
  | `unusedIO` | Allows you to set the `io` for an unused schema added to the components section. Defaults to `output`. |
44
46
 
45
- You can also set standard OpenAPI properties directly in the `.meta()` method, such as:
47
+ You can also set standard OpenAPI properties directly in Zod's native `.meta()` method, such as:
46
48
 
47
49
  ```typescript
48
50
  z.string().meta({
@@ -51,7 +53,7 @@ z.string().meta({
51
53
  });
52
54
  ```
53
55
 
54
- You can set additional metadata to the rendered schema in a few different ways. Zod's `.meta()` method allows you to directly set OpenAPI directly to the schema. However, if you wanted to override any field that Zod generates, this may not work as expected. In this case, you can use the `override` option to customize the rendered OpenAPI schema.
56
+ You can set additional metadata to the rendered schema in a few different ways. Zod's native `.meta()` method allows you to directly set OpenAPI properties to the schema. However, if you wanted to override any field that Zod generates, this may not work as expected. In this case, you can use the `override` option to customize the rendered OpenAPI schema.
55
57
 
56
58
  eg.
57
59
 
@@ -74,7 +76,7 @@ Would render the following OpenAPI schema. Note that format is not overridden wi
74
76
  }
75
77
  ```
76
78
 
77
- In order to override fields which are generated by Zod or this library, you can use the `override` option in the `.meta()` method. This allows you to customize the rendered OpenAPI schema after we have both processed it.
79
+ In order to override fields which are generated by Zod or this library, you can use the `override` option in Zod's `.meta()` method. This allows you to customize the rendered OpenAPI schema after we have both processed it.
78
80
 
79
81
  ##### override object
80
82
 
package/dist/api.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_components = require('./components-Ccvxvize.cjs');
1
+ const require_components = require('./components-C8ab2kZS.cjs');
2
2
 
3
3
  exports.createComponents = require_components.createComponents;
4
4
  exports.createRegistry = require_components.createRegistry;
package/dist/api.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { ComponentRegistry, ZodOpenApiBaseMetadata, ZodOpenApiMetadata, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, createComponents, createRegistry } from "./components-Br5MCUeG.cjs";
1
+ import { ComponentRegistry, ZodOpenApiBaseMetadata, ZodOpenApiMetadata, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, createComponents, createRegistry } from "./components-JnL0iOr_.cjs";
2
2
  import * as core from "zod/v4/core";
3
3
  import { $ZodObject, $ZodType, $ZodTypes } from "zod/v4/core";
4
4
 
@@ -8,4 +8,4 @@ declare const unwrapZodObject: (zodType: $ZodTypes, io: "input" | "output", path
8
8
  //#region src/zod.d.ts
9
9
  declare const isAnyZodType: (schema: unknown) => schema is core.$ZodTypes;
10
10
  //#endregion
11
- export { ComponentRegistry, ZodOpenApiBaseMetadata, ZodOpenApiMetadata, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, createComponents, createRegistry, isAnyZodType, unwrapZodObject };
11
+ export { type ComponentRegistry, ZodOpenApiBaseMetadata, ZodOpenApiMetadata, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, createComponents, createRegistry, isAnyZodType, unwrapZodObject };
package/dist/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ComponentRegistry, ZodOpenApiBaseMetadata, ZodOpenApiMetadata, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, createComponents, createRegistry } from "./components-DkyUTLcs.js";
1
+ import { ComponentRegistry, ZodOpenApiBaseMetadata, ZodOpenApiMetadata, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, createComponents, createRegistry } from "./components-CXzxKPFp.js";
2
2
  import * as core from "zod/v4/core";
3
3
  import { $ZodObject, $ZodType, $ZodTypes } from "zod/v4/core";
4
4
 
@@ -8,4 +8,4 @@ declare const unwrapZodObject: (zodType: $ZodTypes, io: "input" | "output", path
8
8
  //#region src/zod.d.ts
9
9
  declare const isAnyZodType: (schema: unknown) => schema is core.$ZodTypes;
10
10
  //#endregion
11
- export { ComponentRegistry, ZodOpenApiBaseMetadata, ZodOpenApiMetadata, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, createComponents, createRegistry, isAnyZodType, unwrapZodObject };
11
+ export { type ComponentRegistry, ZodOpenApiBaseMetadata, ZodOpenApiMetadata, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, createComponents, createRegistry, isAnyZodType, unwrapZodObject };
package/dist/api.js CHANGED
@@ -1,3 +1,3 @@
1
- import { createComponents, createRegistry, isAnyZodType, unwrapZodObject } from "./components-BAO_3m-h.js";
1
+ import { createComponents, createRegistry, isAnyZodType, unwrapZodObject } from "./components-D0GND9iu.js";
2
2
 
3
3
  export { createComponents, createRegistry, isAnyZodType, unwrapZodObject };
@@ -67,10 +67,9 @@ const unwrapZodObject = (zodType, io, path) => {
67
67
  switch (def.type) {
68
68
  case "object": return zodType;
69
69
  case "lazy": return unwrapZodObject(def.getter(), io, path);
70
- case "pipe": {
70
+ case "pipe":
71
71
  if (io === "input") return unwrapZodObject(def.in, io, path);
72
72
  return unwrapZodObject(def.out, io, path);
73
- }
74
73
  }
75
74
  throw new Error(`Failed to unwrap ZodObject from type: ${zodType._zod.def.type} at ${path.join(" > ")}`);
76
75
  };
@@ -211,16 +210,27 @@ const createPaths = (paths, registry$1, path) => {
211
210
  return pathsObject;
212
211
  };
213
212
 
213
+ //#endregion
214
+ //#region src/openapi.ts
215
+ const openApiVersions = [
216
+ "3.0.0",
217
+ "3.0.1",
218
+ "3.0.2",
219
+ "3.0.3",
220
+ "3.1.0",
221
+ "3.1.1"
222
+ ];
223
+ const satisfiesVersion = (test, against) => openApiVersions.indexOf(test) >= openApiVersions.indexOf(against);
224
+
214
225
  //#endregion
215
226
  //#region src/create/schema/override.ts
216
227
  const override = (ctx) => {
217
228
  const def = ctx.zodSchema._zod.def;
218
229
  switch (def.type) {
219
- case "bigint": {
230
+ case "bigint":
220
231
  ctx.jsonSchema.type = "integer";
221
232
  ctx.jsonSchema.format = "int64";
222
233
  break;
223
- }
224
234
  case "union": {
225
235
  if ("discriminator" in def && typeof def.discriminator === "string") {
226
236
  ctx.jsonSchema.oneOf = ctx.jsonSchema.anyOf;
@@ -253,18 +263,15 @@ const override = (ctx) => {
253
263
  }
254
264
  break;
255
265
  }
256
- case "date": {
266
+ case "date":
257
267
  ctx.jsonSchema.type = "string";
258
268
  break;
259
- }
260
- case "literal": {
269
+ case "literal":
261
270
  if (def.values.includes(void 0)) break;
262
271
  break;
263
- }
264
- case "undefined": {
272
+ case "undefined":
265
273
  ctx.jsonSchema.not = {};
266
274
  break;
267
- }
268
275
  }
269
276
  };
270
277
  const validate = (ctx, opts) => {
@@ -273,27 +280,23 @@ const validate = (ctx, opts) => {
273
280
  const allowEmptySchema = opts.allowEmptySchema?.[def.type];
274
281
  if (allowEmptySchema === true || allowEmptySchema?.[ctx.io]) return;
275
282
  switch (def.type) {
276
- case "optional": {
283
+ case "optional":
277
284
  validate({
278
285
  ...ctx,
279
286
  zodSchema: def.innerType
280
287
  }, opts);
281
288
  return;
282
- }
283
289
  case "any": return;
284
290
  case "unknown": return;
285
- case "pipe": {
291
+ case "pipe":
286
292
  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()\``);
287
293
  return;
288
- }
289
- case "transform": {
294
+ case "transform":
290
295
  if (ctx.io === "output") return;
291
296
  break;
292
- }
293
- case "literal": {
297
+ case "literal":
294
298
  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.`);
295
299
  return;
296
- }
297
300
  }
298
301
  throw new Error(`Zod schema of type \`${def.type}\` at ${ctx.path.join(" > ")} cannot be represented in OpenAPI. Please assign it metadata with \`.meta()\``);
299
302
  };
@@ -364,7 +367,8 @@ const createSchema = (schema, ctx = {
364
367
  opts: {
365
368
  ...ctx.opts,
366
369
  schemaRefPath: ctx.schemaRefPath
367
- }
370
+ },
371
+ openapiVersion: ctx.openapiVersion
368
372
  });
369
373
  return {
370
374
  schema: jsonSchemas.schemas.zodOpenApiCreateSchema,
@@ -423,6 +427,7 @@ const createSchemas = (schemas, ctx) => {
423
427
  unrepresentable: "any",
424
428
  reused: ctx.opts.reused,
425
429
  cycles: ctx.opts.cycles,
430
+ target: satisfiesVersion(ctx.openapiVersion ?? "3.1.0", "3.1.0") ? void 0 : "openapi-3.0",
426
431
  uri: (id) => id === "__shared" ? `#ZOD_OPENAPI/${id}` : `#ZOD_OPENAPI/__shared#/$defs/${id}`
427
432
  });
428
433
  const components = jsonSchema.schemas.__shared?.$defs ?? {};
@@ -595,6 +600,7 @@ const createRegistry = (components) => {
595
600
  const ref = { $ref: `#/components/parameters/${id}` };
596
601
  registry$1.components.parameters.seen.set(parameter, ref);
597
602
  registry$1.components.parameters.ids.set(id, parameterObject);
603
+ if (opts?.manualId) return parameterObject;
598
604
  return ref;
599
605
  }
600
606
  if (opts?.location?.name || opts?.location?.in) return parameterObject;
@@ -619,6 +625,7 @@ const createRegistry = (components) => {
619
625
  const ref = { $ref: `#/components/headers/${id}` };
620
626
  registry$1.components.headers.ids.set(id, headerObject);
621
627
  registry$1.components.headers.seen.set(header, ref);
628
+ if (opts?.manualId) return headerObject;
622
629
  return ref;
623
630
  }
624
631
  registry$1.components.headers.seen.set(header, headerObject);
@@ -641,6 +648,7 @@ const createRegistry = (components) => {
641
648
  const ref = { $ref: `#/components/requestBodies/${id}` };
642
649
  registry$1.components.requestBodies.ids.set(id, requestBodyObject);
643
650
  registry$1.components.requestBodies.seen.set(requestBody, ref);
651
+ if (opts?.manualId) return requestBodyObject;
644
652
  return ref;
645
653
  }
646
654
  registry$1.components.requestBodies.seen.set(requestBody, requestBodyObject);
@@ -672,6 +680,7 @@ const createRegistry = (components) => {
672
680
  const ref = { $ref: `#/components/pathItems/${id}` };
673
681
  registry$1.components.pathItems.ids.set(id, pathItemObject);
674
682
  registry$1.components.pathItems.seen.set(pathItem, ref);
683
+ if (opts?.manualId) return pathItemObject;
675
684
  return ref;
676
685
  }
677
686
  registry$1.components.pathItems.seen.set(pathItem, pathItemObject);
@@ -695,6 +704,7 @@ const createRegistry = (components) => {
695
704
  const ref = { $ref: `#/components/responses/${id}` };
696
705
  registry$1.components.responses.ids.set(id, responseObject);
697
706
  registry$1.components.responses.seen.set(response, ref);
707
+ if (opts?.manualId) return responseObject;
698
708
  return ref;
699
709
  }
700
710
  registry$1.components.responses.seen.set(response, responseObject);
@@ -718,6 +728,7 @@ const createRegistry = (components) => {
718
728
  const ref = { $ref: `#/components/callbacks/${id}` };
719
729
  registry$1.components.callbacks.ids.set(id, callbackObject);
720
730
  registry$1.components.callbacks.seen.set(callback, ref);
731
+ if (opts?.manualId) return callbackObject;
721
732
  return ref;
722
733
  }
723
734
  registry$1.components.callbacks.seen.set(callback, callbackObject);
@@ -734,6 +745,7 @@ const createRegistry = (components) => {
734
745
  const ref = { $ref: `#/components/securitySchemes/${id}` };
735
746
  registry$1.components.securitySchemes.ids.set(id, securitySchemeObject);
736
747
  registry$1.components.securitySchemes.seen.set(securityScheme, ref);
748
+ if (opts?.manualId) return securitySchemeObject;
737
749
  return ref;
738
750
  }
739
751
  registry$1.components.securitySchemes.seen.set(securityScheme, securitySchemeObject);
@@ -750,6 +762,7 @@ const createRegistry = (components) => {
750
762
  const ref = { $ref: `#/components/links/${id}` };
751
763
  registry$1.components.links.ids.set(id, linkObject);
752
764
  registry$1.components.links.seen.set(link, ref);
765
+ if (opts?.manualId) return linkObject;
753
766
  return ref;
754
767
  }
755
768
  registry$1.components.links.seen.set(link, linkObject);
@@ -766,6 +779,7 @@ const createRegistry = (components) => {
766
779
  const ref = { $ref: `#/components/examples/${id}` };
767
780
  registry$1.components.examples.ids.set(id, exampleObject);
768
781
  registry$1.components.examples.seen.set(example, ref);
782
+ if (opts?.manualId) return exampleObject;
769
783
  return ref;
770
784
  }
771
785
  registry$1.components.examples.seen.set(example, exampleObject);
@@ -912,16 +926,18 @@ const createManualSchemas = (registry$1) => {
912
926
  registry$1.components.schemas.ids.set(key, schema);
913
927
  }
914
928
  };
915
- const createComponents = (registry$1, opts) => {
929
+ const createComponents = (registry$1, opts, openapiVersion) => {
916
930
  createIOSchemas({
917
931
  registry: registry$1,
918
932
  io: "input",
919
- opts
933
+ opts,
934
+ openapiVersion
920
935
  });
921
936
  createIOSchemas({
922
937
  registry: registry$1,
923
938
  io: "output",
924
- opts
939
+ opts,
940
+ openapiVersion
925
941
  });
926
942
  createManualSchemas(registry$1);
927
943
  const components = {};
@@ -1,7 +1,7 @@
1
1
  import { $ZodType, $ZodTypes, JSONSchemaMeta, toJSONSchema } from "zod/v4/core";
2
2
 
3
3
  //#region src/openapi.d.ts
4
- declare const openApiVersions: readonly ["3.1.0", "3.1.1"];
4
+ declare const openApiVersions: readonly ["3.0.0", "3.0.1", "3.0.2", "3.0.3", "3.1.0", "3.1.1"];
5
5
  type OpenApiVersion = (typeof openApiVersions)[number];
6
6
  //#endregion
7
7
  //#region packages/openapi3-ts/lib-types/dist/model/specification-extension.d.ts
@@ -630,6 +630,6 @@ interface ComponentRegistry {
630
630
  }) => ExampleObject | ReferenceObject;
631
631
  }
632
632
  declare const createRegistry: (components?: ZodOpenApiComponentsObject) => ComponentRegistry;
633
- declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions) => ComponentsObject;
633
+ declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions, openapiVersion?: OpenApiVersion) => ComponentsObject;
634
634
  //#endregion
635
- 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, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };
635
+ export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, type ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OpenApiVersion, OperationObject, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };
@@ -44,10 +44,9 @@ const unwrapZodObject = (zodType, io, path) => {
44
44
  switch (def.type) {
45
45
  case "object": return zodType;
46
46
  case "lazy": return unwrapZodObject(def.getter(), io, path);
47
- case "pipe": {
47
+ case "pipe":
48
48
  if (io === "input") return unwrapZodObject(def.in, io, path);
49
49
  return unwrapZodObject(def.out, io, path);
50
- }
51
50
  }
52
51
  throw new Error(`Failed to unwrap ZodObject from type: ${zodType._zod.def.type} at ${path.join(" > ")}`);
53
52
  };
@@ -188,16 +187,27 @@ const createPaths = (paths, registry$1, path) => {
188
187
  return pathsObject;
189
188
  };
190
189
 
190
+ //#endregion
191
+ //#region src/openapi.ts
192
+ const openApiVersions = [
193
+ "3.0.0",
194
+ "3.0.1",
195
+ "3.0.2",
196
+ "3.0.3",
197
+ "3.1.0",
198
+ "3.1.1"
199
+ ];
200
+ const satisfiesVersion = (test, against) => openApiVersions.indexOf(test) >= openApiVersions.indexOf(against);
201
+
191
202
  //#endregion
192
203
  //#region src/create/schema/override.ts
193
204
  const override = (ctx) => {
194
205
  const def = ctx.zodSchema._zod.def;
195
206
  switch (def.type) {
196
- case "bigint": {
207
+ case "bigint":
197
208
  ctx.jsonSchema.type = "integer";
198
209
  ctx.jsonSchema.format = "int64";
199
210
  break;
200
- }
201
211
  case "union": {
202
212
  if ("discriminator" in def && typeof def.discriminator === "string") {
203
213
  ctx.jsonSchema.oneOf = ctx.jsonSchema.anyOf;
@@ -230,18 +240,15 @@ const override = (ctx) => {
230
240
  }
231
241
  break;
232
242
  }
233
- case "date": {
243
+ case "date":
234
244
  ctx.jsonSchema.type = "string";
235
245
  break;
236
- }
237
- case "literal": {
246
+ case "literal":
238
247
  if (def.values.includes(void 0)) break;
239
248
  break;
240
- }
241
- case "undefined": {
249
+ case "undefined":
242
250
  ctx.jsonSchema.not = {};
243
251
  break;
244
- }
245
252
  }
246
253
  };
247
254
  const validate = (ctx, opts) => {
@@ -250,27 +257,23 @@ const validate = (ctx, opts) => {
250
257
  const allowEmptySchema = opts.allowEmptySchema?.[def.type];
251
258
  if (allowEmptySchema === true || allowEmptySchema?.[ctx.io]) return;
252
259
  switch (def.type) {
253
- case "optional": {
260
+ case "optional":
254
261
  validate({
255
262
  ...ctx,
256
263
  zodSchema: def.innerType
257
264
  }, opts);
258
265
  return;
259
- }
260
266
  case "any": return;
261
267
  case "unknown": return;
262
- case "pipe": {
268
+ case "pipe":
263
269
  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()\``);
264
270
  return;
265
- }
266
- case "transform": {
271
+ case "transform":
267
272
  if (ctx.io === "output") return;
268
273
  break;
269
- }
270
- case "literal": {
274
+ case "literal":
271
275
  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.`);
272
276
  return;
273
- }
274
277
  }
275
278
  throw new Error(`Zod schema of type \`${def.type}\` at ${ctx.path.join(" > ")} cannot be represented in OpenAPI. Please assign it metadata with \`.meta()\``);
276
279
  };
@@ -341,7 +344,8 @@ const createSchema = (schema, ctx = {
341
344
  opts: {
342
345
  ...ctx.opts,
343
346
  schemaRefPath: ctx.schemaRefPath
344
- }
347
+ },
348
+ openapiVersion: ctx.openapiVersion
345
349
  });
346
350
  return {
347
351
  schema: jsonSchemas.schemas.zodOpenApiCreateSchema,
@@ -400,6 +404,7 @@ const createSchemas = (schemas, ctx) => {
400
404
  unrepresentable: "any",
401
405
  reused: ctx.opts.reused,
402
406
  cycles: ctx.opts.cycles,
407
+ target: satisfiesVersion(ctx.openapiVersion ?? "3.1.0", "3.1.0") ? void 0 : "openapi-3.0",
403
408
  uri: (id) => id === "__shared" ? `#ZOD_OPENAPI/${id}` : `#ZOD_OPENAPI/__shared#/$defs/${id}`
404
409
  });
405
410
  const components = jsonSchema.schemas.__shared?.$defs ?? {};
@@ -572,6 +577,7 @@ const createRegistry = (components) => {
572
577
  const ref = { $ref: `#/components/parameters/${id}` };
573
578
  registry$1.components.parameters.seen.set(parameter, ref);
574
579
  registry$1.components.parameters.ids.set(id, parameterObject);
580
+ if (opts?.manualId) return parameterObject;
575
581
  return ref;
576
582
  }
577
583
  if (opts?.location?.name || opts?.location?.in) return parameterObject;
@@ -596,6 +602,7 @@ const createRegistry = (components) => {
596
602
  const ref = { $ref: `#/components/headers/${id}` };
597
603
  registry$1.components.headers.ids.set(id, headerObject);
598
604
  registry$1.components.headers.seen.set(header, ref);
605
+ if (opts?.manualId) return headerObject;
599
606
  return ref;
600
607
  }
601
608
  registry$1.components.headers.seen.set(header, headerObject);
@@ -618,6 +625,7 @@ const createRegistry = (components) => {
618
625
  const ref = { $ref: `#/components/requestBodies/${id}` };
619
626
  registry$1.components.requestBodies.ids.set(id, requestBodyObject);
620
627
  registry$1.components.requestBodies.seen.set(requestBody, ref);
628
+ if (opts?.manualId) return requestBodyObject;
621
629
  return ref;
622
630
  }
623
631
  registry$1.components.requestBodies.seen.set(requestBody, requestBodyObject);
@@ -649,6 +657,7 @@ const createRegistry = (components) => {
649
657
  const ref = { $ref: `#/components/pathItems/${id}` };
650
658
  registry$1.components.pathItems.ids.set(id, pathItemObject);
651
659
  registry$1.components.pathItems.seen.set(pathItem, ref);
660
+ if (opts?.manualId) return pathItemObject;
652
661
  return ref;
653
662
  }
654
663
  registry$1.components.pathItems.seen.set(pathItem, pathItemObject);
@@ -672,6 +681,7 @@ const createRegistry = (components) => {
672
681
  const ref = { $ref: `#/components/responses/${id}` };
673
682
  registry$1.components.responses.ids.set(id, responseObject);
674
683
  registry$1.components.responses.seen.set(response, ref);
684
+ if (opts?.manualId) return responseObject;
675
685
  return ref;
676
686
  }
677
687
  registry$1.components.responses.seen.set(response, responseObject);
@@ -695,6 +705,7 @@ const createRegistry = (components) => {
695
705
  const ref = { $ref: `#/components/callbacks/${id}` };
696
706
  registry$1.components.callbacks.ids.set(id, callbackObject);
697
707
  registry$1.components.callbacks.seen.set(callback, ref);
708
+ if (opts?.manualId) return callbackObject;
698
709
  return ref;
699
710
  }
700
711
  registry$1.components.callbacks.seen.set(callback, callbackObject);
@@ -711,6 +722,7 @@ const createRegistry = (components) => {
711
722
  const ref = { $ref: `#/components/securitySchemes/${id}` };
712
723
  registry$1.components.securitySchemes.ids.set(id, securitySchemeObject);
713
724
  registry$1.components.securitySchemes.seen.set(securityScheme, ref);
725
+ if (opts?.manualId) return securitySchemeObject;
714
726
  return ref;
715
727
  }
716
728
  registry$1.components.securitySchemes.seen.set(securityScheme, securitySchemeObject);
@@ -727,6 +739,7 @@ const createRegistry = (components) => {
727
739
  const ref = { $ref: `#/components/links/${id}` };
728
740
  registry$1.components.links.ids.set(id, linkObject);
729
741
  registry$1.components.links.seen.set(link, ref);
742
+ if (opts?.manualId) return linkObject;
730
743
  return ref;
731
744
  }
732
745
  registry$1.components.links.seen.set(link, linkObject);
@@ -743,6 +756,7 @@ const createRegistry = (components) => {
743
756
  const ref = { $ref: `#/components/examples/${id}` };
744
757
  registry$1.components.examples.ids.set(id, exampleObject);
745
758
  registry$1.components.examples.seen.set(example, ref);
759
+ if (opts?.manualId) return exampleObject;
746
760
  return ref;
747
761
  }
748
762
  registry$1.components.examples.seen.set(example, exampleObject);
@@ -889,16 +903,18 @@ const createManualSchemas = (registry$1) => {
889
903
  registry$1.components.schemas.ids.set(key, schema);
890
904
  }
891
905
  };
892
- const createComponents = (registry$1, opts) => {
906
+ const createComponents = (registry$1, opts, openapiVersion) => {
893
907
  createIOSchemas({
894
908
  registry: registry$1,
895
909
  io: "input",
896
- opts
910
+ opts,
911
+ openapiVersion
897
912
  });
898
913
  createIOSchemas({
899
914
  registry: registry$1,
900
915
  io: "output",
901
- opts
916
+ opts,
917
+ openapiVersion
902
918
  });
903
919
  createManualSchemas(registry$1);
904
920
  const components = {};
@@ -1,7 +1,7 @@
1
1
  import { $ZodType, $ZodTypes, JSONSchemaMeta, toJSONSchema } from "zod/v4/core";
2
2
 
3
3
  //#region src/openapi.d.ts
4
- declare const openApiVersions: readonly ["3.1.0", "3.1.1"];
4
+ declare const openApiVersions: readonly ["3.0.0", "3.0.1", "3.0.2", "3.0.3", "3.1.0", "3.1.1"];
5
5
  type OpenApiVersion = (typeof openApiVersions)[number];
6
6
  //#endregion
7
7
  //#region packages/openapi3-ts/lib-types/dist/model/specification-extension.d.ts
@@ -630,6 +630,6 @@ interface ComponentRegistry {
630
630
  }) => ExampleObject | ReferenceObject;
631
631
  }
632
632
  declare const createRegistry: (components?: ZodOpenApiComponentsObject) => ComponentRegistry;
633
- declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions) => ComponentsObject;
633
+ declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions, openapiVersion?: OpenApiVersion) => ComponentsObject;
634
634
  //#endregion
635
- 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, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };
635
+ export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, type ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OpenApiVersion, OperationObject, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_components = require('./components-Ccvxvize.cjs');
1
+ const require_components = require('./components-C8ab2kZS.cjs');
2
2
 
3
3
  //#region src/create/document.ts
4
4
  const createDocument = (zodOpenApiObject, opts = {}) => {
@@ -9,7 +9,7 @@ const createDocument = (zodOpenApiObject, opts = {}) => {
9
9
  if (createdPaths) document.paths = createdPaths;
10
10
  const createdWebhooks = require_components.createPaths(webhooks, registry, ["webhooks"]);
11
11
  if (createdWebhooks) document.webhooks = createdWebhooks;
12
- const createdComponents = require_components.createComponents(registry, opts);
12
+ const createdComponents = require_components.createComponents(registry, opts, zodOpenApiObject.openapi);
13
13
  if (Object.keys(createdComponents).length > 0) document.components = createdComponents;
14
14
  return document;
15
15
  };
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { 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, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument } from "./components-Br5MCUeG.cjs";
1
+ import { 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, OpenApiVersion, OperationObject, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument } from "./components-JnL0iOr_.cjs";
2
2
  import * as core from "zod/v4/core";
3
3
 
4
4
  //#region rolldown:runtime
@@ -23,9 +23,10 @@ declare const createSchema: (schema: core.$ZodType, ctx?: {
23
23
  * The $ref path to use for a schema component. Defaults to `#/components/schemas/`
24
24
  */
25
25
  schemaRefPath?: string;
26
+ openapiVersion?: OpenApiVersion;
26
27
  }) => {
27
28
  schema: SchemaObject | ReferenceObject;
28
29
  components: Record<string, SchemaObject>;
29
30
  };
30
31
  //#endregion
31
- export { CreateDocumentOptions, SchemaResult, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument, createSchema, oas31_d_exports as oas31 };
32
+ export { CreateDocumentOptions, type SchemaResult, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument, createSchema, oas31_d_exports as oas31 };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { 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, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument } from "./components-DkyUTLcs.js";
1
+ import { 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, OpenApiVersion, OperationObject, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument } from "./components-CXzxKPFp.js";
2
2
  import * as core from "zod/v4/core";
3
3
 
4
4
  //#region rolldown:runtime
@@ -23,9 +23,10 @@ declare const createSchema: (schema: core.$ZodType, ctx?: {
23
23
  * The $ref path to use for a schema component. Defaults to `#/components/schemas/`
24
24
  */
25
25
  schemaRefPath?: string;
26
+ openapiVersion?: OpenApiVersion;
26
27
  }) => {
27
28
  schema: SchemaObject | ReferenceObject;
28
29
  components: Record<string, SchemaObject>;
29
30
  };
30
31
  //#endregion
31
- export { CreateDocumentOptions, SchemaResult, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument, createSchema, oas31_d_exports as oas31 };
32
+ export { CreateDocumentOptions, type SchemaResult, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiOverride, ZodOpenApiOverrideContext, ZodOpenApiOverrideMeta, ZodOpenApiOverrideMetaContext, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createDocument, createSchema, oas31_d_exports as oas31 };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createComponents, createPaths, createRegistry, createSchema } from "./components-BAO_3m-h.js";
1
+ import { createComponents, createPaths, createRegistry, createSchema } from "./components-D0GND9iu.js";
2
2
 
3
3
  //#region src/create/document.ts
4
4
  const createDocument = (zodOpenApiObject, opts = {}) => {
@@ -9,7 +9,7 @@ const createDocument = (zodOpenApiObject, opts = {}) => {
9
9
  if (createdPaths) document.paths = createdPaths;
10
10
  const createdWebhooks = createPaths(webhooks, registry, ["webhooks"]);
11
11
  if (createdWebhooks) document.webhooks = createdWebhooks;
12
- const createdComponents = createComponents(registry, opts);
12
+ const createdComponents = createComponents(registry, opts, zodOpenApiObject.openapi);
13
13
  if (Object.keys(createdComponents).length > 0) document.components = createdComponents;
14
14
  return document;
15
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-openapi",
3
- "version": "5.3.0",
3
+ "version": "5.4.0",
4
4
  "description": "Convert Zod Schemas to OpenAPI v3.x documentation",
5
5
  "keywords": [
6
6
  "typescript",
@@ -44,19 +44,19 @@
44
44
  "devDependencies": {
45
45
  "@arethetypeswrong/cli": "0.18.2",
46
46
  "@changesets/changelog-github": "0.5.1",
47
- "@changesets/cli": "2.29.5",
48
- "@redocly/cli": "1.34.4",
47
+ "@changesets/cli": "2.29.6",
48
+ "@redocly/cli": "2.0.2",
49
49
  "@types/node": "22.15.21",
50
50
  "@vitest/coverage-v8": "3.2.4",
51
51
  "@zod-openapi/openapi3-ts": "1.0.0",
52
52
  "ajv": "8.17.1",
53
- "eslint-plugin-import-zod": "1.1.1",
53
+ "eslint-plugin-import-zod": "1.2.0",
54
54
  "eslint-plugin-zod-openapi": "2.0.0",
55
- "skuba": "12.0.2",
56
- "tsdown": "0.12.9",
55
+ "skuba": "12.1.1",
56
+ "tsdown": "0.14.0",
57
57
  "vitest": "3.2.4",
58
- "yaml": "2.8.0",
59
- "zod": "4.0.5"
58
+ "yaml": "2.8.1",
59
+ "zod": "4.1.1"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "zod": "^3.25.74 || ^4.0.0"
@@ -72,7 +72,7 @@
72
72
  "entryPoint": "src/index.ts",
73
73
  "template": "oss-npm-package",
74
74
  "type": "package",
75
- "version": "11.0.0"
75
+ "version": "12.1.1"
76
76
  },
77
77
  "scripts": {
78
78
  "build": "pnpm -r build && tsdown",