Repository navigation
feat(api-reference): show each tag's operations as cards - #415
Conversation
DOCS-1909 Show REST API operations as cards on each tag page, with verb and route
The main REST API landing page shows a card per operation with its verb. The tag pages ( Do. Render the tag pages as cards too, each with the title, the verb and the route (path). Keep the Markdown list in the page's Markdown twin and Not in this issue. Splitting long tags (Chats has 54 visible operations, Enterprise 107) into groups needs the grouping decision, which waits on the redirect review. Done when. Every tag page shows cards with title, verb and route, and passes the axe pass. |
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
16a7477 to
6f376a2
Compare
Jesswinters
left a comment
There was a problem hiding this comment.
No P0 or P1 issues found. The approach (b) is sound: the Markdown twin and llms.txt keep the list because the generator still writes it into the page source (pinned by the docs-build test). The cards are the same component on both pages. Each build rewrites the OpenAPI data (openapi-output.ts), so the new required path never meets stale data.
Checked at 6f376a2 on Node 26: pnpm install --frozen-lockfile, the package build, pnpm typecheck and pnpm lint pass. Tests pass in @coder/docs-build (200), @coder/docs-next (491) and @coder/docs-config (106).
Inline (P2 and below, none blocking):
- P2: on a tag page the cards'
<h3>titles follow the page<h1>with no<h2>between them. axe'sheading-orderreports this; it isn't enforced, so CI won't fail. - P3: the route and the first sentence join with no space in the text (copy and paste, reader mode, some screen readers).
- P3: the paragraph text is used as the React key.
Not verified: the preview (behind Vercel SSO), the axe pass and the fixture next build (CI runs them), and the QA steps in a browser.
Generated with Coder Agents on behalf of @Jesswinters
| {tag.description?.split("\n\n").map((paragraph) => ( | ||
| <p key={paragraph}>{paragraph}</p> | ||
| ))} | ||
| <OperationCards operations={tag.operations} hrefFor={hrefFor} /> |
There was a problem hiding this comment.
P2, accessibility: each Card title is an <h3> (fumadocs-ui card.tsx). On the landing, a tag's <h2> comes before its cards. On a tag page they come straight after the page <h1>, so the outline skips a level, and axe's heading-order (best-practice, reported but not enforced here) flags /reference/api/workspaces. People who move by heading land on level 3 with no level 2 above it.
A visually hidden level-2 heading keeps the design unchanged (no visible group heading) and fixes the outline. The label is a suggestion:
| {tag.description?.split("\n\n").map((paragraph) => ( | |
| <p key={paragraph}>{paragraph}</p> | |
| ))} | |
| <OperationCards operations={tag.operations} hrefFor={hrefFor} /> | |
| {tag.description?.split("\n\n").map((paragraph, index) => ( | |
| <p key={index}>{paragraph}</p> | |
| ))} | |
| <h2 className="sr-only">Endpoints</h2> | |
| <OperationCards operations={tag.operations} hrefFor={hrefFor} /> |
(This also covers the key nit below.) If you take it, the tag-page test could assert h2.sr-only before the first card.
Generated with Coder Agents on behalf of @Jesswinters
There was a problem hiding this comment.
Added a visually hidden <h2 className="sr-only">Endpoints</h2> before the cards on tag pages, and the tag-page test now asserts it comes before the first card (39fd004).
| replace: ( | ||
| <> | ||
| {tag.description?.split("\n\n").map((paragraph) => ( | ||
| <p key={paragraph}>{paragraph}</p> |
There was a problem hiding this comment.
P3 nit: the key is the paragraph text, so a description with two identical paragraphs would produce duplicate keys and a React warning. The index is safe here because the list is static per render (the suggestion above uses it).
Generated with Coder Agents on behalf of @Jesswinters
There was a problem hiding this comment.
The paragraphs are keyed by index now (39fd004). The repo lints react/no-array-index-key, so there is a one-line oxlint-disable-next-line with the reason.
| <code className="coder-api-route">{operation.path}</code> | ||
| {operation.description ? ( | ||
| <span className="coder-api-card-text">{operation.description}</span> | ||
| ) : null} |
There was a problem hiding this comment.
P3: display: block separates the route and the sentence on screen, but the text has no space between them. The new test pins "/api/v2/users/{user}Returns one user.". That joined string is what copy and paste, reader mode and some screen readers get. A space between the two costs nothing visually:
| <code className="coder-api-route">{operation.path}</code> | |
| {operation.description ? ( | |
| <span className="coder-api-card-text">{operation.description}</span> | |
| ) : null} | |
| <code className="coder-api-route">{operation.path}</code> | |
| {operation.description ? ( | |
| <> | |
| {" "} | |
| <span className="coder-api-card-text">{operation.description}</span> | |
| </> | |
| ) : null} |
The test's expected text would then be "/api/v2/users/{user} Returns one user.".
Generated with Coder Agents on behalf of @Jesswinters
There was a problem hiding this comment.
Added a space between the route and the description in the shared card markup, so the landing and tag pages match, and the test expects "/api/v2/users/{user} Returns one user." (39fd004).
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
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
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
Jesswinters
left a comment
There was a problem hiding this comment.
I found no P0 or P1 issues, so I'm approving. My three earlier comments are fixed in 39fd004: the sr-only level-2 heading before the cards, the paragraph keys, and the space between the route and the description.
I checked this locally on 39fd004. Tests pass in @coder/docs-build (200/200), @coder/docs-next (491/491), @coder/docs-config (106/106) and @coder/docs-theme (37/37). Typecheck is clean, oxlint reports 0 warnings and oxfmt --check passes.
Before merging: the CI run on 39fd004 (run 46487152214) was cancelled after about 6 minutes. That cancelled axe accessibility pass and packages on node 22, so build & check failed. You said the axe pass and the fixture build can only run in CI, and the axe pass is the only check on the new /reference/api/workspaces page entry. Please re-run it and get a green result first.
I left one P2 inline. It agrees with the Vercel security note.
This review was generated by Coder Agents on behalf of @Jesswinters.
| function plainParagraphs(markdown: string | undefined): string | undefined { | ||
| const text = markdown | ||
| ?.split(/\n\s*\n/) | ||
| .map(inlineMarkdownText) |
There was a problem hiding this comment.
P2: tag descriptions reach the link regex with no length limit. firstSentence cuts its input to 2000 characters because the link pattern in inlineMarkdownText is quadratic. plainParagraphs sends the whole tag description through the same pattern with no cut. A Swagger file whose tag description has a long run of [x]( with no closing ) can therefore burn build CPU on preview and export builds. Coder's own tags are short, so this is low risk, but this is the one new place that takes text from the document without a bound.
The simplest fix is to cap the description before it is split, the same way firstSentence does. For example, markdown?.slice(0, 10_000) keeps any real tag description whole. A test with a long [x]( run would pin it down. Another option is to make the link pattern linear, for example by excluding ( inside the URL part, so both callers are safe.
There was a problem hiding this comment.
Already covered by 7a8ebd8: each tag paragraph is cut to 2000 characters (the cap firstSentence uses) and at most 20 paragraphs are kept before inlineMarkdownText runs, so the regex input is bounded to 40,000 characters in total, tighter than the 10,000-per-description suggestion for any single run. The long-run case is pinned by the test added in that commit in openapi-reference.test.ts.
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
Jesswinters
left a comment
There was a problem hiding this comment.
No P0 or P1 issues found. The inline P2/P3 suggestions are optional.
Generated with Coder Agents on behalf of @Jesswinters
Merge order
Independent now. It was stacked on #414, which has merged, and this branch has been rebased onto main.
Summary
Each REST API tag page now shows its operations as cards, the same cards as the landing page: the title as a link, the coloured verb badge, the route (the API path, in a code span that wraps instead of overflowing), the first sentence of the description if any, and the Deprecated label from #414, with deprecated operations last. The main landing cards now show the route too, so every card has title, verb and route. No group headings, grouping, filtering or sorting were added; a tag with many operations is one list of cards. No URL changes, and the operation count and sidebar are unchanged.
Design
Two approaches were compared. (a) Emit the list inside
<div class="cards">forremark-coder-cards. That would also change the Markdown twin and llms.txt, which are built from the page source, and it would give a plain code verb with no coloured badge and no Deprecated label, so the card would differ from the landing's. (b) Keep the plain Markdown list in the page source and render the cards from the landing data in the page-body hook. The twin and llms.txt keep the list, and the card is the one component both pages use. I chose (b).The hook swaps the page body at render time (
replace), as the schemas page already does, so the list is removed from the rendered HTML by the renderer, not hidden by CSS. The data contract gainspathon each landing operation and, on each section,route(the tag page) anddescription. A tag page whose route matches no section keeps its Markdown, so data written before this change renders as before.Trade-off for maintainers: because the body is replaced, the tag's description is carried in the data as plain paragraphs and shown above the cards, so inline Markdown in a tag description (links, emphasis) shows as plain text on the rendered tag page. The Markdown twin keeps the formatting. Coder's tag descriptions are short plain sentences today.
QA
Production still shows the old list until the engine is republished, so use the preview. Steps work in Chrome and Firefox; the Firefox steps are not verified.
/api/v2/workspaces, and "Create user workspace by organization POST" with a "Deprecated" label and its route, last.- [Title](./tag/slug.md): \VERB /path``.Pages to compare
/docs/reference/api/workspaces//docs/reference/api/chats//docs/reference/api/The preview alias always serves the PR's latest deploy and needs a Vercel login.
Testing
New tests were written first. The generator tests (
path,route,description, and the tag page source still holding the Markdown list) failed before the generator change; the render tests cover the tag page cards (title, verb text, route text, Deprecated label on the last card, no second list, links unchanged, non-tag pages untouched) and the route on landing cards. They use the fixture swagger's Workspaces tag with its deprecated operation. The Markdown twin and llms.txt come from the page source, which the generator test pins. Tests pass in docs-build, docs-next, docs-config, apps/docs and apps/offlinedocs, and typecheck, Oxfmt and Oxlint pass./reference/api/workspacesis added to the axe page list;fixtures/url-parity-approved.jsonneeds no change because no URL changes.next buildaborts under the local virtual-memory cap, so the fixture build checks and the axe pass could not run locally; CI runs them.Upstream
No. This is Coder's own page layout and generated reference, not a generic Fumadocs bug or option.
https://linear.app/codercom/issue/DOCS-1909/show-rest-api-operations-as-cards-on-each-tag-page-with-verb-and-route
🤖 Built with AI assistance.