mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
feat(docs): implement swagger ui endpoint for internal api
This commit is contained in:
parent
8752182e7e
commit
f9a3606ca2
4112
apps/server/src/assets/api-openapi.yaml
Normal file
4112
apps/server/src/assets/api-openapi.yaml
Normal file
File diff suppressed because it is too large
Load Diff
@ -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 }'
|
||||
})
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user