Skip to content

Build your personal knowledge base with Trilium Notes

feat(docs): keep the operation ID beside the route

Elian Doran7354147c8fdc
diff --git a/apps/edit-docs/src/openapi_markdown.spec.ts b/apps/edit-docs/src/openapi_markdown.spec.ts
index 595431bb17..b9b6eaad85 100644
--- a/apps/edit-docs/src/openapi_markdown.spec.ts
+++ b/apps/edit-docs/src/openapi_markdown.spec.ts
@@ -143,8 +143,9 @@ describe("openApiToMarkdown", () => {
expect(markdown.indexOf("### `POST /api/login`")).toBeLessThan(markdown.indexOf("## Notes"));
expect(markdown.indexOf("### `GET /api/tree`")).toBeLessThan(markdown.indexOf("## Misc"));
expect(markdown.indexOf("## Misc")).toBeLessThan(markdown.indexOf("### `GET /api/misc`"));
- // A summary wins over the operation ID; an operation with neither is named by its route.
- expect(markdown).toContain("### List notes\n\n`GET /api/notes`\n\n### `GET /api/tree`");
+ // A summary wins over the operation ID, which then follows the route; an operation with
+ // neither is named by its route.
+ expect(markdown).toContain("### List notes\n\n`GET /api/notes` · `getNotes`\n\n### `GET /api/tree`");
// Schemes of one requirement are all needed; an empty requirement makes them optional.
expect(markdown).toContain("**Authorization**: `A` and `B` or none");
diff --git a/apps/edit-docs/src/openapi_markdown.ts b/apps/edit-docs/src/openapi_markdown.ts
index f668fe0263..314a3fbc09 100644
--- a/apps/edit-docs/src/openapi_markdown.ts
+++ b/apps/edit-docs/src/openapi_markdown.ts
@@ -168,10 +168,14 @@ function groupOperations(spec: OpenApiSpec) {
}
function renderOperation(spec: OpenApiSpec, { method, path, pathItem, operation }: OperationEntry) {
- // Named like Redocly does: by summary, else by operation ID, else by the route.
+ // Named like Redocly does: by summary, else by operation ID, else by the route. The route line
+ // keeps the operation ID in sight when the summary takes the heading.
const route = code(`${method.toUpperCase()} ${path}`);
- const title = operation.summary?.trim() || code(operation.operationId ?? "");
- const blocks = title ? [ `### ${title}`, route ] : [ `### ${route}` ];
+ const id = code(operation.operationId ?? "");
+ const summary = operation.summary?.trim();
+ const blocks = summary
+ ? [ `### ${summary}`, id ? `${route} · ${id}` : route ]
+ : id ? [ `### ${id}`, route ] : [ `### ${route}` ];
if (operation.description) {
blocks.push(operation.description.trim());
}