zod-openapi 5.0.0-beta.8 → 5.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,6 +1,5 @@
1
+ import * as core from "zod/v4/core";
1
2
  import { $ZodType, $ZodTypes } from "zod/v4/core";
2
- import { ZodType, ZodTypeDef } from "zod";
3
- import { core } from "zod/v4";
4
3
 
5
4
  //#region src/openapi3-ts/dist/model/specification-extension.d.ts
6
5
  type IExtensionName = `x-${string}`;
@@ -330,42 +329,47 @@ type Override = (ctx: {
330
329
  jsonSchema: core.JSONSchema.BaseSchema;
331
330
  io: 'input' | 'output';
332
331
  }) => void;
333
- declare module 'zod/v4' {
334
- interface GlobalMeta {
335
- /**
336
- * Used to set metadata for a parameter
337
- */
338
- param?: Partial<ParameterObject> & {
339
- /**
340
- * Used to output this Zod Schema in the components parameters section. Any usage of this Zod Schema will then be transformed into a $ref.
341
- */
342
- id?: string;
343
- };
344
- /**
345
- * Used to set metadata for a response header
346
- */
347
- header?: Partial<HeaderObject> & {
348
- /**
349
- * Used to output this Zod Schema in the components headers section. Any usage of this Zod Schema will then be transformed into a $ref.
350
- */
351
- id?: string;
352
- };
353
- /**
354
- * Use to override the rendered schema
355
- */
356
- override?: SchemaObject | Override;
332
+ interface ZodOpenApiBaseMetadata {
333
+ /**
334
+ * Used to set metadata for a parameter
335
+ */
336
+ param?: Partial<ParameterObject> & {
357
337
  /**
358
- * For use only if this Zod Schema is manually registered in the `components` section
359
- * and is not used anywhere else in the document.
360
- * Defaults to `output` if not specified.
338
+ * Used to output this Zod Schema in the components parameters section. Any usage of this Zod Schema will then be transformed into a $ref.
361
339
  */
362
- unusedIO?: 'input' | 'output';
340
+ id?: string;
341
+ };
342
+ /**
343
+ * Used to set metadata for a response header
344
+ */
345
+ header?: Partial<HeaderObject> & {
363
346
  /**
364
- * An alternate id to use for this schema in the event the schema is used in both input and output contexts.
365
- * If not specified, the id will be simply derived as the id of the schema plus an `Output` suffix. Please note that `id` must be set.
347
+ * Used to output this Zod Schema in the components headers section. Any usage of this Zod Schema will then be transformed into a $ref.
366
348
  */
367
- outputId?: string;
368
- }
349
+ id?: string;
350
+ };
351
+ /**
352
+ * Use to override the rendered schema
353
+ */
354
+ override?: SchemaObject | Override;
355
+ /**
356
+ * For use only if this Zod Schema is manually registered in the `components` section
357
+ * and is not used anywhere else in the document.
358
+ * Defaults to `output` if not specified.
359
+ */
360
+ unusedIO?: 'input' | 'output';
361
+ /**
362
+ * An alternate id to use for this schema in the event a registered schema is used in both a request and response schema.
363
+ * If not specified, the id will be simply derived as the id of the schema plus an `Output` suffix. Please note that `id` must be set.
364
+ */
365
+ outputId?: string;
366
+ }
367
+ interface ZodOpenApiMetadata extends ZodOpenApiBaseMetadata, core.JSONSchemaMeta {
368
+ examples?: unknown[];
369
+ example?: unknown;
370
+ }
371
+ declare module 'zod/v4' {
372
+ interface GlobalMeta extends ZodOpenApiMetadata {}
369
373
  }
370
374
  //#endregion
371
375
  //#region src/create/document.d.ts
@@ -382,9 +386,10 @@ interface ZodOpenApiRequestBodyObject extends Omit<RequestBodyObject, 'content'>
382
386
  id?: string;
383
387
  }
384
388
  type ZodOpenApiHeadersObject = ZodObjectInput | HeadersObject;
385
- interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers'> {
389
+ interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers' | 'links'> {
386
390
  content?: ZodOpenApiContentObject;
387
391
  headers?: ZodOpenApiHeadersObject;
392
+ links?: ZodOpenApiLinksObject;
388
393
  /** Use this field to auto register this response object as a component */
389
394
  id?: string;
390
395
  }
@@ -428,8 +433,23 @@ interface ZodOpenApiPathsObject extends ISpecificationExtension {
428
433
  type ZodOpenApiParameterObject = $ZodType | ParameterObject | ReferenceObject;
429
434
  type ZodOpenApiHeaderObject = $ZodType | HeaderObject | ReferenceObject;
430
435
  type ZodOpenApiSchemaObject = $ZodType | SchemaObject | ReferenceObject;
431
- type ZodOpenApiRequestBody = $ZodType | RequestBodyObject | ReferenceObject;
432
- interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' | 'responses' | 'requestBodies' | 'headers' | 'parameters' | 'pathItems' | 'callbacks'> {
436
+ interface ZodOpenApiSecuritySchemeObject extends SecuritySchemeObject {
437
+ /**
438
+ * Used to register this security scheme as a component.
439
+ */
440
+ id?: string;
441
+ }
442
+ interface ZodOpenApiLinkObject extends LinkObject {
443
+ /** Use this field to auto register this link object as a component */
444
+ id?: string;
445
+ }
446
+ type ZodOpenApiLinksObject = Record<string, ZodOpenApiLinkObject | ReferenceObject>;
447
+ interface ZodOpenApiExampleObject extends ExampleObject {
448
+ /** Use this field to auto register this example object as a component */
449
+ id?: string;
450
+ }
451
+ type ZodOpenApiExamplesObject = Record<string, ZodOpenApiExampleObject | ReferenceObject>;
452
+ interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' | 'responses' | 'requestBodies' | 'headers' | 'parameters' | 'pathItems' | 'callbacks' | 'securitySchemes' | 'examples'> {
433
453
  parameters?: Record<string, ZodOpenApiParameterObject>;
434
454
  schemas?: Record<string, ZodOpenApiSchemaObject>;
435
455
  requestBodies?: Record<string, ZodOpenApiRequestBodyObject>;
@@ -437,6 +457,9 @@ interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' |
437
457
  responses?: Record<string, ZodOpenApiResponseObject>;
438
458
  callbacks?: Record<string, ZodOpenApiCallbackObject>;
439
459
  pathItems?: Record<string, ZodOpenApiPathItemObject>;
460
+ securitySchemes?: Record<string, ZodOpenApiSecuritySchemeObject>;
461
+ links?: Record<string, ZodOpenApiLinkObject>;
462
+ examples?: Record<string, ZodOpenApiExampleObject>;
440
463
  }
441
464
  type ZodOpenApiVersion = OpenApiVersion;
442
465
  interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'webhooks' | 'components'> {
@@ -445,16 +468,15 @@ interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'we
445
468
  webhooks?: ZodOpenApiPathsObject;
446
469
  components?: ZodOpenApiComponentsObject;
447
470
  }
448
- type ZodObjectInputType<Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Record<string, unknown>> = ZodType<Output, Def, Input>;
449
471
  type ZodObjectInput = $ZodType<unknown, Record<string, unknown>>;
450
472
  type OverrideType = $ZodTypes['_zod']['def']['type'];
451
473
  interface CreateDocumentOptions {
452
474
  /**
453
475
  * Use this to allowlist empty schemas to be created for given types
454
- * - `true` — Allow empty schemas for input and output
455
- * - `{ input: true, output: true }` — Allow empty schemas for input and output
456
- * - `{ input: true }` — Allow empty schemas for input only
457
- * - `{ output: true }` — Allow empty schemas for output only
476
+ * - `{ [ZodType]: true}` — Allow empty schemas for input and output
477
+ * - `{ [ZodType]: { input: true, output: true } }` — Allow empty schemas for input and output
478
+ * - `{ [ZodType]: { input: true } }` — Allow empty schemas for input only
479
+ * - `{ [ZodType]: { output: true } }` — Allow empty schemas for output only
458
480
  */
459
481
  allowEmptySchema?: Partial<Record<OverrideType, true | Partial<{
460
482
  input: true;
@@ -466,6 +488,14 @@ interface CreateDocumentOptions {
466
488
  * - `(ctx) => { ctx.jsonSchema.type = 'string'; }` — Override the schema type to be a string using a function
467
489
  */
468
490
  override?: Override;
491
+ /**
492
+ * Suffix to append to the output ID of the schema.
493
+ * This is useful to avoid conflicts with other schemas that may have the same name.
494
+ * For example, if you have a schema named `Person`, you can set this to `Response` to get `PersonResponse`.
495
+ * If not set, the default suffix is `Output`.
496
+ * @default 'Output'
497
+ */
498
+ outputIdSuffix?: string;
469
499
  /**
470
500
  * How to handle reused schemas.
471
501
  * - `"ref"` — Reused schemas will be rendered as references
@@ -480,63 +510,120 @@ interface CreateDocumentOptions {
480
510
  declare const createDocument: (zodOpenApiObject: ZodOpenApiObject, opts?: CreateDocumentOptions) => OpenAPIObject;
481
511
  //#endregion
482
512
  //#region src/create/components.d.ts
513
+ type SchemaSource = {
514
+ type: 'mediaType' | 'header';
515
+ } | {
516
+ type: 'parameter';
517
+ location: {
518
+ in: string;
519
+ name: string;
520
+ };
521
+ };
483
522
  interface ComponentRegistry {
484
- /**
485
- * Contains a map of component name to their OpenAPI schema object or reference.
486
- */
487
- schemas: {
488
- dynamicSchemaCount: number;
489
- input: Map<string, {
490
- zodType: $ZodType;
491
- schemaObject: SchemaObject | ReferenceObject;
492
- }>;
493
- output: Map<string, {
494
- zodType: $ZodType;
495
- schemaObject: SchemaObject | ReferenceObject;
496
- }>;
497
- ids: Map<string, SchemaObject | ReferenceObject>;
498
- manual: Map<string, {
499
- identifier: string;
500
- io: {
523
+ components: {
524
+ schemas: {
525
+ dynamicSchemaCount: number;
526
+ input: Map<string, {
527
+ zodType: $ZodType;
528
+ schemaObject: SchemaObject | ReferenceObject;
529
+ source: SchemaSource & {
530
+ path: string[];
531
+ };
532
+ }>;
533
+ output: Map<string, {
534
+ zodType: $ZodType;
535
+ schemaObject: SchemaObject | ReferenceObject;
536
+ source: SchemaSource & {
537
+ path: string[];
538
+ };
539
+ }>;
540
+ ids: Map<string, SchemaObject | ReferenceObject>;
541
+ manual: Map<string, {
501
542
  input: {
502
- used: number;
543
+ used?: true;
503
544
  schemaObject: SchemaObject;
504
545
  };
505
546
  output: {
506
- used: number;
547
+ used?: true;
507
548
  schemaObject: SchemaObject;
508
549
  };
509
- };
510
- zodType: $ZodType;
511
- }>;
512
- setSchema: (key: string, schema: $ZodType, io: 'input' | 'output') => SchemaObject | ReferenceObject;
513
- };
514
- headers: {
515
- ids: Map<string, HeaderObject | ReferenceObject>;
516
- seen: WeakMap<$ZodType, HeaderObject | ReferenceObject>;
517
- };
518
- requestBodies: {
519
- ids: Map<string, RequestBodyObject | ReferenceObject>;
520
- seen: WeakMap<ZodOpenApiRequestBodyObject, RequestBodyObject | ReferenceObject>;
521
- };
522
- responses: {
523
- ids: Map<string, ResponseObject | ReferenceObject>;
524
- seen: WeakMap<ZodOpenApiResponseObject, ResponseObject | ReferenceObject>;
525
- };
526
- parameters: {
527
- ids: Map<string, ParameterObject | ReferenceObject>;
528
- seen: WeakMap<$ZodType, ParameterObject | ReferenceObject>;
529
- };
530
- callbacks: {
531
- ids: Map<string, ZodOpenApiCallbackObject | ReferenceObject>;
532
- seen: WeakMap<ZodOpenApiCallbackObject, ZodOpenApiCallbackObject | ReferenceObject>;
533
- };
534
- pathItems: {
535
- ids: Map<string, PathItemObject | ReferenceObject>;
536
- seen: WeakMap<ZodOpenApiPathItemObject, PathItemObject | ReferenceObject>;
550
+ zodType: $ZodType;
551
+ }>;
552
+ };
553
+ headers: {
554
+ ids: Map<string, HeaderObject | ReferenceObject>;
555
+ seen: WeakMap<$ZodType, HeaderObject | ReferenceObject>;
556
+ };
557
+ requestBodies: {
558
+ ids: Map<string, RequestBodyObject | ReferenceObject>;
559
+ seen: WeakMap<ZodOpenApiRequestBodyObject, RequestBodyObject | ReferenceObject>;
560
+ };
561
+ responses: {
562
+ ids: Map<string, ResponseObject | ReferenceObject>;
563
+ seen: WeakMap<ZodOpenApiResponseObject, ResponseObject | ReferenceObject>;
564
+ };
565
+ parameters: {
566
+ ids: Map<string, ParameterObject | ReferenceObject>;
567
+ seen: WeakMap<$ZodType, ParameterObject | ReferenceObject>;
568
+ };
569
+ callbacks: {
570
+ ids: Map<string, ZodOpenApiCallbackObject | ReferenceObject>;
571
+ seen: WeakMap<ZodOpenApiCallbackObject, ZodOpenApiCallbackObject | ReferenceObject>;
572
+ };
573
+ pathItems: {
574
+ ids: Map<string, PathItemObject | ReferenceObject>;
575
+ seen: WeakMap<ZodOpenApiPathItemObject, PathItemObject | ReferenceObject>;
576
+ };
577
+ securitySchemes: {
578
+ ids: Map<string, SecuritySchemeObject | ReferenceObject>;
579
+ seen: WeakMap<ZodOpenApiSecuritySchemeObject, SecuritySchemeObject | ReferenceObject>;
580
+ };
581
+ links: {
582
+ ids: Map<string, LinkObject | ReferenceObject>;
583
+ seen: WeakMap<ZodOpenApiLinkObject, LinkObject | ReferenceObject>;
584
+ };
585
+ examples: {
586
+ ids: Map<string, ExampleObject | ReferenceObject>;
587
+ seen: WeakMap<ZodOpenApiExampleObject, ExampleObject | ReferenceObject>;
588
+ };
537
589
  };
590
+ addSchema: (schema: $ZodType, path: string[], opts: {
591
+ io: 'input' | 'output';
592
+ source: SchemaSource;
593
+ }) => SchemaObject | ReferenceObject;
594
+ addHeader: (header: $ZodType, path: string[], opts?: {
595
+ manualId?: string;
596
+ }) => HeaderObject | ReferenceObject;
597
+ addParameter: (parameter: $ZodType, path: string[], opts?: {
598
+ location?: {
599
+ in: ParameterLocation;
600
+ name: string;
601
+ };
602
+ manualId?: string;
603
+ }) => ParameterObject | ReferenceObject;
604
+ addRequestBody: (requestBody: ZodOpenApiRequestBodyObject, path: string[], opts?: {
605
+ manualId?: string;
606
+ }) => RequestBodyObject | ReferenceObject;
607
+ addPathItem: (pathItem: ZodOpenApiPathItemObject, path: string[], opts?: {
608
+ manualId?: string;
609
+ }) => PathItemObject | ReferenceObject;
610
+ addResponse: (response: ZodOpenApiResponseObject, path: string[], opts?: {
611
+ manualId?: string;
612
+ }) => ResponseObject | ReferenceObject;
613
+ addCallback: (callback: ZodOpenApiCallbackObject, path: string[], opts?: {
614
+ manualId?: string;
615
+ }) => CallbackObject | ReferenceObject;
616
+ addSecurityScheme: (securityScheme: ZodOpenApiSecuritySchemeObject, path: string[], opts?: {
617
+ manualId?: string;
618
+ }) => SecuritySchemeObject | ReferenceObject;
619
+ addLink: (link: ZodOpenApiLinkObject, path: string[], opts?: {
620
+ manualId?: string;
621
+ }) => LinkObject | ReferenceObject;
622
+ addExample: (example: ZodOpenApiExampleObject, path: string[], opts?: {
623
+ manualId?: string;
624
+ }) => ExampleObject | ReferenceObject;
538
625
  }
539
626
  declare const createRegistry: (components?: ZodOpenApiComponentsObject) => ComponentRegistry;
540
627
  declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions) => ComponentsObject;
541
628
  //#endregion
542
- export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodObjectInputType, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBody, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };
629
+ export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry, ComponentsObject, ContactObject, ContentObject, CreateDocumentOptions, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, Override, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject, ZodObjectInput, ZodOpenApiBaseMetadata, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiMetadata, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };