Add OpenAPI schema generation and validation for API routes
This commit is contained in:
1 parent
5d822e6c7e
commit
5ce5664b29
25 files changed
+2019
-52
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const nullableUuidSchema = z.uuid().nullable();
|
||||
const nullableDateTimeSchema = z.iso.datetime().nullable();
|
||||
|
||||
export const replayConfigSchema = z
|
||||
.looseObject({
|
||||
replayEnabled: z.boolean().optional(),
|
||||
heatmapEnabled: z.boolean().optional(),
|
||||
sampleRate: z.number().min(0).max(1).optional(),
|
||||
heatmapSampleRate: z.number().min(0).max(1).optional(),
|
||||
maskLevel: z.enum(['strict', 'moderate']).optional(),
|
||||
maxDuration: z.number().int().positive().optional(),
|
||||
blockSelector: z.string().optional(),
|
||||
})
|
||||
.meta({ id: 'ReplayConfig' });
|
||||
|
||||
const websiteUserSchema = z
|
||||
.object({
|
||||
id: z.uuid(),
|
||||
username: z.string(),
|
||||
})
|
||||
.meta({ id: 'WebsiteUser' });
|
||||
|
||||
export const websiteSchema = z
|
||||
.object({
|
||||
id: z.uuid(),
|
||||
name: z.string(),
|
||||
domain: z.string().nullable(),
|
||||
resetAt: nullableDateTimeSchema,
|
||||
userId: nullableUuidSchema,
|
||||
teamId: nullableUuidSchema,
|
||||
createdBy: nullableUuidSchema,
|
||||
createdAt: nullableDateTimeSchema,
|
||||
updatedAt: nullableDateTimeSchema,
|
||||
deletedAt: nullableDateTimeSchema,
|
||||
recorderEnabled: z.boolean(),
|
||||
replayConfig: replayConfigSchema.nullable(),
|
||||
shareId: z.string().nullable(),
|
||||
user: websiteUserSchema.optional(),
|
||||
})
|
||||
.meta({ id: 'Website' });
|
||||
|
||||
export const websitePageSchema = z
|
||||
.object({
|
||||
data: z.array(websiteSchema),
|
||||
count: z.number().int().nonnegative(),
|
||||
page: z.number().int().positive(),
|
||||
pageSize: z.number().int().nonnegative(),
|
||||
orderBy: z.string().optional(),
|
||||
search: z.string().optional(),
|
||||
})
|
||||
.meta({ id: 'WebsitePage' });
|
||||
|
||||
export const websiteIdPathSchema = z.object({
|
||||
websiteId: z.uuid().meta({
|
||||
description: 'Website ID.',
|
||||
param: { description: 'Website ID.' },
|
||||
}),
|
||||
});
|
||||
Reference in new issue
Block a user