-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.ts
More file actions
121 lines (113 loc) · 3.31 KB
/
schemas.ts
File metadata and controls
121 lines (113 loc) · 3.31 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
import { z } from 'zod'
export const ParameterSchema = z.object({
name: z.string(),
in: z.enum(['query', 'header', 'path', 'cookie']),
description: z.string().default(''),
required: z.boolean().default(false),
schema: z
.object({
type: z.string(),
format: z.string().optional(),
})
.optional(),
deprecated: z.boolean().default(false),
'x-undocumented': z.string().default(''),
'x-deprecated': z.string().default(''),
'x-draft': z.string().default(''),
})
const ResponseSchema = z.record(
z.string(),
z.object({
description: z.string(),
content: z
.record(
z.string(),
z.object({
schema: z.object({
$ref: z.string().optional(),
type: z.string().optional(),
items: z
.object({
$ref: z.string(),
})
.optional(),
}),
}),
)
.optional(),
}),
)
export const AuthMethodSchema = z
.enum([
'api_key',
'client_session',
'console_session_token_with_workspace',
'console_session_token_without_workspace',
'pat_with_workspace',
'pat_without_workspace',
'publishable_key',
'unknown',
])
.catch('unknown')
export const OpenapiOperationSchema = z.object({
operationId: z.string(),
summary: z.string().optional(),
description: z.string().default(''),
parameters: z.array(ParameterSchema).optional(),
requestBody: z
.object({
content: z.record(
z.string(),
z.object({
schema: z.object({
$ref: z.string().optional(),
type: z.string().optional(),
}),
}),
),
})
.optional(),
responses: ResponseSchema,
security: z
.array(z.record(z.string().pipe(AuthMethodSchema), z.array(z.never())))
.default([]),
deprecated: z.boolean().default(false),
'x-response-key': z.string().nullable().optional(),
'x-title': z.string().default(''),
'x-undocumented': z.string().default(''),
'x-deprecated': z.string().default(''),
'x-draft': z.string().default(''),
})
export const EnumValueSchema = z.object({
description: z.string().default(''),
undocumented: z.string().default(''),
deprecated: z.string().default(''),
draft: z.string().default(''),
})
export const PropertySchema: z.ZodSchema<any> = z.object({
type: z.enum(['string', 'number', 'integer', 'boolean', 'array', 'object']),
description: z.string().default(''),
deprecated: z.boolean().default(false),
'x-undocumented': z.string().default(''),
'x-deprecated': z.string().default(''),
'x-draft': z.string().default(''),
enum: z.array(z.string().or(z.boolean())).optional(),
'x-enums': z.record(z.string(), EnumValueSchema).optional(),
$ref: z.string().optional(),
format: z.string().optional(),
})
export const ResourceSchema = z.object({
type: z.literal('object'),
properties: z.record(z.string(), PropertySchema),
required: z.array(z.string()).default([]),
description: z.string().default(''),
'x-route-path': z.string().default(''),
'x-undocumented': z.string().default(''),
'x-deprecated': z.string().default(''),
'x-draft': z.string().default(''),
})
export const EventResourceSchema = z.object({
'x-route-path': z.string().default(''),
discriminator: z.object({ propertyName: z.string() }),
oneOf: z.array(ResourceSchema),
})