fix: OpenAPI spec not generating properly

Summary:

Test Plan:
This commit is contained in:
2024-05-24 14:56:34 -04:00
parent 88b1a4ced5
commit 62e780e8bf
4 changed files with 28 additions and 19 deletions

View File

@@ -2,11 +2,13 @@ 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: z.literal(true) });
return z.object({ success });
}
return z.object({ success: z.literal(true), result: schema });
return z.object({ success, result: schema });
};
export const PaginatedResponseSchema = <T extends ZodSchema>(schema: T) => {
@@ -18,9 +20,12 @@ export const PaginatedResponseSchema = <T extends ZodSchema>(schema: T) => {
};
export const ErrorResponseSchema = z.object({
success: z.literal(false),
success: z.literal(false).openapi({ type: "boolean" }),
});
export const AniListIdSchema = z
.number({ coerce: true })
.openapi({ type: "integer" });
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" });