-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema_utils.ts
More file actions
145 lines (142 loc) · 2.92 KB
/
Copy pathschema_utils.ts
File metadata and controls
145 lines (142 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import {
extendZodWithOpenApi,
type ResponseConfig,
type RouteConfig,
} from "@asteasolutions/zod-to-openapi";
/**
* Open API Schema interface, usable when composing the request/response
* schema for a REST endpoint (declared when using the
* decorators such as {@linkcode Get}, {@linkcode Post}, etc.)
* @example
* ```ts
* import { Get } from "@dklab/oak-routing-ctrl"
*
* const GetItemsSchema: OakOpenApiSpec = {
* responses: {
* "200": { "description": "OK" }
* }
* }
*
* // later inside the Controller Class
* class ExampleClass {
* ;@Get("/", GetItemsSchema)
* async getSomething() {
* //
* }
* }
* ```
*/
export type OakOpenApiSpec =
& Omit<RouteConfig, "method" | "path" | "responses" | "requestBody">
& {
request?: RouteConfig["request"];
responses?: {
[statusCode: string]: ResponseConfig;
};
};
// must import from `npm:` instead of from `deno.land` to be compatible with `@asteasolutions/zod-to-openapi`
import { z as slowTypedZ } from "zod";
extendZodWithOpenApi(slowTypedZ);
type SubsetOfZ = Pick<
typeof slowTypedZ,
| "object"
| "array"
| "string"
| "number"
| "boolean"
| "void"
| "undefined"
| "null"
| "enum"
| "any"
| "bigint"
| "coerce"
| "custom"
| "date"
| "discriminatedUnion"
| "file"
| "base64"
| "base64url"
| "catch"
| "check"
| "clone"
| "decode"
| "decodeAsync"
| "encode"
| "encodeAsync"
| "endsWith"
| "startsWith"
| "stringFormat"
| "uppercase"
| "lowercase"
| "toLowerCase"
| "toUpperCase"
| "url"
| "uuid"
| "uuidv4"
| "uuidv6"
| "uuidv7"
| "safeDecode"
| "safeDecodeAsync"
| "safeEncode"
| "safeEncodeAsync"
| "safeParse"
| "safeParseAsync"
| "regex"
| "refine"
| "regexes"
| "stringbool"
| "config"
| "email"
| "emoji"
| "float32"
| "float64"
| "hex"
| "hash"
| "nan"
| "uint32"
| "uint64"
| "json"
| "jwt"
| "ipv4"
| "ipv6"
| "function"
| "getErrorMap"
| "instanceof"
| "intersection"
| "lazy"
| "literal"
| "map"
| "optional"
| "preprocess"
| "promise"
| "record"
| "set"
| "setErrorMap"
| "strictObject"
| "symbol"
| "tuple"
| "union"
| "unknown"
| "util"
| "ZodError"
>;
/**
* entry to the `Zod` API, enhanced with `@asteasolutions/zod-to-openapi`;
* for usage documentation please refer to https://github.com/asteasolutions/zod-to-openapi?tab=readme-ov-file#purpose-and-quick-example
* @example
* ```ts
* const SomeZodSchema = z.object({ name: z.string() });
* ```
*/
export const z: SubsetOfZ = slowTypedZ;
/**
* re-exported `z.infer` type inference API;
* for usage documentation please refer to https://github.com/colinhacks/zod?tab=readme-ov-file#type-inference
* @example
* ```ts
* const SomeZodSchema = z.object({ name: z.string() });
* const somePathParam: zInfer<typeof SomeZodSchema> = { name: "foo" };
* ```
*/
export type zInfer<T extends slowTypedZ.ZodType> = slowTypedZ.infer<T>;