Public
fiberplaneHonoZodStarter
Script
99
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
import { z } from "https://esm.sh/@hono/zod-openapi@0.18.4";
// Schema that defines presence of an ID in the path
export const UserIdPathParamSchema = z.object({
id: z
.coerce
.number()
.openapi({ example: 1 }),
});
// Schema that defines the body of a request to create a new user
export const NewUserSchema = z
.object({
name: z.string().min(2).max(50).openapi({ example: "Mark Scout" }),
email: z.string().email().openapi({ example: "mark@lumen.co" }),
age: z.number().int().min(18).max(120).openapi({ example: 35 }),
}).openapi("NewUser");
// Schema that defines the response of a request to get a user
export const UserSchema = z
.object({
id: z.number().int(),
name: z.string().openapi({ example: "Mark Scout" }),
email: z.string().email().openapi({ example: "mark@lumen.co" }),
age: z.number().int().openapi({ example: 35 }),
}).openapi("User");
export const UpdateUserSchema = z
.object({
name: z.string().optional().openapi({
example: "Marcus Scoutius",
}),
age: z.number().int().optional().openapi({
example: 53,
}),
})
H
index.ts