zod-openapi 3.0.1 → 3.1.1
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 +92 -11
- package/dist/components.chunk.cjs +205 -103
- package/dist/components.chunk.mjs +205 -103
- package/dist/create/components.d.ts +2 -2
- package/dist/create/content.d.ts +2 -1
- package/dist/create/document.d.ts +12 -2
- package/dist/create/parameters.d.ts +2 -2
- package/dist/create/schema/single.d.ts +28 -0
- package/dist/extendZodTypes.d.ts +1 -1
- package/dist/index.cjs +34 -4
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +35 -5
- package/package.json +6 -6
package/dist/create/content.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ZodType } from 'zod';
|
|
2
2
|
import { SchemaObject, ReferenceObject } from '../openapi3-ts/dist/model/openapi31.js';
|
|
3
3
|
import { ComponentsObject, CreationType } from './components.js';
|
|
4
|
+
import { CreateDocumentOptions } from './document.js';
|
|
4
5
|
|
|
5
|
-
declare const createMediaTypeSchema: (schemaObject: ZodType | SchemaObject | ReferenceObject | undefined, components: ComponentsObject, type: CreationType, subpath: string[]) => SchemaObject | ReferenceObject | undefined;
|
|
6
|
+
declare const createMediaTypeSchema: (schemaObject: ZodType | SchemaObject | ReferenceObject | undefined, components: ComponentsObject, type: CreationType, subpath: string[], documentOptions?: CreateDocumentOptions) => SchemaObject | ReferenceObject | undefined;
|
|
6
7
|
|
|
7
8
|
export { createMediaTypeSchema };
|
|
@@ -73,6 +73,16 @@ interface ZodOpenApiObject extends Omit<OpenAPIObject, 'openapi' | 'paths' | 'we
|
|
|
73
73
|
components?: ZodOpenApiComponentsObject;
|
|
74
74
|
}
|
|
75
75
|
type ZodObjectInputType<Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Record<string, unknown>> = ZodType<Output, Def, Input>;
|
|
76
|
-
|
|
76
|
+
interface CreateDocumentOptions {
|
|
77
|
+
/**
|
|
78
|
+
* Used to change the default Zod Date schema
|
|
79
|
+
*/
|
|
80
|
+
defaultDateSchema?: Pick<SchemaObject, 'type' | 'format'>;
|
|
81
|
+
/**
|
|
82
|
+
* Used to set the output of a ZodUnion to be `oneOf` instead of `allOf`
|
|
83
|
+
*/
|
|
84
|
+
unionOneOf?: boolean;
|
|
85
|
+
}
|
|
86
|
+
declare const createDocument: (zodOpenApiObject: ZodOpenApiObject, documentOptions?: CreateDocumentOptions) => OpenAPIObject;
|
|
77
87
|
|
|
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 };
|
|
88
|
+
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 };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ZodType } from 'zod';
|
|
2
2
|
import { ParameterObject, ReferenceObject } from '../openapi3-ts/dist/model/openapi31.js';
|
|
3
3
|
import { ComponentsObject } from './components.js';
|
|
4
|
-
import { ZodOpenApiParameters } from './document.js';
|
|
4
|
+
import { ZodOpenApiParameters, CreateDocumentOptions } from './document.js';
|
|
5
5
|
|
|
6
|
-
declare const createParamOrRef: (zodSchema: ZodType, components: ComponentsObject, subpath: string[], type?: keyof ZodOpenApiParameters, name?: string) => ParameterObject | ReferenceObject;
|
|
6
|
+
declare const createParamOrRef: (zodSchema: ZodType, components: ComponentsObject, subpath: string[], type?: keyof ZodOpenApiParameters, name?: string, documentOptions?: CreateDocumentOptions) => ParameterObject | ReferenceObject;
|
|
7
7
|
|
|
8
8
|
export { createParamOrRef };
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
declare const createSchema: (zodType: ZodType, opts?: CreateSchemaOptions) => SchemaResult;
|
|
27
|
+
|
|
28
|
+
export { type CreateSchemaOptions, type SchemaResult, createSchema };
|
package/dist/extendZodTypes.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ interface ZodOpenApiMetadata<T extends ZodTypeAny, TInferred = z.input<T> | z.ou
|
|
|
20
20
|
*/
|
|
21
21
|
ref?: string;
|
|
22
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`
|
|
23
|
+
* Used when you are manually adding a Zod Schema to the components section. This controls whether this should be rendered as a request (`input`) or response (`output`). Defaults to `output`
|
|
24
24
|
*/
|
|
25
25
|
refType?: CreationType;
|
|
26
26
|
/**
|
package/dist/index.cjs
CHANGED
|
@@ -2,15 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const components = require("./components.chunk.cjs");
|
|
4
4
|
const extendZod = require("./extendZod.chunk.cjs");
|
|
5
|
-
const createDocument = (zodOpenApiObject) => {
|
|
5
|
+
const createDocument = (zodOpenApiObject, documentOptions) => {
|
|
6
6
|
const { paths, webhooks, components: components$1 = {}, ...rest } = zodOpenApiObject;
|
|
7
7
|
const defaultComponents = components.getDefaultComponents(
|
|
8
8
|
components$1,
|
|
9
9
|
zodOpenApiObject.openapi
|
|
10
10
|
);
|
|
11
|
-
const createdPaths = components.createPaths(paths, defaultComponents);
|
|
12
|
-
const createdWebhooks = components.createPaths(
|
|
13
|
-
|
|
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
|
+
);
|
|
14
22
|
return {
|
|
15
23
|
...rest,
|
|
16
24
|
...createdPaths && { paths: createdPaths },
|
|
@@ -18,6 +26,27 @@ const createDocument = (zodOpenApiObject) => {
|
|
|
18
26
|
...createdComponents && { components: createdComponents }
|
|
19
27
|
};
|
|
20
28
|
};
|
|
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
|
+
};
|
|
21
50
|
const oas30 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
22
51
|
__proto__: null
|
|
23
52
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -26,5 +55,6 @@ const oas31 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
26
55
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
27
56
|
exports.extendZodWithOpenApi = extendZod.extendZodWithOpenApi;
|
|
28
57
|
exports.createDocument = createDocument;
|
|
58
|
+
exports.createSchema = createSchema;
|
|
29
59
|
exports.oas30 = oas30;
|
|
30
60
|
exports.oas31 = oas31;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { ZodObjectInputType, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiVersion, createDocument } from './create/document.js';
|
|
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';
|
|
2
3
|
export { extendZodWithOpenApi } from './extendZod.js';
|
|
3
4
|
import * as oas30 from './openapi3-ts/dist/oas30.js';
|
|
4
5
|
export { oas30 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { ZodObjectInputType, ZodOpenApiCallbackObject, ZodOpenApiCallbacksObject, ZodOpenApiComponentsObject, ZodOpenApiContentObject, ZodOpenApiMediaTypeObject, ZodOpenApiObject, ZodOpenApiOperationObject, ZodOpenApiParameters, ZodOpenApiPathItemObject, ZodOpenApiPathsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiResponsesObject, ZodOpenApiVersion, createDocument } from './create/document.js';
|
|
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';
|
|
2
3
|
export { extendZodWithOpenApi } from './extendZod.js';
|
|
3
4
|
import * as oas30 from './openapi3-ts/dist/oas30.js';
|
|
4
5
|
export { oas30 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import { getDefaultComponents, createPaths, createComponents } from "./components.chunk.mjs";
|
|
1
|
+
import { getDefaultComponents, createPaths, createComponents, createSchema as createSchema$1, createSchemaComponents } from "./components.chunk.mjs";
|
|
2
2
|
import { extendZodWithOpenApi } from "./extendZod.chunk.mjs";
|
|
3
|
-
const createDocument = (zodOpenApiObject) => {
|
|
3
|
+
const createDocument = (zodOpenApiObject, documentOptions) => {
|
|
4
4
|
const { paths, webhooks, components = {}, ...rest } = zodOpenApiObject;
|
|
5
5
|
const defaultComponents = getDefaultComponents(
|
|
6
6
|
components,
|
|
7
7
|
zodOpenApiObject.openapi
|
|
8
8
|
);
|
|
9
|
-
const createdPaths = createPaths(paths, defaultComponents);
|
|
10
|
-
const createdWebhooks = createPaths(
|
|
11
|
-
|
|
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
|
+
);
|
|
12
20
|
return {
|
|
13
21
|
...rest,
|
|
14
22
|
...createdPaths && { paths: createdPaths },
|
|
@@ -16,6 +24,27 @@ const createDocument = (zodOpenApiObject) => {
|
|
|
16
24
|
...createdComponents && { components: createdComponents }
|
|
17
25
|
};
|
|
18
26
|
};
|
|
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
|
+
};
|
|
19
48
|
const oas30 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
20
49
|
__proto__: null
|
|
21
50
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -24,6 +53,7 @@ const oas31 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
|
|
|
24
53
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
25
54
|
export {
|
|
26
55
|
createDocument,
|
|
56
|
+
createSchema,
|
|
27
57
|
extendZodWithOpenApi,
|
|
28
58
|
oas30,
|
|
29
59
|
oas31
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-openapi",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Convert Zod Schemas to OpenAPI v3.x documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -72,13 +72,13 @@
|
|
|
72
72
|
"test:watch": "skuba test --watch"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@arethetypeswrong/cli": "0.16.
|
|
75
|
+
"@arethetypeswrong/cli": "0.16.4",
|
|
76
76
|
"@crackle/cli": "0.15.5",
|
|
77
|
-
"@redocly/cli": "1.25.
|
|
77
|
+
"@redocly/cli": "1.25.5",
|
|
78
78
|
"@types/node": "^20.3.0",
|
|
79
|
-
"eslint-plugin-zod-openapi": "^0.
|
|
79
|
+
"eslint-plugin-zod-openapi": "^1.0.0-beta.0",
|
|
80
80
|
"openapi3-ts": "4.4.0",
|
|
81
|
-
"skuba": "
|
|
81
|
+
"skuba": "9.0.1",
|
|
82
82
|
"yaml": "2.5.1",
|
|
83
83
|
"zod": "3.23.8"
|
|
84
84
|
},
|
|
@@ -97,6 +97,6 @@
|
|
|
97
97
|
"entryPoint": "src/index.ts",
|
|
98
98
|
"template": "oss-npm-package",
|
|
99
99
|
"type": "package",
|
|
100
|
-
"version": "
|
|
100
|
+
"version": "9.0.0-main-20240928013837"
|
|
101
101
|
}
|
|
102
102
|
}
|