zod-openapi 5.0.0-beta.9 → 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.
- package/README.md +185 -47
- package/dist/api.d.mts +2 -11
- package/dist/api.d.ts +2 -11
- package/dist/api.js +1 -2
- package/dist/api.mjs +2 -2
- package/dist/components-BRLB21IO.js +958 -0
- package/dist/components-DuIz-WUQ.mjs +900 -0
- package/dist/{components-26wns3Hd.d.mts → components-Dus8apcN.d.mts} +183 -91
- package/dist/{components-CokUEQbL.d.ts → components-T2U31sZh.d.ts} +183 -91
- package/dist/index.d.mts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +6 -4
- package/dist/components-0QHfGwg0.mjs +0 -791
- package/dist/components-CB3cj8u3.js +0 -855
|
@@ -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,47 @@ type Override = (ctx: {
|
|
|
329
329
|
jsonSchema: core.JSONSchema.BaseSchema;
|
|
330
330
|
io: 'input' | 'output';
|
|
331
331
|
}) => void;
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
340
|
+
id?: string;
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Used to set metadata for a response header
|
|
344
|
+
*/
|
|
345
|
+
header?: Partial<HeaderObject> & {
|
|
362
346
|
/**
|
|
363
|
-
*
|
|
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
|
-
|
|
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
|
+
example?: unknown;
|
|
370
|
+
}
|
|
371
|
+
declare module 'zod/v4' {
|
|
372
|
+
interface GlobalMeta extends ZodOpenApiMetadata {}
|
|
368
373
|
}
|
|
369
374
|
//#endregion
|
|
370
375
|
//#region src/create/document.d.ts
|
|
@@ -381,9 +386,10 @@ interface ZodOpenApiRequestBodyObject extends Omit<RequestBodyObject, 'content'>
|
|
|
381
386
|
id?: string;
|
|
382
387
|
}
|
|
383
388
|
type ZodOpenApiHeadersObject = ZodObjectInput | HeadersObject;
|
|
384
|
-
interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers'> {
|
|
389
|
+
interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers' | 'links'> {
|
|
385
390
|
content?: ZodOpenApiContentObject;
|
|
386
391
|
headers?: ZodOpenApiHeadersObject;
|
|
392
|
+
links?: ZodOpenApiLinksObject;
|
|
387
393
|
/** Use this field to auto register this response object as a component */
|
|
388
394
|
id?: string;
|
|
389
395
|
}
|
|
@@ -427,8 +433,23 @@ interface ZodOpenApiPathsObject extends ISpecificationExtension {
|
|
|
427
433
|
type ZodOpenApiParameterObject = $ZodType | ParameterObject | ReferenceObject;
|
|
428
434
|
type ZodOpenApiHeaderObject = $ZodType | HeaderObject | ReferenceObject;
|
|
429
435
|
type ZodOpenApiSchemaObject = $ZodType | SchemaObject | ReferenceObject;
|
|
430
|
-
|
|
431
|
-
|
|
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'> {
|
|
432
453
|
parameters?: Record<string, ZodOpenApiParameterObject>;
|
|
433
454
|
schemas?: Record<string, ZodOpenApiSchemaObject>;
|
|
434
455
|
requestBodies?: Record<string, ZodOpenApiRequestBodyObject>;
|
|
@@ -436,6 +457,9 @@ interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' |
|
|
|
436
457
|
responses?: Record<string, ZodOpenApiResponseObject>;
|
|
437
458
|
callbacks?: Record<string, ZodOpenApiCallbackObject>;
|
|
438
459
|
pathItems?: Record<string, ZodOpenApiPathItemObject>;
|
|
460
|
+
securitySchemes?: Record<string, ZodOpenApiSecuritySchemeObject>;
|
|
461
|
+
links?: Record<string, ZodOpenApiLinkObject>;
|
|
462
|
+
examples?: Record<string, ZodOpenApiExampleObject>;
|
|
439
463
|
}
|
|
440
464
|
type ZodOpenApiVersion = OpenApiVersion;
|
|
441
465
|
interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'webhooks' | 'components'> {
|
|
@@ -449,10 +473,10 @@ type OverrideType = $ZodTypes['_zod']['def']['type'];
|
|
|
449
473
|
interface CreateDocumentOptions {
|
|
450
474
|
/**
|
|
451
475
|
* 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
|
|
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
|
|
456
480
|
*/
|
|
457
481
|
allowEmptySchema?: Partial<Record<OverrideType, true | Partial<{
|
|
458
482
|
input: true;
|
|
@@ -464,6 +488,14 @@ interface CreateDocumentOptions {
|
|
|
464
488
|
* - `(ctx) => { ctx.jsonSchema.type = 'string'; }` — Override the schema type to be a string using a function
|
|
465
489
|
*/
|
|
466
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;
|
|
467
499
|
/**
|
|
468
500
|
* How to handle reused schemas.
|
|
469
501
|
* - `"ref"` — Reused schemas will be rendered as references
|
|
@@ -478,60 +510,120 @@ interface CreateDocumentOptions {
|
|
|
478
510
|
declare const createDocument: (zodOpenApiObject: ZodOpenApiObject, opts?: CreateDocumentOptions) => OpenAPIObject;
|
|
479
511
|
//#endregion
|
|
480
512
|
//#region src/create/components.d.ts
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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>;
|
|
513
|
+
type SchemaSource = {
|
|
514
|
+
type: 'mediaType' | 'header';
|
|
515
|
+
} | {
|
|
516
|
+
type: 'parameter';
|
|
517
|
+
location: {
|
|
518
|
+
in: string;
|
|
519
|
+
name: string;
|
|
524
520
|
};
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
521
|
+
};
|
|
522
|
+
interface ComponentRegistry {
|
|
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, {
|
|
542
|
+
input: {
|
|
543
|
+
used?: true;
|
|
544
|
+
schemaObject: SchemaObject;
|
|
545
|
+
};
|
|
546
|
+
output: {
|
|
547
|
+
used?: true;
|
|
548
|
+
schemaObject: SchemaObject;
|
|
549
|
+
};
|
|
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
|
+
};
|
|
532
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;
|
|
533
625
|
}
|
|
534
626
|
declare const createRegistry: (components?: ZodOpenApiComponentsObject) => ComponentRegistry;
|
|
535
627
|
declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions) => ComponentsObject;
|
|
536
628
|
//#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,
|
|
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 };
|
|
@@ -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,47 @@ type Override = (ctx: {
|
|
|
329
329
|
jsonSchema: core.JSONSchema.BaseSchema;
|
|
330
330
|
io: 'input' | 'output';
|
|
331
331
|
}) => void;
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
340
|
+
id?: string;
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* Used to set metadata for a response header
|
|
344
|
+
*/
|
|
345
|
+
header?: Partial<HeaderObject> & {
|
|
362
346
|
/**
|
|
363
|
-
*
|
|
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
|
-
|
|
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
|
+
example?: unknown;
|
|
370
|
+
}
|
|
371
|
+
declare module 'zod/v4' {
|
|
372
|
+
interface GlobalMeta extends ZodOpenApiMetadata {}
|
|
368
373
|
}
|
|
369
374
|
//#endregion
|
|
370
375
|
//#region src/create/document.d.ts
|
|
@@ -381,9 +386,10 @@ interface ZodOpenApiRequestBodyObject extends Omit<RequestBodyObject, 'content'>
|
|
|
381
386
|
id?: string;
|
|
382
387
|
}
|
|
383
388
|
type ZodOpenApiHeadersObject = ZodObjectInput | HeadersObject;
|
|
384
|
-
interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers'> {
|
|
389
|
+
interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers' | 'links'> {
|
|
385
390
|
content?: ZodOpenApiContentObject;
|
|
386
391
|
headers?: ZodOpenApiHeadersObject;
|
|
392
|
+
links?: ZodOpenApiLinksObject;
|
|
387
393
|
/** Use this field to auto register this response object as a component */
|
|
388
394
|
id?: string;
|
|
389
395
|
}
|
|
@@ -427,8 +433,23 @@ interface ZodOpenApiPathsObject extends ISpecificationExtension {
|
|
|
427
433
|
type ZodOpenApiParameterObject = $ZodType | ParameterObject | ReferenceObject;
|
|
428
434
|
type ZodOpenApiHeaderObject = $ZodType | HeaderObject | ReferenceObject;
|
|
429
435
|
type ZodOpenApiSchemaObject = $ZodType | SchemaObject | ReferenceObject;
|
|
430
|
-
|
|
431
|
-
|
|
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'> {
|
|
432
453
|
parameters?: Record<string, ZodOpenApiParameterObject>;
|
|
433
454
|
schemas?: Record<string, ZodOpenApiSchemaObject>;
|
|
434
455
|
requestBodies?: Record<string, ZodOpenApiRequestBodyObject>;
|
|
@@ -436,6 +457,9 @@ interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' |
|
|
|
436
457
|
responses?: Record<string, ZodOpenApiResponseObject>;
|
|
437
458
|
callbacks?: Record<string, ZodOpenApiCallbackObject>;
|
|
438
459
|
pathItems?: Record<string, ZodOpenApiPathItemObject>;
|
|
460
|
+
securitySchemes?: Record<string, ZodOpenApiSecuritySchemeObject>;
|
|
461
|
+
links?: Record<string, ZodOpenApiLinkObject>;
|
|
462
|
+
examples?: Record<string, ZodOpenApiExampleObject>;
|
|
439
463
|
}
|
|
440
464
|
type ZodOpenApiVersion = OpenApiVersion;
|
|
441
465
|
interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'webhooks' | 'components'> {
|
|
@@ -449,10 +473,10 @@ type OverrideType = $ZodTypes['_zod']['def']['type'];
|
|
|
449
473
|
interface CreateDocumentOptions {
|
|
450
474
|
/**
|
|
451
475
|
* 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
|
|
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
|
|
456
480
|
*/
|
|
457
481
|
allowEmptySchema?: Partial<Record<OverrideType, true | Partial<{
|
|
458
482
|
input: true;
|
|
@@ -464,6 +488,14 @@ interface CreateDocumentOptions {
|
|
|
464
488
|
* - `(ctx) => { ctx.jsonSchema.type = 'string'; }` — Override the schema type to be a string using a function
|
|
465
489
|
*/
|
|
466
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;
|
|
467
499
|
/**
|
|
468
500
|
* How to handle reused schemas.
|
|
469
501
|
* - `"ref"` — Reused schemas will be rendered as references
|
|
@@ -478,60 +510,120 @@ interface CreateDocumentOptions {
|
|
|
478
510
|
declare const createDocument: (zodOpenApiObject: ZodOpenApiObject, opts?: CreateDocumentOptions) => OpenAPIObject;
|
|
479
511
|
//#endregion
|
|
480
512
|
//#region src/create/components.d.ts
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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>;
|
|
513
|
+
type SchemaSource = {
|
|
514
|
+
type: 'mediaType' | 'header';
|
|
515
|
+
} | {
|
|
516
|
+
type: 'parameter';
|
|
517
|
+
location: {
|
|
518
|
+
in: string;
|
|
519
|
+
name: string;
|
|
524
520
|
};
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
521
|
+
};
|
|
522
|
+
interface ComponentRegistry {
|
|
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, {
|
|
542
|
+
input: {
|
|
543
|
+
used?: true;
|
|
544
|
+
schemaObject: SchemaObject;
|
|
545
|
+
};
|
|
546
|
+
output: {
|
|
547
|
+
used?: true;
|
|
548
|
+
schemaObject: SchemaObject;
|
|
549
|
+
};
|
|
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
|
+
};
|
|
532
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;
|
|
533
625
|
}
|
|
534
626
|
declare const createRegistry: (components?: ZodOpenApiComponentsObject) => ComponentRegistry;
|
|
535
627
|
declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions) => ComponentsObject;
|
|
536
628
|
//#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,
|
|
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 };
|