80 lines
2.9 KiB
TypeScript
80 lines
2.9 KiB
TypeScript
import {createRoute, OpenAPIHono, z} from "@hono/zod-openapi";
|
|
import {getInfo} from "../controller/getInfo.js";
|
|
|
|
const app = new OpenAPIHono();
|
|
|
|
const AddSetting = z.object({
|
|
name: z.string().openapi({example: "server"}),
|
|
value: z.string().openapi({example: "localhost"}),
|
|
description: z.string().openapi({example: "The server we are going to connect to"}),
|
|
roles: z.string().openapi({example: "admin"}),
|
|
module: z.string().openapi({example: "production"}),
|
|
});
|
|
|
|
app.openapi(
|
|
createRoute({
|
|
tags: ["ocme"],
|
|
summary: "Get all current info",
|
|
method: "get",
|
|
path: "/getinfo",
|
|
request: {
|
|
body: {
|
|
content: {
|
|
"application/json": {schema: AddSetting},
|
|
},
|
|
},
|
|
},
|
|
responses: {
|
|
200: {
|
|
content: {
|
|
"application/json": {
|
|
schema: z.object({
|
|
success: z.boolean().openapi({example: true}),
|
|
message: z.string().openapi({example: "Starter"}),
|
|
data: z.array(z.object({})).optional().openapi({example: []}),
|
|
}),
|
|
},
|
|
},
|
|
description: "Response message",
|
|
},
|
|
400: {
|
|
content: {
|
|
"application/json": {
|
|
schema: z.object({
|
|
success: z.boolean().openapi({example: false}),
|
|
message: z.string().optional().openapi({example: "Internal Server error"}),
|
|
data: z.array(z.object({})).optional().openapi({example: []}),
|
|
}),
|
|
},
|
|
},
|
|
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",
|
|
// },
|
|
},
|
|
}),
|
|
async (c) => {
|
|
// make sure we have a vaid user being accessed thats really logged in
|
|
try {
|
|
return c.json({success: true, message: "Ocme Info", data: await getInfo()}, 200);
|
|
} catch (error) {
|
|
return c.json({success: false, message: "There was an error getting ocmeInfo data", data: error}, 400);
|
|
}
|
|
}
|
|
);
|
|
export default app;
|