zod-openapi 5.0.0-beta.9 → 5.0.1

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