feat(api): added in a response function to reduce the over responses as they are always the same
This commit is contained in:
45
server/globalUtils/routeDefs/responses.ts
Normal file
45
server/globalUtils/routeDefs/responses.ts
Normal 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",
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user