zod-openapi 2.12.0 → 2.14.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.
- package/README.md +13 -11
- package/lib-commonjs/index.js +708 -292
- package/lib-esm/{index.js → index.mjs} +708 -292
- package/lib-types/create/components.d.ts +25 -2
- package/lib-types/create/document.d.ts +3 -2
- package/lib-types/create/parameters.d.ts +3 -2
- package/lib-types/create/schema/index.d.ts +19 -12
- package/lib-types/create/schema/metadata.d.ts +2 -1
- package/lib-types/create/schema/parsers/array.d.ts +2 -3
- package/lib-types/create/schema/parsers/boolean.d.ts +2 -2
- package/lib-types/create/schema/parsers/brand.d.ts +2 -3
- package/lib-types/create/schema/parsers/catch.d.ts +2 -3
- package/lib-types/create/schema/parsers/date.d.ts +2 -2
- package/lib-types/create/schema/parsers/default.d.ts +2 -3
- package/lib-types/create/schema/parsers/discriminatedUnion.d.ts +2 -2
- package/lib-types/create/schema/parsers/enum.d.ts +2 -2
- package/lib-types/create/schema/parsers/index.d.ts +2 -3
- package/lib-types/create/schema/parsers/intersection.d.ts +2 -3
- package/lib-types/create/schema/parsers/lazy.d.ts +2 -3
- package/lib-types/create/schema/parsers/literal.d.ts +2 -2
- package/lib-types/create/schema/parsers/manual.d.ts +2 -3
- package/lib-types/create/schema/parsers/nativeEnum.d.ts +2 -3
- package/lib-types/create/schema/parsers/null.d.ts +2 -2
- package/lib-types/create/schema/parsers/nullable.d.ts +2 -3
- package/lib-types/create/schema/parsers/number.d.ts +2 -2
- package/lib-types/create/schema/parsers/object.d.ts +14 -6
- package/lib-types/create/schema/parsers/optional.d.ts +9 -4
- package/lib-types/create/schema/parsers/pipeline.d.ts +2 -3
- package/lib-types/create/schema/parsers/preprocess.d.ts +2 -3
- package/lib-types/create/schema/parsers/readonly.d.ts +2 -3
- package/lib-types/create/schema/parsers/record.d.ts +2 -3
- package/lib-types/create/schema/parsers/refine.d.ts +2 -3
- package/lib-types/create/schema/parsers/set.d.ts +2 -3
- package/lib-types/create/schema/parsers/string.d.ts +2 -2
- package/lib-types/create/schema/parsers/transform.d.ts +8 -4
- package/lib-types/create/schema/parsers/tuple.d.ts +2 -3
- package/lib-types/create/schema/parsers/union.d.ts +2 -3
- package/lib-types/create/schema/parsers/unknown.d.ts +2 -2
- package/lib-types/extendZod.d.ts +26 -7
- package/lib-types/openapi3-ts/dist/model/openapi31.d.ts +1 -1
- package/package.json +17 -11
|
@@ -2,11 +2,34 @@ import type { ZodType } from 'zod';
|
|
|
2
2
|
import type { oas30, oas31 } from '../openapi3-ts/dist';
|
|
3
3
|
import type { ZodOpenApiComponentsObject, ZodOpenApiRequestBodyObject, ZodOpenApiResponseObject, ZodOpenApiVersion } from './document';
|
|
4
4
|
export type CreationType = 'input' | 'output';
|
|
5
|
+
type BaseEffect = {
|
|
6
|
+
zodType: ZodType;
|
|
7
|
+
path: string[];
|
|
8
|
+
};
|
|
9
|
+
export type ComponentEffect = BaseEffect & {
|
|
10
|
+
type: 'component';
|
|
11
|
+
};
|
|
12
|
+
export type SchemaEffect = BaseEffect & {
|
|
13
|
+
type: 'schema';
|
|
14
|
+
creationType: CreationType;
|
|
15
|
+
};
|
|
16
|
+
export type Effect = ComponentEffect | SchemaEffect;
|
|
17
|
+
export type ResolvedEffect = {
|
|
18
|
+
creationType: CreationType;
|
|
19
|
+
path: string[];
|
|
20
|
+
zodType: ZodType;
|
|
21
|
+
component?: {
|
|
22
|
+
ref: string;
|
|
23
|
+
zodType: ZodType;
|
|
24
|
+
path: string[];
|
|
25
|
+
};
|
|
26
|
+
};
|
|
5
27
|
export interface CompleteSchemaComponent extends BaseSchemaComponent {
|
|
6
28
|
type: 'complete';
|
|
7
29
|
schemaObject: oas31.SchemaObject | oas31.ReferenceObject | oas30.SchemaObject | oas30.ReferenceObject;
|
|
8
|
-
/** Set when the created schemaObject is specific to a particular
|
|
9
|
-
|
|
30
|
+
/** Set when the created schemaObject is specific to a particular effect */
|
|
31
|
+
effects?: Effect[];
|
|
32
|
+
resolvedEffect?: ResolvedEffect;
|
|
10
33
|
}
|
|
11
34
|
/**
|
|
12
35
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyZodObject, ZodType } from 'zod';
|
|
1
|
+
import type { AnyZodObject, ZodType, ZodTypeDef } from 'zod';
|
|
2
2
|
import type { OpenApiVersion } from '../openapi';
|
|
3
3
|
import type { oas30, oas31 } from '../openapi3-ts/dist';
|
|
4
4
|
export interface ZodOpenApiMediaTypeObject extends Omit<oas31.MediaTypeObject & oas30.MediaTypeObject, 'schema'> {
|
|
@@ -24,7 +24,7 @@ export interface ZodOpenApiResponsesObject extends oas31.ISpecificationExtension
|
|
|
24
24
|
[statuscode: `${1 | 2 | 3 | 4 | 5}${string}`]: ZodOpenApiResponseObject | oas31.ReferenceObject;
|
|
25
25
|
}
|
|
26
26
|
export type ZodOpenApiParameters = {
|
|
27
|
-
[type in oas31.ParameterLocation & oas30.ParameterLocation]?:
|
|
27
|
+
[type in oas31.ParameterLocation & oas30.ParameterLocation]?: ZodObjectInputType;
|
|
28
28
|
};
|
|
29
29
|
export interface ZodOpenApiOperationObject extends Omit<oas31.OperationObject & oas30.OperationObject, 'requestBody' | 'responses' | 'parameters'> {
|
|
30
30
|
parameters?: Array<ZodType | oas31.ParameterObject | oas30.ParameterObject | oas31.ReferenceObject | oas30.ReferenceObject>;
|
|
@@ -59,4 +59,5 @@ export interface ZodOpenApiObject extends Omit<oas31.OpenAPIObject, 'openapi' |
|
|
|
59
59
|
webhooks?: ZodOpenApiPathsObject;
|
|
60
60
|
components?: ZodOpenApiComponentsObject;
|
|
61
61
|
}
|
|
62
|
+
export type ZodObjectInputType<Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Record<string, unknown>> = ZodType<Output, Def, Input>;
|
|
62
63
|
export declare const createDocument: (zodOpenApiObject: ZodOpenApiObject) => oas31.OpenAPIObject;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { ZodType } from 'zod';
|
|
1
|
+
import type { AnyZodObject, ZodType } from 'zod';
|
|
2
2
|
import type { oas30, oas31 } from '../openapi3-ts/dist';
|
|
3
3
|
import type { ComponentsObject } from './components';
|
|
4
|
-
import type { ZodOpenApiParameters } from './document';
|
|
4
|
+
import type { ZodObjectInputType, ZodOpenApiParameters } from './document';
|
|
5
5
|
export declare const createComponentParamRef: (ref: string) => string;
|
|
6
6
|
export declare const createBaseParameter: (schema: ZodType, components: ComponentsObject, subpath: string[]) => oas31.BaseParameterObject;
|
|
7
7
|
export declare const createParamOrRef: (zodSchema: ZodType, components: ComponentsObject, subpath: string[], type?: keyof ZodOpenApiParameters, name?: string) => oas31.ParameterObject | oas31.ReferenceObject;
|
|
8
8
|
export declare const createManualParameters: (parameters: Array<oas31.ParameterObject | oas31.ReferenceObject | oas30.ParameterObject | oas30.ReferenceObject | ZodType> | undefined, components: ComponentsObject, subpath: string[]) => Array<oas31.ParameterObject | oas31.ReferenceObject>;
|
|
9
9
|
export declare const createParametersObject: (parameters: Array<oas31.ParameterObject | oas31.ReferenceObject | oas30.ParameterObject | oas30.ReferenceObject | ZodType> | undefined, requestParams: ZodOpenApiParameters | undefined, components: ComponentsObject, subpath: string[]) => Array<oas31.ParameterObject | oas31.ReferenceObject> | undefined;
|
|
10
|
+
export declare const getZodObject: (schema: ZodObjectInputType, type: 'input' | 'output') => AnyZodObject;
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import type { ZodType, ZodTypeDef } from 'zod';
|
|
2
2
|
import type { oas31 } from '../../openapi3-ts/dist';
|
|
3
|
-
import { type ComponentsObject, type CreationType, type SchemaComponent } from '../components';
|
|
3
|
+
import { type ComponentsObject, type CreationType, type Effect, type SchemaComponent } from '../components';
|
|
4
4
|
export type LazyMap = Map<ZodType, true>;
|
|
5
5
|
export interface SchemaState {
|
|
6
6
|
components: ComponentsObject;
|
|
7
7
|
type: CreationType;
|
|
8
|
-
effectType?: CreationType;
|
|
9
8
|
path: string[];
|
|
10
9
|
visited: Set<ZodType>;
|
|
11
10
|
}
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
schema: oas31.ReferenceObject | oas31.SchemaObject;
|
|
18
|
-
newState: SchemaState;
|
|
11
|
+
export declare const createNewSchema: <Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => Schema;
|
|
12
|
+
export declare const createNewRef: <Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(ref: string, zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => Schema;
|
|
13
|
+
export declare const createExistingRef: <Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, component: SchemaComponent | undefined, state: SchemaState) => Schema | undefined;
|
|
14
|
+
export type BaseObject = {
|
|
15
|
+
effects?: Effect[];
|
|
19
16
|
};
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
export type RefObject = BaseObject & {
|
|
18
|
+
type: 'ref';
|
|
19
|
+
schema: oas31.ReferenceObject;
|
|
20
|
+
zodType: ZodType;
|
|
21
|
+
};
|
|
22
|
+
export type SchemaObject = BaseObject & {
|
|
23
|
+
type: 'schema';
|
|
24
|
+
schema: oas31.SchemaObject;
|
|
25
|
+
};
|
|
26
|
+
export type Schema = SchemaObject | RefObject;
|
|
27
|
+
export declare const createSchemaOrRef: <Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => Schema;
|
|
28
|
+
export declare const createSchemaObject: <Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState, subpath: string[]) => Schema;
|
|
29
|
+
export declare const createSchema: <Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState, subpath: string[]) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { oas31 } from '../../openapi3-ts/dist';
|
|
2
|
-
|
|
2
|
+
import type { Schema } from '.';
|
|
3
|
+
export declare const enhanceWithMetadata: (schema: Schema, metadata: oas31.SchemaObject | oas31.ReferenceObject) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ArrayCardinality, ZodArray, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createArraySchema: <T extends ZodTypeAny, Cardinality extends ArrayCardinality = "many">(zodArray: ZodArray<T, Cardinality>, state: SchemaState) => oas31.SchemaObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createArraySchema: <T extends ZodTypeAny, Cardinality extends ArrayCardinality = "many">(zodArray: ZodArray<T, Cardinality>, state: SchemaState) => Schema;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ZodBoolean } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const createBooleanSchema: (_zodBoolean: ZodBoolean) =>
|
|
2
|
+
import type { Schema } from '..';
|
|
3
|
+
export declare const createBooleanSchema: (_zodBoolean: ZodBoolean) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodBranded, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createBrandedSchema: <T extends ZodTypeAny, B extends string | number | symbol>(zodBranded: ZodBranded<T, B>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createBrandedSchema: <T extends ZodTypeAny, B extends string | number | symbol>(zodBranded: ZodBranded<T, B>, state: SchemaState) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodCatch, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createCatchSchema: <T extends ZodTypeAny>(zodCatch: ZodCatch<T>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createCatchSchema: <T extends ZodTypeAny>(zodCatch: ZodCatch<T>, state: SchemaState) => Schema;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ZodDate } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const createDateSchema: (_zodDate: ZodDate) =>
|
|
2
|
+
import type { Schema } from '..';
|
|
3
|
+
export declare const createDateSchema: (_zodDate: ZodDate) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodDefault, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createDefaultSchema: <T extends ZodTypeAny>(zodDefault: ZodDefault<T>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createDefaultSchema: <T extends ZodTypeAny>(zodDefault: ZodDefault<T>, state: SchemaState) => Schema;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyZodObject, ZodDiscriminatedUnion, ZodDiscriminatedUnionOption } from 'zod';
|
|
2
2
|
import type { oas31 } from '../../../openapi3-ts/dist';
|
|
3
|
-
import { type SchemaState } from '../../schema';
|
|
4
|
-
export declare const createDiscriminatedUnionSchema: <Discriminator extends string, Options extends ZodDiscriminatedUnionOption<Discriminator>[]>(zodDiscriminatedUnion: ZodDiscriminatedUnion<Discriminator, Options>, state: SchemaState) =>
|
|
3
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
4
|
+
export declare const createDiscriminatedUnionSchema: <Discriminator extends string, Options extends ZodDiscriminatedUnionOption<Discriminator>[]>(zodDiscriminatedUnion: ZodDiscriminatedUnion<Discriminator, Options>, state: SchemaState) => Schema;
|
|
5
5
|
export declare const mapDiscriminator: (schemas: Array<oas31.SchemaObject | oas31.ReferenceObject>, zodObjects: AnyZodObject[], discriminator: unknown, state: SchemaState) => oas31.SchemaObject['discriminator'];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ZodEnum } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const createEnumSchema: <T extends [string, ...string[]]>(zodEnum: ZodEnum<T>) =>
|
|
2
|
+
import type { Schema } from '..';
|
|
3
|
+
export declare const createEnumSchema: <T extends [string, ...string[]]>(zodEnum: ZodEnum<T>) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodType, ZodTypeDef } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export declare const createSchemaSwitch: <Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
2
|
+
import type { Schema, SchemaState } from '../../schema';
|
|
3
|
+
export declare const createSchemaSwitch: <Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodIntersection, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createIntersectionSchema: <T extends ZodTypeAny, U extends ZodTypeAny>(zodIntersection: ZodIntersection<T, U>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createIntersectionSchema: <T extends ZodTypeAny, U extends ZodTypeAny>(zodIntersection: ZodIntersection<T, U>, state: SchemaState) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodLazy, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createLazySchema: <T extends ZodTypeAny>(zodLazy: ZodLazy<T>, state: SchemaState) => oas31.ReferenceObject | oas31.SchemaObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createLazySchema: <T extends ZodTypeAny>(zodLazy: ZodLazy<T>, state: SchemaState) => Schema;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ZodLiteral } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const createLiteralSchema: (zodLiteral: ZodLiteral<unknown>) =>
|
|
2
|
+
import type { Schema } from '..';
|
|
3
|
+
export declare const createLiteralSchema: (zodLiteral: ZodLiteral<unknown>) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodType, ZodTypeDef } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export declare const createManualTypeSchema: <Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => oas31.SchemaObject;
|
|
2
|
+
import type { Schema, SchemaState } from '../../schema';
|
|
3
|
+
export declare const createManualTypeSchema: <Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => Schema;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { EnumLike, ZodNativeEnum } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export declare const createNativeEnumSchema: <T extends EnumLike>(zodEnum: ZodNativeEnum<T>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
2
|
+
import type { Schema, SchemaState } from '../../schema';
|
|
3
|
+
export declare const createNativeEnumSchema: <T extends EnumLike>(zodEnum: ZodNativeEnum<T>, state: SchemaState) => Schema;
|
|
5
4
|
interface StringsAndNumbers {
|
|
6
5
|
strings: string[];
|
|
7
6
|
numbers: number[];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ZodNull } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const createNullSchema: (_zodNull: ZodNull) =>
|
|
2
|
+
import type { Schema } from '..';
|
|
3
|
+
export declare const createNullSchema: (_zodNull: ZodNull) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodNullable, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createNullableSchema: <T extends ZodTypeAny>(zodNullable: ZodNullable<T>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createNullableSchema: <T extends ZodTypeAny>(zodNullable: ZodNullable<T>, state: SchemaState) => Schema;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ZodNumber, ZodNumberCheck } from 'zod';
|
|
2
2
|
import type { oas30, oas31 } from '../../../openapi3-ts/dist';
|
|
3
3
|
import type { ZodOpenApiVersion } from '../../document';
|
|
4
|
-
import type { SchemaState } from '../../schema';
|
|
5
|
-
export declare const createNumberSchema: (zodNumber: ZodNumber, state: SchemaState) =>
|
|
4
|
+
import type { Schema, SchemaState } from '../../schema';
|
|
5
|
+
export declare const createNumberSchema: (zodNumber: ZodNumber, state: SchemaState) => Schema;
|
|
6
6
|
export declare const mapMaximum: (zodNumberCheck: ZodNumberCheckMap, openapi: ZodOpenApiVersion) => Pick<oas31.SchemaObject | oas30.SchemaObject, 'maximum' | 'exclusiveMaximum'> | undefined;
|
|
7
7
|
export declare const mapMinimum: (zodNumberCheck: ZodNumberCheckMap, openapi: ZodOpenApiVersion) => Pick<oas31.SchemaObject | oas30.SchemaObject, 'minimum' | 'exclusiveMinimum'> | undefined;
|
|
8
8
|
type ZodNumberCheckMap = {
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import type { UnknownKeysParam, ZodObject, ZodRawShape, ZodType, ZodTypeAny, objectInputType, objectOutputType } from 'zod';
|
|
2
2
|
import type { oas31 } from '../../../openapi3-ts/dist';
|
|
3
|
-
import { type
|
|
4
|
-
|
|
5
|
-
export declare const
|
|
3
|
+
import { type Effect } from '../../components';
|
|
4
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
5
|
+
export declare const createObjectSchema: <T extends ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny, Output = objectOutputType<T, Catchall, UnknownKeys>, Input = objectInputType<T, Catchall, UnknownKeys>>(zodObject: ZodObject<T, UnknownKeys, Catchall, Output, Input>, state: SchemaState) => Schema;
|
|
6
|
+
export declare const createExtendedSchema: <T extends ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny, Output = objectOutputType<T, Catchall, UnknownKeys>, Input = objectInputType<T, Catchall, UnknownKeys>>(zodObject: ZodObject<T, UnknownKeys, Catchall, Output, Input>, baseZodObject: ZodObject<T, UnknownKeys, Catchall, Output, Input> | undefined, state: SchemaState) => Schema | undefined;
|
|
6
7
|
interface AdditionalPropertyOptions {
|
|
7
8
|
unknownKeys?: UnknownKeysParam;
|
|
8
9
|
catchAll: ZodType;
|
|
9
10
|
}
|
|
10
|
-
export declare const createObjectSchemaFromShape: (shape: ZodRawShape, { unknownKeys, catchAll }: AdditionalPropertyOptions, state: SchemaState) =>
|
|
11
|
-
export declare const mapRequired: (shape: ZodRawShape, state: SchemaState) =>
|
|
12
|
-
|
|
11
|
+
export declare const createObjectSchemaFromShape: (shape: ZodRawShape, { unknownKeys, catchAll }: AdditionalPropertyOptions, state: SchemaState) => Schema;
|
|
12
|
+
export declare const mapRequired: (shape: ZodRawShape, state: SchemaState) => {
|
|
13
|
+
required: string[];
|
|
14
|
+
effects?: Effect[] | undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
interface PropertyMap {
|
|
17
|
+
properties: NonNullable<oas31.SchemaObject['properties']>;
|
|
18
|
+
effects: Array<Effect[] | undefined>;
|
|
19
|
+
}
|
|
20
|
+
export declare const mapProperties: (shape: ZodRawShape, state: SchemaState) => PropertyMap | undefined;
|
|
13
21
|
export {};
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ZodOptional, ZodTypeAny } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
import { type SchemaState } from '../../schema';
|
|
4
|
-
export declare const createOptionalSchema: <T extends ZodTypeAny>(zodOptional: ZodOptional<T>, state: SchemaState) =>
|
|
5
|
-
|
|
2
|
+
import type { Effect } from '../../components';
|
|
3
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
4
|
+
export declare const createOptionalSchema: <T extends ZodTypeAny>(zodOptional: ZodOptional<T>, state: SchemaState) => Schema;
|
|
5
|
+
type OptionalResult = {
|
|
6
|
+
optional: boolean;
|
|
7
|
+
effects?: Effect[];
|
|
8
|
+
};
|
|
9
|
+
export declare const isOptionalSchema: (zodSchema: ZodTypeAny, state: SchemaState) => OptionalResult;
|
|
10
|
+
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodPipeline, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createPipelineSchema: <A extends ZodTypeAny, B extends ZodTypeAny>(zodPipeline: ZodPipeline<A, B>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createPipelineSchema: <A extends ZodTypeAny, B extends ZodTypeAny>(zodPipeline: ZodPipeline<A, B>, state: SchemaState) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodEffects, ZodTypeAny, input, output } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createPreprocessSchema: <T extends ZodTypeAny, Output = output<T>, Input = input<T>>(zodPreprocess: ZodEffects<T, Output, Input>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createPreprocessSchema: <T extends ZodTypeAny, Output = output<T>, Input = input<T>>(zodPreprocess: ZodEffects<T, Output, Input>, state: SchemaState) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodReadonly, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createReadonlySchema: <T extends ZodTypeAny>(zodReadonly: ZodReadonly<T>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createReadonlySchema: <T extends ZodTypeAny>(zodReadonly: ZodReadonly<T>, state: SchemaState) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { KeySchema, ZodRecord, ZodString, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createRecordSchema: <Key extends KeySchema = ZodString, Value extends ZodTypeAny = ZodTypeAny>(zodRecord: ZodRecord<Key, Value>, state: SchemaState) => oas31.SchemaObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createRecordSchema: <Key extends KeySchema = ZodString, Value extends ZodTypeAny = ZodTypeAny>(zodRecord: ZodRecord<Key, Value>, state: SchemaState) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodEffects, ZodTypeAny, input, output } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createRefineSchema: <T extends ZodTypeAny, Output = output<T>, Input = input<T>>(zodRefine: ZodEffects<T, Output, Input>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createRefineSchema: <T extends ZodTypeAny, Output = output<T>, Input = input<T>>(zodRefine: ZodEffects<T, Output, Input>, state: SchemaState) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodSet, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createSetSchema: <Value extends ZodTypeAny = ZodTypeAny>(zodSet: ZodSet<Value>, state: SchemaState) => oas31.SchemaObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createSetSchema: <Value extends ZodTypeAny = ZodTypeAny>(zodSet: ZodSet<Value>, state: SchemaState) => Schema;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ZodString } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const createStringSchema: (zodString: ZodString) =>
|
|
2
|
+
import type { Schema } from '..';
|
|
3
|
+
export declare const createStringSchema: (zodString: ZodString) => Schema;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import type { ZodEffects,
|
|
1
|
+
import type { ZodEffects, ZodTypeAny, input, output } from 'zod';
|
|
2
2
|
import type { oas31 } from '../../../openapi3-ts/dist';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import type { Effect, ResolvedEffect } from '../../components';
|
|
4
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
5
|
+
export declare const createTransformSchema: <T extends ZodTypeAny, Output = output<T>, Input = input<T>>(zodTransform: ZodEffects<T, Output, Input>, state: SchemaState) => Schema;
|
|
5
6
|
export declare const createManualOutputTransformSchema: <T extends ZodTypeAny, Output = output<T>, Input = input<T>>(zodTransform: ZodEffects<T, Output, Input>, state: SchemaState) => oas31.SchemaObject;
|
|
6
|
-
export declare const throwTransformError: (
|
|
7
|
+
export declare const throwTransformError: (effect: ResolvedEffect) => never;
|
|
8
|
+
export declare const resolveEffect: (effects: Effect[], state: SchemaState) => ResolvedEffect | undefined;
|
|
9
|
+
export declare const verifyEffects: (effects: Effect[], state: SchemaState) => void;
|
|
10
|
+
export declare const flattenEffects: (effects: Array<Effect[] | undefined>) => Effect[] | undefined;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodTuple, ZodTypeAny } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createTupleSchema: <T extends [] | [ZodTypeAny, ...ZodTypeAny[]] = [ZodTypeAny, ...ZodTypeAny[]], Rest extends ZodTypeAny | null = null>(zodTuple: ZodTuple<T, Rest>, state: SchemaState) => oas31.SchemaObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createTupleSchema: <T extends [] | [ZodTypeAny, ...ZodTypeAny[]] = [ZodTypeAny, ...ZodTypeAny[]], Rest extends ZodTypeAny | null = null>(zodTuple: ZodTuple<T, Rest>, state: SchemaState) => Schema;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ZodTypeAny, ZodUnion } from 'zod';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
export declare const createUnionSchema: <T extends readonly [ZodTypeAny, ...ZodTypeAny[]]>(zodUnion: ZodUnion<T>, state: SchemaState) => oas31.SchemaObject;
|
|
2
|
+
import { type Schema, type SchemaState } from '../../schema';
|
|
3
|
+
export declare const createUnionSchema: <T extends readonly [ZodTypeAny, ...ZodTypeAny[]]>(zodUnion: ZodUnion<T>, state: SchemaState) => Schema;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ZodAny, ZodUnknown } from 'zod';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const createUnknownSchema: (_zodUnknown: ZodUnknown | ZodAny) =>
|
|
2
|
+
import type { Schema } from '..';
|
|
3
|
+
export declare const createUnknownSchema: (_zodUnknown: ZodUnknown | ZodAny) => Schema;
|
package/lib-types/extendZod.d.ts
CHANGED
|
@@ -2,51 +2,70 @@ import type { UnknownKeysParam, ZodDate, ZodObject, ZodRawShape, ZodTypeAny, z }
|
|
|
2
2
|
import type { CreationType } from './create/components';
|
|
3
3
|
import type { oas30, oas31 } from './openapi3-ts/dist';
|
|
4
4
|
type SchemaObject = oas30.SchemaObject & oas31.SchemaObject;
|
|
5
|
+
/**
|
|
6
|
+
* zod-openapi metadata
|
|
7
|
+
*/
|
|
5
8
|
interface ZodOpenApiMetadata<T extends ZodTypeAny, TInferred = z.input<T> | z.output<T>> extends SchemaObject {
|
|
6
9
|
example?: TInferred;
|
|
7
10
|
examples?: [TInferred, ...TInferred[]];
|
|
8
11
|
default?: T extends ZodDate ? string : TInferred;
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
13
|
+
* Used to set the output of a ZodUnion to be `oneOf` instead of `allOf`
|
|
11
14
|
*/
|
|
12
15
|
unionOneOf?: boolean;
|
|
13
16
|
/**
|
|
14
|
-
*
|
|
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.
|
|
15
18
|
*/
|
|
16
19
|
ref?: string;
|
|
17
20
|
/**
|
|
18
|
-
*
|
|
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`
|
|
19
22
|
*/
|
|
20
23
|
refType?: CreationType;
|
|
21
24
|
/**
|
|
22
|
-
*
|
|
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
|
|
23
30
|
*/
|
|
24
|
-
effectType?: CreationType;
|
|
25
31
|
param?: Partial<oas31.ParameterObject> & {
|
|
26
32
|
example?: TInferred;
|
|
27
33
|
examples?: Record<string, (oas31.ExampleObject & {
|
|
28
34
|
value: TInferred;
|
|
29
35
|
}) | oas31.ReferenceObject>;
|
|
30
36
|
/**
|
|
31
|
-
*
|
|
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.
|
|
32
38
|
*/
|
|
33
39
|
ref?: string;
|
|
34
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* Used to set data for a response header
|
|
43
|
+
*/
|
|
35
44
|
header?: Partial<oas31.HeaderObject & oas30.HeaderObject> & {
|
|
36
45
|
/**
|
|
37
|
-
*
|
|
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.
|
|
38
47
|
*/
|
|
39
48
|
ref?: string;
|
|
40
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Used to override the generated type. If this is provided no metadata will be generated.
|
|
52
|
+
*/
|
|
53
|
+
type?: SchemaObject['type'];
|
|
41
54
|
}
|
|
42
55
|
interface ZodOpenApiExtendMetadata {
|
|
43
56
|
extends: ZodObject<any, any, any, any, any>;
|
|
44
57
|
}
|
|
45
58
|
declare module 'zod' {
|
|
46
59
|
interface ZodType<Output, Def extends ZodTypeDef, Input = Output> {
|
|
60
|
+
/**
|
|
61
|
+
* Add OpenAPI metadata to a Zod Type
|
|
62
|
+
*/
|
|
47
63
|
openapi<T extends ZodTypeAny>(this: T, metadata: ZodOpenApiMetadata<T>): T;
|
|
48
64
|
}
|
|
49
65
|
interface ZodTypeDef {
|
|
66
|
+
/**
|
|
67
|
+
* OpenAPI metadata
|
|
68
|
+
*/
|
|
50
69
|
openapi?: ZodOpenApiMetadata<ZodTypeAny>;
|
|
51
70
|
}
|
|
52
71
|
interface ZodObjectDef<T extends ZodRawShape = ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam, Catchall extends ZodTypeAny = ZodTypeAny> extends ZodTypeDef {
|
|
@@ -88,7 +88,7 @@ export interface OperationObject extends ISpecificationExtension {
|
|
|
88
88
|
operationId?: string;
|
|
89
89
|
parameters?: (ParameterObject | ReferenceObject)[];
|
|
90
90
|
requestBody?: RequestBodyObject | ReferenceObject;
|
|
91
|
-
responses
|
|
91
|
+
responses?: ResponsesObject;
|
|
92
92
|
callbacks?: CallbacksObject;
|
|
93
93
|
deprecated?: boolean;
|
|
94
94
|
security?: SecurityRequirementObject[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-openapi",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "Convert Zod Schemas to OpenAPI v3.x documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -21,34 +21,40 @@
|
|
|
21
21
|
},
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"sideEffects": false,
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"import": "./lib-esm/index.mjs",
|
|
27
|
+
"require": "./lib-commonjs/index.js",
|
|
28
|
+
"types": "./lib-types/index.d.ts"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
24
31
|
"main": "./lib-commonjs/index.js",
|
|
25
|
-
"module": "./lib-esm/index.
|
|
32
|
+
"module": "./lib-esm/index.mjs",
|
|
26
33
|
"types": "./lib-types/index.d.ts",
|
|
27
34
|
"files": [
|
|
28
35
|
"lib*/**/*.d.ts",
|
|
29
|
-
"lib*/**/*.js",
|
|
30
|
-
"lib*/**/*.js.map",
|
|
36
|
+
"lib*/**/*.{js,mjs}{,.map}",
|
|
31
37
|
"lib*/**/*.json"
|
|
32
38
|
],
|
|
33
39
|
"scripts": {
|
|
34
|
-
"build": "
|
|
40
|
+
"build": "pnpm copy:types && node esbuild.mjs && node esbuild.esm.mjs && tsc --allowJS false --declaration --emitDeclarationOnly --outDir lib-types --project tsconfig.build.json",
|
|
35
41
|
"copy:types": "skuba node scripts/copyTypes.ts",
|
|
36
42
|
"create:docs": " skuba node examples/simple/createSchema.ts && redocly build-docs examples/simple/openapi.yml --output=examples/simple/redoc-static.html",
|
|
37
43
|
"format": "skuba format",
|
|
38
44
|
"lint": "skuba lint",
|
|
39
|
-
"prepare": "
|
|
45
|
+
"prepare": "pnpm build",
|
|
40
46
|
"test": "skuba test",
|
|
41
47
|
"test:ci": "skuba test --coverage",
|
|
42
48
|
"test:watch": "skuba test --watch"
|
|
43
49
|
},
|
|
44
50
|
"dependencies": {},
|
|
45
51
|
"devDependencies": {
|
|
46
|
-
"@redocly/cli": "1.
|
|
52
|
+
"@redocly/cli": "1.9.1",
|
|
47
53
|
"@types/node": "^20.3.0",
|
|
48
54
|
"eslint-plugin-zod-openapi": "^0.1.0",
|
|
49
|
-
"openapi3-ts": "4.2.
|
|
50
|
-
"skuba": "7.
|
|
51
|
-
"yaml": "2.
|
|
55
|
+
"openapi3-ts": "4.2.2",
|
|
56
|
+
"skuba": "7.5.0",
|
|
57
|
+
"yaml": "2.4.0",
|
|
52
58
|
"zod": "3.22.4"
|
|
53
59
|
},
|
|
54
60
|
"peerDependencies": {
|
|
@@ -65,6 +71,6 @@
|
|
|
65
71
|
"entryPoint": "src/index.ts",
|
|
66
72
|
"template": "oss-npm-package",
|
|
67
73
|
"type": "package",
|
|
68
|
-
"version": "
|
|
74
|
+
"version": "7.4.1"
|
|
69
75
|
}
|
|
70
76
|
}
|