zod-openapi 5.0.0-beta.3 → 5.0.0-beta.5

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,65 +1,125 @@
1
- import { $ZodType } from 'zod/v4/core';
2
- import { SchemaObject, ReferenceObject, HeaderObject, RequestBodyObject, ResponseObject, ParameterObject, PathItemObject, ComponentsObject } from '../openapi3-ts/dist/model/openapi31.js';
3
- import { ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiCallbackObject, ZodOpenApiPathItemObject, CreateDocumentOptions, ZodOpenApiComponentsObject } from './document.js';
1
+ import { ZodType } from 'zod';
2
+ import { SchemaObject as SchemaObject$1, ReferenceObject as ReferenceObject$1, ParameterObject as ParameterObject$1, HeaderObject as HeaderObject$1, RequestBodyObject as RequestBodyObject$1, ResponseObject as ResponseObject$1, CallbackObject as CallbackObject$1 } from '../openapi3-ts/dist/model/openapi30.js';
3
+ import { SchemaObject, ReferenceObject, ParameterLocation, ParameterObject, HeaderObject, RequestBodyObject, ResponseObject, CallbackObject, ComponentsObject as ComponentsObject$1 } from '../openapi3-ts/dist/model/openapi31.js';
4
+ import { ZodOpenApiComponentsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiCallbackObject, ZodOpenApiVersion, CreateDocumentOptions } from './document.js';
4
5
 
5
- interface ComponentRegistry {
6
- /**
7
- * Contains a map of component name to their OpenAPI schema object or reference.
8
- */
9
- schemas: {
10
- dynamicSchemaCount: number;
11
- input: Map<string, {
12
- zodType: $ZodType;
13
- schemaObject: SchemaObject | ReferenceObject;
14
- }>;
15
- output: Map<string, {
16
- zodType: $ZodType;
17
- schemaObject: SchemaObject | ReferenceObject;
18
- }>;
19
- ids: Map<string, SchemaObject | ReferenceObject>;
20
- manual: Map<string, {
21
- identifier: string;
22
- io: {
23
- input: {
24
- used: number;
25
- schemaObject: SchemaObject;
26
- };
27
- output: {
28
- used: number;
29
- schemaObject: SchemaObject;
30
- };
31
- };
32
- zodType: $ZodType;
33
- }>;
34
- setSchema: (key: string, schema: $ZodType, io: 'input' | 'output') => SchemaObject | ReferenceObject;
35
- };
36
- headers: {
37
- ids: Map<string, HeaderObject | ReferenceObject>;
38
- seen: WeakMap<$ZodType, HeaderObject | ReferenceObject>;
39
- };
40
- requestBodies: {
41
- ids: Map<string, RequestBodyObject | ReferenceObject>;
42
- seen: WeakMap<ZodOpenApiRequestBodyObject, RequestBodyObject | ReferenceObject>;
43
- };
44
- responses: {
45
- ids: Map<string, ResponseObject | ReferenceObject>;
46
- seen: WeakMap<ZodOpenApiResponseObject, ResponseObject | ReferenceObject>;
47
- };
48
- parameters: {
49
- ids: Map<string, ParameterObject | ReferenceObject>;
50
- seen: WeakMap<$ZodType, ParameterObject | ReferenceObject>;
51
- };
52
- callbacks: {
53
- ids: Map<string, ZodOpenApiCallbackObject | ReferenceObject>;
54
- seen: WeakMap<ZodOpenApiCallbackObject, ZodOpenApiCallbackObject | ReferenceObject>;
55
- };
56
- pathItems: {
57
- ids: Map<string, PathItemObject | ReferenceObject>;
58
- seen: WeakMap<ZodOpenApiPathItemObject, PathItemObject | ReferenceObject>;
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[];
59
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;
60
120
  }
61
- declare const createRegistry: (components?: ZodOpenApiComponentsObject) => ComponentRegistry;
62
- declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions) => ComponentsObject;
121
+ declare const getDefaultComponents: (componentsObject?: ZodOpenApiComponentsObject, openapi?: ZodOpenApiVersion) => ComponentsObject;
122
+ declare const createComponents: (componentsObject: ZodOpenApiComponentsObject, components: ComponentsObject, documentOptions?: CreateDocumentOptions) => ComponentsObject$1 | undefined;
63
123
 
64
- export { createComponents, createRegistry };
65
- export type { ComponentRegistry };
124
+ export { createComponents, getDefaultComponents };
125
+ export type { BaseCallbackComponent, CallbackComponent, CallbackComponentMap, CompleteCallbackComponent, CompleteHeaderComponent, CompleteParameterComponent, CompleteRequestBodyComponent, CompleteResponseComponent, CompleteSchemaComponent, ComponentEffect, ComponentsObject, CreationType, Effect, HeaderComponent, HeaderComponentMap, InProgressSchemaComponent, ManualSchemaComponent, ParameterComponent, ParameterComponentMap, PartialCallbackComponent, PartialHeaderComponent, PartialParameterComponent, PartialRequestBodyComponent, PartialResponseComponent, RequestBodyComponent, RequestBodyComponentMap, ResolvedEffect, ResponseComponent, ResponseComponentMap, SchemaComponent, SchemaComponentMap, SchemaEffect };
@@ -1,10 +1,8 @@
1
- import { MediaTypeObject } from '../openapi3-ts/dist/model/openapi31.js';
2
- import { ComponentRegistry } from './components.js';
3
- import { ZodOpenApiMediaTypeObject } from './document.js';
1
+ import { ZodType } from 'zod';
2
+ import { SchemaObject, ReferenceObject } from '../openapi3-ts/dist/model/openapi31.js';
3
+ import { ComponentsObject, CreationType } from './components.js';
4
+ import { CreateDocumentOptions } from './document.js';
4
5
 
5
- declare const createMediaTypeObject: (mediaTypeObject: ZodOpenApiMediaTypeObject, ctx: {
6
- registry: ComponentRegistry;
7
- io: "input" | "output";
8
- }, path: string[]) => MediaTypeObject;
6
+ declare const createMediaTypeSchema: (schemaObject: ZodType | SchemaObject | ReferenceObject | undefined, components: ComponentsObject, type: CreationType, subpath: string[], documentOptions?: CreateDocumentOptions) => SchemaObject | ReferenceObject | undefined;
9
7
 
10
- export { createMediaTypeObject };
8
+ export { createMediaTypeSchema };
@@ -1,50 +1,48 @@
1
- import { ZodTypeDef, ZodType } from 'zod';
2
- import { $ZodType, $ZodTypes } from 'zod/v4/core';
1
+ import { ZodType, AnyZodObject, ZodTypeDef } from 'zod';
3
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, PathItemObject as PathItemObject$1, OperationObject as OperationObject$1, ParameterObject as ParameterObject$1, ComponentsObject as ComponentsObject$1, SchemaObject as SchemaObject$1, HeaderObject as HeaderObject$1 } from '../openapi3-ts/dist/model/openapi30.js';
4
4
  import { ISpecificationExtension } from '../openapi3-ts/dist/model/specification-extension.js';
5
- import { RequestBodyObject, MediaTypeObject, SchemaObject, ReferenceObject, ResponseObject, HeadersObject, PathItemObject, OperationObject, ParameterObject, ParameterLocation, HeaderObject, ComponentsObject, OpenAPIObject } from '../openapi3-ts/dist/model/openapi31.js';
6
- import { Override } from '../zod.js';
5
+ import { MediaTypeObject, SchemaObject, ReferenceObject, RequestBodyObject, ResponseObject, HeadersObject as HeadersObject$1, ParameterLocation, PathItemObject, OperationObject, ParameterObject, ComponentsObject, HeaderObject, OpenAPIObject } from '../openapi3-ts/dist/model/openapi31.js';
7
6
 
8
- interface ZodOpenApiMediaTypeObject extends Omit<MediaTypeObject, 'schema'> {
9
- schema?: $ZodType | SchemaObject | ReferenceObject;
7
+ interface ZodOpenApiMediaTypeObject extends Omit<MediaTypeObject & MediaTypeObject$1, 'schema'> {
8
+ schema?: ZodType | SchemaObject | ReferenceObject;
10
9
  }
11
10
  interface ZodOpenApiContentObject {
12
11
  'application/json'?: ZodOpenApiMediaTypeObject;
13
12
  [mediatype: string]: ZodOpenApiMediaTypeObject | undefined;
14
13
  }
15
- interface ZodOpenApiRequestBodyObject extends Omit<RequestBodyObject, 'content'> {
14
+ interface ZodOpenApiRequestBodyObject extends Omit<RequestBodyObject & RequestBodyObject$1, 'content'> {
16
15
  content: ZodOpenApiContentObject;
17
16
  /** Use this field to auto register this request body as a component */
18
- id?: string;
17
+ ref?: string;
19
18
  }
20
- type ZodOpenApiHeadersObject = ZodObjectInput | HeadersObject;
21
- interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers'> {
19
+ interface ZodOpenApiResponseObject extends Omit<ResponseObject & ResponseObject$1, 'content' | 'headers'> {
22
20
  content?: ZodOpenApiContentObject;
23
- headers?: ZodOpenApiHeadersObject;
21
+ headers?: AnyZodObject | HeadersObject | HeadersObject$1;
24
22
  /** Use this field to auto register this response object as a component */
25
- id?: string;
23
+ ref?: string;
26
24
  }
27
25
  interface ZodOpenApiResponsesObject extends ISpecificationExtension {
28
- default?: ZodOpenApiResponseObject | ReferenceObject;
26
+ default?: ZodOpenApiResponseObject | ReferenceObject | ReferenceObject$1;
29
27
  [statuscode: `${1 | 2 | 3 | 4 | 5}${string}`]: ZodOpenApiResponseObject | ReferenceObject;
30
28
  }
31
- type ZodOpenApiParameters = Partial<Record<ParameterLocation, ZodObjectInput>>;
29
+ type ZodOpenApiParameters = Partial<Record<ParameterLocation & ParameterLocation$1, ZodObjectInputType>>;
32
30
  interface ZodOpenApiCallbacksObject extends ISpecificationExtension {
33
31
  [name: string]: ZodOpenApiCallbackObject;
34
32
  }
35
33
  interface ZodOpenApiCallbackObject extends ISpecificationExtension {
36
34
  /** Use this field to auto register this callback object as a component */
37
- id?: string;
35
+ ref?: string;
38
36
  [name: string]: ZodOpenApiPathItemObject | string | undefined;
39
37
  }
40
- interface ZodOpenApiOperationObject extends Omit<OperationObject, 'requestBody' | 'responses' | 'parameters' | 'callbacks'> {
41
- parameters?: Array<$ZodType | ParameterObject | ReferenceObject>;
38
+ interface ZodOpenApiOperationObject extends Omit<OperationObject & OperationObject$1, 'requestBody' | 'responses' | 'parameters' | 'callbacks'> {
39
+ parameters?: Array<ZodType | ParameterObject | ParameterObject$1 | ReferenceObject | ReferenceObject$1>;
42
40
  requestBody?: ZodOpenApiRequestBodyObject;
43
41
  requestParams?: ZodOpenApiParameters;
44
42
  responses: ZodOpenApiResponsesObject;
45
43
  callbacks?: ZodOpenApiCallbacksObject;
46
44
  }
47
- interface ZodOpenApiPathItemObject extends Omit<PathItemObject, 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace'> {
45
+ interface ZodOpenApiPathItemObject extends Omit<PathItemObject & PathItemObject$1, 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace'> {
48
46
  get?: ZodOpenApiOperationObject;
49
47
  put?: ZodOpenApiOperationObject;
50
48
  post?: ZodOpenApiOperationObject;
@@ -53,26 +51,17 @@ interface ZodOpenApiPathItemObject extends Omit<PathItemObject, 'get' | 'put' |
53
51
  head?: ZodOpenApiOperationObject;
54
52
  patch?: ZodOpenApiOperationObject;
55
53
  trace?: ZodOpenApiOperationObject;
56
- /**
57
- * Used to register this path item as a component.
58
- */
59
- id?: string;
60
54
  }
61
55
  interface ZodOpenApiPathsObject extends ISpecificationExtension {
62
56
  [path: string]: ZodOpenApiPathItemObject;
63
57
  }
64
- type ZodOpenApiParameterObject = $ZodType | ParameterObject | ReferenceObject;
65
- type ZodOpenApiHeaderObject = $ZodType | HeaderObject | ReferenceObject;
66
- type ZodOpenApiSchemaObject = $ZodType | SchemaObject | ReferenceObject;
67
- type ZodOpenApiRequestBody = $ZodType | RequestBodyObject | ReferenceObject;
68
- interface ZodOpenApiComponentsObject extends Omit<ComponentsObject, 'schemas' | 'responses' | 'requestBodies' | 'headers' | 'parameters' | 'pathItems' | 'callbacks'> {
69
- parameters?: Record<string, ZodOpenApiParameterObject>;
70
- schemas?: Record<string, ZodOpenApiSchemaObject>;
58
+ interface ZodOpenApiComponentsObject extends Omit<ComponentsObject & ComponentsObject$1, 'schemas' | 'responses' | 'requestBodies' | 'headers' | 'parameters'> {
59
+ parameters?: Record<string, ZodType | ParameterObject | ParameterObject$1 | ReferenceObject | ReferenceObject$1>;
60
+ schemas?: Record<string, ZodType | SchemaObject | ReferenceObject | SchemaObject$1 | ReferenceObject$1>;
71
61
  requestBodies?: Record<string, ZodOpenApiRequestBodyObject>;
72
- headers?: Record<string, ZodOpenApiHeaderObject>;
62
+ headers?: Record<string, ZodType | HeaderObject | HeaderObject$1 | ReferenceObject | ReferenceObject$1>;
73
63
  responses?: Record<string, ZodOpenApiResponseObject>;
74
64
  callbacks?: Record<string, ZodOpenApiCallbackObject>;
75
- pathItems?: Record<string, ZodOpenApiPathItemObject>;
76
65
  }
77
66
  type ZodOpenApiVersion = OpenApiVersion;
78
67
  interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'webhooks' | 'components'> {
@@ -82,16 +71,21 @@ interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'we
82
71
  components?: ZodOpenApiComponentsObject;
83
72
  }
84
73
  type ZodObjectInputType<Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Record<string, unknown>> = ZodType<Output, Def, Input>;
85
- type ZodObjectInput = $ZodType<unknown, Record<string, unknown>>;
86
- type OverrideType = $ZodTypes['_zod']['def']['type'];
87
74
  interface CreateDocumentOptions {
88
75
  /**
89
- * Use to override the rendered schema
76
+ * Used to throw an error if a Discriminated Union member is not registered as a component
77
+ */
78
+ enforceDiscriminatedUnionComponents?: boolean;
79
+ /**
80
+ * Used to change the default Zod Date schema
81
+ */
82
+ defaultDateSchema?: Pick<SchemaObject, 'type' | 'format'>;
83
+ /**
84
+ * Used to set the output of a ZodUnion to be `oneOf` instead of `anyOf`
90
85
  */
91
- override?: Override;
92
- allowEmptySchema?: Partial<Record<OverrideType, true>>;
86
+ unionOneOf?: boolean;
93
87
  }
94
- declare const createDocument: (zodOpenApiObject: ZodOpenApiObject, opts?: CreateDocumentOptions) => OpenAPIObject;
88
+ declare const createDocument: (zodOpenApiObject: ZodOpenApiObject, documentOptions?: CreateDocumentOptions) => OpenAPIObject;
95
89
 
96
90
  export { createDocument };
97
- export type { CreateDocumentOptions, ZodObjectInput, ZodObjectInputType, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBody, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion };
91
+ export type { CreateDocumentOptions, ZodObjectInputType, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiVersion };
@@ -1,14 +1,9 @@
1
- import { $ZodType } from 'zod/v4/core';
2
- import { ParameterLocation, ParameterObject, ReferenceObject } from '../openapi3-ts/dist/model/openapi31.js';
3
- import { ComponentRegistry } from './components.js';
4
- import '../zod.js';
1
+ import { ZodType, AnyZodObject } from 'zod';
2
+ import { ParameterObject, ReferenceObject } from '../openapi3-ts/dist/model/openapi31.js';
3
+ import { ComponentsObject } from './components.js';
4
+ import { ZodOpenApiParameters, CreateDocumentOptions, ZodObjectInputType } from './document.js';
5
5
 
6
- declare const createParameter: (parameter: $ZodType, location: {
7
- in: ParameterLocation;
8
- name: string;
9
- } | undefined, ctx: {
10
- registry: ComponentRegistry;
11
- io: "input" | "output";
12
- }, path: string[]) => ParameterObject | ReferenceObject;
6
+ declare const createParamOrRef: (zodSchema: ZodType, components: ComponentsObject, subpath: string[], type?: keyof ZodOpenApiParameters, name?: string, documentOptions?: CreateDocumentOptions) => ParameterObject | ReferenceObject;
7
+ declare const getZodObject: (schema: ZodObjectInputType, type: "input" | "output") => AnyZodObject;
13
8
 
14
- export { createParameter };
9
+ export { createParamOrRef, getZodObject };
@@ -0,0 +1,33 @@
1
+ import { ZodType } from 'zod';
2
+ import { OpenApiVersion } from '../../openapi.js';
3
+ import { SchemaObject } from '../../openapi3-ts/dist/model/openapi30.js';
4
+ import { SchemaObject as SchemaObject$1, ReferenceObject } from '../../openapi3-ts/dist/model/openapi31.js';
5
+ import { CreationType } from '../components.js';
6
+ import { CreateDocumentOptions } from '../document.js';
7
+
8
+ interface SchemaResult {
9
+ schema: SchemaObject | SchemaObject$1 | ReferenceObject;
10
+ components?: Record<string, SchemaObject | SchemaObject$1 | ReferenceObject> | undefined;
11
+ }
12
+ interface CreateSchemaOptions extends CreateDocumentOptions {
13
+ /**
14
+ * This controls whether this should be rendered as a request (`input`) or response (`output`). Defaults to `output`
15
+ */
16
+ schemaType?: CreationType;
17
+ /**
18
+ * OpenAPI version to use, defaults to `'3.1.0'`
19
+ */
20
+ openapi?: OpenApiVersion;
21
+ /**
22
+ * Additional components to use and create while rendering the schema
23
+ */
24
+ components?: Record<string, ZodType>;
25
+ /**
26
+ * The $ref path to use for the component. Defaults to `#/components/schemas/`
27
+ */
28
+ componentRefPath?: string;
29
+ }
30
+ declare const createSchema: (zodType: ZodType, opts?: CreateSchemaOptions) => SchemaResult;
31
+
32
+ export { createSchema };
33
+ export type { CreateSchemaOptions, SchemaResult };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ const zod = require("zod");
3
+ const extendZod = require("./extendZod.chunk.cjs");
4
+ extendZod.extendZodWithOpenApi(zod.z);
@@ -0,0 +1 @@
1
+ import './extendZodTypes.js';
@@ -0,0 +1 @@
1
+ import './extendZodTypes.js';
@@ -0,0 +1,3 @@
1
+ import { z } from "zod";
2
+ import { extendZodWithOpenApi } from "./extendZod.chunk.mjs";
3
+ extendZodWithOpenApi(z);
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ const extendZodSymbols = require("./extendZodSymbols.chunk.cjs");
3
+ const mergeOpenApi = (openapi, {
4
+ ref: _ref,
5
+ refType: _refType,
6
+ param: _param,
7
+ header: _header,
8
+ ...rest
9
+ } = {}) => ({
10
+ ...rest,
11
+ ...openapi
12
+ });
13
+ function extendZodWithOpenApi(zod) {
14
+ if (typeof zod.ZodType.prototype.openapi !== "undefined") {
15
+ return;
16
+ }
17
+ zod.ZodType.prototype.openapi = function(openapi) {
18
+ const { zodOpenApi, ...rest } = this._def;
19
+ const result = new this.constructor({
20
+ ...rest,
21
+ zodOpenApi: {
22
+ openapi: mergeOpenApi(
23
+ openapi,
24
+ zodOpenApi == null ? void 0 : zodOpenApi.openapi
25
+ )
26
+ }
27
+ });
28
+ result._def.zodOpenApi[extendZodSymbols.currentSymbol] = result;
29
+ if (zodOpenApi) {
30
+ result._def.zodOpenApi[extendZodSymbols.previousSymbol] = this;
31
+ }
32
+ return result;
33
+ };
34
+ const zodDescribe = zod.ZodType.prototype.describe;
35
+ zod.ZodType.prototype.describe = function(...args) {
36
+ const result = zodDescribe.apply(this, args);
37
+ const def = result._def;
38
+ if (def.zodOpenApi) {
39
+ const cloned = { ...def.zodOpenApi };
40
+ cloned.openapi = mergeOpenApi({ description: args[0] }, cloned.openapi);
41
+ cloned[extendZodSymbols.previousSymbol] = this;
42
+ cloned[extendZodSymbols.currentSymbol] = result;
43
+ def.zodOpenApi = cloned;
44
+ } else {
45
+ def.zodOpenApi = {
46
+ openapi: { description: args[0] },
47
+ [extendZodSymbols.currentSymbol]: result
48
+ };
49
+ }
50
+ return result;
51
+ };
52
+ const zodObjectExtend = zod.ZodObject.prototype.extend;
53
+ zod.ZodObject.prototype.extend = function(...args) {
54
+ const extendResult = zodObjectExtend.apply(this, args);
55
+ const zodOpenApi = extendResult._def.zodOpenApi;
56
+ if (zodOpenApi) {
57
+ const cloned = { ...zodOpenApi };
58
+ cloned.openapi = mergeOpenApi({}, cloned.openapi);
59
+ cloned[extendZodSymbols.previousSymbol] = this;
60
+ extendResult._def.zodOpenApi = cloned;
61
+ } else {
62
+ extendResult._def.zodOpenApi = {
63
+ [extendZodSymbols.previousSymbol]: this
64
+ };
65
+ }
66
+ return extendResult;
67
+ };
68
+ const zodObjectOmit = zod.ZodObject.prototype.omit;
69
+ zod.ZodObject.prototype.omit = function(...args) {
70
+ const omitResult = zodObjectOmit.apply(this, args);
71
+ const zodOpenApi = omitResult._def.zodOpenApi;
72
+ if (zodOpenApi) {
73
+ const cloned = { ...zodOpenApi };
74
+ cloned.openapi = mergeOpenApi({}, cloned.openapi);
75
+ delete cloned[extendZodSymbols.previousSymbol];
76
+ delete cloned[extendZodSymbols.currentSymbol];
77
+ omitResult._def.zodOpenApi = cloned;
78
+ }
79
+ return omitResult;
80
+ };
81
+ const zodObjectPick = zod.ZodObject.prototype.pick;
82
+ zod.ZodObject.prototype.pick = function(...args) {
83
+ const pickResult = zodObjectPick.apply(this, args);
84
+ const zodOpenApi = pickResult._def.zodOpenApi;
85
+ if (zodOpenApi) {
86
+ const cloned = { ...zodOpenApi };
87
+ cloned.openapi = mergeOpenApi({}, cloned.openapi);
88
+ delete cloned[extendZodSymbols.previousSymbol];
89
+ delete cloned[extendZodSymbols.currentSymbol];
90
+ pickResult._def.zodOpenApi = cloned;
91
+ }
92
+ return pickResult;
93
+ };
94
+ }
95
+ exports.extendZodWithOpenApi = extendZodWithOpenApi;
@@ -0,0 +1,96 @@
1
+ import { currentSymbol, previousSymbol } from "./extendZodSymbols.chunk.mjs";
2
+ const mergeOpenApi = (openapi, {
3
+ ref: _ref,
4
+ refType: _refType,
5
+ param: _param,
6
+ header: _header,
7
+ ...rest
8
+ } = {}) => ({
9
+ ...rest,
10
+ ...openapi
11
+ });
12
+ function extendZodWithOpenApi(zod) {
13
+ if (typeof zod.ZodType.prototype.openapi !== "undefined") {
14
+ return;
15
+ }
16
+ zod.ZodType.prototype.openapi = function(openapi) {
17
+ const { zodOpenApi, ...rest } = this._def;
18
+ const result = new this.constructor({
19
+ ...rest,
20
+ zodOpenApi: {
21
+ openapi: mergeOpenApi(
22
+ openapi,
23
+ zodOpenApi == null ? void 0 : zodOpenApi.openapi
24
+ )
25
+ }
26
+ });
27
+ result._def.zodOpenApi[currentSymbol] = result;
28
+ if (zodOpenApi) {
29
+ result._def.zodOpenApi[previousSymbol] = this;
30
+ }
31
+ return result;
32
+ };
33
+ const zodDescribe = zod.ZodType.prototype.describe;
34
+ zod.ZodType.prototype.describe = function(...args) {
35
+ const result = zodDescribe.apply(this, args);
36
+ const def = result._def;
37
+ if (def.zodOpenApi) {
38
+ const cloned = { ...def.zodOpenApi };
39
+ cloned.openapi = mergeOpenApi({ description: args[0] }, cloned.openapi);
40
+ cloned[previousSymbol] = this;
41
+ cloned[currentSymbol] = result;
42
+ def.zodOpenApi = cloned;
43
+ } else {
44
+ def.zodOpenApi = {
45
+ openapi: { description: args[0] },
46
+ [currentSymbol]: result
47
+ };
48
+ }
49
+ return result;
50
+ };
51
+ const zodObjectExtend = zod.ZodObject.prototype.extend;
52
+ zod.ZodObject.prototype.extend = function(...args) {
53
+ const extendResult = zodObjectExtend.apply(this, args);
54
+ const zodOpenApi = extendResult._def.zodOpenApi;
55
+ if (zodOpenApi) {
56
+ const cloned = { ...zodOpenApi };
57
+ cloned.openapi = mergeOpenApi({}, cloned.openapi);
58
+ cloned[previousSymbol] = this;
59
+ extendResult._def.zodOpenApi = cloned;
60
+ } else {
61
+ extendResult._def.zodOpenApi = {
62
+ [previousSymbol]: this
63
+ };
64
+ }
65
+ return extendResult;
66
+ };
67
+ const zodObjectOmit = zod.ZodObject.prototype.omit;
68
+ zod.ZodObject.prototype.omit = function(...args) {
69
+ const omitResult = zodObjectOmit.apply(this, args);
70
+ const zodOpenApi = omitResult._def.zodOpenApi;
71
+ if (zodOpenApi) {
72
+ const cloned = { ...zodOpenApi };
73
+ cloned.openapi = mergeOpenApi({}, cloned.openapi);
74
+ delete cloned[previousSymbol];
75
+ delete cloned[currentSymbol];
76
+ omitResult._def.zodOpenApi = cloned;
77
+ }
78
+ return omitResult;
79
+ };
80
+ const zodObjectPick = zod.ZodObject.prototype.pick;
81
+ zod.ZodObject.prototype.pick = function(...args) {
82
+ const pickResult = zodObjectPick.apply(this, args);
83
+ const zodOpenApi = pickResult._def.zodOpenApi;
84
+ if (zodOpenApi) {
85
+ const cloned = { ...zodOpenApi };
86
+ cloned.openapi = mergeOpenApi({}, cloned.openapi);
87
+ delete cloned[previousSymbol];
88
+ delete cloned[currentSymbol];
89
+ pickResult._def.zodOpenApi = cloned;
90
+ }
91
+ return pickResult;
92
+ };
93
+ }
94
+ export {
95
+ extendZodWithOpenApi
96
+ };
@@ -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,5 @@
1
+ "use strict";
2
+ const currentSymbol = Symbol("current");
3
+ const previousSymbol = Symbol("previous");
4
+ exports.currentSymbol = currentSymbol;
5
+ exports.previousSymbol = previousSymbol;
@@ -0,0 +1,6 @@
1
+ const currentSymbol = Symbol("current");
2
+ const previousSymbol = Symbol("previous");
3
+ export {
4
+ currentSymbol,
5
+ previousSymbol
6
+ };
@@ -0,0 +1,4 @@
1
+ declare const currentSymbol: unique symbol;
2
+ declare const previousSymbol: unique symbol;
3
+
4
+ export { currentSymbol, previousSymbol };