feat(docs): implement swagger ui endpoint for internal api

This commit is contained in:
perf3ct 2025-08-20 17:11:54 +00:00
parent 8752182e7e
commit f9a3606ca2
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
2 changed files with 4126 additions and 3 deletions

File diff suppressed because it is too large Load Diff

View File

@ -3,12 +3,22 @@ import swaggerUi from "swagger-ui-express";
import { join } from "path";
import yaml from "js-yaml";
import type { JsonObject } from "swagger-ui-express";
import { readFileSync } from "fs";
import { readFileSync, existsSync } from "fs";
import { RESOURCE_DIR } from "../services/resource_dir";
export default function register(app: Application) {
const etapiDocument = yaml.load(readFileSync(join(RESOURCE_DIR, "etapi.openapi.yaml"), "utf8")) as JsonObject;
const apiDocument = JSON.parse(readFileSync(join(RESOURCE_DIR, "openapi.json"), "utf-8"));
// Load the comprehensive API documentation (YAML) if available, otherwise fall back to JSON
const apiYamlPath = join(RESOURCE_DIR, "api-openapi.yaml");
const apiJsonPath = join(RESOURCE_DIR, "openapi.json");
let apiDocument: JsonObject;
if (existsSync(apiYamlPath)) {
apiDocument = yaml.load(readFileSync(apiYamlPath, "utf8")) as JsonObject;
} else {
apiDocument = JSON.parse(readFileSync(apiJsonPath, "utf-8"));
}
app.use(
"/etapi/docs/",
@ -24,7 +34,8 @@ export default function register(app: Application) {
swaggerUi.serveFiles(apiDocument),
swaggerUi.setup(apiDocument, {
explorer: true,
customSiteTitle: "TriliumNext Internal API Documentation"
customSiteTitle: "TriliumNext Internal API Documentation",
customCss: '.swagger-ui .topbar { display: none }'
})
);
}