zod-openapi 2.19.0 → 3.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.
@@ -0,0 +1,124 @@
1
+ import { ZodType } from 'zod';
2
+ import { SchemaObject as SchemaObject$1, ReferenceObject as ReferenceObject$1, ParameterObject as ParameterObject$1, HeaderObject as HeaderObject$1, ResponseObject as ResponseObject$1, RequestBodyObject as RequestBodyObject$1, CallbackObject as CallbackObject$1 } from '../openapi3-ts/dist/model/openapi30.js';
3
+ import { ComponentsObject as ComponentsObject$1, SchemaObject, ReferenceObject, ParameterObject, ParameterLocation, HeaderObject, ResponseObject, RequestBodyObject, CallbackObject } from '../openapi3-ts/dist/model/openapi31.js';
4
+ import { ZodOpenApiVersion, ZodOpenApiComponentsObject, ZodOpenApiResponseObject, ZodOpenApiRequestBodyObject, ZodOpenApiCallbackObject } from './document.js';
5
+
6
+ type CreationType = 'input' | 'output';
7
+ type BaseEffect = {
8
+ zodType: ZodType;
9
+ path: string[];
10
+ };
11
+ type ComponentEffect = BaseEffect & {
12
+ type: 'component';
13
+ };
14
+ type SchemaEffect = BaseEffect & {
15
+ type: 'schema';
16
+ creationType: CreationType;
17
+ };
18
+ type Effect = ComponentEffect | SchemaEffect;
19
+ type ResolvedEffect = {
20
+ creationType: CreationType;
21
+ path: string[];
22
+ zodType: ZodType;
23
+ component?: {
24
+ ref: string;
25
+ zodType: ZodType;
26
+ path: string[];
27
+ };
28
+ };
29
+ interface CompleteSchemaComponent extends BaseSchemaComponent {
30
+ type: 'complete';
31
+ schemaObject: SchemaObject | ReferenceObject | SchemaObject$1 | ReferenceObject$1;
32
+ /** Set when the created schemaObject is specific to a particular effect */
33
+ effects?: Effect[];
34
+ resolvedEffect?: ResolvedEffect;
35
+ }
36
+ /**
37
+ *
38
+ */
39
+ interface ManualSchemaComponent extends BaseSchemaComponent {
40
+ type: 'manual';
41
+ }
42
+ interface InProgressSchemaComponent extends BaseSchemaComponent {
43
+ type: 'in-progress';
44
+ }
45
+ interface BaseSchemaComponent {
46
+ ref: string;
47
+ }
48
+ type SchemaComponent = CompleteSchemaComponent | ManualSchemaComponent | InProgressSchemaComponent;
49
+ type SchemaComponentMap = Map<ZodType, SchemaComponent>;
50
+ interface CompleteParameterComponent extends BaseParameterComponent {
51
+ type: 'complete';
52
+ paramObject: ParameterObject | ReferenceObject | ParameterObject$1 | ReferenceObject$1;
53
+ }
54
+ interface PartialParameterComponent extends BaseParameterComponent {
55
+ type: 'manual';
56
+ }
57
+ interface BaseParameterComponent {
58
+ ref: string;
59
+ in: ParameterLocation;
60
+ name: string;
61
+ }
62
+ type ParameterComponent = CompleteParameterComponent | PartialParameterComponent;
63
+ type ParameterComponentMap = Map<ZodType, ParameterComponent>;
64
+ interface CompleteHeaderComponent extends BaseHeaderComponent {
65
+ type: 'complete';
66
+ headerObject: HeaderObject | ReferenceObject | HeaderObject$1 | ReferenceObject$1;
67
+ }
68
+ interface PartialHeaderComponent extends BaseHeaderComponent {
69
+ type: 'manual';
70
+ }
71
+ interface BaseHeaderComponent {
72
+ ref: string;
73
+ }
74
+ type HeaderComponent = CompleteHeaderComponent | PartialHeaderComponent;
75
+ type HeaderComponentMap = Map<ZodType, HeaderComponent>;
76
+ interface BaseResponseComponent {
77
+ ref: string;
78
+ }
79
+ interface CompleteResponseComponent extends BaseResponseComponent {
80
+ type: 'complete';
81
+ responseObject: ResponseObject | ReferenceObject | ResponseObject$1 | ReferenceObject$1;
82
+ }
83
+ interface PartialResponseComponent extends BaseResponseComponent {
84
+ type: 'manual';
85
+ }
86
+ type ResponseComponent = CompleteResponseComponent | PartialResponseComponent;
87
+ type ResponseComponentMap = Map<ZodOpenApiResponseObject, ResponseComponent>;
88
+ interface BaseRequestBodyComponent {
89
+ ref: string;
90
+ }
91
+ interface CompleteRequestBodyComponent extends BaseRequestBodyComponent {
92
+ type: 'complete';
93
+ requestBodyObject: RequestBodyObject | ReferenceObject | RequestBodyObject$1 | ReferenceObject$1;
94
+ }
95
+ interface PartialRequestBodyComponent extends BaseRequestBodyComponent {
96
+ type: 'manual';
97
+ }
98
+ type RequestBodyComponent = CompleteRequestBodyComponent | PartialRequestBodyComponent;
99
+ type RequestBodyComponentMap = Map<ZodOpenApiRequestBodyObject, RequestBodyComponent>;
100
+ interface BaseCallbackComponent {
101
+ ref: string;
102
+ }
103
+ interface CompleteCallbackComponent extends BaseCallbackComponent {
104
+ type: 'complete';
105
+ callbackObject: ZodOpenApiCallbackObject | CallbackObject | CallbackObject$1;
106
+ }
107
+ interface PartialCallbackComponent extends BaseCallbackComponent {
108
+ type: 'manual';
109
+ }
110
+ type CallbackComponent = CompleteCallbackComponent | PartialCallbackComponent;
111
+ type CallbackComponentMap = Map<ZodOpenApiCallbackObject, CallbackComponent>;
112
+ interface ComponentsObject {
113
+ schemas: SchemaComponentMap;
114
+ parameters: ParameterComponentMap;
115
+ headers: HeaderComponentMap;
116
+ requestBodies: RequestBodyComponentMap;
117
+ responses: ResponseComponentMap;
118
+ callbacks: CallbackComponentMap;
119
+ openapi: ZodOpenApiVersion;
120
+ }
121
+ declare const getDefaultComponents: (componentsObject?: ZodOpenApiComponentsObject, openapi?: ZodOpenApiVersion) => ComponentsObject;
122
+ declare const createComponents: (componentsObject: ZodOpenApiComponentsObject, components: ComponentsObject) => ComponentsObject$1 | undefined;
123
+
124
+ export { type BaseCallbackComponent, type CallbackComponent, type CallbackComponentMap, type CompleteCallbackComponent, type CompleteHeaderComponent, type CompleteParameterComponent, type CompleteRequestBodyComponent, type CompleteResponseComponent, type CompleteSchemaComponent, type ComponentEffect, type ComponentsObject, type CreationType, type Effect, type HeaderComponent, type HeaderComponentMap, type InProgressSchemaComponent, type ManualSchemaComponent, type ParameterComponent, type ParameterComponentMap, type PartialCallbackComponent, type PartialHeaderComponent, type PartialParameterComponent, type PartialRequestBodyComponent, type PartialResponseComponent, type RequestBodyComponent, type RequestBodyComponentMap, type ResolvedEffect, type ResponseComponent, type ResponseComponentMap, type SchemaComponent, type SchemaComponentMap, type SchemaEffect, createComponents, getDefaultComponents };
@@ -0,0 +1,7 @@
1
+ import { ZodType } from 'zod';
2
+ import { SchemaObject, ReferenceObject } from '../openapi3-ts/dist/model/openapi31.js';
3
+ import { ComponentsObject, CreationType } from './components.js';
4
+
5
+ declare const createMediaTypeSchema: (schemaObject: ZodType | SchemaObject | ReferenceObject | undefined, components: ComponentsObject, type: CreationType, subpath: string[]) => SchemaObject | ReferenceObject | undefined;
6
+
7
+ export { createMediaTypeSchema };
@@ -0,0 +1,78 @@
1
+ import { ZodType, AnyZodObject, ZodTypeDef } from 'zod';
2
+ import { OpenApiVersion } from '../openapi.js';
3
+ import { MediaTypeObject as MediaTypeObject$1, RequestBodyObject as RequestBodyObject$1, ResponseObject as ResponseObject$1, HeadersObject, ReferenceObject as ReferenceObject$1, ParameterLocation as ParameterLocation$1, OperationObject as OperationObject$1, ParameterObject as ParameterObject$1, PathItemObject as PathItemObject$1, ComponentsObject as ComponentsObject$1, SchemaObject as SchemaObject$1, HeaderObject as HeaderObject$1 } from '../openapi3-ts/dist/model/openapi30.js';
4
+ import { ISpecificationExtension } from '../openapi3-ts/dist/model/specification-extension.js';
5
+ import { MediaTypeObject, SchemaObject, ReferenceObject, RequestBodyObject, ResponseObject, HeadersObject as HeadersObject$1, ParameterLocation, OperationObject, ParameterObject, PathItemObject, ComponentsObject, HeaderObject, OpenAPIObject } from '../openapi3-ts/dist/model/openapi31.js';
6
+
7
+ interface ZodOpenApiMediaTypeObject extends Omit<MediaTypeObject & MediaTypeObject$1, 'schema'> {
8
+ schema?: ZodType | SchemaObject | ReferenceObject;
9
+ }
10
+ interface ZodOpenApiContentObject {
11
+ 'application/json'?: ZodOpenApiMediaTypeObject;
12
+ [mediatype: string]: ZodOpenApiMediaTypeObject | undefined;
13
+ }
14
+ interface ZodOpenApiRequestBodyObject extends Omit<RequestBodyObject & RequestBodyObject$1, 'content'> {
15
+ content: ZodOpenApiContentObject;
16
+ /** Use this field to auto register this request body as a component */
17
+ ref?: string;
18
+ }
19
+ interface ZodOpenApiResponseObject extends Omit<ResponseObject & ResponseObject$1, 'content' | 'headers'> {
20
+ content?: ZodOpenApiContentObject;
21
+ headers?: AnyZodObject | HeadersObject | HeadersObject$1;
22
+ /** Use this field to auto register this response object as a component */
23
+ ref?: string;
24
+ }
25
+ interface ZodOpenApiResponsesObject extends ISpecificationExtension {
26
+ default?: ZodOpenApiResponseObject | ReferenceObject | ReferenceObject$1;
27
+ [statuscode: `${1 | 2 | 3 | 4 | 5}${string}`]: ZodOpenApiResponseObject | ReferenceObject;
28
+ }
29
+ type ZodOpenApiParameters = {
30
+ [type in ParameterLocation & ParameterLocation$1]?: ZodObjectInputType;
31
+ };
32
+ interface ZodOpenApiCallbacksObject extends ISpecificationExtension {
33
+ [name: string]: ZodOpenApiCallbackObject;
34
+ }
35
+ interface ZodOpenApiCallbackObject extends ISpecificationExtension {
36
+ /** Use this field to auto register this callback object as a component */
37
+ ref?: string;
38
+ [name: string]: ZodOpenApiPathItemObject | string | undefined;
39
+ }
40
+ interface ZodOpenApiOperationObject extends Omit<OperationObject & OperationObject$1, 'requestBody' | 'responses' | 'parameters' | 'callbacks'> {
41
+ parameters?: Array<ZodType | ParameterObject | ParameterObject$1 | ReferenceObject | ReferenceObject$1>;
42
+ requestBody?: ZodOpenApiRequestBodyObject;
43
+ requestParams?: ZodOpenApiParameters;
44
+ responses: ZodOpenApiResponsesObject;
45
+ callbacks?: ZodOpenApiCallbacksObject;
46
+ }
47
+ interface ZodOpenApiPathItemObject extends Omit<PathItemObject & PathItemObject$1, 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace'> {
48
+ get?: ZodOpenApiOperationObject;
49
+ put?: ZodOpenApiOperationObject;
50
+ post?: ZodOpenApiOperationObject;
51
+ delete?: ZodOpenApiOperationObject;
52
+ options?: ZodOpenApiOperationObject;
53
+ head?: ZodOpenApiOperationObject;
54
+ patch?: ZodOpenApiOperationObject;
55
+ trace?: ZodOpenApiOperationObject;
56
+ }
57
+ interface ZodOpenApiPathsObject extends ISpecificationExtension {
58
+ [path: string]: ZodOpenApiPathItemObject;
59
+ }
60
+ interface ZodOpenApiComponentsObject extends Omit<ComponentsObject & ComponentsObject$1, 'schemas' | 'responses' | 'requestBodies' | 'headers' | 'parameters'> {
61
+ parameters?: Record<string, ZodType | ParameterObject | ParameterObject$1 | ReferenceObject | ReferenceObject$1>;
62
+ schemas?: Record<string, ZodType | SchemaObject | ReferenceObject | SchemaObject$1 | ReferenceObject$1>;
63
+ requestBodies?: Record<string, ZodOpenApiRequestBodyObject>;
64
+ headers?: Record<string, ZodType | HeaderObject | HeaderObject$1 | ReferenceObject | ReferenceObject$1>;
65
+ responses?: Record<string, ZodOpenApiResponseObject>;
66
+ callbacks?: Record<string, ZodOpenApiCallbackObject>;
67
+ }
68
+ type ZodOpenApiVersion = OpenApiVersion;
69
+ interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'webhooks' | 'components'> {
70
+ openapi: ZodOpenApiVersion;
71
+ paths?: ZodOpenApiPathsObject;
72
+ webhooks?: ZodOpenApiPathsObject;
73
+ components?: ZodOpenApiComponentsObject;
74
+ }
75
+ type ZodObjectInputType<Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Record<string, unknown>> = ZodType<Output, Def, Input>;
76
+ declare const createDocument: (zodOpenApiObject: ZodOpenApiObject) => OpenAPIObject;
77
+
78
+ export { type ZodObjectInputType, type ZodOpenApiCallbackObject, type ZodOpenApiCallbacksObject, type ZodOpenApiComponentsObject, type ZodOpenApiContentObject, type ZodOpenApiMediaTypeObject, type ZodOpenApiObject, type ZodOpenApiOperationObject, type ZodOpenApiParameters, type ZodOpenApiPathItemObject, type ZodOpenApiPathsObject, type ZodOpenApiRequestBodyObject, type ZodOpenApiResponseObject, type ZodOpenApiResponsesObject, type ZodOpenApiVersion, createDocument };
@@ -0,0 +1,8 @@
1
+ import { ZodType } from 'zod';
2
+ import { ParameterObject, ReferenceObject } from '../openapi3-ts/dist/model/openapi31.js';
3
+ import { ComponentsObject } from './components.js';
4
+ import { ZodOpenApiParameters } from './document.js';
5
+
6
+ declare const createParamOrRef: (zodSchema: ZodType, components: ComponentsObject, subpath: string[], type?: keyof ZodOpenApiParameters, name?: string) => ParameterObject | ReferenceObject;
7
+
8
+ export { createParamOrRef };
package/dist/extend.d.mts CHANGED
@@ -1 +1 @@
1
- import './index.js';
1
+ import './extendZodTypes.js';
package/dist/extend.d.ts CHANGED
@@ -1 +1 @@
1
- import './index.js';
1
+ import './extendZodTypes.js';
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+ import './extendZodTypes.js';
3
+
4
+ declare function extendZodWithOpenApi(zod: typeof z): void;
5
+
6
+ export { extendZodWithOpenApi };
@@ -0,0 +1,76 @@
1
+ import { ZodTypeAny, z, ZodDate, ZodObject } from 'zod';
2
+ import { CreationType } from './create/components.js';
3
+ import { HeaderObject as HeaderObject$1, SchemaObject as SchemaObject$1 } from './openapi3-ts/dist/model/openapi30.js';
4
+ import { ParameterObject, ExampleObject, ReferenceObject, HeaderObject, SchemaObject as SchemaObject$2 } from './openapi3-ts/dist/model/openapi31.js';
5
+
6
+ type SchemaObject = SchemaObject$1 & SchemaObject$2;
7
+ /**
8
+ * zod-openapi metadata
9
+ */
10
+ interface ZodOpenApiMetadata<T extends ZodTypeAny, TInferred = z.input<T> | z.output<T>> extends SchemaObject {
11
+ example?: TInferred;
12
+ examples?: [TInferred, ...TInferred[]];
13
+ default?: T extends ZodDate ? string : TInferred;
14
+ /**
15
+ * Used to set the output of a ZodUnion to be `oneOf` instead of `allOf`
16
+ */
17
+ unionOneOf?: boolean;
18
+ /**
19
+ * Used to output this Zod Schema in the components schemas section. Any usage of this Zod Schema will then be transformed into a $ref.
20
+ */
21
+ ref?: string;
22
+ /**
23
+ * Used when you are manually adding a Zod Schema to the components section. This controls whether this should be rendered as request (`input`) or response (`output`). Defaults to `output`
24
+ */
25
+ refType?: CreationType;
26
+ /**
27
+ * Used to set the created type of an effect.
28
+ */
29
+ effectType?: CreationType | (z.input<T> extends z.output<T> ? z.output<T> extends z.input<T> ? 'same' : never : never);
30
+ /**
31
+ * Used to set metadata for a parameter, request header or cookie
32
+ */
33
+ param?: Partial<ParameterObject> & {
34
+ example?: TInferred;
35
+ examples?: Record<string, (ExampleObject & {
36
+ value: TInferred;
37
+ }) | ReferenceObject>;
38
+ /**
39
+ * Used to output this Zod Schema in the components parameters section. Any usage of this Zod Schema will then be transformed into a $ref.
40
+ */
41
+ ref?: string;
42
+ };
43
+ /**
44
+ * Used to set data for a response header
45
+ */
46
+ header?: Partial<HeaderObject & HeaderObject$1> & {
47
+ /**
48
+ * Used to output this Zod Schema in the components headers section. Any usage of this Zod Schema will then be transformed into a $ref.
49
+ */
50
+ ref?: string;
51
+ };
52
+ /**
53
+ * Used to override the generated type. If this is provided no metadata will be generated.
54
+ */
55
+ type?: SchemaObject['type'];
56
+ }
57
+ interface ZodOpenApiExtendMetadata {
58
+ extends: ZodObject<any, any, any, any, any>;
59
+ }
60
+ declare module 'zod' {
61
+ interface ZodType {
62
+ /**
63
+ * Add OpenAPI metadata to a Zod Type
64
+ */
65
+ openapi<T extends ZodTypeAny>(this: T, metadata: ZodOpenApiMetadata<T>): T;
66
+ }
67
+ interface ZodTypeDef {
68
+ /**
69
+ * OpenAPI metadata
70
+ */
71
+ openapi?: ZodOpenApiMetadata<ZodTypeAny>;
72
+ }
73
+ interface ZodObjectDef {
74
+ extendMetadata?: ZodOpenApiExtendMetadata;
75
+ }
76
+ }