mirror of
https://github.com/zadam/trilium.git
synced 2025-11-06 05:15:59 +01:00
add Swagger UI endpoint and add to router
This commit is contained in:
26
src/routes/api_docs.ts
Normal file
26
src/routes/api_docs.ts
Normal 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
|
||||
};
|
||||
Reference in New Issue
Block a user