From 6f376a21a3483185f3b419e0a50c8a3a936746bb Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Wed, 25 Nov 2026 17:39:06 +0000 Subject: [PATCH 1/4] feat(api-reference): show each tag's operations as cards A tag page listed its operations as a plain Markdown list, while the landing page showed them as cards. Both now render the same card: title, coloured method badge, route and description, with the Deprecated label on a deprecated operation, in the order the generator already sorts them. The generator records each operation's path and each section's tag page route and description. The tag page's source keeps the Markdown list, so the Markdown twin and llms.txt still list the operations, and the render hook swaps the list for the cards. The tag page is added to the axe pass. Assisted-by: AI --- apps/docs/scripts/a11y-axe-helpers.mjs | 1 + .../docs-build/src/openapi-reference.test.ts | 47 +++++++++- packages/docs-build/src/openapi-reference.ts | 14 +++ packages/docs-config/src/openapi.ts | 6 ++ packages/docs-next/src/openapi/index.tsx | 20 +++- .../docs-next/src/openapi/landing.test.tsx | 92 ++++++++++++++++++- packages/docs-next/src/openapi/landing.tsx | 66 ++++++++----- packages/docs-theme/src/brand.css | 11 +++ 8 files changed, 225 insertions(+), 32 deletions(-) diff --git a/apps/docs/scripts/a11y-axe-helpers.mjs b/apps/docs/scripts/a11y-axe-helpers.mjs index c8938cce..5a9a9382 100644 --- a/apps/docs/scripts/a11y-axe-helpers.mjs +++ b/apps/docs/scripts/a11y-axe-helpers.mjs @@ -24,6 +24,7 @@ export const DEFAULT_PAGES = [ "/reference/api", "/reference/api/schemas", "/reference/api/users", + "/reference/api/workspaces", "/reference/api/users/create-new-user", "/reference/api/workspaces/list-workspaces", "/reference/api/workspaces/create-user-workspace-by-organization", diff --git a/packages/docs-build/src/openapi-reference.test.ts b/packages/docs-build/src/openapi-reference.test.ts index 88a9cbc8..33d54545 100644 --- a/packages/docs-build/src/openapi-reference.test.ts +++ b/packages/docs-build/src/openapi-reference.test.ts @@ -266,19 +266,33 @@ test("the landing sections follow the sidebar's tag order, one card per operatio { title: "Users", id: "users", + route: "reference/api/users", operations: [ - { route: "reference/api/users/create-new-user", title: "Create new user", method: "post" }, - { route: "reference/api/users/get-user-by-name", title: "Get user by name", method: "get" }, + { + route: "reference/api/users/create-new-user", + title: "Create new user", + method: "post", + path: "/api/v2/users", + }, + { + route: "reference/api/users/get-user-by-name", + title: "Get user by name", + method: "get", + path: "/api/v2/users/{user}", + }, ], }, { title: "Workspaces", id: "workspaces", + route: "reference/api/workspaces", + description: "Create, list, and manage workspaces.", operations: [ { route: "reference/api/workspaces/list-workspaces", title: "List workspaces", method: "get", + path: "/api/v2/workspaces", description: "Returns the workspaces the caller can read, filtered by the search query.", }, ], @@ -462,3 +476,32 @@ test("only a deprecated operation page and card carry the deprecated flag", asyn } } }); + +test("a tag page's source keeps its Markdown list of operations, and its section names the page", async () => { + const { source: out, reference } = await applyOpenApiReference(source, fixture); + const lines = pageContent(out.files, "reference/api/workspaces.md").split("\n"); + assert.deepEqual( + lines.filter((line) => line.startsWith("- [")), + [ + "- [List workspaces](./workspaces/list-workspaces.md): `GET /api/v2/workspaces`", + `- [Create user workspace by organization](./workspaces/create-user-workspace-by-organization.md): \`POST ${DEPRECATED_PATH}\``, + ], + ); + const section = reference.landing.sections.find((s) => s.title === "Workspaces"); + assert.equal(section?.route, "reference/api/workspaces"); + assert.deepEqual( + section?.operations.map((op) => op.path), + ["/api/v2/workspaces", DEPRECATED_PATH], + ); +}); + +test("a tag's description reaches its section as plain text, paragraph by paragraph", async () => { + const doc = structuredClone(swagger); + doc.tags[0].description = + "Manage [workspaces](https://example.com) with `q`.\n\nSecond *paragraph*."; + const { reference } = await applyOpenApiReference(source, doc); + const section = reference.landing.sections.find((s) => s.title === "Workspaces"); + assert.equal(section?.description, "Manage workspaces with q.\n\nSecond paragraph."); + const users = reference.landing.sections.find((s) => s.title === "Users"); + assert.ok(!("description" in (users ?? {}))); +}); diff --git a/packages/docs-build/src/openapi-reference.ts b/packages/docs-build/src/openapi-reference.ts index a6815480..2df855be 100644 --- a/packages/docs-build/src/openapi-reference.ts +++ b/packages/docs-build/src/openapi-reference.ts @@ -389,15 +389,19 @@ export async function applyOpenApiReference( const tag = child.path === undefined ? undefined : tagByFile.get(child.path); const group = tag === undefined ? undefined : byTag.get(tag); if (tag === undefined || !group) continue; + const tagText = plainParagraphs(tagInfo.get(tag)); sections.push({ title: tag, id: landing.slugger.slug(safeHeadingId(slugify(tag))), + route: routeOf(tagFile(tag)), + ...(tagText ? { description: tagText } : {}), operations: group.ops.map((op) => { const description = firstSentence(op.description); return { route: routeOf(op.file), title: op.summary, method: op.method, + path: op.path, ...(op.deprecated ? { deprecated: true as const } : {}), ...(description ? { description } : {}), }; @@ -512,3 +516,13 @@ function firstSentence(markdown: string | undefined): string | undefined { const space = sentence.lastIndexOf(" ", 199); return `${sentence.slice(0, space > 0 ? space : 199)}…`; } + +/** Markdown as plain paragraphs separated by blank lines. */ +function plainParagraphs(markdown: string | undefined): string | undefined { + const text = markdown + ?.split(/\n\s*\n/) + .map(inlineMarkdownText) + .filter(Boolean) + .join("\n\n"); + return text || undefined; +} diff --git a/packages/docs-config/src/openapi.ts b/packages/docs-config/src/openapi.ts index fb6f4d95..1e32687a 100644 --- a/packages/docs-config/src/openapi.ts +++ b/packages/docs-config/src/openapi.ts @@ -57,6 +57,8 @@ export interface OpenApiLandingOperation { route: string; title: string; method: HttpMethod; + /** The OpenAPI path, shown as the card's route. */ + path: string; /** Set only on a deprecated operation; the cards sort it last and mark it. */ deprecated?: true; description?: string; @@ -66,6 +68,10 @@ export interface OpenApiLandingOperation { export interface OpenApiLandingSection { title: string; id: string; + /** The tag page's route, which shows the same cards. */ + route: string; + /** The tag's description as plain paragraphs separated by blank lines, shown above its cards on the tag page. */ + description?: string; operations: OpenApiLandingOperation[]; } diff --git a/packages/docs-next/src/openapi/index.tsx b/packages/docs-next/src/openapi/index.tsx index 636d5e53..1da2a2dc 100644 --- a/packages/docs-next/src/openapi/index.tsx +++ b/packages/docs-next/src/openapi/index.tsx @@ -12,7 +12,7 @@ import type { RenderBody } from "../types.js"; import { AnchorRedirect } from "./anchor-redirect.js"; import { ApiPage } from "./api-page-lazy.js"; import { withCodeSamples } from "./code-samples.js"; -import { ApiLanding } from "./landing.js"; +import { ApiLanding, OperationCards } from "./landing.js"; import { SetupHrefProvider } from "./samples-note.js"; import { SchemaTables } from "./schemas.js"; @@ -124,13 +124,27 @@ export function createOpenApiRenderBody( }; } const anchors = data.anchors[route]; - if (!anchors) return undefined; + const tag = landing.sections.find((section) => section.route === route); + if (!anchors && !tag) return undefined; const targets: Record = {}; - for (const [anchor, target] of Object.entries(anchors)) { + for (const [anchor, target] of Object.entries(anchors ?? {})) { const href = hrefFor(target); if (href) targets[anchor] = href; } const redirect = ; + if (tag) { + return { + replace: ( + <> + {tag.description?.split("\n\n").map((paragraph) => ( +

{paragraph}

+ ))} + + + ), + after: redirect, + }; + } if (route !== data.schemas.route) return { after: redirect }; return { replace: ( diff --git a/packages/docs-next/src/openapi/landing.test.tsx b/packages/docs-next/src/openapi/landing.test.tsx index b653d35c..4661977a 100644 --- a/packages/docs-next/src/openapi/landing.test.tsx +++ b/packages/docs-next/src/openapi/landing.test.tsx @@ -12,12 +12,19 @@ const landing: OpenApiLanding = { { title: "Users", id: "users", + route: "reference/api/users", operations: [ - { route: "reference/api/users/create-new-user", title: "Create new user", method: "post" }, + { + route: "reference/api/users/create-new-user", + title: "Create new user", + method: "post", + path: "/api/v2/users", + }, { route: "reference/api/users/get-user-by-name", title: "Get user by name", method: "get", + path: "/api/v2/users/{user}", description: "Returns one user.", }, ], @@ -25,8 +32,14 @@ const landing: OpenApiLanding = { { title: "Workspaces", id: "workspaces", + route: "reference/api/workspaces", operations: [ - { route: "reference/api/workspaces/delete", title: "Delete workspace", method: "delete" }, + { + route: "reference/api/workspaces/delete", + title: "Delete workspace", + method: "delete", + path: "/api/v2/workspaces/{workspace}", + }, ], }, ], @@ -53,7 +66,7 @@ test("each tag is a section heading with a card per operation, in order", () => href: link?.getAttribute("href"), name: link?.textContent, badge: link?.querySelector("span.font-mono")?.textContent, - description: card.querySelector("p")?.textContent ?? null, + description: card.querySelector("p .coder-api-card-text")?.textContent ?? null, }; }), [ @@ -111,7 +124,14 @@ test("the landing route gets the cards after its body and their headings in its test("a protected section id is the heading id and the TOC link, unchanged", async () => { const reserved: OpenApiLanding = { ...landing, - sections: [{ title: "__next_f", id: "user-content-__next_f", operations: [] }], + sections: [ + { + title: "__next_f", + id: "user-content-__next_f", + route: "reference/api/next", + operations: [], + }, + ], }; const renderBody = createOpenApiRenderBody(async () => ({ document: {}, @@ -136,16 +156,20 @@ const deprecatedSections: OpenApiLanding["sections"] = [ { title: "Workspaces", id: "workspaces", + route: "reference/api/workspaces", + description: "Create, list, and manage workspaces.", operations: [ { route: "reference/api/workspaces/list-workspaces", title: "List workspaces", method: "get", + path: "/api/v2/workspaces", }, { route: "reference/api/workspaces/create-user-workspace-by-organization", title: "Create user workspace by organization", method: "post", + path: "/api/v2/organizations/{organization}/members/{user}/workspaces", deprecated: true, }, ], @@ -168,3 +192,63 @@ test("a deprecated operation's card is last and carries a visible Deprecated lab ); assert.equal(last?.querySelector(".docs-deprecated-pill .sr-only")?.textContent, " endpoint"); }); + +test("every landing card shows its route as code beside the description", () => { + const page = renderToFragment(); + const routes = [...page.querySelectorAll(`${CARDS} code`)].map((code) => code.textContent); + assert.deepEqual(routes, [ + "/api/v2/users", + "/api/v2/users/{user}", + "/api/v2/workspaces/{workspace}", + ]); + const described = page.querySelectorAll(CARDS)[1]; + assert.equal(described?.querySelector("p")?.textContent, "/api/v2/users/{user}Returns one user."); +}); + +const tagRoute = "reference/api/workspaces"; + +const tagBody = async (slugs = tagRoute.split("/")) => { + const renderBody = createOpenApiRenderBody(async () => ({ + document: {}, + operations: {}, + anchors: {}, + schemas: { route: "reference/api/schemas", rows: [] }, + landing: { ...landing, sections: [...landing.sections.slice(0, 1), ...deprecatedSections] }, + })); + return renderBody({ versionId: undefined, slugs, hrefFor }); +}; + +test("a tag page replaces its Markdown list with the landing's cards, deprecated last", async () => { + const result = await tagBody(); + const body = renderToFragment(result?.replace); + assert.equal(body.querySelector("p")?.textContent, "Create, list, and manage workspaces."); + const cards = [...body.querySelectorAll(CARDS)]; + assert.equal(cards.length, 2); + assert.equal(cards[0]?.querySelector("h3 a")?.textContent, "List workspaces GET"); + assert.equal(cards[0]?.querySelector("h3 a span.font-mono")?.textContent, "GET"); + assert.equal(cards[0]?.querySelector("code")?.textContent, "/api/v2/workspaces"); + assert.equal(cards[0]?.querySelector(".docs-deprecated-pill"), null); + assert.equal( + cards[1]?.querySelector("code")?.textContent, + "/api/v2/organizations/{organization}/members/{user}/workspaces", + ); + assert.equal( + cards[1]?.querySelector("h3 a .docs-deprecated-pill")?.textContent, + "Deprecated endpoint", + ); + assert.equal(body.querySelectorAll("ul, ol, li").length, 0, "no second list"); + assert.equal(renderToFragment(result?.after).querySelectorAll("li, [data-card]").length, 0); + assert.equal(result?.toc, undefined); +}); + +test("a tag page links each card to the operation page it always had", async () => { + const body = renderToFragment((await tagBody())?.replace); + assert.equal( + body.querySelectorAll(CARDS)[0]?.querySelector("h3 a")?.getAttribute("href"), + "/beta-docs/reference/api/workspaces/list-workspaces/", + ); +}); + +test("a page that is not a tag page keeps its Markdown", async () => { + assert.equal(await tagBody(["reference", "api", "nothing"]), undefined); +}); diff --git a/packages/docs-next/src/openapi/landing.tsx b/packages/docs-next/src/openapi/landing.tsx index bb66df7b..bf1833df 100644 --- a/packages/docs-next/src/openapi/landing.tsx +++ b/packages/docs-next/src/openapi/landing.tsx @@ -5,6 +5,48 @@ import { Fragment } from "react"; import { DeprecatedMarker } from "./deprecated-marker.js"; import { MethodBadge } from "./method-badge.js"; +/** A card for each operation: title link, method badge, route and first sentence of its description. */ +export function OperationCards({ + operations, + hrefFor, +}: { + operations: OpenApiLanding["sections"][number]["operations"]; + hrefFor: (route: string) => string | undefined; +}) { + return ( + + {operations.map((operation) => { + const href = hrefFor(operation.route); + if (href === undefined) return null; + return ( + + {operation.title} + {operation.deprecated ? ( + <> + {" "} + + + ) : null} + + } + description={ + <> + {operation.path} + {operation.description ? ( + {operation.description} + ) : null} + + } + /> + ); + })} + + ); +} + /** * A card for every operation, under a heading per tag in sidebar order. The * cards are server-rendered plain links (no client `Link`, so no prefetch), @@ -23,29 +65,7 @@ export function ApiLanding({ {section.title} - - {section.operations.map((operation) => { - const href = hrefFor(operation.route); - if (href === undefined) return null; - return ( - - {operation.title} - {operation.deprecated ? ( - <> - {" "} - - - ) : null} - - } - description={operation.description} - /> - ); - })} - + )); } diff --git a/packages/docs-theme/src/brand.css b/packages/docs-theme/src/brand.css index 9f88b6bd..619febf3 100644 --- a/packages/docs-theme/src/brand.css +++ b/packages/docs-theme/src/brand.css @@ -1007,6 +1007,17 @@ figure.shiki:not(.not-fumadocs-codeblock *) pre { position: relative; } +.coder-api-route { + display: block; + overflow-wrap: anywhere; + font-size: 0.8125rem; +} + +.coder-api-card-text { + display: block; + margin-top: 0.25rem; +} + .coder-api-cards > [data-card]:hover { background-color: color-mix(in oklab, var(--color-fd-accent) 80%, transparent); } From 39fd004512c3694a2a221377405eaffa1a268d6b Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Mon, 30 Nov 2026 18:41:50 +0000 Subject: [PATCH 2/4] fix(api-reference): add an endpoints heading and a space in cards On a tag page the card titles are h3s that followed the page h1, so the outline skipped a level. A visually hidden h2 fixes that without changing the design. The route and the first sentence of a card had no space between them in the text, which is what copy and paste, reader mode and some screen readers see. The tag description paragraphs are now keyed by index, since identical paragraphs made duplicate keys. Assisted-by: AI --- packages/docs-next/src/openapi/index.tsx | 6 ++++-- packages/docs-next/src/openapi/landing.test.tsx | 10 +++++++++- packages/docs-next/src/openapi/landing.tsx | 5 ++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/docs-next/src/openapi/index.tsx b/packages/docs-next/src/openapi/index.tsx index 1da2a2dc..57fa6b4a 100644 --- a/packages/docs-next/src/openapi/index.tsx +++ b/packages/docs-next/src/openapi/index.tsx @@ -136,9 +136,11 @@ export function createOpenApiRenderBody( return { replace: ( <> - {tag.description?.split("\n\n").map((paragraph) => ( -

{paragraph}

+ {tag.description?.split("\n\n").map((paragraph, index) => ( + // oxlint-disable-next-line react/no-array-index-key -- paragraphs can repeat and the list is static. +

{paragraph}

))} +

Endpoints

), diff --git a/packages/docs-next/src/openapi/landing.test.tsx b/packages/docs-next/src/openapi/landing.test.tsx index 4661977a..57b4510d 100644 --- a/packages/docs-next/src/openapi/landing.test.tsx +++ b/packages/docs-next/src/openapi/landing.test.tsx @@ -202,7 +202,10 @@ test("every landing card shows its route as code beside the description", () => "/api/v2/workspaces/{workspace}", ]); const described = page.querySelectorAll(CARDS)[1]; - assert.equal(described?.querySelector("p")?.textContent, "/api/v2/users/{user}Returns one user."); + assert.equal( + described?.querySelector("p")?.textContent, + "/api/v2/users/{user} Returns one user.", + ); }); const tagRoute = "reference/api/workspaces"; @@ -224,6 +227,11 @@ test("a tag page replaces its Markdown list with the landing's cards, deprecated assert.equal(body.querySelector("p")?.textContent, "Create, list, and manage workspaces."); const cards = [...body.querySelectorAll(CARDS)]; assert.equal(cards.length, 2); + const outline = [...body.querySelectorAll("h2, [data-card]")]; + assert.equal(outline[0]?.tagName, "H2"); + assert.ok(outline[0]?.classList.contains("sr-only")); + assert.equal(outline[0]?.textContent, "Endpoints"); + assert.equal(body.querySelectorAll("h2").length, 1); assert.equal(cards[0]?.querySelector("h3 a")?.textContent, "List workspaces GET"); assert.equal(cards[0]?.querySelector("h3 a span.font-mono")?.textContent, "GET"); assert.equal(cards[0]?.querySelector("code")?.textContent, "/api/v2/workspaces"); diff --git a/packages/docs-next/src/openapi/landing.tsx b/packages/docs-next/src/openapi/landing.tsx index bf1833df..c00e1c7f 100644 --- a/packages/docs-next/src/openapi/landing.tsx +++ b/packages/docs-next/src/openapi/landing.tsx @@ -36,7 +36,10 @@ export function OperationCards({ <> {operation.path} {operation.description ? ( - {operation.description} + <> + {" "} + {operation.description} + ) : null} } From 7a8ebd8a9517c184cdc02b85a9dc00be76bb137d Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Mon, 30 Nov 2026 18:47:39 +0000 Subject: [PATCH 3/4] fix(docs-build): bound tag descriptions before the link pattern runs The Markdown link pattern in the plain-text conversion is quadratic, and operation descriptions were already cut to 2000 characters first. Tag descriptions skipped that bound, so a spec with one huge paragraph could burn build CPU. Each tag paragraph is now cut to the same 2000 characters, and at most 20 paragraphs are kept. The limits are shared constants, so both conversions use one value. Assisted-by: AI --- packages/docs-build/src/openapi-reference.test.ts | 10 ++++++++++ packages/docs-build/src/openapi-reference.ts | 9 ++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/docs-build/src/openapi-reference.test.ts b/packages/docs-build/src/openapi-reference.test.ts index 33d54545..20f9db3b 100644 --- a/packages/docs-build/src/openapi-reference.test.ts +++ b/packages/docs-build/src/openapi-reference.test.ts @@ -505,3 +505,13 @@ test("a tag's description reaches its section as plain text, paragraph by paragr const users = reference.landing.sections.find((s) => s.title === "Users"); assert.ok(!("description" in (users ?? {}))); }); + +test("a tag's description is bounded before its link patterns run", async () => { + const doc = structuredClone(swagger); + doc.tags[0].description = `${"[".repeat(50_000)}\n\n${Array.from({ length: 30 }, (_, i) => `P${i}`).join("\n\n")}`; + const { reference } = await applyOpenApiReference(source, doc); + const section = reference.landing.sections.find((s) => s.title === "Workspaces"); + const paragraphs = section?.description?.split("\n\n") ?? []; + assert.equal(paragraphs[0]?.length, 2000); + assert.equal(paragraphs.length, 20); +}); diff --git a/packages/docs-build/src/openapi-reference.ts b/packages/docs-build/src/openapi-reference.ts index 2df855be..ecc36f14 100644 --- a/packages/docs-build/src/openapi-reference.ts +++ b/packages/docs-build/src/openapi-reference.ts @@ -502,12 +502,15 @@ const inlineMarkdownText = (markdown: string): string => .replace(/\s+/g, " ") .trim(); +const MAX_MARKDOWN_CHARS = 2000; +const MAX_PARAGRAPHS = 20; + /** The first sentence of an operation's Markdown description, as plain text for its card. */ function firstSentence(markdown: string | undefined): string | undefined { // The link pattern below is quadratic, and only the first 200 characters are kept. const paragraph = markdown ?.trim() - .slice(0, 2000) + .slice(0, MAX_MARKDOWN_CHARS) .split(/\n\s*\n/)[0]; if (!paragraph) return undefined; const text = inlineMarkdownText(paragraph); @@ -520,8 +523,8 @@ function firstSentence(markdown: string | undefined): string | undefined { /** Markdown as plain paragraphs separated by blank lines. */ function plainParagraphs(markdown: string | undefined): string | undefined { const text = markdown - ?.split(/\n\s*\n/) - .map(inlineMarkdownText) + ?.split(/\n\s*\n/, MAX_PARAGRAPHS) + .map((paragraph) => inlineMarkdownText(paragraph.slice(0, MAX_MARKDOWN_CHARS))) .filter(Boolean) .join("\n\n"); return text || undefined; From 3ba45daaf96607a9495e89746488ae70c0f255d7 Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Mon, 30 Nov 2026 19:06:17 +0000 Subject: [PATCH 4/4] ci: re-run the checks The single-version e2e job failed on a dropped connection while syncing the corpus, and the previous run was cancelled, so the head had no green run. No code changes. Assisted-by: AI