Notes/src/routes/api_docs.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-02-15 00:25:23 +02:00
import type { Application, 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));
2025-02-15 00:25:23 +02:00
const etapiDocument = 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-15 00:25:23 +02:00
const apiDocument = JSON.parse(await readFile(join(__dirname, "api", "openapi.json"), "utf-8"));
2025-02-15 00:25:23 +02:00
function register(app: Application) {
app.use(
"/etapi/docs/",
swaggerUi.serveFiles(etapiDocument),
swaggerUi.setup(etapiDocument, {
explorer: true,
2025-02-09 22:17:31 +00:00
customSiteTitle: "TriliumNext ETAPI Documentation"
})
);
2025-02-15 00:25:23 +02:00
app.use(
"/api/docs/",
swaggerUi.serveFiles(apiDocument),
swaggerUi.setup(apiDocument, {
explorer: true,
customSiteTitle: "TriliumNext Internal API Documentation"
})
);
}
export default {
register
};