mirror of
https://github.com/zadam/trilium.git
synced 2025-12-04 22:44:25 +01:00
fix(docs): try to fix swagger ui api pages, take 1
This commit is contained in:
parent
3795be4750
commit
a58cfbec05
@ -3,31 +3,51 @@ import swaggerUi from "swagger-ui-express";
|
|||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import type { JsonObject } from "swagger-ui-express";
|
import type { JsonObject } from "swagger-ui-express";
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync, existsSync } from "fs";
|
||||||
import { RESOURCE_DIR } from "../services/resource_dir";
|
import { RESOURCE_DIR } from "../services/resource_dir";
|
||||||
|
import log from "../services/log";
|
||||||
|
|
||||||
export default function register(app: Application) {
|
export default function register(app: Application) {
|
||||||
const etapiDocument = yaml.load(readFileSync(join(RESOURCE_DIR, "etapi.openapi.yaml"), "utf8")) as JsonObject;
|
try {
|
||||||
|
const etapiPath = join(RESOURCE_DIR, "etapi.openapi.yaml");
|
||||||
// Load the comprehensive API documentation from YAML
|
const apiPath = join(RESOURCE_DIR, "api-openapi.yaml");
|
||||||
const apiDocument = yaml.load(readFileSync(join(RESOURCE_DIR, "api-openapi.yaml"), "utf8")) as JsonObject;
|
|
||||||
|
// Check if files exist
|
||||||
|
if (!existsSync(etapiPath)) {
|
||||||
|
log.error(`ETAPI OpenAPI spec not found at: ${etapiPath}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!existsSync(apiPath)) {
|
||||||
|
log.error(`API OpenAPI spec not found at: ${apiPath}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const etapiDocument = yaml.load(readFileSync(etapiPath, "utf8")) as JsonObject;
|
||||||
|
const apiDocument = yaml.load(readFileSync(apiPath, "utf8")) as JsonObject;
|
||||||
|
|
||||||
app.use(
|
// Use serveFiles for multiple Swagger instances
|
||||||
"/etapi/docs/",
|
// Note: serveFiles returns an array of middleware, so we need to spread it
|
||||||
swaggerUi.serveFiles(etapiDocument),
|
app.use(
|
||||||
swaggerUi.setup(etapiDocument, {
|
"/etapi/docs",
|
||||||
explorer: true,
|
...swaggerUi.serveFiles(etapiDocument),
|
||||||
customSiteTitle: "TriliumNext ETAPI Documentation"
|
swaggerUi.setup(etapiDocument, {
|
||||||
})
|
explorer: true,
|
||||||
);
|
customSiteTitle: "TriliumNext ETAPI Documentation"
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
"/api/docs/",
|
"/api/docs",
|
||||||
swaggerUi.serveFiles(apiDocument),
|
...swaggerUi.serveFiles(apiDocument),
|
||||||
swaggerUi.setup(apiDocument, {
|
swaggerUi.setup(apiDocument, {
|
||||||
explorer: true,
|
explorer: true,
|
||||||
customSiteTitle: "TriliumNext Internal API Documentation",
|
customSiteTitle: "TriliumNext Internal API Documentation",
|
||||||
customCss: '.swagger-ui .topbar { display: none }'
|
customCss: '.swagger-ui .topbar { display: none }'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
log.info("Swagger UI endpoints registered at /etapi/docs and /api/docs");
|
||||||
|
} catch (error) {
|
||||||
|
log.error(`Failed to setup API documentation: ${error}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user