2025-02-09 21:15:12 +00:00
|
|
|
import type { Router } from "express";
|
|
|
|
import swaggerUi from "swagger-ui-express";
|
2025-02-10 00:50:43 +00:00
|
|
|
import { readFile } from "fs/promises";
|
2025-02-09 21:15:12 +00:00
|
|
|
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";
|
2025-02-09 21:15:12 +00:00
|
|
|
|
|
|
|
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;
|
2025-02-09 21:15:12 +00:00
|
|
|
|
|
|
|
function register(router: Router) {
|
|
|
|
router.use(
|
2025-02-09 22:17:31 +00:00
|
|
|
"/etapi",
|
2025-02-09 21:15:12 +00:00
|
|
|
swaggerUi.serve,
|
|
|
|
swaggerUi.setup(swaggerDocument, {
|
|
|
|
explorer: true,
|
2025-02-09 22:17:31 +00:00
|
|
|
customSiteTitle: "TriliumNext ETAPI Documentation"
|
2025-02-09 21:15:12 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
register
|
|
|
|
};
|