zod-openapi 5.0.0-beta.10 → 5.0.0-beta.12

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/dist/api.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { ComponentRegistry, Override, createComponents, createRegistry } from "./components-DLZ-sf1V.mjs";
1
+ import { ComponentRegistry, Override, createComponents, createRegistry } from "./components-VJHAKH5Q.mjs";
2
2
  import { $ZodObject, $ZodType, $ZodTypes } from "zod/v4/core";
3
3
  import { core } from "zod/v4";
4
4
 
package/dist/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ComponentRegistry, Override, createComponents, createRegistry } from "./components-CtvxFnRF.js";
1
+ import { ComponentRegistry, Override, createComponents, createRegistry } from "./components-Ci95nsUp.js";
2
2
  import { $ZodObject, $ZodType, $ZodTypes } from "zod/v4/core";
3
3
  import { core } from "zod/v4";
4
4
 
package/dist/api.js CHANGED
@@ -1,4 +1,4 @@
1
- const require_components = require('./components-Cp63fKGN.js');
1
+ const require_components = require('./components-DPGXI3C3.js');
2
2
 
3
3
  exports.createComponents = require_components.createComponents;
4
4
  exports.createRegistry = require_components.createRegistry;
package/dist/api.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { createComponents, createRegistry, isAnyZodType, unwrapZodObject } from "./components-DKJ1Dtzd.mjs";
1
+ import { createComponents, createRegistry, isAnyZodType, unwrapZodObject } from "./components-GWr6bv6y.mjs";
2
2
 
3
3
  export { createComponents, createRegistry, isAnyZodType, unwrapZodObject };
@@ -473,6 +473,10 @@ interface CreateDocumentOptions {
473
473
  * - `"ref"` — Default. Cycles will be broken using $defs
474
474
  * - `"throw"` — Cycles will throw an error if encountered */
475
475
  cycles?: 'ref' | 'throw';
476
+ /**
477
+ * The $ref path to use for a schema component. Defaults to `#/components/schemas/`
478
+ */
479
+ schemaRefPath?: string;
476
480
  }
477
481
  declare const createDocument: (zodOpenApiObject: ZodOpenApiObject, opts?: CreateDocumentOptions) => OpenAPIObject;
478
482
  //#endregion
@@ -484,10 +488,12 @@ interface ComponentRegistry {
484
488
  input: Map<string, {
485
489
  zodType: $ZodType;
486
490
  schemaObject: SchemaObject | ReferenceObject;
491
+ path: string[];
487
492
  }>;
488
493
  output: Map<string, {
489
494
  zodType: $ZodType;
490
495
  schemaObject: SchemaObject | ReferenceObject;
496
+ path: string[];
491
497
  }>;
492
498
  ids: Map<string, SchemaObject | ReferenceObject>;
493
499
  manual: Map<string, {
@@ -259,14 +259,15 @@ const validate = (ctx, opts) => {
259
259
 
260
260
  //#endregion
261
261
  //#region src/create/schema/rename.ts
262
- const renameComponents = (components, outputIds, ctx) => {
262
+ const renameComponents = (components, outputIds, ctx, refPath) => {
263
263
  const componentsToRename = /* @__PURE__ */ new Map();
264
264
  if (ctx.io === "input") return componentsToRename;
265
265
  const componentDependencies = /* @__PURE__ */ new Map();
266
266
  const stringifiedComponents = /* @__PURE__ */ new Map();
267
267
  for (const [key, value] of Object.entries(components)) {
268
268
  const stringified = JSON.stringify(value);
269
- const matches = stringified.matchAll(/"#\/components\/schemas\/([^"]+)"/g);
269
+ const regex = new RegExp(`"${refPath}([^"]+)"`, "g");
270
+ const matches = stringified.matchAll(regex);
270
271
  const dependencies = /* @__PURE__ */ new Set();
271
272
  for (const match of matches) {
272
273
  const dep = match[1];
@@ -334,6 +335,7 @@ const createSchema = (schema, ctx = {
334
335
  };
335
336
  };
336
337
  const createSchemas = (schemas, ctx) => {
338
+ const refPath = ctx.opts.schemaRefPath ?? "#/components/schemas/";
337
339
  const entries = {};
338
340
  for (const [name, { zodType }] of Object.entries(schemas)) entries[name] = zodType;
339
341
  const zodRegistry = (0, zod_v4.registry)();
@@ -375,7 +377,7 @@ const createSchemas = (schemas, ctx) => {
375
377
  const dynamicComponents = /* @__PURE__ */ new Map();
376
378
  for (const [key, value] of Object.entries(components)) if (/^schema\d+$/.test(key)) {
377
379
  const newName = `__schema${ctx.registry.components.schemas.dynamicSchemaCount++}`;
378
- dynamicComponents.set(key, `"#/components/schemas/${newName}"`);
380
+ dynamicComponents.set(key, `"${refPath}${newName}"`);
379
381
  if (newName !== key) {
380
382
  components[newName] = value;
381
383
  delete components[key];
@@ -387,7 +389,7 @@ const createSchemas = (schemas, ctx) => {
387
389
  if (dynamic) return dynamic;
388
390
  const manualComponent = ctx.registry.components.schemas.manual.get(match);
389
391
  if (manualComponent) manualUsed[match] = true;
390
- return `"#/components/schemas/${match}"`;
392
+ return `"${refPath}${match}"`;
391
393
  }));
392
394
  const parsedComponents = parsedJsonSchema.schemas.__shared?.$defs ?? {};
393
395
  parsedJsonSchema.schemas.__shared ??= { $defs: parsedComponents };
@@ -403,7 +405,7 @@ const createSchemas = (schemas, ctx) => {
403
405
  parsedComponents[key] = manualComponent;
404
406
  }
405
407
  }
406
- const componentsToRename = renameComponents(parsedComponents, outputIds, ctx);
408
+ const componentsToRename = renameComponents(parsedComponents, outputIds, ctx, refPath);
407
409
  if (!componentsToRename.size) {
408
410
  const parsedSchemas = parsedJsonSchema.schemas.zodOpenApiCreateSchema?.properties;
409
411
  delete parsedJsonSchema.schemas.zodOpenApiCreateSchema;
@@ -414,10 +416,10 @@ const createSchemas = (schemas, ctx) => {
414
416
  manual: parsedJsonSchema.schemas
415
417
  };
416
418
  }
417
- const renamedJsonSchema = JSON.parse(JSON.stringify(parsedJsonSchema).replace(/"#\/components\/schemas\/([^"]+)"/g, (_, match) => {
419
+ const renamedJsonSchema = JSON.parse(JSON.stringify(parsedJsonSchema).replace(new RegExp(`"${refPath}([^"]+)"`, "g"), (_, match) => {
418
420
  const replacement = componentsToRename.get(match);
419
- if (replacement) return `"#/components/schemas/${replacement}"`;
420
- return `"#/components/schemas/${match}"`;
421
+ if (replacement) return `"${refPath}${replacement}"`;
422
+ return `"${refPath}${match}"`;
421
423
  }));
422
424
  const renamedSchemas = renamedJsonSchema.schemas.zodOpenApiCreateSchema?.properties;
423
425
  const renamedComponents = renamedJsonSchema.schemas.__shared?.$defs ?? {};
@@ -472,7 +474,8 @@ const createRegistry = (components) => {
472
474
  const schemaObject = {};
473
475
  registry$1.components.schemas[io].set(path.join(" > "), {
474
476
  schemaObject,
475
- zodType: schema
477
+ zodType: schema,
478
+ path
476
479
  });
477
480
  return schemaObject;
478
481
  },
@@ -236,14 +236,15 @@ const validate = (ctx, opts) => {
236
236
 
237
237
  //#endregion
238
238
  //#region src/create/schema/rename.ts
239
- const renameComponents = (components, outputIds, ctx) => {
239
+ const renameComponents = (components, outputIds, ctx, refPath) => {
240
240
  const componentsToRename = /* @__PURE__ */ new Map();
241
241
  if (ctx.io === "input") return componentsToRename;
242
242
  const componentDependencies = /* @__PURE__ */ new Map();
243
243
  const stringifiedComponents = /* @__PURE__ */ new Map();
244
244
  for (const [key, value] of Object.entries(components)) {
245
245
  const stringified = JSON.stringify(value);
246
- const matches = stringified.matchAll(/"#\/components\/schemas\/([^"]+)"/g);
246
+ const regex = new RegExp(`"${refPath}([^"]+)"`, "g");
247
+ const matches = stringified.matchAll(regex);
247
248
  const dependencies = /* @__PURE__ */ new Set();
248
249
  for (const match of matches) {
249
250
  const dep = match[1];
@@ -311,6 +312,7 @@ const createSchema = (schema, ctx = {
311
312
  };
312
313
  };
313
314
  const createSchemas = (schemas, ctx) => {
315
+ const refPath = ctx.opts.schemaRefPath ?? "#/components/schemas/";
314
316
  const entries = {};
315
317
  for (const [name, { zodType }] of Object.entries(schemas)) entries[name] = zodType;
316
318
  const zodRegistry = registry();
@@ -352,7 +354,7 @@ const createSchemas = (schemas, ctx) => {
352
354
  const dynamicComponents = /* @__PURE__ */ new Map();
353
355
  for (const [key, value] of Object.entries(components)) if (/^schema\d+$/.test(key)) {
354
356
  const newName = `__schema${ctx.registry.components.schemas.dynamicSchemaCount++}`;
355
- dynamicComponents.set(key, `"#/components/schemas/${newName}"`);
357
+ dynamicComponents.set(key, `"${refPath}${newName}"`);
356
358
  if (newName !== key) {
357
359
  components[newName] = value;
358
360
  delete components[key];
@@ -364,7 +366,7 @@ const createSchemas = (schemas, ctx) => {
364
366
  if (dynamic) return dynamic;
365
367
  const manualComponent = ctx.registry.components.schemas.manual.get(match);
366
368
  if (manualComponent) manualUsed[match] = true;
367
- return `"#/components/schemas/${match}"`;
369
+ return `"${refPath}${match}"`;
368
370
  }));
369
371
  const parsedComponents = parsedJsonSchema.schemas.__shared?.$defs ?? {};
370
372
  parsedJsonSchema.schemas.__shared ??= { $defs: parsedComponents };
@@ -380,7 +382,7 @@ const createSchemas = (schemas, ctx) => {
380
382
  parsedComponents[key] = manualComponent;
381
383
  }
382
384
  }
383
- const componentsToRename = renameComponents(parsedComponents, outputIds, ctx);
385
+ const componentsToRename = renameComponents(parsedComponents, outputIds, ctx, refPath);
384
386
  if (!componentsToRename.size) {
385
387
  const parsedSchemas = parsedJsonSchema.schemas.zodOpenApiCreateSchema?.properties;
386
388
  delete parsedJsonSchema.schemas.zodOpenApiCreateSchema;
@@ -391,10 +393,10 @@ const createSchemas = (schemas, ctx) => {
391
393
  manual: parsedJsonSchema.schemas
392
394
  };
393
395
  }
394
- const renamedJsonSchema = JSON.parse(JSON.stringify(parsedJsonSchema).replace(/"#\/components\/schemas\/([^"]+)"/g, (_, match) => {
396
+ const renamedJsonSchema = JSON.parse(JSON.stringify(parsedJsonSchema).replace(new RegExp(`"${refPath}([^"]+)"`, "g"), (_, match) => {
395
397
  const replacement = componentsToRename.get(match);
396
- if (replacement) return `"#/components/schemas/${replacement}"`;
397
- return `"#/components/schemas/${match}"`;
398
+ if (replacement) return `"${refPath}${replacement}"`;
399
+ return `"${refPath}${match}"`;
398
400
  }));
399
401
  const renamedSchemas = renamedJsonSchema.schemas.zodOpenApiCreateSchema?.properties;
400
402
  const renamedComponents = renamedJsonSchema.schemas.__shared?.$defs ?? {};
@@ -449,7 +451,8 @@ const createRegistry = (components) => {
449
451
  const schemaObject = {};
450
452
  registry$1.components.schemas[io].set(path.join(" > "), {
451
453
  schemaObject,
452
- zodType: schema
454
+ zodType: schema,
455
+ path
453
456
  });
454
457
  return schemaObject;
455
458
  },
@@ -473,6 +473,10 @@ interface CreateDocumentOptions {
473
473
  * - `"ref"` — Default. Cycles will be broken using $defs
474
474
  * - `"throw"` — Cycles will throw an error if encountered */
475
475
  cycles?: 'ref' | 'throw';
476
+ /**
477
+ * The $ref path to use for a schema component. Defaults to `#/components/schemas/`
478
+ */
479
+ schemaRefPath?: string;
476
480
  }
477
481
  declare const createDocument: (zodOpenApiObject: ZodOpenApiObject, opts?: CreateDocumentOptions) => OpenAPIObject;
478
482
  //#endregion
@@ -484,10 +488,12 @@ interface ComponentRegistry {
484
488
  input: Map<string, {
485
489
  zodType: $ZodType;
486
490
  schemaObject: SchemaObject | ReferenceObject;
491
+ path: string[];
487
492
  }>;
488
493
  output: Map<string, {
489
494
  zodType: $ZodType;
490
495
  schemaObject: SchemaObject | ReferenceObject;
496
+ path: string[];
491
497
  }>;
492
498
  ids: Map<string, SchemaObject | ReferenceObject>;
493
499
  manual: Map<string, {
package/dist/index.d.mts 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, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createDocument } from "./components-DLZ-sf1V.mjs";
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, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createDocument } from "./components-VJHAKH5Q.mjs";
2
2
  import { core } from "zod/v4";
3
3
 
4
4
  //#region rolldown:runtime
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, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createDocument } from "./components-CtvxFnRF.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, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createDocument } from "./components-Ci95nsUp.js";
2
2
  import { core } from "zod/v4";
3
3
 
4
4
  //#region rolldown:runtime
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const require_components = require('./components-Cp63fKGN.js');
1
+ const require_components = require('./components-DPGXI3C3.js');
2
2
 
3
3
  //#region src/create/document.ts
4
4
  const createDocument = (zodOpenApiObject, opts = {}) => {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { createComponents, createPaths, createRegistry, createSchema } from "./components-DKJ1Dtzd.mjs";
1
+ import { createComponents, createPaths, createRegistry, createSchema } from "./components-GWr6bv6y.mjs";
2
2
 
3
3
  //#region src/create/document.ts
4
4
  const createDocument = (zodOpenApiObject, opts = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-openapi",
3
- "version": "5.0.0-beta.10",
3
+ "version": "5.0.0-beta.12",
4
4
  "description": "Convert Zod Schemas to OpenAPI v3.x documentation",
5
5
  "keywords": [
6
6
  "typescript",