-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.ts
93 lines (78 loc) · 2.17 KB
/
model.ts
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
import { z } from 'zod';
import { linkSchema, modelResponseSchema, modelSchema, listRequestSchema } from '../model.js';
const vaccinationSchema = z
.object({
name: z.string().min(1),
})
.strict();
export const petRequestSchema = z
.object({
name: z.string().min(1),
tag: z.string().min(1).optional(),
vaccinations: z.array(vaccinationSchema).optional(),
})
.strict();
export type PetRequest = z.infer<typeof petRequestSchema>;
export const petSchema = z
.object({
...modelSchema.shape,
...petRequestSchema.shape,
})
.strict();
export type Pet = z.infer<typeof petSchema>;
export const petResponseSchema = z
.object({
...modelResponseSchema.shape,
...petRequestSchema.shape,
_links: z
.object({
read: linkSchema.optional(),
update: linkSchema.optional(),
delete: linkSchema.optional(),
})
.optional(),
})
.strict();
export type PetResponse = z.infer<typeof petResponseSchema>;
export const petRequestListSchema = z
.object({
...listRequestSchema.shape,
filters: z.object({ name: z.string().optional() }).strict().default({}),
sort: z
.object({ name: z.enum(['asc', 'desc']).optional() })
.strict()
.default({}),
})
.strict();
export type PetRequestList = z.infer<typeof petRequestListSchema>;
export const petListSchema = z
.object({
...petRequestListSchema.shape,
items: z.array(petSchema),
count: z.number(),
})
.strict();
export type PetList = z.infer<typeof petListSchema>;
export const petListResponseSchema = z
.object({
...petListSchema.shape,
offset: z.number(),
limit: z.number(),
items: z.array(petResponseSchema),
_links: z
.object({
create: linkSchema.optional(),
})
.optional(),
})
.strict();
export type PetListResponse = z.infer<typeof petListResponseSchema>;
export const petRequestListOpenApiSchema = z
.object({
offset: z.number().default(0),
limit: z.number().default(20),
'filters[name]': z.string().optional(),
'sort[name]': z.enum(['asc', 'desc']).optional(),
})
.strict();
export type PetRequestListOpenApi = z.infer<typeof petRequestListOpenApiSchema>;