Repository navigation
feat(api-reference): render the REST API reference with fumadocs-openapi - #273
Conversation
Throwaway spike, not for merge. The sync converts coder/coder's Swagger 2.0 document to OpenAPI 3 with swagger2openapi, replaces the mainline version's per-tag Markdown pages with one page per operation grouped by tag, and keeps the tag and schemas pages as short lists so existing links still land. The page renders each operation through fumadocs-openapi from a document pruned to that operation, loads its client code only on operation pages, and redirects the old anchors client-side. Assisted-by: AI
…the docs tree The OpenAPI bundler fetches or reads any $ref that is not in-document, so the converter now fails closed, naming the JSON pointer, on any $ref that does not start with #/ before conversion and again after it, and the page renderer checks the same before bundling. Nothing reaches .generated/openapi when it fails. swagger.json is now read through a new readContainedFile in docs-sources, with the tree walk's guarantees: no symbolic link anywhere from the checkout root down, a regular file under the per-file cap, and still inside the checkout once resolved. The git path caps the blob the same way, parse errors never carry file content, and the DOCS_OPENAPI_FILE override is gone. The tag pages list their endpoints instead of a two-column table, which crushed the endpoint names next to long paths. Assisted-by: AI
The method badges and links fumadocs-openapi draws use -600 and -400 shades that fall short of 4.5:1 on its card surface, and of 7:1 under More contrast, so the theme darkens or lightens them inside the API page only. Its code blocks leave their scroll regions unnamed, which made every block on a page the same landmark; each now carries its language as its name. The fixture API pages join the axe pass, and the fixture's moved anchors are approved in the URL parity check, since the tag and schemas pages redirect them. Assisted-by: AI
…ing the theme token The contrast check only allows theme tokens in the known :root selectors, so the dark More-contrast override for the API page's links sets their colour directly instead of redefining --color-fd-primary. Assisted-by: AI
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
DOCS-1431 Spike: render the REST API reference with fumadocs-openapi (per-endpoint pages, try-it panel)
One-night spike to see whether Why
Scope
OutcomeGo or no-go. On go, the follow-ups are the per-endpoint API split and the Shiki theme decision. On no-go, split the Markdown pages by endpoint group in the generator instead. DOCS-1439 Fill in the REST API descriptions in coder/coder's swagger annotations
Problemcoder/docs-engine#273 renders the REST API reference straight from The raw annotation counts understate the gap.
Where each piece of text comes from
Field comments also land in Audit by tagComputed from
All 11 MCP operations are skipped, so MCP has no row. Other findings:
First wave: most-used endpointsThere's no usage telemetry behind this list.
These all fall in the first seven PRs of the plan, which together cover 132 operations, 159 thin parameters, and 605 fields. Style guidecoder/coder's docs style guide and content guidelines apply. Operations (
|
| # | PR | Ops | Fields |
|---|---|---|---|
| 1 | Users | 34 | 106 |
| 2 | Authorization: login, OTP, password checks, authcheck, API key scopes |
7 | 17 |
| 3 | Organizations | 7 | 39 |
| 4 | Members | 11 | 40 |
| 5 | Builds, including the build, resource, and agent schemas a build returns | 12 | 156 |
| 6 | Workspaces | 23 | 80 |
| 7 | Templates | 38 | 167 |
| 8 | Agents | 23 | 18 |
| 9 | Enterprise: OAuth2 provider (apps, secrets, authorize, tokens, client registration, metadata) | 21 | 94 |
| 10 | Enterprise: AI governance (AI budgets and spend, AI Gateway keys, Agent Firewall sessions) | 18 | 44 |
| 11 | Enterprise: licenses, entitlements, appearance, notification dispatch | 10 | 43 |
| 12 | Enterprise: template and workspace controls (template ACLs, prebuild invalidation, quiet hours, connection log, workspace sharing, external agent credentials) | 11 | 77 |
| 13 | Enterprise: groups and workspace quotas | 11 | 14 |
| 14 | Enterprise: workspace proxies, provisioner keys and daemons, replicas | 12 | 48 |
| 15 | Enterprise: IdP sync | 16 | 12 |
| 16 | Enterprise: SCIM | 6 | 0 |
| 17 | Chats: chats, messages, files, streams | 29 | 228 |
| 18 | Chats: configuration (/api/v2/chats/config/* and organization chat settings) |
22 | 149 |
| 19 | General: operations, plus a pointer to options for deployment settings |
11 | 18 |
| 20 to 35 | One PR each for Notifications, Secrets, AI Gateway, AI Providers, Debug, Git, Insights, TemplateBuilder, PortSharing, Applications, Files, Prebuilds, Audit, InitScript, Provisioning, WorkspaceProxies | 62 | 323 |
Enterprise and Chats are split by area because one PR each would be 105 and 51 operations.
The Chats PRs need the Coder Agents team, and DOCS-717 tracks the chat routes that have no annotations yet.
For each PR:
- Title:
docs: describe the <Tag> API operations, parameters, and fields, with no scope because the change spanscoderd/,codersdk/, and generated files. - Verify every permission and license claim against the handler, and list them in the PR body so the reviewer can check each one.
- Run
make gen,make lint, andgo test ./coderd/coderdtest/ ./enterprise/coderd/coderdenttest/ -run 'EndpointsDocumented|SDKFieldsFormatted', then rerun the audit to show the tag at zero. - Open as a draft with no reviewers.
Open decisions
- Field comments: OK to stop opening them with the Go identifier?
Go doesn't require that for struct fields, but most existingcodersdkcomments do it. - Splits: OK to split Enterprise into eight PRs and Chats into two, as above?
- Ratchet: after the first wave, should
VerifySwaggerDefinitionsrequire@Descriptionon every published route, with an allowlist that each PR shrinks, so new endpoints don't add to the backlog?
This adds a rule for every engineer adding an endpoint, so it needs engineering buy-in. - Audit script: commit it (rewritten in Go under
scripts/apidocgen/) with PR 1 so every PR can rerun the same counts, or keep it out of the repository?
Done when
- Every published operation has a
@Description. - Every parameter says more than its name, and each shared parameter uses one wording.
- Every field on a published
codersdkschema has a comment, exceptDeploymentValues, whichoptionsalready describes.
Related: DOCS-1431 and coder/docs-engine#273 (the renderer), DOCS-1122 (annotation bugs), DOCS-717 (unannotated chat routes), DOCS-1438 (retiring the Markdown generator).
Created by Coder Agents on Nick's behalf.
…on summaries The tag and schemas pages put each summary in Markdown link text, and the old helper escaped table pipes but not the backslash that escapes them, so a summary ending in a backslash could break the table. Summaries are plain text, so every character Markdown would read as syntax is escaped. Assisted-by: AI
…ground
The playground's Send can never reach a Coder deployment from the docs
origin: coderd's CORS answers the Coder-Session-Token preflight with no
Access-Control-Allow-Origin, and even CODER_DANGEROUS_ALLOW_ALL_CORS does
not allow that header. It also kept the reader's token in sessionStorage
on the docs origin.
Each operation page now carries one curl command, built on the server from
the spec and handed to fumadocs-openapi as the operation's x-codeSamples,
so it renders in the same example panel and code block as before. The
deployment URL comes from `coder whoami -o json` and the token from
`coder login token`, both substituted by the shell, so the token is never
typed, shown, or written to shell history. Path parameters and required
query and header parameters stay {name} placeholders; a JSON body is the
schema's example or a sample of its required fields (the first three
fields when none are required), and operations without security send no
token. The playground is off, the default code generators are replaced
by an empty registry, and the server URL variable the playground needed
is gone from the document.
Assisted-by: AI
Both now ship. The Try in Playground panel is back as it was, with the
{deployment} server variable, the Coder-Session-Token field and the
coder-api- storage keys, while the Example Request sample stays the
command that reads the URL and token from the Coder CLI. Its Send still
cannot reach a deployment from the docs origin, which stays pending a
security decision.
The built-in code generators stay replaced by an empty registry, so the
operation's own sample is the only one; the playground's request panel
shows that same command rather than a live one with the typed token.
The playground dialog is portalled out of the API page, so its method
badge missed the page's contrast overrides and fell to 4.15:1 in light
mode. The overrides now cover the portalled dialog too, and the axe pass
scans the playground open in every mode so it stays covered.
Assisted-by: AI
A preview dispatched by hand has no pull request, and Vercel now rejects the deploy with "meta.pr_number should NOT be shorter than 1 characters". Pass the pr_number meta only when one was given. Assisted-by: AI
…d Go Readers script the API in more than the shell, so each operation now carries four server-built samples, as tabs: curl, fetch, requests and net/http. Every sample reads the deployment URL and session token from CODER_URL and CODER_SESSION_TOKEN, the variables the coder CLI itself reads, instead of inlining `coder whoami` and `coder login token` substitutions, so a sample pasted into a script or CI job works as is. The request (placeholders for path and required query parameters, the JSON body sample, the auth header only when the operation needs auth) is built once and written out per language, with each language's own string escaping. curl.ts becomes code-samples.ts, and the lazy highlighter gains the JavaScript, Python and Go grammars. Assisted-by: AI
With one sidebar entry per operation, readers scan for the endpoint by
its verb as much as its name, as on fumadocs.dev. fumadocs-openapi's own
loader plugin draws the badge from a page's `_openapi.method` data, so
the sync now records the method in each operation stub and passes a
validated `_openapi: { method }` frontmatter through to the page, failing
the sync on any other shape, and both apps load the plugin.
The badge's -600/-400 colours fall short of 4.5:1 (7:1 under More
contrast) on the sidebar too, so the existing contrast overrides now also
cover the sidebar and the landing page's cards.
Assisted-by: AI
…nding page The code samples now read CODER_URL and CODER_SESSION_TOKEN, so the landing page tells readers how to set them: from an existing CLI login, or from a long-lived `coder tokens create` token kept in a secret store. The sync inserts that section before the page's first section, and each operation page's note above its samples links to it through the base-path-aware href. Below the page's own Markdown, every operation gets a fumadocs-ui card with its method badge and the first sentence of its description, grouped under one heading per tag in sidebar order. A render-body hook can now add the headings it renders to the page's table of contents, so "On this page" lists the tag sections. The cards are server-rendered with plain links stretched over each card, not client Links, so the few hundred of them add no hydration and no prefetching; the sync computes their heading ids with the same slugger over the page's own headings so none repeats. The language samples are now one tab each, where fumadocs-openapi's default is a select in the code block's header. Assisted-by: AI
…r footer badges With four samples, the playground's code block shows fumadocs-openapi's language select, a combobox with no accessible name, which the axe pass fails as button-name; the code block now names it. The method badge also appears on the previous and next links in the page footer, where its -600 shades fell short of 4.5:1, so the contrast overrides cover the footer too. Assisted-by: AI
Sending a request from the docs needs a proxy or a CORS change on each deployment, and the playground keeps the reader's session token in the browser. Until there is a decision on both, the operation pages show the code samples only, and the axe pass no longer opens the playground. Assisted-by: AI
…penapi-spike # Conflicts: # apps/offlinedocs/scripts/sync-docs.mjs
Jesswinters
left a comment
There was a problem hiding this comment.
Reviewed at 93b9dd0. It's a careful piece of work, and the security claims I could test all held up (details below). However, a real CI failure came in with the latest merge of main, so I'm commenting rather than approving. The PR is also still a draft.
P1: the axe pass fails, so build & check is red, and the merge of main caused it
- Evidence: job 138069003097 reports
color-contrast [serious]on/reference/api/users/create-new-userand/reference/api/workspaces/list-workspacesin the light, more-light and mobile-light modes, with "5 WCAG rule violations, 0 allowlisted". The failing elements are spans insidediv[aria-label="json code"]. - Before the merge: the previous head,
bec26bb, passed the axe pass, and so does main. - Cause: #381 (dark code windows) gives every code span dark Shiki token colours (
brand.css:288). fumadocs-openapi draws its response/request example inside a lightbg-fd-cardwith the code figure set tobg-transparent, so light-on-dark token colours end up on a light card. Dark mode passes, which fits. - Fix: make the API page's example blocks dark code windows like every other block, for example in the PR's API block:
Or exclude that card from the dark-token rule. I couldn't run the axe pass locally (no browser), so please confirm the fix on CI. The PR body's "axe green" line is out of date since this merge.
.coder-api-page figure.shiki.bg-transparent:not(.not-fumadocs-codeblock *) { background-color: var(--docs-code-bg); }
P2: a webpack build of the app breaks on node:path
- Cause:
packages/docs-config/src/openapi-data.tsimportsnode:path, and it is now exported from the@coder/docs-configroot. That's the firstnode:import there, and docs-ui's clientdocs-contextimports that root, so the import ends up in browser code. - Evidence:
next build --webpackinapps/offlinedocsfails withUnhandledSchemeError: Reading from "node:path", with the import traceopenapi-data.js → docs-config/dist/index.js → docs-ui/dist/docs-context.js. With that module changed to plain string joins, the webpack build passes andplayground:checkstays clean. - Why it matters: Turbopack is unaffected. But
withoutOpenApiPlaygroundexplicitly supports webpack and the offline-docs kit is published, and no CI job builds with webpack. - Fix: move
openApiDataDir/openApiDataFileto a server-only subpath export, or dropnode:pathfrom that module. A webpack fixture build in CI would keep this from coming back.
P3
brand.css:1011:.coder-schema-group > summary { font-weight: 600 }is the last 600. Since #380 the theme uses 500 only.openapi-reference.ts:303/306: schema names go raw into backtick code spans inside a table row, so a|or a backtick in a name would break the table. Use the existingcodeSpan()and escape|.code-samples.ts:183: curl leaves out multipart fields whose name contains=, but the JS, Python and Go samples keep them, so the four samples can send different fields. Either skip the field in all four samples, or note in the curl sample that it was left out.openapi/index.tsxpruneDocument:split("/")doesn't decode the JSON Pointer escapes~1/~0, so a component name containing/would be silently dropped from the pruned document. No current Swagger document hits this.- CI also shows
Vercel Security Reviewred here and onbec26bb, while it's green on main. I couldn't see why without a Vercel login, so it's worth a look.
Security checks that held up
- Playground removal: a fixture offlinedocs build passes
playground:checkwith the wrapper, under both Turbopack and webpack (with the P2 patched). Without the wrapper it fails on 5 markers (fumadocs-openapi-flow,fumadocs-openapi-oauth,grant_type,device_code,proxyForwardCookie), so the guard is real. The loader pattern covers all six stubbed modules.playground/index.jsmatches but has no stub, so the build fails loudly if anything imports it. $refchecks: they run before swagger2openapi, after conversion, and before the renderer bundles. In-document refs under a$idset to a URL or a file path triggered no fetch and no file read in the bundler. I interceptedfetchto check this.- Code samples: I used a hostile string containing
' " $(…) \…` \ ${x}and a newline, in the path, header name and value, form field names and JSON keys/values. curl ran under bash with nothing executed, and the samples passnode --check,py_compileandgofmt -e`. - Old-anchor redirect: it uses an
Object.hasOwnlookup into page links built on the server, so there is no open redirect. Descriptions go through remark with no raw HTML, so HTML in a description isn't rendered.readContainedFilerejects absolute paths,.., symlinks on the path, non-regular files and oversized files, and re-checks containment after resolving the path. - Publishing:
rendersOpenApiselects main and lines and tags from 2.24 up and leaves 2.23 and older on Markdown.DOCS_OPENAPI=0turns it off. WithDOCS_PUBLISH=1, a 2.24+ version missingswagger.jsonfails the publish.publish-version.yml,historical-sync.ymlanddocs-pr-preview.ymlall sparse-check-outcoderd/apidoc. Apart from the two theme items above, the merge with main (#388/#390/#391/#392/#278/#383) is consistent.
Checks run locally (all pass): docs-build 188, docs-config 105, docs-manifest 157, docs-next 477, docs-sources 84, docs-theme 34, docs-transforms 461, docs-ui 198, dist-release 88 (+7 skipped), apps/docs 386, offlinedocs 80. Typecheck passes everywhere, along with oxlint --deny-warnings, oxfmt --check and actionlint. I also ran Turbopack and webpack fixture builds of offlinedocs, with and without the wrapper. In CI, everything is green except the axe pass (the P1), build & check because of it, and Vercel Security Review.
This review was generated by Coder Agents on behalf of @Jesswinters.
| } | ||
|
|
||
| /* The example column has a max height: the tab list keeps its size and the sample scrolls. */ | ||
| .coder-sample-tabs > [role="tablist"] { |
There was a problem hiding this comment.
P1: since the merge of #381, code spans get dark Shiki token colours (brand.css:288), but fumadocs-openapi's example card is light bg-fd-card with a bg-transparent figure. The axe pass fails color-contrast on the API pages in light, more-light and mobile-light (job 138069003097). Giving these figures background-color: var(--docs-code-bg) in this block, or excluding the card from the dark-token rule, should fix it.
This review was generated by Coder Agents on behalf of @Jesswinters.
There was a problem hiding this comment.
Fixed in e75537f. .coder-api-page figure.shiki.bg-transparent:not(.not-fumadocs-codeblock *) now sets background-color: var(--docs-code-bg), so the example figures are dark code windows like every other block; the same background applies in More contrast and dark mode through the existing token. The selector matches the figure in the emitted markup of /reference/api/users/create-new-user from a fixture build (inside .coder-api-page), and a new brand.test.mjs pins the rule and fails without it. I can't run axe here (no browser), so the CI axe pass is the check.
| @@ -0,0 +1,13 @@ | |||
| import path from "node:path"; | |||
There was a problem hiding this comment.
P2: this is the first node: import in the @coder/docs-config root, and docs-ui's client docs-context imports that root. next build --webpack in apps/offlinedocs fails with UnhandledSchemeError: Reading from "node:path". Turbopack is fine. Consider a server-only subpath export, or plain string joins here.
This review was generated by Coder Agents on behalf of @Jesswinters.
There was a problem hiding this comment.
Fixed in 410fc59. openapi-data.ts builds its paths with plain string joins and no longer imports node:path. A new test in client-entry.test.ts walks the package root's imports and fails on any node: module (it fails on the old code). A webpack fixture build of apps/offlinedocs (next build --webpack) now passes, and playground:check is clean.
| align-items: center; | ||
| min-height: 2.5rem; | ||
| cursor: pointer; | ||
| font-weight: 600; |
There was a problem hiding this comment.
P3: this is the theme's last font-weight: 600. Since #380 the theme uses 500 only.
This review was generated by Coder Agents on behalf of @Jesswinters.
There was a problem hiding this comment.
Changed to 500 in e75537f. The new brand.test.mjs fails on any font-weight above 500 in brand.css.
| if (best) { | ||
| schemaTargets.set(anchor, best); | ||
| schemaRows.push( | ||
| `| \`${name}\` | [${linkText(best.summary)}](./${best.file.slice(dir.length + 1)}) |`, |
There was a problem hiding this comment.
P3: name goes raw into a code span inside a table row, so a | or backtick would break the row. Use codeSpan() and escape | here and on line 306.
This review was generated by Coder Agents on behalf of @Jesswinters.
There was a problem hiding this comment.
Done in ae799b0: the schema name goes through codeSpan() and its pipes are escaped. I could not write a test that fails on the old code, because swagger2openapi already rewrites a name like a|bctoa_b_c` before this table is built, so the break isn't reachable today. The test pins that the sanitised row stays one cell; the change guards the table against a converter that stops doing that.
| if (body?.kind === "json") lines.push(`-d ${shellSingleQuoted(jsonText(body.value))}`); | ||
| if (body?.kind === "form") { | ||
| // curl splits a field at its first =, so such a name can't be written. | ||
| for (const name of body.fields.filter((field) => !field.includes("="))) |
There was a problem hiding this comment.
P3: curl skips =-named fields, but the JS, Python and Go samples keep them, so the samples can disagree. Skip them in all four, or note in the curl sample that the field was left out.
This review was generated by Coder Agents on behalf of @Jesswinters.
There was a problem hiding this comment.
Fixed in 328316f. The form body drops any field name containing = once, where it is built, so the shell, JavaScript, Python and Go samples all leave it out. A new test checks all four and failed for JavaScript before the change.
The dark token colours from the code window rule landed on fumadocs-openapi's light example card, which fails color-contrast in the light modes. Give the transparent example figures the code window background, and drop the last font-weight above 500. Assisted-by: AI
openApiDataDir and openApiDataFile imported node:path, and the root is read by docs-ui client code, so a webpack build failed on the node: scheme. Plain string joins give the same paths, and a test now walks the root's imports for any node: module. Assisted-by: AI
A name goes through codeSpan() and has its pipes escaped, so it can't end its cell. swagger2openapi already rewrites such names, so this guards the table rather than fixing a reachable break. Assisted-by: AI
The shell sample cannot write a multipart field whose name holds an =, while the JavaScript, Python and Go samples kept it, so the samples sent different fields. The form body now drops such names once, for every language. Assisted-by: AI
A reference to a component whose name holds / or ~ is written with ~1 or ~0, so the pruned document dropped it. Decode each segment before the lookup. Assisted-by: AI
Assisted-by: AI
|
Jess's third review is addressed in 5eceeac, with a reply in each inline thread. A follow-up suggestion, not part of this PR: the webpack failure from the I can't read the Vercel Security Review findings. This round changed no lockfile or package.json; the branch's lockfile differs from main only by the fumadocs-openapi upgrade and its dependencies, and the check was already red on bec26bb, before the merge. |
Keeps the API page's dark example window and sample-tab rules beside main's heading # link rules, and the keyboard check's header names both checks. Assisted-by: AI
The theme uses 500 only, and the weight test fails on the 600 that main's heading link brought in. Assisted-by: AI
Jesswinters
left a comment
There was a problem hiding this comment.
Re-reviewed at 1e469ac. Every finding from my last review is fixed, and I found no P0/P1, so I'm approving.
Fixed
- P1 (axe contrast on API examples):
.coder-api-page figure.shiki.bg-transparentnow gets--docs-code-bg, andbrand.test.mjspins the rule. Theaxe accessibility passis green at this head. - P2 (
node:pathin the docs-config root):openapi-data.tsuses string joins, and the newclient-entry.test.tsfails on anynode:import in the package root. I confirmednext build --webpackofapps/offlinedocsnow succeeds, andplayground:checkon that webpack output says "no API playground code". - The P3s:
font-weightis 500, andbrand.test.mjsfails on anything above 500. 1e469ac also brings main's heading-anchor 600 into line.- Schema names go through
codeSpan()with|escaped. =form fields are dropped once, for all four samples.pruneDocumentdecodes~1before~0, which is the correct order.
Merge with current main: the branch is 3 commits behind (#393, #377, #403). I merged origin/main locally; it merges cleanly, and everything passes on the result:
| Package or app | Tests passed |
|---|---|
| docs-build | 190 |
| docs-config | 106 |
| docs-next | 482 |
| docs-theme | 36 |
| docs-ui | 210 |
| docs-sources | 84 |
| docs-transforms | 463 |
| apps/docs | 386 |
| offlinedocs | 80 |
| dist-release | 92 |
Typecheck passes everywhere it exists, along with oxlint --deny-warnings, oxfmt --check and actionlint.
Remaining (non-blocking)
Vercel Security Reviewis still red here and green on main. I can't see why without a Vercel login. It's worth having someone with access look before merging, since this PR changes the lockfile (the fumadocs-openapi upgrade).- A webpack fixture build in CI, which you suggested as a follow-up, is worth filing now, because the offline kit supports webpack and nothing else tests it.
- After merging, remember to republish
mainand lines 2.24–2.39 on thedocssite, and to re-run URL parity, as the PR body says.
This review was generated by Coder Agents on behalf of @Jesswinters.
…arses it The OpenAPI landing preprocessing runs headingIds before sync's nesting check, so a deeply nested blockquote or list in the API landing page reached the Markdown parser first. headingIds now scans the body and throws past the same MAX_MARKDOWN_NESTING_DEPTH sync enforces, which is exported from one place and imported by sync. Assisted-by: AI
…trap names A Swagger tag named __next_f became a landing section id that never passed through safeHeadingId, so the DOM id shadowed the Flight global. Section ids are now allocated from the protected slug, so deduplication sees final values and the rendered headings and TOC links use the same ids. safeHeadingId is exported from docs-transforms for reuse. Assisted-by: AI
Jesswinters
left a comment
There was a problem hiding this comment.
Re-reviewed at 7912137. The two new commits fix the Vercel Security Review findings, and I found no P0/P1, so I'm approving again.
What changed
- 00a4c21 (nesting before parse):
headingIdsnow runsscanMarkdownNestingand throws pastMAX_MARKDOWN_NESTING_DEPTHbeforefromMarkdown. The constant moved to docs-transforms, so sync and the landing-page rewrite share one cap. The only caller outside transforms isopenapi-reference.ts:457, and I found no otherfromMarkdown/unified()in docs-build or the docs-next OpenAPI code, so that was the only path around the cap. Both new tests (openapi-output.test.tsandtransform.test.ts) check the 100/101 boundary. - 7912137 (DOM-clobbering ids): section ids now go through
safeHeadingId(slugify(tag))before the slugger, so a tag named__next_fbecomesuser-content-__next_f, the same protection ordinary headings get. The test also covers a real tag that already readsuser-content-__next_f: that one gets-1instead of colliding. The docs-next test pins the heading id and the TOC link to the same value.
Checks: I merged current origin/main locally (the branch is 3 commits behind; it merges cleanly), and on the result these all pass:
| Package or app | Tests passed |
|---|---|
| docs-build | 192 |
| docs-transforms | 464 |
| docs-next | 483 |
| docs-config | 106 |
| docs-ui | 210 |
| apps/docs | 386 |
| offlinedocs | 80 |
Typecheck, oxlint --deny-warnings and oxfmt --check also pass. In CI at this head, axe accessibility pass and build & check are green.
Remaining (non-blocking, but please check before merging)
Vercel Security Reviewis still red at 7912137 ("Open findings in coder/docs-engine"). The bot marked the section-id finding resolved, but not the earlier nesting one (transform.ts:1163, 01M7J7QF1ZDP95ZCNCRF2A0Y82). The code fixes that finding, so it most likely just needs marking resolved.vercel security vulnerabilities --scope codercom --repository coder/docs-engine --git-branch vigilante/docs-1431-openapi-spikewill show whether anything else is open; I can't see it without a Vercel login.headingIds' error reportsnesting.linein the comment-stripped content. IfstripHtmlCommentsdoesn't keep line numbers, the line could be off for a page with multi-line comments. That's cosmetic.- Unchanged from before: republish
mainand lines 2.24–2.39 after merging, and re-run URL parity.
This review was generated by Coder Agents on behalf of @Jesswinters.
`lint` has failed on every push to `main` and `release/2.40` since the docs site was republished on the 24th, e.g. https://github.com/coder/coder/actions/runs/45560160492/job/139021802160 coder/docs-engine#273 has the docs site generate one page per REST API endpoint from `coderd/apidoc/swagger.json`, at `reference/api/<section>/<endpoint>`, and list them in `llms.txt`. `lint/docs-redirects` downloads that list, and treats any page on it that isn't in `docs/manifest.json` as a page we removed, so it reported all 389 endpoint pages: ``` docs route "reference/api/agents/authenticate-agent-on-aws-instance" no longer resolves (from the live page list https://coder.com/beta-docs/@main/llms.txt). Add a rule to docs/redirects.json, for example: {"source": "reference/api/agents/authenticate-agent-on-aws-instance", "destination": "/"} ``` Nothing is broken on the site, those pages are live, and I don't think the docs engine is doing anything wrong either. The actual problem is that `make lint` depends on whatever coder.com is serving at the time, so a docs site release can turn `main` red without a commit here. It also fails where nobody can act on it: a PR only downloads the list when it changes `docs/manifest.json` or `docs/redirects.json`, whilst every push to `main` downloads it, and that run is after the merge. So PRs kept passing lint and merging onto a red `main`. To fix, `lint/docs-redirects` now runs with `-offline`, and only compares the manifest and redirects against the base branch. A PR that moves or removes a page without a redirect still fails, as that comparison never needed the download. I think this is the right fix, rather than just teaching the check about endpoint pages, because the download wasn't catching anything. The site is built from the manifest, so a page can only be on the live list and missing from the manifest if a PR removed it, in which case the base comparison already fails that PR, or if the docs engine made the page itself. Today 391 live pages aren't in the manifest, and all of them are the second kind: the 389 endpoint pages, plus 2 pages the site serves with hyphens for dots, which the check already special-cased. Endpoint pages would be the second special case of that kind, and the next docs engine change that adds pages would need a third. What we lose is a second failure on `main` when a page removal is merged past a failing lint, and that failure clears by itself once the site is republished without the page. On a push there's no base branch to compare against, so only the rules themselves are validated there. Alternatives I considered: - Only skipping the endpoint pages, which is what this PR did at first. It fixes today's failure and leaves the cause in place, as above. - Deriving the endpoint pages from `swagger.json` in the check, so they're compared like any other page. That means copying the docs engine's URL rules into this repo and keeping the two in step, in order to catch renamed or removed endpoints. In the last 90 days on `main` that was one removal and no renames. - Deleting the live comparison outright. I've kept it, as it's still useful to run by hand without `-offline`, e.g. after a change to how the docs engine builds its routes. So that it's usable, the first commit stays: routes of the endpoint page form are left out of that comparison whilst their section page is still in the manifest, and it prints how many were skipped. `go run ./scripts/docsredirectscheck -branch main` goes from 389 failures to passing. - Comparing against the previous commit on push runs, so that `main` keeps a removed-route check. That's the comparison the PR already ran, and a failure there comes after the merge. The URL of an endpoint page changes whenever its `@Summary` or tag does, and nothing here will notice. Catching that would mean requiring a redirect on those API changes, which I've left out of this PR. This also needs backporting to `release/2.40`.
Merge order
Independent:
mainis on Fumadocs 16.19.0, which fumadocs-openapi 12.6.1 needs, so nothing has to land first. The docs are live on coder.com/docs (see the runbook), and/beta-docsredirects there, so only thedocssite needs republishing. The new reference renders onmainand every release line and tag from 2.24 up, so after merging, republishmainand the lines 2.24–2.39 on thedocssite. Tags already published stay as they were. Re-run URL parity against thedocssite afterwards, since the API reference's URLs change shape (old anchors redirect, below).Review fixes
The review's 26 comments each have an inline reply. In short:
coderd/apidoctoo, and a publish fails if a version from 2.24 up has noswagger.json, instead of quietly falling back to Markdown.DOCS_OPENAPIis declared on turbo'ssynctask, so the off switch reaches it. A missing Swagger document is told apart from a failedgitread.docs.json, whateverDOCS_VERSIONis.CoderProvisionerKeyis now defined (headerCoder-Provisioner-Daemon-Key, the one coderd reads) instead of dropped. Two pages that would share a path fail the build. A path containing a backtick is fenced so it can't end its code span. A multipart field name can't break the curl sample. The old-anchor redirect no longer crashes on a fragment like#%or a prototype key. The card description caps its input before the link regex.pruneDocumentkeeps, show both$refchecks reject non-local references, and narrow the 64-character exemption to a URL line on its own./oauth2and/.well-knownbase path (the Markdown reference had the same wrong prefix), lighter landing cards, theserversquestion, the keyboard runner's RegExp, and long comments, for a follow-up cleanup. The sharedisObject/collectRefsand the try-it comment were done in the second review round.The second review's 15 comments are all applied, each with an inline reply. The REST API reference contract (HTTP methods, the
$refchecks,isObject, the reference directory, the data file's location and the samples' environment variable names) now lives in one@coder/docs-configmodule that docs-build, docs-next and docs-sources import, instead of separate copies. Both source providers read the Swagger document from the version's own checkout through a newapiDocumentoption, which deletesswaggerFromCloneandswaggerFromTree. OnecreateOpenApiDataLoaderreads the data file,pageHrefbuilds every served link,isLineAtLeastcompares throughcompareVersionIdsDesc, the landing page takes its heading ids from a newheadingIdspass in docs-transforms, and the samples escape single-quoted strings in one place. The client tests sharemountClientandtypeIntohelpers, and a new test pins each select's name to the value it shows. The optional singlereachableRefswalker was left out; the reply says why.Summary
Renders coder/coder's REST API reference with
fumadocs-openapi12.6.1 (on Fumadocs 16.19): one page per endpoint, grouped by tag, like the CLI reference, with code samples in curl, JavaScript, Python and Go, a colored method badge on each endpoint in the sidebar, and a landing page that explains how to set up the two environment variables the samples read and lists every endpoint as a card.mainand every release line and tag from 2.24 up get the new reference; 2.23 and older keep today's Markdown pages. The schemas page gets a filter and is grouped by package. The "Try in Playground" panel is not just turned off but removed from the build: Security decided there is no API playground on coder.com, and a CI check fails any docs or offline-docs export that contains its code.Design
applyOpenApiReferencein@coder/docs-buildconvertscoderd/apidoc/swagger.json(Swagger 2.0) to OpenAPI 3 withswagger2openapi, validates it withoas-validator, and repairs the two source defects that make it invalid, logging each: an undefinedCoderProvisionerKeysecurity scheme and anorganizationpath parameter on two idpsync paths that have no such segment. Operations withx-apidocgen.skipstay hidden, as today (384 of 483 operations are documented).OPENAPI_MIN_LINE = "2.24", checked with a newisLineAtLeasthelper in@coder/docs-manifest:mainand every line or tag from 2.24 up render the new reference, 2.23 and older keep Markdown, andDOCS_OPENAPI=0turns it off everywhere. A dry run of the converter on every published line found 2.24–2.38 andmainconvert cleanly and 2.9–2.23 fail (2.23–2.15 reuse an operationId on the port-share DELETE, fixed in coder/coder 2.24; 2.16 and older also lay the reference out differently), so the floor sits at 2.24. Older Swagger documents that declarebasePath: /api/v2(every line from 2.24 to 2.33 does) have it folded into each path. The offline export follows the same rule for the version it builds. The Swagger readers live in@coder/docs-sourcesand the reference output in@coder/docs-build, soapps/offlinedocsno longer imports fromapps/docsand the offline-docs builder kit still depends only on published packages.DocSourcebeforesyncDocSource: one.mdper operation atreference/api/<tag>/<summary-slug>, with the method and path and the description as its body (so search, the Markdown twin and llms.txt keep working unchanged), and the manifest gains the operations under each tag. Each stub records its HTTP method in a checked_openapifrontmatter field, which the sync passes through and fails on in any other shape. The.md-only invariant holds: nothing is emitted as MDX.renderBodyhook oncreateVersionedDocsandcreateDocsPageswaps an operation page's body for fumadocs-openapi's page, given a document pruned to that one operation and the components it reaches, so a page's props never carry the whole API. The client component sits behindnext/dynamic, so its JavaScript loads only on operation pages. Shiki runs on the JavaScript regex engine with only the grammars the pages use. docs-next pins shiki 4.5.0, the version fumadocs-openapi brings, so the whole site moves from 4.4.3 to 4.5.0 and the lockfile holds one copy.x-codeSamples: curl, JavaScript (fetch), Python (requests) and Go (net/http, standard library only). Every sample reads the deployment URL and token fromCODER_URLandCODER_SESSION_TOKEN, the variables the Coder CLI itself reads, so no sample contains a token or a setup command. Path parameters, and required query and header parameters, stay{name}placeholders; optional query parameters are left out. A JSON body is the schema's example, or@fumadocs/json-schema's sample of the required fields, or the first three fields when none are required, escaped for each language and pretty-printed. Each sample puts the URL in a variable and reads the token once, so lines stay within 64 characters except for a path too long to break; a test pins that, and all 381 real samples passsh -n, shellcheck,node --check,py_compileand gofmt. Operations withoutsecuritysend no token, and the seven that use another scheme get a{SchemeName}header placeholder. fumadocs-openapi's own generators are replaced by an empty registry. The samples render as tabs through itsrenderAPIExampleUsageTabshook, straight from the server-built text, so nothing resolves the reader's stored server URL.playground: { enabled: false }only stops it rendering, though. fumadocs-openapi 12.5.4 imported the playground client statically inui/operation/index.jsand always mountedPlaygroundAuthProviderinutils/create-page.js, which on mount read a pending OAuth flow fromsessionStorageand could post to a stored token URL, so the request UI, fetcher, OAuth flows and the server proxy were all in the shipped JavaScript. 12.5.7 and later (fix(openapi): leave the playground out when it is disabled fuma-nama/fumadocs#3768) lazy-load the client and drop the provider, so a disabled playground no longer runs on the page, but the code is still emitted as a chunk and still reachable from the engine's entry points, which is what the stubs and the CI guard are for.withoutOpenApiPlayground(nextConfig), exported from@coder/docs-next/next-config, adds a Turbopack rule and a webpack rule whose loader replaces those six modules (playground/auth,fetcher,use-playground,ui/playground/client,server/proxy,server/oauth) with inert stubs: the playground renders nothing and every other export throws. The rule matches the resolved file path, so it holds however a module is imported; Turbopack'sresolveAliasmatches only the request string, so it was ruled out. The loader fails the build if a matched module has no stub or its exports differ from the stub's, so a fumadocs-openapi upgrade that moves things breaks loudly.apps/docsandapps/offlinedocsopt in by wrapping their config; a future in-product docs app could leave it out, after a new security review. There is no pnpm patch. A test walks fumadocs-openapi's import graph from the engine's entry points and shows the stubs cut every path to playground code, andplayground:checkin CI (both exports, and the offline-docs kit's smoke build) fails on any of six marker strings found only in that code.localStorageon every operation page, even with the playground off, and in 12.5.4 an invalid value (for example a stray space or period from a paste) threw during render and left every API page on the error boundary until the reader cleared site data. 12.5.7 and later fall back to the page's origin (fix(openapi): fall back to page origin on invalid server URL fuma-nama/fumadocs#3763), so the repair this branch had, which trimmed the stored value and removed it if it wasn't an absolute http(s) URL, is gone. The render tests that seed a leading space with a trailing dot and a non-URL stay, and pass without it.shiki(4.6.0) andlucide-react(1.73.0) pins follow what 12.6.1 resolves, so the lockfile still holds one copy of each;@scalar/json-magicis 0.18.0 for the same reason and a second copy, 0.16.1, stays because@fumadocs/json-schema0.3.5, its latest, still needs it. Upstream now names the example, status and example-response selects, so the wrapper that labelled them is gone and the test pins upstream's names ("Example request", "Response status", "Example"). The playground auth module no longer exportsPlaygroundAuthProvider, so its stub drops it; the stub check failed the build on exactly that, as designed._openapi.method. Outsidereference/api, each tag folder is collapsed to its index page, so non-API pages don't carry 381 extra links in their payload.reference/api/below coder/coder's intro: "Set up your environment", which shows how to setCODER_URLandCODER_SESSION_TOKENfrom an existing CLI login or from a long-lived token, and one card per operation (title, method badge, first sentence of the description), grouped under a heading per tag in sidebar order, so the page's table of contents lists the sections. The cards are server-rendered fumadocs-uiCards, each covered by one plain link, so there are no next/link prefetches or client JavaScript for them. The setup text belongs in coder/coder'sreference/api/index.mdin the long run; it is generated here so this PR doesn't depend on a content change.renderOperationLayouthook the column is now about half the content width (467 / 547 / 552px at 1280 / 1440 / 1920), still sticky with the same height cap; the columns still stack on narrow screens. The sticky column's height cap also let flexbox shrink the language tab list to zero height once a tall sample was selected, so the code covered the tabs and switching back to cURL failed; the tab list no longer shrinks, and thea11y:keyboardrunner now clicks every sample tab in Chromium and Firefox at desktop and mobile widths. Measured over 24 endpoint pages at 1440px, pages where every sample fits without sideways scrolling went from 0 to 17.codersdk,agentsdk, …), with a labelled filter, a live count ("12 of 682 schemas") and an empty state; filtering opens the groups with matches and hides the rest. Without JavaScript, and in the Markdown twin and offline docs, the full table is still there. An oldschemas#<anchor>link still redirects, including when a filter is set.reference/api/<tag>#<anchor>links map toreference/api/<tag>/<anchor>. The tag page becomes a list of its endpoints and redirects an old anchor client-side; the schemas page becomes a table naming, for each of the 682 schemas, the endpoint that shows it most directly, and redirectsschemas#<anchor>there.brand.cssrecolors them on API pages, in the sidebar and on the landing cards, in light, dark and both More contrast modes. Its code blocks left their scroll regions unnamed and its language select had no accessible name; both are named now. The landing page and three fixture API pages are in the axe pass.$refthat is not#/..., before conversion and after it, and the renderer checks the same before fumadocs bundles the document (its bundler would otherwise fetch URLs or read files).swagger.jsonis read through a newreadContainedFilein@coder/docs-sourceswith the tree walk's guarantees: no symlink anywhere on the path, a regular file under the 25 MiB per-file cap, still inside the checkout once resolved; parse errors never include file content, and there is no env override for the path. Nothing on the page needs a new script origin orunsafe-eval.docs-pr-preview.ymlbuildsapps/offlinedocsfrom a sparsedocs/checkout, so this branch addscoderd/apidocto that sparse checkout and wires the same reference intoapps/offlinedocs.publish-version.ymlandhistorical-sync.ymladdcoderd/apidocto their sparse checkouts the same way.Findings
Page weight. Production build of the real corpus, HTML raw / gz:
reference/api/For comparison,
reference/cli/is 306 / 38.4 KiB. The API UI adds about 225 KiB gz of JavaScript, loaded only on operation pages; global CSS grows 4.5 KiB gz for fumadocs-openapi's preset.Build memory (8 GiB cgroup, two-version build, peak): 7.13 / 7.06 GiB on main; about 4.3–4.7 GiB with the mainline on the new reference. The mainline has 844 pages instead of 463 and its pass takes the same time.
Playground Send. Send cannot work against a Coder deployment from this site: coderd's CORS middleware answers the preflight for the
Coder-Session-Tokenheader withoutAccess-Control-Allow-Origin, and evenCODER_DANGEROUS_ALLOW_ALL_CORSallows only Accept, Content-Type, X-LATENCY-CHECK and X-CSRF-TOKEN. It works through a same-origin proxy (tried locally against dogfood with a throwaway proxy, not part of this PR), but a proxy on the docs router would see every reader's token. If the playground comes back with its token field, keep the token in component state only, never in browser storage.Swagger 2.0.
POST /api/v2/filestakes a raw tar or zip body that Swagger 2.0 cannot express, so it renders as a form upload, and/oauth2/revoke(a form-encoded body) gets a file-upload sample.QA
Wait for the preview from
engine-pr-preview.yml, which builds this branch against coder/codermainon every push; once adocs-previewreviewer approves its deploy, it comments the URL here and links it from thedocs previewstatus. Then, in Firefox and Chrome:<preview>/reference/api/. Expected: coder/coder's intro, then "Set up your environment" with twoexportlines, then cards grouped under a heading per API section, each with a title, a colored method badge and a short description; "On this page" lists the sections.CODER_URLandCODER_SESSION_TOKEN(linking back to the setup section), then tabs for cURL, JavaScript, Python and Go./api/v2/users/{user}, reads both variables from the environment, contains no token, and fits the column without scrolling sideways. Click Go, then click cURL; reload and do it again. Expected: the tabs switch every time.exportlines from step 1, copy the cURL sample, replace{user}withme, and run it. Expected: your user as JSON.<preview>/reference/api/templates/#update-template-settings-by-id. Expected: the page moves on to the update-template-settings-by-id page.<preview>/reference/api/schemas/#codersdkworkspace. Expected: it moves on to an endpoint page that shows the Workspace schema. Then open<preview>/reference/api/schemas/and typeworkspacein the filter. Expected: only matching rows remain, their groups open, and the count reads "N of 682 schemas".localStorage.setItem("coder-api-server-url", " http://localhost:3142.")and reload step 2's page. Expected: the page renders normally.fumadocs-openapi-flow(Chrome: Sources, then Cmd+Option+F or Ctrl+Shift+F; Firefox: Debugger, then Cmd+Shift+F or Ctrl+Shift+F). Expected: no results, because the playground code isn't in the build.Pages to compare
The preview URL is the one in the bot's comment and the
docs previewstatus; it needs a Vercel login, and it always shows this PR's latest deploy. Append each path to it.<preview>/reference/api/<preview>/reference/api/users/get-user-by-name/<preview>/reference/api/templates/update-template-settings-by-id/<preview>/reference/api/templates/<preview>/reference/api/schemas/<preview>/install/Testing
After merging
mainonce more (heading#links, README badge stripping, product descriptions) at 1e469ac: two files conflicted,brand.css(both sides appended rules, both kept) and a header comment ina11y-keyboard.mjs. The heading#link rule onmainused weight 600, so it now uses 500 to matchbrand.test.mjs. Unit tests pass in docs-theme 36, docs-next 482, docs-build 190, docs-transforms 463, docs-config 106 and apps/docs 386, and the package builds andcontrast:checkpass. CI at this head passes the axe pass, which covers the dark code window rule for the API examples. The Vercel Security Review reported two low findings, both fixed after that merge.headingIdsnow refuses Markdown nested past 100 levels before it parses, so the OpenAPI landing rewrite cannot bypass sync's nesting limit (00a4c21). Generated API section ids now go throughsafeHeadingId, so a Swagger tag named__next_fcannot shadow a Next.js bootstrap global, and the ids are de-duplicated on their final values (7912137). Each new test fails on the old code except the landing render test in docs-next, which only pins that the heading id and TOC link follow the generated id. Tests pass in docs-transforms 464, docs-build 192, docs-config 106, docs-next 483 and apps/docs 386. The Vercel check needs a rerun to confirm it clears.After merging
mainagain (product switcher, code-server pin, cards): the package builds and typechecks pass; unit tests pass in docs-next 477, docs-build 188, docs-sources 84, docs-manifest 157, docs-transforms 461, docs-config 105, docs-ui 198, docs-site 386 and offlinedocs 80 (docs-router, docs-theme and dist-release were not re-run locally); oxlint and oxfmt are clean on the changed files; and a fixture build passesplayground:check(both exports),csp:check,first-load:checkandparity:urls. CI is the check for the axe pass,a11y:keyboard, the e2e suites andactionlint.After the earlier refresh onto
mainand fumadocs-openapi 12.6.1: unit tests passed in every package and app (docs-next 443, docs-build 185, docs-sources 84, docs-manifest 157, docs-transforms 425, docs-router 218, docs-theme 30, docs-config 102, docs-ui 194, docs-site 357, offlinedocs 80, dist-release 88),pnpm lintwas clean and typecheck passed in all 19 tasks. A strict sync of coder/codermainat d721122 passes: 387 operation pages, the same as the 387 documented operations in itsswagger.json, with 883 pages and 330 images in all. On the fixture build,playground:checkandparity:urlspass (no unapproved mismatches). CI on the pushed commit passesbuild & check, including the axe pass, the single-version and stitch e2e,actionlintandcode samples format; I couldn't run the axe pass locally, because the browser needs a system library that this workspace lacks. The render tests with a leading space plus trailing dot and a non-URL stored server pass with the repair removed. Before this refresh, unit tests passed in every package and app (docs-next 427, docs-build 159, docs-sources 85, docs-manifest 140, docs-transforms 388, docs-router 150, docs-theme 30, docs-config 96, docs-ui 182, docs-site 314, offlinedocs 76, dist-release 78), including new tests for the four samples (auth and no auth, path and query parameters, body escaping per language, line length), the version floor (main, 2.38, 2.24, 2.23, 2.24.x and 2.23.x tags, 2.39, the off switch), thebasePathfold, the schemas filter and groups, the_openapifrontmatter check, the landing page, and a render test that seeds a bad stored server URL and fails on the old code with "Invalid URL".pnpm lintand every typecheck are clean. The axe pass runs 88 scans with no new violations, thea11y:keyboardrunner passes 8 of 8, and the offline-docs kit dry run passes. A real multi-version sync gave operation pages for 2.38, 2.37, 2.36, 2.34, 2.29 and main. On the real corpus, a production single-version build and the dev server both render the landing page and the endpoint pages. The playground guard failed theapps/docsexport before the strip (one 440 KB chunk with five markers, and the same in the offline export) and finds none after it in either fixture export or a real-corpus v2.38.1 offline export; the offline server bundle holds the stubs' error text, not the playground. After the second review round,csp:check,first-load:check,parity:urls,samples:format, the axe pass,a11y:keyboardand the offline-docs kit dry run all passed again. Earlier on this branch:csp:check,first-load:check,parity:urls,a11y:keyboardand the e2e suites passed, and all generated curl commands passedshellcheck.Upstream
Filed fuma-nama/fumadocs#3762 (an invalid stored server URL threw during render) and #3764 (DOCS-1441; a disabled playground still bundled the client and mounted its auth provider). Both are fixed upstream, in #3763 and #3768, and 12.6.1 has them, so the stored-server repair and the select-naming wrapper are removed from this PR. The playground stubs stay: the client is now lazy-loaded but still emitted, and the stub test that walks the import graph still finds playground code without them. The CI guard stays too. Possible later, as options rather than fixes: keeping its bundler to in-document references, and a way to give the page a pruned per-operation document.
https://linear.app/codercom/issue/DOCS-1431
🤖 Built with AI assistance.