From 7bfb48b81fcfe759e8f448db30db93b1c320de1a Mon Sep 17 00:00:00 2001 From: Blake Matthes Date: Sun, 16 Mar 2025 15:34:55 -0500 Subject: [PATCH] feat(api): added in a response function to reduce the over responses as they are always the same --- server/globalUtils/routeDefs/responses.ts | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 server/globalUtils/routeDefs/responses.ts diff --git a/server/globalUtils/routeDefs/responses.ts b/server/globalUtils/routeDefs/responses.ts new file mode 100644 index 0000000..ec3edb7 --- /dev/null +++ b/server/globalUtils/routeDefs/responses.ts @@ -0,0 +1,45 @@ +import {z} from "@hono/zod-openapi"; + +const responseSchema = z.object({ + success: z.boolean().openapi({example: true}), + message: z.string().optional(), + data: z + .array(z.object({}).optional()) + .optional() + .openapi({example: [{data: "hi"}]}), +}); + +export const responses = () => { + return { + 200: { + content: { + "application/json": {schema: responseSchema}, + }, + description: "Response message", + }, + 400: { + content: { + "application/json": { + schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}), + }, + }, + description: "Internal Server Error", + }, + 401: { + content: { + "application/json": { + schema: z.object({message: z.string().optional().openapi({example: "Unauthenticated"})}), + }, + }, + description: "Unauthorized", + }, + 500: { + content: { + "application/json": { + schema: z.object({message: z.string().optional().openapi({example: "Internal Server error"})}), + }, + }, + description: "Internal Server Error", + }, + }; +};