46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { type ZodSchema, z } from "zod";
|
|
|
|
export const SuccessResponse = { success: true } as const;
|
|
export const SuccessResponseSchema = <T extends ZodSchema>(schema?: T) => {
|
|
const success = z.literal(true).openapi({ type: "boolean" });
|
|
|
|
if (!schema) {
|
|
return z.object({ success });
|
|
}
|
|
|
|
return z.object({ success, result: schema });
|
|
};
|
|
|
|
export const PaginatedResponseSchema = <T extends ZodSchema>(schema: T) => {
|
|
return z.object({
|
|
success: z.boolean(),
|
|
results: z.array(schema),
|
|
hasNextPage: z.boolean(),
|
|
});
|
|
};
|
|
|
|
export const ErrorResponse = { success: false } as const;
|
|
export const ErrorResponseSchema = z.object({
|
|
success: z.literal(false).openapi({ type: "boolean" }),
|
|
});
|
|
|
|
export const NullableNumberSchema = z.number().int().nullable();
|
|
|
|
export const AniListIdSchema = z.number().int().openapi({ format: "int64" });
|
|
export const AniListIdQuerySchema = z
|
|
.string()
|
|
.openapi({ type: "integer", format: "int64" });
|
|
|
|
export const EpisodeNumberSchema = z.number().openapi({
|
|
minimum: 0,
|
|
multipleOf: 0.5,
|
|
examples: [1, 2, 3.5],
|
|
type: "number",
|
|
format: "float",
|
|
});
|
|
|
|
export const SkippableSchema = z
|
|
.array(z.number().openapi({ minimum: 0, type: "integer", format: "int64" }))
|
|
.nullish()
|
|
.openapi({ examples: [[200, 289]], minItems: 2, maxItems: 2 });
|