Revive generate-openapi script

This commit is contained in:
FliegendeWurst 2025-05-03 09:05:21 +02:00
parent 6467265cfd
commit f2c3ea78f5
3 changed files with 14 additions and 10 deletions

File diff suppressed because one or more lines are too long

View File

@ -17,6 +17,7 @@
"server:start-prod": "nx run server:start-prod", "server:start-prod": "nx run server:start-prod",
"electron:build": "nx build desktop", "electron:build": "nx build desktop",
"chore:ci-update-nightly-version": "tsx ./scripts/update-nightly-version.ts", "chore:ci-update-nightly-version": "tsx ./scripts/update-nightly-version.ts",
"chore:generate-openapi": "tsx ./scripts/generate-openapi.ts",
"chore:update-build-info": "tsx ./scripts/update-build-info.ts", "chore:update-build-info": "tsx ./scripts/update-build-info.ts",
"chore:update-version": "tsx ./scripts/update-version.ts", "chore:update-version": "tsx ./scripts/update-version.ts",

View File

@ -5,18 +5,23 @@ import fs from "fs";
/* /*
* Usage: npm run chore:generate-openapi * Usage: npm run chore:generate-openapi
* Output: ./src/routes/api/openapi.json * Output: ./apps/server/src/assets/openapi.json
* *
* Inspect generated file by opening it in https://editor-next.swagger.io/ * Inspect generated file by opening it in https://editor-next.swagger.io/
* *
*/ */
const scriptDir = dirname(fileURLToPath(import.meta.url));
const outputPath = join(scriptDir, "..", "apps", "server", "src", "assets", "openapi.json");
const packageJson = JSON.parse(fs.readFileSync(join(scriptDir, "..", "package.json"), 'utf8'));
const options = { const options = {
definition: { definition: {
openapi: "3.1.1", openapi: "3.1.1",
info: { info: {
title: "Trilium Notes - Sync server API", title: "Trilium Notes - Sync server API",
version: "0.93.0", version: packageJson["version"],
description: description:
"This is the internal sync server API used by Trilium Notes / TriliumNext Notes.\n\n_If you're looking for the officially supported External Trilium API, see [here](https://triliumnext.github.io/Docs/Wiki/etapi.html)._\n\nThis page does not yet list all routes. For a full list, see the [route controller](https://github.com/TriliumNext/Notes/blob/v0.91.6/src/routes/routes.ts).", "This is the internal sync server API used by Trilium Notes / TriliumNext Notes.\n\n_If you're looking for the officially supported External Trilium API, see [here](https://triliumnext.github.io/Docs/Wiki/etapi.html)._\n\nThis page does not yet list all routes. For a full list, see the [route controller](https://github.com/TriliumNext/Notes/blob/v0.91.6/src/routes/routes.ts).",
contact: { contact: {
@ -31,19 +36,17 @@ const options = {
}, },
apis: [ apis: [
// Put individual files here to have them ordered first. // Put individual files here to have them ordered first.
"./src/routes/api/setup.ts", "./apps/server/src/routes/api/setup.ts",
// all other files // all other files
"./src/routes/api/*.ts", "./apps/server/src/routes/api/*.ts",
"./src/routes/*.ts", "./apps/server/src/routes/*.ts",
"./bin/generate-openapi.ts" "./scripts/generate-openapi.ts"
] ]
}; };
const openapiSpecification = swaggerJsdoc(options); const openapiSpecification = swaggerJsdoc(options);
const scriptDir = dirname(fileURLToPath(import.meta.url));
const outputPath = join(scriptDir, "..", "src", "routes", "api", "openapi.json");
fs.writeFileSync(outputPath, JSON.stringify(openapiSpecification)); fs.writeFileSync(outputPath, JSON.stringify(openapiSpecification));
console.log("Saved to ", outputPath); console.log("Saved to", outputPath);
/** /**
* @swagger * @swagger