zod-openapi 2.17.0-beta.1 → 2.17.0-beta.2
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 +0 -2
- package/lib-types/extend.d.ts +1 -1
- package/lib-types/extendZod.d.ts +2 -75
- package/lib-types/extendZodTypes.d.ts +75 -0
- package/package.json +9 -1
package/README.md
CHANGED
package/lib-types/extend.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './extendZodTypes';
|
package/lib-types/extendZod.d.ts
CHANGED
|
@@ -1,76 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
import type { oas30, oas31 } from './openapi3-ts/dist';
|
|
4
|
-
type SchemaObject = oas30.SchemaObject & oas31.SchemaObject;
|
|
5
|
-
/**
|
|
6
|
-
* zod-openapi metadata
|
|
7
|
-
*/
|
|
8
|
-
interface ZodOpenApiMetadata<T extends ZodTypeAny, TInferred = z.input<T> | z.output<T>> extends SchemaObject {
|
|
9
|
-
example?: TInferred;
|
|
10
|
-
examples?: [TInferred, ...TInferred[]];
|
|
11
|
-
default?: T extends ZodDate ? string : TInferred;
|
|
12
|
-
/**
|
|
13
|
-
* Used to set the output of a ZodUnion to be `oneOf` instead of `allOf`
|
|
14
|
-
*/
|
|
15
|
-
unionOneOf?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Used to output this Zod Schema in the components schemas section. Any usage of this Zod Schema will then be transformed into a $ref.
|
|
18
|
-
*/
|
|
19
|
-
ref?: string;
|
|
20
|
-
/**
|
|
21
|
-
* 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`
|
|
22
|
-
*/
|
|
23
|
-
refType?: CreationType;
|
|
24
|
-
/**
|
|
25
|
-
* Used to set the created type of an effect.
|
|
26
|
-
*/
|
|
27
|
-
effectType?: CreationType | (z.input<T> extends z.output<T> ? z.output<T> extends z.input<T> ? 'same' : never : never);
|
|
28
|
-
/**
|
|
29
|
-
* Used to set metadata for a parameter, request header or cookie
|
|
30
|
-
*/
|
|
31
|
-
param?: Partial<oas31.ParameterObject> & {
|
|
32
|
-
example?: TInferred;
|
|
33
|
-
examples?: Record<string, (oas31.ExampleObject & {
|
|
34
|
-
value: TInferred;
|
|
35
|
-
}) | oas31.ReferenceObject>;
|
|
36
|
-
/**
|
|
37
|
-
* Used to output this Zod Schema in the components parameters section. Any usage of this Zod Schema will then be transformed into a $ref.
|
|
38
|
-
*/
|
|
39
|
-
ref?: string;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Used to set data for a response header
|
|
43
|
-
*/
|
|
44
|
-
header?: Partial<oas31.HeaderObject & oas30.HeaderObject> & {
|
|
45
|
-
/**
|
|
46
|
-
* Used to output this Zod Schema in the components headers section. Any usage of this Zod Schema will then be transformed into a $ref.
|
|
47
|
-
*/
|
|
48
|
-
ref?: string;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Used to override the generated type. If this is provided no metadata will be generated.
|
|
52
|
-
*/
|
|
53
|
-
type?: SchemaObject['type'];
|
|
54
|
-
}
|
|
55
|
-
interface ZodOpenApiExtendMetadata {
|
|
56
|
-
extends: ZodObject<any, any, any, any, any>;
|
|
57
|
-
}
|
|
58
|
-
declare module 'zod' {
|
|
59
|
-
interface ZodType {
|
|
60
|
-
/**
|
|
61
|
-
* Add OpenAPI metadata to a Zod Type
|
|
62
|
-
*/
|
|
63
|
-
openapi<T extends ZodTypeAny>(this: T, metadata: ZodOpenApiMetadata<T>): T;
|
|
64
|
-
}
|
|
65
|
-
interface ZodTypeDef {
|
|
66
|
-
/**
|
|
67
|
-
* OpenAPI metadata
|
|
68
|
-
*/
|
|
69
|
-
openapi?: ZodOpenApiMetadata<ZodTypeAny>;
|
|
70
|
-
}
|
|
71
|
-
interface ZodObjectDef {
|
|
72
|
-
extendMetadata?: ZodOpenApiExtendMetadata;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import './extendZodTypes';
|
|
75
3
|
export declare function extendZodWithOpenApi(zod: typeof z): void;
|
|
76
|
-
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { ZodDate, ZodObject, ZodTypeAny, z } from 'zod';
|
|
2
|
+
import type { CreationType } from './create/components';
|
|
3
|
+
import type { oas30, oas31 } from './openapi3-ts/dist';
|
|
4
|
+
type SchemaObject = oas30.SchemaObject & oas31.SchemaObject;
|
|
5
|
+
/**
|
|
6
|
+
* zod-openapi metadata
|
|
7
|
+
*/
|
|
8
|
+
interface ZodOpenApiMetadata<T extends ZodTypeAny, TInferred = z.input<T> | z.output<T>> extends SchemaObject {
|
|
9
|
+
example?: TInferred;
|
|
10
|
+
examples?: [TInferred, ...TInferred[]];
|
|
11
|
+
default?: T extends ZodDate ? string : TInferred;
|
|
12
|
+
/**
|
|
13
|
+
* Used to set the output of a ZodUnion to be `oneOf` instead of `allOf`
|
|
14
|
+
*/
|
|
15
|
+
unionOneOf?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Used to output this Zod Schema in the components schemas section. Any usage of this Zod Schema will then be transformed into a $ref.
|
|
18
|
+
*/
|
|
19
|
+
ref?: string;
|
|
20
|
+
/**
|
|
21
|
+
* 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`
|
|
22
|
+
*/
|
|
23
|
+
refType?: CreationType;
|
|
24
|
+
/**
|
|
25
|
+
* Used to set the created type of an effect.
|
|
26
|
+
*/
|
|
27
|
+
effectType?: CreationType | (z.input<T> extends z.output<T> ? z.output<T> extends z.input<T> ? 'same' : never : never);
|
|
28
|
+
/**
|
|
29
|
+
* Used to set metadata for a parameter, request header or cookie
|
|
30
|
+
*/
|
|
31
|
+
param?: Partial<oas31.ParameterObject> & {
|
|
32
|
+
example?: TInferred;
|
|
33
|
+
examples?: Record<string, (oas31.ExampleObject & {
|
|
34
|
+
value: TInferred;
|
|
35
|
+
}) | oas31.ReferenceObject>;
|
|
36
|
+
/**
|
|
37
|
+
* Used to output this Zod Schema in the components parameters section. Any usage of this Zod Schema will then be transformed into a $ref.
|
|
38
|
+
*/
|
|
39
|
+
ref?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Used to set data for a response header
|
|
43
|
+
*/
|
|
44
|
+
header?: Partial<oas31.HeaderObject & oas30.HeaderObject> & {
|
|
45
|
+
/**
|
|
46
|
+
* Used to output this Zod Schema in the components headers section. Any usage of this Zod Schema will then be transformed into a $ref.
|
|
47
|
+
*/
|
|
48
|
+
ref?: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Used to override the generated type. If this is provided no metadata will be generated.
|
|
52
|
+
*/
|
|
53
|
+
type?: SchemaObject['type'];
|
|
54
|
+
}
|
|
55
|
+
interface ZodOpenApiExtendMetadata {
|
|
56
|
+
extends: ZodObject<any, any, any, any, any>;
|
|
57
|
+
}
|
|
58
|
+
declare module 'zod' {
|
|
59
|
+
interface ZodType {
|
|
60
|
+
/**
|
|
61
|
+
* Add OpenAPI metadata to a Zod Type
|
|
62
|
+
*/
|
|
63
|
+
openapi<T extends ZodTypeAny>(this: T, metadata: ZodOpenApiMetadata<T>): T;
|
|
64
|
+
}
|
|
65
|
+
interface ZodTypeDef {
|
|
66
|
+
/**
|
|
67
|
+
* OpenAPI metadata
|
|
68
|
+
*/
|
|
69
|
+
openapi?: ZodOpenApiMetadata<ZodTypeAny>;
|
|
70
|
+
}
|
|
71
|
+
interface ZodObjectDef {
|
|
72
|
+
extendMetadata?: ZodOpenApiExtendMetadata;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-openapi",
|
|
3
|
-
"version": "2.17.0-beta.
|
|
3
|
+
"version": "2.17.0-beta.2",
|
|
4
4
|
"description": "Convert Zod Schemas to OpenAPI v3.x documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -40,6 +40,14 @@
|
|
|
40
40
|
"main": "./lib-commonjs/index.js",
|
|
41
41
|
"module": "./lib-esm/index.mjs",
|
|
42
42
|
"types": "./lib-types/index.d.ts",
|
|
43
|
+
"typesVersions": {
|
|
44
|
+
"*": {
|
|
45
|
+
"*": [
|
|
46
|
+
"lib-types/index.d.ts",
|
|
47
|
+
"lib-types/extend.d.ts"
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
},
|
|
43
51
|
"files": [
|
|
44
52
|
"lib*/**/*.d.ts",
|
|
45
53
|
"lib*/**/*.{js,mjs}{,.map}",
|