32 lines
896 B
TypeScript
32 lines
896 B
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 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" });
|