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 CHANGED
@@ -33,8 +33,6 @@ pnpm install zod zod-openapi
33
33
 
34
34
  This mutates Zod to add an extra `.openapi()` method. Call this at the top of your entry point(s).
35
35
 
36
- #### Automatic
37
-
38
36
  ```ts
39
37
  import 'zod-openapi/extend';
40
38
  import { z } from 'zod';
@@ -1 +1 @@
1
- export type * from './extendZod';
1
+ export * from './extendZodTypes';
@@ -1,76 +1,3 @@
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
- }
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.1",
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}",