Notes/src/routes/api_docs.ts

28 lines
751 B
TypeScript
Raw Normal View History

import type { Router } from "express";
import swaggerUi from "swagger-ui-express";
2025-02-10 00:50:43 +00:00
import { readFile } from "fs/promises";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
import yaml from "js-yaml";
2025-02-10 16:03:01 +00:00
import type { JsonObject } from "swagger-ui-express";
const __dirname = dirname(fileURLToPath(import.meta.url));
const swaggerDocument = yaml.load(
2025-02-10 00:50:43 +00:00
await readFile(join(__dirname, "../etapi/etapi.openapi.yaml"), "utf8")
2025-02-10 16:03:01 +00:00
) as JsonObject;
function register(router: Router) {
router.use(
2025-02-09 22:17:31 +00:00
"/etapi",
swaggerUi.serve,
swaggerUi.setup(swaggerDocument, {
explorer: true,
2025-02-09 22:17:31 +00:00
customSiteTitle: "TriliumNext ETAPI Documentation"
})
);
}
export default {
register
};