Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

Commit 1652481

Browse files
authored
Merge pull request #1846 from FliegendeWurst/openapi-revive
OpenAPI documentation fixes
2 parents 5090dae + f2c3ea7 commit 1652481

File tree

7 files changed

+55
-17
lines changed

7 files changed

+55
-17
lines changed

apps/server/src/assets/openapi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

apps/server/src/routes/api/sync.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ function forceFullSync() {
124124
* type: object
125125
* properties:
126126
* entityChanges:
127-
* type: list
127+
* type: array
128128
* items:
129129
* $ref: '#/components/schemas/EntityChange'
130130
* lastEntityChangeId:
131131
* type: integer
132132
* description: If `outstandingPullCount > 0`, pass this as parameter in your next request to continue.
133133
* outstandingPullCount:
134-
* type: int
134+
* type: integer
135135
* example: 42
136136
* description: Number of changes not yet returned by the remote.
137137
* security:
@@ -247,7 +247,7 @@ const partialRequests: Record<
247247
* type: string
248248
* description: Local instance ID
249249
* entities:
250-
* type: list
250+
* type: array
251251
* items:
252252
* $ref: '#/components/schemas/EntityChange'
253253
* responses:

apps/server/src/routes/api/tree.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ function getNotesAndBranchesAndAttributes(_noteIds: string[] | Set<string>) {
152152
* type: object
153153
* properties:
154154
* branches:
155-
* type: list
155+
* type: array
156156
* items:
157157
* $ref: '#/components/schemas/Branch'
158158
* notes:
159-
* type: list
159+
* type: array
160160
* items:
161161
* $ref: '#/components/schemas/Note'
162162
* attributes:
163-
* type: list
163+
* type: array
164164
* items:
165165
* $ref: '#/components/schemas/Attribute'
166166
* security:

apps/server/src/routes/login.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,36 @@ function setPassword(req: Request, res: Response) {
6262
res.redirect("login");
6363
}
6464

65+
/**
66+
* @swagger
67+
* /login:
68+
* post:
69+
* tags:
70+
* - auth
71+
* summary: Log in using password
72+
* description: This will give you a Trilium session, which is required for some other API endpoints. `totpToken` is only required if the user configured TOTP authentication.
73+
* operationId: login-normal
74+
* externalDocs:
75+
* description: HMAC calculation
76+
* url: https://github.com/TriliumNext/Notes/blob/v0.91.6/src/services/utils.ts#L62-L66
77+
* requestBody:
78+
* content:
79+
* application/x-www-form-urlencoded:
80+
* schema:
81+
* type: object
82+
* required:
83+
* - password
84+
* properties:
85+
* password:
86+
* type: string
87+
* totpToken:
88+
* type: string
89+
* responses:
90+
* '200':
91+
* description: Successful operation
92+
* '401':
93+
* description: Password / TOTP mismatch
94+
*/
6595
function login(req: Request, res: Response) {
6696
if (openID.isOpenIDEnabled()) {
6797
res.oidc.login({
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# attachments
2-
<figure class="table" style="width:100%;"><table class="ck-table-resized"><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Column Name</th><th>Data Type</th><th>Nullity</th><th>Default value</th><th>Description</th></tr></thead><tbody><tr><th><code>attachmentId</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>Unique ID (e.g. <code>qhC1vzU4nwSE</code>)</td></tr><tr><th><code>ownerId</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>The unique ID of a row in&nbsp;<a class="reference-link" href="notes.md">notes</a>.</td></tr><tr><th><code>role</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>The role of the attachment: <code>image</code> for images that are attached to a note.</td></tr><tr><th><code>mime</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>The MIME type of the attachment (e.g. <code>image/png</code>)</td></tr><tr><th><code>title</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>The title of the attachment.</td></tr><tr><th><code>isProtected</code></th><td>Integer</td><td>Non-null</td><td>0</td><td><code>1</code> if the entity is <a href="../Protected%20entities.md">protected</a>, <code>0</code> otherwise.</td></tr><tr><th><code>position</code></th><td>Integer</td><td>Non-null</td><td>0</td><td>Not sure where the position is relevant for attachments (saw it with values of 10 and 0).</td></tr><tr><th><code>blobId</code></th><td>Text</td><td>Nullable</td><td><code>null</code></td><td>The corresponding <code>blobId</code> from the&nbsp;<a class="reference-link" href="blobs.md">blobs</a>&nbsp;table.</td></tr><tr><th><code>dateModified</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>Localized modification date (e.g. <code>2023-11-08 18:43:44.204+0200</code>)</td></tr><tr><th><code>utcDateModified</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>Modification date in UTC format (e.g. <code>2023-11-08 16:43:44.204Z</code>)</td></tr><tr><th><code>utcDateScheduledForErasure</code></th><td>Text</td><td>Nullable</td><td><code>null</code></td><td>&nbsp;</td></tr><tr><th><code>isDeleted</code></th><td>Integer</td><td>Non-null</td><td>&nbsp;</td><td><code>1</code> if the entity is <a href="../Deleted%20notes.md">deleted</a>, <code>0</code> otherwise.</td></tr><tr><th><code>deleteId</code></th><td>Text</td><td>Nullable</td><td><code>null</code></td><td>&nbsp;</td></tr></tbody></table></figure>
2+
<figure class="table" style="width:100%;"><table class="ck-table-resized"><colgroup><col> <col> <col> <col> <col></colgroup><thead><tr><th>Column Name</th><th>Data Type</th><th>Nullity</th><th>Default value</th><th>Description</th></tr></thead><tbody><tr><th><code>attachmentId</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>Unique ID (e.g. <code>qhC1vzU4nwSE</code>)</td></tr><tr><th><code>ownerId</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>The unique ID of a row in&nbsp;<a class="reference-link" href="notes.md">notes</a>.</td></tr><tr><th><code>role</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>The role of the attachment: <code>image</code> for images that are attached to a note, <code>file</code> for uploaded files.</td></tr><tr><th><code>mime</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>The MIME type of the attachment (e.g. <code>image/png</code>)</td></tr><tr><th><code>title</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>The title of the attachment.</td></tr><tr><th><code>isProtected</code></th><td>Integer</td><td>Non-null</td><td>0</td><td><code>1</code> if the entity is <a href="../Protected%20entities.md">protected</a>, <code>0</code> otherwise.</td></tr><tr><th><code>position</code></th><td>Integer</td><td>Non-null</td><td>0</td><td>Not sure where the position is relevant for attachments (saw it with values of 10 and 0).</td></tr><tr><th><code>blobId</code></th><td>Text</td><td>Nullable</td><td><code>null</code></td><td>The corresponding <code>blobId</code> from the&nbsp;<a class="reference-link" href="blobs.md">blobs</a>&nbsp;table.</td></tr><tr><th><code>dateModified</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>Localized modification date (e.g. <code>2023-11-08 18:43:44.204+0200</code>)</td></tr><tr><th><code>utcDateModified</code></th><td>Text</td><td>Non-null</td><td>&nbsp;</td><td>Modification date in UTC format (e.g. <code>2023-11-08 16:43:44.204Z</code>)</td></tr><tr><th><code>utcDateScheduledForErasure</code></th><td>Text</td><td>Nullable</td><td><code>null</code></td><td>&nbsp;</td></tr><tr><th><code>isDeleted</code></th><td>Integer</td><td>Non-null</td><td>&nbsp;</td><td><code>1</code> if the entity is <a href="../Deleted%20notes.md">deleted</a>, <code>0</code> otherwise.</td></tr><tr><th><code>deleteId</code></th><td>Text</td><td>Nullable</td><td><code>null</code></td><td>&nbsp;</td></tr></tbody></table></figure>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"server:start-prod": "nx run server:start-prod",
1717
"electron:build": "nx build desktop",
1818
"chore:ci-update-nightly-version": "tsx ./scripts/update-nightly-version.ts",
19+
"chore:generate-openapi": "tsx ./scripts/generate-openapi.ts",
1920
"chore:update-build-info": "tsx ./scripts/update-build-info.ts",
2021
"chore:update-version": "tsx ./scripts/update-version.ts",
2122
"test": "pnpm nx run-many -t test",

_regroup/bin/generate-openapi.ts renamed to scripts/generate-openapi.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ import swaggerJsdoc from "swagger-jsdoc";
44
import fs from "fs";
55

66
/*
7-
* Usage: npm run generate-openapi | tail -n1 > x.json
7+
* Usage: npm run chore:generate-openapi
8+
* Output: ./apps/server/src/assets/openapi.json
89
*
910
* Inspect generated file by opening it in https://editor-next.swagger.io/
1011
*
1112
*/
1213

14+
const scriptDir = dirname(fileURLToPath(import.meta.url));
15+
const outputPath = join(scriptDir, "..", "apps", "server", "src", "assets", "openapi.json");
16+
17+
const packageJson = JSON.parse(fs.readFileSync(join(scriptDir, "..", "package.json"), 'utf8'));
18+
1319
const options = {
1420
definition: {
1521
openapi: "3.1.1",
1622
info: {
1723
title: "Trilium Notes - Sync server API",
18-
version: "0.96.6",
24+
version: packageJson["version"],
1925
description:
2026
"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).",
2127
contact: {
@@ -30,18 +36,17 @@ const options = {
3036
},
3137
apis: [
3238
// Put individual files here to have them ordered first.
33-
"./src/routes/api/setup.ts",
39+
"./apps/server/src/routes/api/setup.ts",
3440
// all other files
35-
"./src/routes/api/*.ts",
36-
"./bin/generate-openapi.js"
41+
"./apps/server/src/routes/api/*.ts",
42+
"./apps/server/src/routes/*.ts",
43+
"./scripts/generate-openapi.ts"
3744
]
3845
};
3946

4047
const openapiSpecification = swaggerJsdoc(options);
41-
const scriptDir = dirname(fileURLToPath(import.meta.url));
42-
const outputPath = join(scriptDir, "..", "src", "routes", "api", "openapi.json");
4348
fs.writeFileSync(outputPath, JSON.stringify(openapiSpecification));
44-
console.log("Saved to ", outputPath);
49+
console.log("Saved to", outputPath);
4550

4651
/**
4752
* @swagger
@@ -67,7 +72,7 @@ console.log("Saved to ", outputPath);
6772
* $ref: "#/components/schemas/NoteId"
6873
* type:
6974
* type: string
70-
* enum: ["attribute", "relation"]
75+
* enum: ["label", "relation"]
7176
* name:
7277
* type: string
7378
* example: "internalLink"
@@ -99,6 +104,7 @@ console.log("Saved to ", outputPath);
99104
* $ref: "#/components/schemas/UtcDateTime"
100105
* Branch:
101106
* type: object
107+
* required: ["branchId", "noteId", "parentNoteId", "notePosition"]
102108
* properties:
103109
* branchId:
104110
* $ref: "#/components/schemas/BranchId"
@@ -141,6 +147,7 @@ console.log("Saved to ", outputPath);
141147
* description: Encoded entity data. Object has one property for each database column.
142148
* Note:
143149
* type: object
150+
* required: ["noteId", "title", "isProtected", "type", "mime", "blobId"]
144151
* properties:
145152
* noteId:
146153
* $ref: "#/components/schemas/NoteId"

0 commit comments

Comments
 (0)