add Swagger UI endpoint and add to router

This commit is contained in:
perf3ct 2025-02-09 21:15:12 +00:00
parent 72fe367988
commit 18f5f1b759
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
2 changed files with 30 additions and 1 deletions

26
src/routes/api_docs.ts Normal file
View File

@ -0,0 +1,26 @@
import type { Router } from "express";
import swaggerUi from "swagger-ui-express";
import { readFileSync } from "fs";
import { fileURLToPath } from "url";
import { dirname, join } from "path";
import yaml from "js-yaml";
const __dirname = dirname(fileURLToPath(import.meta.url));
const swaggerDocument = yaml.load(
readFileSync(join(__dirname, "../etapi/etapi.openapi.yaml"), "utf8")
) as object;
function register(router: Router) {
router.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(swaggerDocument, {
explorer: true,
customSiteTitle: "Trilium ETAPI Documentation"
})
);
}
export default {
register
};

View File

@ -71,7 +71,7 @@ import etapiSpecialNoteRoutes from "../etapi/special_notes.js";
import etapiSpecRoute from "../etapi/spec.js";
import etapiBackupRoute from "../etapi/backup.js";
import apiDocsRoute from "./api_docs.js";
const MAX_ALLOWED_FILE_SIZE_MB = 250;
const GET = "get",
@ -369,6 +369,9 @@ function register(app: express.Application) {
etapiSpecRoute.register(router);
etapiBackupRoute.register(router);
// API Documentation
apiDocsRoute.register(app);
app.use("", router);
}