zod-openapi 5.0.0-beta.20 → 5.0.0-beta.4

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,4 +1,5 @@
1
1
  import { $ZodType, $ZodTypes } from "zod/v4/core";
2
+ import { ZodType, ZodTypeDef } from "zod";
2
3
  import { core } from "zod/v4";
3
4
 
4
5
  //#region src/openapi3-ts/dist/model/specification-extension.d.ts
@@ -323,12 +324,13 @@ interface SecurityRequirementObject {
323
324
  declare const openApiVersions: readonly ["3.1.0", "3.1.1"];
324
325
  type OpenApiVersion = (typeof openApiVersions)[number];
325
326
  //#endregion
326
- //#region src/types.d.ts
327
+ //#region src/zod.d.ts
327
328
  type Override = (ctx: {
328
329
  zodSchema: core.$ZodTypes;
329
330
  jsonSchema: core.JSONSchema.BaseSchema;
330
331
  io: 'input' | 'output';
331
332
  }) => void;
333
+ declare const isAnyZodType: (schema: unknown) => schema is core.$ZodTypes;
332
334
  declare module 'zod/v4' {
333
335
  interface GlobalMeta {
334
336
  /**
@@ -360,7 +362,7 @@ declare module 'zod/v4' {
360
362
  */
361
363
  unusedIO?: 'input' | 'output';
362
364
  /**
363
- * An alternate id to use for this schema in the event a registered schema is used in both a request and response schema.
365
+ * An alternate id to use for this schema in the event the schema is used in both input and output contexts.
364
366
  * 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.
365
367
  */
366
368
  outputId?: string;
@@ -381,10 +383,9 @@ interface ZodOpenApiRequestBodyObject extends Omit<RequestBodyObject, 'content'>
381
383
  id?: string;
382
384
  }
383
385
  type ZodOpenApiHeadersObject = ZodObjectInput | HeadersObject;
384
- interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers' | 'links'> {
386
+ interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers'> {
385
387
  content?: ZodOpenApiContentObject;
386
388
  headers?: ZodOpenApiHeadersObject;
387
- links?: ZodOpenApiLinksObject;
388
389
  /** Use this field to auto register this response object as a component */
389
390
  id?: string;
390
391
  }
@@ -428,23 +429,8 @@ interface ZodOpenApiPathsObject extends ISpecificationExtension {
428
429
  type ZodOpenApiParameterObject = $ZodType | ParameterObject | ReferenceObject;
429
430
  type ZodOpenApiHeaderObject = $ZodType | HeaderObject | ReferenceObject;
430
431
  type ZodOpenApiSchemaObject = $ZodType | SchemaObject | ReferenceObject;
431
- interface ZodOpenApiSecuritySchemeObject extends SecuritySchemeObject {
432
- /**
433
- * Used to register this security scheme as a component.
434
- */
435
- id?: string;
436
- }
437
- interface ZodOpenApiLinkObject extends LinkObject {
438
- /** Use this field to auto register this link object as a component */
439
- id?: string;
440
- }
441
- type ZodOpenApiLinksObject = Record<string, ZodOpenApiLinkObject | ReferenceObject>;
442
- interface ZodOpenApiExampleObject extends ExampleObject {
443
- /** Use this field to auto register this example object as a component */
444
- id?: string;
445
- }
446
- type ZodOpenApiExamplesObject = Record<string, ZodOpenApiExampleObject | ReferenceObject>;
447
- interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' | 'responses' | 'requestBodies' | 'headers' | 'parameters' | 'pathItems' | 'callbacks' | 'securitySchemes' | 'examples'> {
432
+ type ZodOpenApiRequestBody = $ZodType | RequestBodyObject | ReferenceObject;
433
+ interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' | 'responses' | 'requestBodies' | 'headers' | 'parameters' | 'pathItems' | 'callbacks'> {
448
434
  parameters?: Record<string, ZodOpenApiParameterObject>;
449
435
  schemas?: Record<string, ZodOpenApiSchemaObject>;
450
436
  requestBodies?: Record<string, ZodOpenApiRequestBodyObject>;
@@ -452,9 +438,6 @@ interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' |
452
438
  responses?: Record<string, ZodOpenApiResponseObject>;
453
439
  callbacks?: Record<string, ZodOpenApiCallbackObject>;
454
440
  pathItems?: Record<string, ZodOpenApiPathItemObject>;
455
- securitySchemes?: Record<string, ZodOpenApiSecuritySchemeObject>;
456
- links?: Record<string, ZodOpenApiLinkObject>;
457
- examples?: Record<string, ZodOpenApiExampleObject>;
458
441
  }
459
442
  type ZodOpenApiVersion = OpenApiVersion;
460
443
  interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'webhooks' | 'components'> {
@@ -463,15 +446,16 @@ interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'we
463
446
  webhooks?: ZodOpenApiPathsObject;
464
447
  components?: ZodOpenApiComponentsObject;
465
448
  }
449
+ type ZodObjectInputType<Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Record<string, unknown>> = ZodType<Output, Def, Input>;
466
450
  type ZodObjectInput = $ZodType<unknown, Record<string, unknown>>;
467
451
  type OverrideType = $ZodTypes['_zod']['def']['type'];
468
452
  interface CreateDocumentOptions {
469
453
  /**
470
454
  * Use this to allowlist empty schemas to be created for given types
471
- * - `{ [ZodType]: true}` — Allow empty schemas for input and output
472
- * - `{ [ZodType]: { input: true, output: true } }` — Allow empty schemas for input and output
473
- * - `{ [ZodType]: { input: true } }` — Allow empty schemas for input only
474
- * - `{ [ZodType]: { output: true } }` — Allow empty schemas for output only
455
+ * - `true` — Allow empty schemas for input and output
456
+ * - `{ input: true, output: true }` — Allow empty schemas for input and output
457
+ * - `{ input: true }` — Allow empty schemas for input only
458
+ * - `{ output: true }` — Allow empty schemas for output only
475
459
  */
476
460
  allowEmptySchema?: Partial<Record<OverrideType, true | Partial<{
477
461
  input: true;
@@ -483,14 +467,6 @@ interface CreateDocumentOptions {
483
467
  * - `(ctx) => { ctx.jsonSchema.type = 'string'; }` — Override the schema type to be a string using a function
484
468
  */
485
469
  override?: Override;
486
- /**
487
- * Suffix to append to the output ID of the schema.
488
- * This is useful to avoid conflicts with other schemas that may have the same name.
489
- * For example, if you have a schema named `Person`, you can set this to `Response` to get `PersonResponse`.
490
- * If not set, the default suffix is `Output`.
491
- * @default 'Output'
492
- */
493
- outputIdSuffix?: string;
494
470
  /**
495
471
  * How to handle reused schemas.
496
472
  * - `"ref"` — Reused schemas will be rendered as references
@@ -501,128 +477,67 @@ interface CreateDocumentOptions {
501
477
  * - `"ref"` — Default. Cycles will be broken using $defs
502
478
  * - `"throw"` — Cycles will throw an error if encountered */
503
479
  cycles?: 'ref' | 'throw';
504
- /**
505
- * The $ref path to use for a schema component. Defaults to `#/components/schemas/`
506
- */
507
- schemaRefPath?: string;
508
480
  }
509
481
  declare const createDocument: (zodOpenApiObject: ZodOpenApiObject, opts?: CreateDocumentOptions) => OpenAPIObject;
510
482
  //#endregion
511
483
  //#region src/create/components.d.ts
512
- type SchemaSource = {
513
- type: 'mediaType' | 'header';
514
- } | {
515
- type: 'parameter';
516
- location: {
517
- in: string;
518
- name: string;
519
- };
520
- };
521
484
  interface ComponentRegistry {
522
- components: {
523
- schemas: {
524
- dynamicSchemaCount: number;
525
- input: Map<string, {
526
- zodType: $ZodType;
527
- schemaObject: SchemaObject | ReferenceObject;
528
- source: SchemaSource & {
529
- path: string[];
530
- };
531
- }>;
532
- output: Map<string, {
533
- zodType: $ZodType;
534
- schemaObject: SchemaObject | ReferenceObject;
535
- source: SchemaSource & {
536
- path: string[];
537
- };
538
- }>;
539
- ids: Map<string, SchemaObject | ReferenceObject>;
540
- manual: Map<string, {
485
+ /**
486
+ * Contains a map of component name to their OpenAPI schema object or reference.
487
+ */
488
+ schemas: {
489
+ dynamicSchemaCount: number;
490
+ input: Map<string, {
491
+ zodType: $ZodType;
492
+ schemaObject: SchemaObject | ReferenceObject;
493
+ }>;
494
+ output: Map<string, {
495
+ zodType: $ZodType;
496
+ schemaObject: SchemaObject | ReferenceObject;
497
+ }>;
498
+ ids: Map<string, SchemaObject | ReferenceObject>;
499
+ manual: Map<string, {
500
+ identifier: string;
501
+ io: {
541
502
  input: {
542
- used?: true;
503
+ used: number;
543
504
  schemaObject: SchemaObject;
544
505
  };
545
506
  output: {
546
- used?: true;
507
+ used: number;
547
508
  schemaObject: SchemaObject;
548
509
  };
549
- zodType: $ZodType;
550
- }>;
551
- };
552
- headers: {
553
- ids: Map<string, HeaderObject | ReferenceObject>;
554
- seen: WeakMap<$ZodType, HeaderObject | ReferenceObject>;
555
- };
556
- requestBodies: {
557
- ids: Map<string, RequestBodyObject | ReferenceObject>;
558
- seen: WeakMap<ZodOpenApiRequestBodyObject, RequestBodyObject | ReferenceObject>;
559
- };
560
- responses: {
561
- ids: Map<string, ResponseObject | ReferenceObject>;
562
- seen: WeakMap<ZodOpenApiResponseObject, ResponseObject | ReferenceObject>;
563
- };
564
- parameters: {
565
- ids: Map<string, ParameterObject | ReferenceObject>;
566
- seen: WeakMap<$ZodType, ParameterObject | ReferenceObject>;
567
- };
568
- callbacks: {
569
- ids: Map<string, ZodOpenApiCallbackObject | ReferenceObject>;
570
- seen: WeakMap<ZodOpenApiCallbackObject, ZodOpenApiCallbackObject | ReferenceObject>;
571
- };
572
- pathItems: {
573
- ids: Map<string, PathItemObject | ReferenceObject>;
574
- seen: WeakMap<ZodOpenApiPathItemObject, PathItemObject | ReferenceObject>;
575
- };
576
- securitySchemes: {
577
- ids: Map<string, SecuritySchemeObject | ReferenceObject>;
578
- seen: WeakMap<ZodOpenApiSecuritySchemeObject, SecuritySchemeObject | ReferenceObject>;
579
- };
580
- links: {
581
- ids: Map<string, LinkObject | ReferenceObject>;
582
- seen: WeakMap<ZodOpenApiLinkObject, LinkObject | ReferenceObject>;
583
- };
584
- examples: {
585
- ids: Map<string, ExampleObject | ReferenceObject>;
586
- seen: WeakMap<ZodOpenApiExampleObject, ExampleObject | ReferenceObject>;
587
- };
510
+ };
511
+ zodType: $ZodType;
512
+ }>;
513
+ setSchema: (key: string, schema: $ZodType, io: 'input' | 'output') => SchemaObject | ReferenceObject;
514
+ };
515
+ headers: {
516
+ ids: Map<string, HeaderObject | ReferenceObject>;
517
+ seen: WeakMap<$ZodType, HeaderObject | ReferenceObject>;
518
+ };
519
+ requestBodies: {
520
+ ids: Map<string, RequestBodyObject | ReferenceObject>;
521
+ seen: WeakMap<ZodOpenApiRequestBodyObject, RequestBodyObject | ReferenceObject>;
522
+ };
523
+ responses: {
524
+ ids: Map<string, ResponseObject | ReferenceObject>;
525
+ seen: WeakMap<ZodOpenApiResponseObject, ResponseObject | ReferenceObject>;
526
+ };
527
+ parameters: {
528
+ ids: Map<string, ParameterObject | ReferenceObject>;
529
+ seen: WeakMap<$ZodType, ParameterObject | ReferenceObject>;
530
+ };
531
+ callbacks: {
532
+ ids: Map<string, ZodOpenApiCallbackObject | ReferenceObject>;
533
+ seen: WeakMap<ZodOpenApiCallbackObject, ZodOpenApiCallbackObject | ReferenceObject>;
534
+ };
535
+ pathItems: {
536
+ ids: Map<string, PathItemObject | ReferenceObject>;
537
+ seen: WeakMap<ZodOpenApiPathItemObject, PathItemObject | ReferenceObject>;
588
538
  };
589
- addSchema: (schema: $ZodType, path: string[], opts: {
590
- io: 'input' | 'output';
591
- source: SchemaSource;
592
- }) => SchemaObject | ReferenceObject;
593
- addHeader: (header: $ZodType, path: string[], opts?: {
594
- manualId?: string;
595
- }) => HeaderObject | ReferenceObject;
596
- addParameter: (parameter: $ZodType, path: string[], opts?: {
597
- location?: {
598
- in: ParameterLocation;
599
- name: string;
600
- };
601
- manualId?: string;
602
- }) => ParameterObject | ReferenceObject;
603
- addRequestBody: (requestBody: ZodOpenApiRequestBodyObject, path: string[], opts?: {
604
- manualId?: string;
605
- }) => RequestBodyObject | ReferenceObject;
606
- addPathItem: (pathItem: ZodOpenApiPathItemObject, path: string[], opts?: {
607
- manualId?: string;
608
- }) => PathItemObject | ReferenceObject;
609
- addResponse: (response: ZodOpenApiResponseObject, path: string[], opts?: {
610
- manualId?: string;
611
- }) => ResponseObject | ReferenceObject;
612
- addCallback: (callback: ZodOpenApiCallbackObject, path: string[], opts?: {
613
- manualId?: string;
614
- }) => CallbackObject | ReferenceObject;
615
- addSecurityScheme: (securityScheme: ZodOpenApiSecuritySchemeObject, path: string[], opts?: {
616
- manualId?: string;
617
- }) => SecuritySchemeObject | ReferenceObject;
618
- addLink: (link: ZodOpenApiLinkObject, path: string[], opts?: {
619
- manualId?: string;
620
- }) => LinkObject | ReferenceObject;
621
- addExample: (example: ZodOpenApiExampleObject, path: string[], opts?: {
622
- manualId?: string;
623
- }) => ExampleObject | ReferenceObject;
624
539
  }
625
540
  declare const createRegistry: (components?: ZodOpenApiComponentsObject) => ComponentRegistry;
626
541
  declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions) => ComponentsObject;
627
542
  //#endregion
628
- 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, ZodOpenApiExampleObject, ZodOpenApiExamplesObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiLinkObject, ZodOpenApiLinksObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiSecuritySchemeObject, ZodOpenApiVersion, createComponents, createDocument, createRegistry };
543
+ 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, isAnyZodType };