feat(api): added in a response function to reduce the over responses as they are always the same

This commit is contained in:
2025-03-16 15:34:55 -05:00
parent 7432decd3c
commit 7bfb48b81f

View File

@@ -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",
},
};
};