zod-openapi 4.2.3 → 5.0.0-beta.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.
@@ -1,124 +1,85 @@
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, CreateDocumentOptions, ZodOpenApiResponseObject, ZodOpenApiRequestBodyObject, ZodOpenApiCallbackObject } from './document.js';
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';
5
4
 
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[];
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: {
12
+ seen: WeakMap<$ZodType, {
13
+ type: 'manual';
14
+ id: string;
15
+ schemaObject: SchemaObject | ReferenceObject;
16
+ } | {
17
+ type: 'schema';
18
+ schemaObject: SchemaObject | ReferenceObject;
19
+ }>;
20
+ schemas: Map<string, {
21
+ zodType: $ZodType;
22
+ schemaObject: SchemaObject | ReferenceObject;
23
+ }>;
24
+ };
25
+ output: {
26
+ seen: WeakMap<$ZodType, {
27
+ type: 'manual';
28
+ id: string;
29
+ schemaObject: SchemaObject | ReferenceObject;
30
+ } | {
31
+ type: 'schema';
32
+ schemaObject: SchemaObject | ReferenceObject;
33
+ }>;
34
+ schemas: Map<string, {
35
+ zodType: $ZodType;
36
+ schemaObject: SchemaObject | ReferenceObject;
37
+ }>;
38
+ };
39
+ ids: Map<string, SchemaObject | ReferenceObject>;
40
+ manual: Map<string, {
41
+ key: string;
42
+ io: {
43
+ input: {
44
+ used?: true;
45
+ schemaObject: SchemaObject;
46
+ };
47
+ output: {
48
+ used?: true;
49
+ schemaObject: SchemaObject;
50
+ };
51
+ };
52
+ zodType: $ZodType;
53
+ }>;
54
+ setSchema: (key: string, schema: $ZodType, io: 'input' | 'output') => SchemaObject | ReferenceObject;
55
+ };
56
+ headers: {
57
+ ids: Map<string, HeaderObject | ReferenceObject>;
58
+ seen: WeakMap<$ZodType, HeaderObject | ReferenceObject>;
59
+ };
60
+ requestBodies: {
61
+ ids: Map<string, RequestBodyObject | ReferenceObject>;
62
+ seen: WeakMap<ZodOpenApiRequestBodyObject, RequestBodyObject | ReferenceObject>;
63
+ };
64
+ responses: {
65
+ ids: Map<string, ResponseObject | ReferenceObject>;
66
+ seen: WeakMap<ZodOpenApiResponseObject, ResponseObject | ReferenceObject>;
67
+ };
68
+ parameters: {
69
+ ids: Map<string, ParameterObject | ReferenceObject>;
70
+ seen: WeakMap<$ZodType, ParameterObject | ReferenceObject>;
71
+ };
72
+ callbacks: {
73
+ ids: Map<string, ZodOpenApiCallbackObject | ReferenceObject>;
74
+ seen: WeakMap<ZodOpenApiCallbackObject, ZodOpenApiCallbackObject | ReferenceObject>;
75
+ };
76
+ pathItems: {
77
+ ids: Map<string, PathItemObject | ReferenceObject>;
78
+ seen: WeakMap<ZodOpenApiPathItemObject, PathItemObject | ReferenceObject>;
27
79
  };
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
80
  }
121
- declare const getDefaultComponents: (componentsObject?: ZodOpenApiComponentsObject, openapi?: ZodOpenApiVersion) => ComponentsObject;
122
- declare const createComponents: (componentsObject: ZodOpenApiComponentsObject, components: ComponentsObject, documentOptions?: CreateDocumentOptions) => ComponentsObject$1 | undefined;
81
+ declare const createRegistry: (components?: ZodOpenApiComponentsObject) => ComponentRegistry;
82
+ declare const createComponents: (registry: ComponentRegistry, opts: CreateDocumentOptions) => ComponentsObject;
123
83
 
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 };
84
+ export { createComponents, createRegistry };
85
+ export type { ComponentRegistry };
@@ -1,8 +1,10 @@
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';
1
+ import { MediaTypeObject } from '../openapi3-ts/dist/model/openapi31.js';
2
+ import { ComponentRegistry } from './components.js';
3
+ import { ZodOpenApiMediaTypeObject } from './document.js';
5
4
 
6
- declare const createMediaTypeSchema: (schemaObject: ZodType | SchemaObject | ReferenceObject | undefined, components: ComponentsObject, type: CreationType, subpath: string[], documentOptions?: CreateDocumentOptions) => SchemaObject | ReferenceObject | undefined;
5
+ declare const createMediaTypeObject: (mediaTypeObject: ZodOpenApiMediaTypeObject, ctx: {
6
+ registry: ComponentRegistry;
7
+ io: "input" | "output";
8
+ }, path: string[]) => MediaTypeObject;
7
9
 
8
- export { createMediaTypeSchema };
10
+ export { createMediaTypeObject };
@@ -1,50 +1,50 @@
1
- import { ZodType, AnyZodObject, ZodTypeDef } from 'zod';
1
+ import { ZodTypeDef, ZodType } from 'zod';
2
+ import { $ZodType, $ZodTypes } from 'zod/v4/core';
2
3
  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
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';
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';
6
7
 
7
- interface ZodOpenApiMediaTypeObject extends Omit<MediaTypeObject & MediaTypeObject$1, 'schema'> {
8
- schema?: ZodType | SchemaObject | ReferenceObject;
8
+ interface ZodOpenApiMediaTypeObject extends Omit<MediaTypeObject, 'schema'> {
9
+ schema?: $ZodType | SchemaObject | ReferenceObject;
9
10
  }
10
11
  interface ZodOpenApiContentObject {
11
12
  'application/json'?: ZodOpenApiMediaTypeObject;
12
13
  [mediatype: string]: ZodOpenApiMediaTypeObject | undefined;
13
14
  }
14
- interface ZodOpenApiRequestBodyObject extends Omit<RequestBodyObject & RequestBodyObject$1, 'content'> {
15
+ interface ZodOpenApiRequestBodyObject extends Omit<RequestBodyObject, 'content'> {
15
16
  content: ZodOpenApiContentObject;
16
17
  /** Use this field to auto register this request body as a component */
17
- ref?: string;
18
+ id?: string;
18
19
  }
19
- interface ZodOpenApiResponseObject extends Omit<ResponseObject & ResponseObject$1, 'content' | 'headers'> {
20
+ type ZodOpenApiHeadersObject = ZodObjectInput | HeadersObject;
21
+ interface ZodOpenApiResponseObject extends Omit<ResponseObject, 'content' | 'headers'> {
20
22
  content?: ZodOpenApiContentObject;
21
- headers?: AnyZodObject | HeadersObject | HeadersObject$1;
23
+ headers?: ZodOpenApiHeadersObject;
22
24
  /** Use this field to auto register this response object as a component */
23
- ref?: string;
25
+ id?: string;
24
26
  }
25
27
  interface ZodOpenApiResponsesObject extends ISpecificationExtension {
26
- default?: ZodOpenApiResponseObject | ReferenceObject | ReferenceObject$1;
28
+ default?: ZodOpenApiResponseObject | ReferenceObject;
27
29
  [statuscode: `${1 | 2 | 3 | 4 | 5}${string}`]: ZodOpenApiResponseObject | ReferenceObject;
28
30
  }
29
- type ZodOpenApiParameters = {
30
- [type in ParameterLocation & ParameterLocation$1]?: ZodObjectInputType;
31
- };
31
+ type ZodOpenApiParameters = Partial<Record<ParameterLocation, ZodObjectInput>>;
32
32
  interface ZodOpenApiCallbacksObject extends ISpecificationExtension {
33
33
  [name: string]: ZodOpenApiCallbackObject;
34
34
  }
35
35
  interface ZodOpenApiCallbackObject extends ISpecificationExtension {
36
36
  /** Use this field to auto register this callback object as a component */
37
- ref?: string;
37
+ id?: string;
38
38
  [name: string]: ZodOpenApiPathItemObject | string | undefined;
39
39
  }
40
- interface ZodOpenApiOperationObject extends Omit<OperationObject & OperationObject$1, 'requestBody' | 'responses' | 'parameters' | 'callbacks'> {
41
- parameters?: Array<ZodType | ParameterObject | ParameterObject$1 | ReferenceObject | ReferenceObject$1>;
40
+ interface ZodOpenApiOperationObject extends Omit<OperationObject, 'requestBody' | 'responses' | 'parameters' | 'callbacks'> {
41
+ parameters?: Array<$ZodType | ParameterObject | ReferenceObject>;
42
42
  requestBody?: ZodOpenApiRequestBodyObject;
43
43
  requestParams?: ZodOpenApiParameters;
44
44
  responses: ZodOpenApiResponsesObject;
45
45
  callbacks?: ZodOpenApiCallbacksObject;
46
46
  }
47
- interface ZodOpenApiPathItemObject extends Omit<PathItemObject & PathItemObject$1, 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace'> {
47
+ interface ZodOpenApiPathItemObject extends Omit<PathItemObject, 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace'> {
48
48
  get?: ZodOpenApiOperationObject;
49
49
  put?: ZodOpenApiOperationObject;
50
50
  post?: ZodOpenApiOperationObject;
@@ -53,17 +53,26 @@ interface ZodOpenApiPathItemObject extends Omit<PathItemObject & PathItemObject$
53
53
  head?: ZodOpenApiOperationObject;
54
54
  patch?: ZodOpenApiOperationObject;
55
55
  trace?: ZodOpenApiOperationObject;
56
+ /**
57
+ * Used to register this path item as a component.
58
+ */
59
+ id?: string;
56
60
  }
57
61
  interface ZodOpenApiPathsObject extends ISpecificationExtension {
58
62
  [path: string]: ZodOpenApiPathItemObject;
59
63
  }
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>;
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>;
63
71
  requestBodies?: Record<string, ZodOpenApiRequestBodyObject>;
64
- headers?: Record<string, ZodType | HeaderObject | HeaderObject$1 | ReferenceObject | ReferenceObject$1>;
72
+ headers?: Record<string, ZodOpenApiHeaderObject>;
65
73
  responses?: Record<string, ZodOpenApiResponseObject>;
66
74
  callbacks?: Record<string, ZodOpenApiCallbackObject>;
75
+ pathItems?: Record<string, ZodOpenApiPathItemObject>;
67
76
  }
68
77
  type ZodOpenApiVersion = OpenApiVersion;
69
78
  interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'webhooks' | 'components'> {
@@ -73,20 +82,16 @@ interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'we
73
82
  components?: ZodOpenApiComponentsObject;
74
83
  }
75
84
  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'];
76
87
  interface CreateDocumentOptions {
77
88
  /**
78
- * Used to throw an error if a Discriminated Union member is not registered as a component
79
- */
80
- enforceDiscriminatedUnionComponents?: boolean;
81
- /**
82
- * Used to change the default Zod Date schema
83
- */
84
- defaultDateSchema?: Pick<SchemaObject, 'type' | 'format'>;
85
- /**
86
- * Used to set the output of a ZodUnion to be `oneOf` instead of `anyOf`
89
+ * Use to override the rendered schema
87
90
  */
88
- unionOneOf?: boolean;
91
+ override?: Override;
92
+ allowEmptySchema?: Partial<Record<OverrideType, true>>;
89
93
  }
90
- declare const createDocument: (zodOpenApiObject: ZodOpenApiObject, documentOptions?: CreateDocumentOptions) => OpenAPIObject;
94
+ declare const createDocument: (zodOpenApiObject: ZodOpenApiObject, opts?: CreateDocumentOptions) => OpenAPIObject;
91
95
 
92
- export { type CreateDocumentOptions, 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 };
96
+ 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 };
@@ -0,0 +1,5 @@
1
+ import { $ZodTypes, $ZodObject } from 'zod/v4/core';
2
+
3
+ declare const unwrapZodObject: (zodType: $ZodTypes, io: "input" | "output", path: string[]) => $ZodObject;
4
+
5
+ export { unwrapZodObject };
@@ -1,9 +1,14 @@
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';
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';
5
5
 
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;
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;
8
13
 
9
- export { createParamOrRef, getZodObject };
14
+ export { createParameter };
@@ -0,0 +1,21 @@
1
+ import { core } from 'zod/v4';
2
+ import { CreateDocumentOptions } from '../document.js';
3
+ import { ComponentRegistry } from '../components.js';
4
+ import '../../zod.js';
5
+ import { SchemaObject, ReferenceObject } from '../../openapi3-ts/dist/model/openapi31.js';
6
+
7
+ interface SchemaResult {
8
+ schema: SchemaObject | ReferenceObject;
9
+ components: Record<string, SchemaObject>;
10
+ }
11
+ declare const createSchema: (schema: core.$ZodType, ctx?: {
12
+ registry?: ComponentRegistry;
13
+ io?: "input" | "output";
14
+ opts?: CreateDocumentOptions;
15
+ }) => {
16
+ schema: SchemaObject | ReferenceObject;
17
+ components: Record<string, SchemaObject>;
18
+ };
19
+
20
+ export { createSchema };
21
+ export type { SchemaResult };
package/dist/index.cjs CHANGED
@@ -1,60 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const components = require("./components.chunk.cjs");
4
- const extendZod = require("./extendZod.chunk.cjs");
5
- const createDocument = (zodOpenApiObject, documentOptions) => {
6
- const { paths, webhooks, components: components$1 = {}, ...rest } = zodOpenApiObject;
7
- const defaultComponents = components.getDefaultComponents(
8
- components$1,
9
- zodOpenApiObject.openapi
10
- );
11
- const createdPaths = components.createPaths(paths, defaultComponents, documentOptions);
12
- const createdWebhooks = components.createPaths(
13
- webhooks,
14
- defaultComponents,
15
- documentOptions
16
- );
17
- const createdComponents = components.createComponents(
18
- components$1,
19
- defaultComponents,
20
- documentOptions
21
- );
22
- return {
23
- ...rest,
24
- ...createdPaths && { paths: createdPaths },
25
- ...createdWebhooks && { webhooks: createdWebhooks },
26
- ...createdComponents && { components: createdComponents }
27
- };
4
+ const createDocument = (zodOpenApiObject, opts = {}) => {
5
+ const { paths, webhooks, components: components$1, ...rest } = zodOpenApiObject;
6
+ const document = rest;
7
+ const registry = components.createRegistry(components$1);
8
+ const createdPaths = components.createPaths(paths, registry, ["paths"]);
9
+ if (createdPaths) {
10
+ document.paths = createdPaths;
11
+ }
12
+ const createdWebhooks = components.createPaths(webhooks, registry, ["webhooks"]);
13
+ if (createdWebhooks) {
14
+ document.webhooks = createdWebhooks;
15
+ }
16
+ const createdComponents = components.createComponents(registry, opts);
17
+ if (Object.keys(createdComponents).length > 0) {
18
+ document.components = createdComponents;
19
+ }
20
+ return document;
28
21
  };
29
- const createSchema = (zodType, opts) => {
30
- const components$1 = components.getDefaultComponents(
31
- {
32
- schemas: opts == null ? void 0 : opts.components
33
- },
34
- opts == null ? void 0 : opts.openapi
35
- );
36
- const state = {
37
- components: components$1,
38
- type: (opts == null ? void 0 : opts.schemaType) ?? "output",
39
- path: [],
40
- visited: /* @__PURE__ */ new Set(),
41
- documentOptions: opts
42
- };
43
- const schema = components.createSchema(zodType, state, ["createSchema"]);
44
- const schemaComponents = components.createSchemaComponents({}, components$1);
45
- return {
46
- schema,
47
- components: schemaComponents
48
- };
49
- };
50
- const oas30 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
51
- __proto__: null
52
- }, Symbol.toStringTag, { value: "Module" }));
53
- const oas31 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
54
- __proto__: null
55
- }, Symbol.toStringTag, { value: "Module" }));
56
- exports.extendZodWithOpenApi = extendZod.extendZodWithOpenApi;
22
+ exports.createSchema = components.createSchema;
57
23
  exports.createDocument = createDocument;
58
- exports.createSchema = createSchema;
59
- exports.oas30 = oas30;
60
- exports.oas31 = oas31;
package/dist/index.d.mts CHANGED
@@ -1,7 +1,5 @@
1
- export { CreateDocumentOptions, ZodObjectInputType, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiVersion, createDocument } from './create/document.js';
2
- export { CreateSchemaOptions, SchemaResult, createSchema } from './create/schema/single.js';
3
- export { extendZodWithOpenApi } from './extendZod.js';
4
- import * as oas30 from './openapi3-ts/dist/oas30.js';
5
- export { oas30 };
6
- import * as oas31 from './openapi3-ts/dist/oas31.js';
1
+ export { CreateDocumentOptions, ZodObjectInput, ZodObjectInputType, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBody, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createDocument } from './create/document.js';
2
+ export { SchemaResult, createSchema } from './create/schema/schema.js';
3
+ export { Override, isAnyZodType } from './zod.js';
4
+ import * as oas31 from './openapi3-ts/oas31.js';
7
5
  export { oas31 };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- export { CreateDocumentOptions, ZodObjectInputType, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiVersion, createDocument } from './create/document.js';
2
- export { CreateSchemaOptions, SchemaResult, createSchema } from './create/schema/single.js';
3
- export { extendZodWithOpenApi } from './extendZod.js';
4
- import * as oas30 from './openapi3-ts/dist/oas30.js';
5
- export { oas30 };
6
- import * as oas31 from './openapi3-ts/dist/oas31.js';
1
+ export { CreateDocumentOptions, ZodObjectInput, ZodObjectInputType, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiHeaderObject, ZodOpenApiHeadersObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameterObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBody, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiSchemaObject, ZodOpenApiVersion, createDocument } from './create/document.js';
2
+ export { SchemaResult, createSchema } from './create/schema/schema.js';
3
+ export { Override, isAnyZodType } from './zod.js';
4
+ import * as oas31 from './openapi3-ts/oas31.js';
7
5
  export { oas31 };
package/dist/index.mjs CHANGED
@@ -1,60 +1,24 @@
1
- import { getDefaultComponents, createPaths, createComponents, createSchema as createSchema$1, createSchemaComponents } from "./components.chunk.mjs";
2
- import { extendZodWithOpenApi } from "./extendZod.chunk.mjs";
3
- const createDocument = (zodOpenApiObject, documentOptions) => {
4
- const { paths, webhooks, components = {}, ...rest } = zodOpenApiObject;
5
- const defaultComponents = getDefaultComponents(
6
- components,
7
- zodOpenApiObject.openapi
8
- );
9
- const createdPaths = createPaths(paths, defaultComponents, documentOptions);
10
- const createdWebhooks = createPaths(
11
- webhooks,
12
- defaultComponents,
13
- documentOptions
14
- );
15
- const createdComponents = createComponents(
16
- components,
17
- defaultComponents,
18
- documentOptions
19
- );
20
- return {
21
- ...rest,
22
- ...createdPaths && { paths: createdPaths },
23
- ...createdWebhooks && { webhooks: createdWebhooks },
24
- ...createdComponents && { components: createdComponents }
25
- };
1
+ import { createRegistry, createPaths, createComponents } from "./components.chunk.mjs";
2
+ import { createSchema } from "./components.chunk.mjs";
3
+ const createDocument = (zodOpenApiObject, opts = {}) => {
4
+ const { paths, webhooks, components, ...rest } = zodOpenApiObject;
5
+ const document = rest;
6
+ const registry = createRegistry(components);
7
+ const createdPaths = createPaths(paths, registry, ["paths"]);
8
+ if (createdPaths) {
9
+ document.paths = createdPaths;
10
+ }
11
+ const createdWebhooks = createPaths(webhooks, registry, ["webhooks"]);
12
+ if (createdWebhooks) {
13
+ document.webhooks = createdWebhooks;
14
+ }
15
+ const createdComponents = createComponents(registry, opts);
16
+ if (Object.keys(createdComponents).length > 0) {
17
+ document.components = createdComponents;
18
+ }
19
+ return document;
26
20
  };
27
- const createSchema = (zodType, opts) => {
28
- const components = getDefaultComponents(
29
- {
30
- schemas: opts == null ? void 0 : opts.components
31
- },
32
- opts == null ? void 0 : opts.openapi
33
- );
34
- const state = {
35
- components,
36
- type: (opts == null ? void 0 : opts.schemaType) ?? "output",
37
- path: [],
38
- visited: /* @__PURE__ */ new Set(),
39
- documentOptions: opts
40
- };
41
- const schema = createSchema$1(zodType, state, ["createSchema"]);
42
- const schemaComponents = createSchemaComponents({}, components);
43
- return {
44
- schema,
45
- components: schemaComponents
46
- };
47
- };
48
- const oas30 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
49
- __proto__: null
50
- }, Symbol.toStringTag, { value: "Module" }));
51
- const oas31 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
52
- __proto__: null
53
- }, Symbol.toStringTag, { value: "Module" }));
54
21
  export {
55
22
  createDocument,
56
- createSchema,
57
- extendZodWithOpenApi,
58
- oas30,
59
- oas31
23
+ createSchema
60
24
  };
package/dist/openapi.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- declare const openApiVersions: readonly ["3.0.0", "3.0.1", "3.0.2", "3.0.3", "3.1.0"];
1
+ declare const openApiVersions: readonly ["3.1.0", "3.1.1"];
2
2
  type OpenApiVersion = (typeof openApiVersions)[number];
3
3
 
4
- export { type OpenApiVersion, openApiVersions };
4
+ export { openApiVersions };
5
+ export type { OpenApiVersion };
@@ -59,6 +59,9 @@ interface ComponentsObject extends ISpecificationExtension {
59
59
  callbacks?: {
60
60
  [callback: string]: CallbackObject | ReferenceObject;
61
61
  };
62
+ pathItems?: {
63
+ [pathItem: string]: PathItemObject | ReferenceObject;
64
+ };
62
65
  }
63
66
  interface PathsObject extends ISpecificationExtension {
64
67
  [path: string]: PathItemObject;
@@ -205,6 +208,7 @@ interface ReferenceObject {
205
208
  }
206
209
  type SchemaObjectType = 'integer' | 'number' | 'string' | 'boolean' | 'object' | 'null' | 'array';
207
210
  interface SchemaObject extends ISpecificationExtension {
211
+ $ref?: string;
208
212
  discriminator?: DiscriminatorObject;
209
213
  readOnly?: boolean;
210
214
  writeOnly?: boolean;
@@ -294,4 +298,5 @@ interface SecurityRequirementObject {
294
298
  [name: string]: string[];
295
299
  }
296
300
 
297
- export { type BaseParameterObject, type CallbackObject, type CallbacksObject, type ComponentsObject, type ContactObject, type ContentObject, type DiscriminatorObject, type EncodingObject, type EncodingPropertyObject, type ExampleObject, type ExamplesObject, type ExternalDocumentationObject, type HeaderObject, type HeadersObject, ISpecificationExtension, type InfoObject, type LicenseObject, type LinkObject, type LinkParametersObject, type LinksObject, type MediaTypeObject, type OAuthFlowObject, type OAuthFlowsObject, type OpenAPIObject, type OperationObject, type ParameterLocation, type ParameterObject, type ParameterStyle, type PathItemObject, type PathObject, type PathsObject, type ReferenceObject, type RequestBodyObject, type ResponseObject, type ResponsesObject, type SchemaObject, type SchemaObjectType, type SchemasObject, type ScopesObject, type SecurityRequirementObject, type SecuritySchemeObject, type SecuritySchemeType, ServerObject, type TagObject, type XmlObject };
301
+ export { ISpecificationExtension, ServerObject };
302
+ export type { BaseParameterObject, CallbackObject, CallbacksObject, ComponentsObject, ContactObject, ContentObject, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, TagObject, XmlObject };