Skip to content

feat(api-reference): render the REST API reference with fumadocs-openapi - #273

Merged
nickvigilante merged 77 commits into
mainfrom
vigilante/docs-1431-openapi-spike
Nov 24, 2026
Merged

nickvigilante merged 77 commits into
mainfrom
vigilante/docs-1431-openapi-spike

Conversation

@nickvigilante

@nickvigilante nickvigilante commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Merge order

Independent: main is 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-docs redirects there, so only the docs site needs republishing. The new reference renders on main and every release line and tag from 2.24 up, so after merging, republish main and the lines 2.24–2.39 on the docs site. Tags already published stay as they were. Re-run URL parity against the docs site 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:

  • Publishing. The publish and historical-sync workflows now check out coderd/apidoc too, and a publish fails if a version from 2.24 up has no swagger.json, instead of quietly falling back to Markdown. DOCS_OPENAPI is declared on turbo's sync task, so the off switch reaches it. A missing Swagger document is told apart from a failed git read.
  • Offline export. It writes and reads one fixed docs.json, whatever DOCS_VERSION is.
  • Correctness. CoderProvisionerKey is now defined (header Coder-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.
  • Tests. New tests pin what pruneDocument keeps, show both $ref checks reject non-local references, and narrow the 64-character exemption to a URL line on its own.
  • Other. The API page's selects are named and the dead language-select workaround is gone; the schema groups have a chevron; ARCHITECTURE.md records the new package edges.
  • Deferred: the /oauth2 and /.well-known base path (the Markdown reference had the same wrong prefix), lighter landing cards, the servers question, the keyboard runner's RegExp, and long comments, for a follow-up cleanup. The shared isObject/collectRefs and 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 $ref checks, isObject, the reference directory, the data file's location and the samples' environment variable names) now lives in one @coder/docs-config module 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 new apiDocument option, which deletes swaggerFromClone and swaggerFromTree. One createOpenApiDataLoader reads the data file, pageHref builds every served link, isLineAtLeast compares through compareVersionIdsDesc, the landing page takes its heading ids from a new headingIds pass in docs-transforms, and the samples escape single-quoted strings in one place. The client tests share mountClient and typeInto helpers, and a new test pins each select's name to the value it shows. The optional single reachableRefs walker was left out; the reply says why.

Summary

Renders coder/coder's REST API reference with fumadocs-openapi 12.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. main and 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

  • Conversion at sync time. applyOpenApiReference in @coder/docs-build converts coderd/apidoc/swagger.json (Swagger 2.0) to OpenAPI 3 with swagger2openapi, validates it with oas-validator, and repairs the two source defects that make it invalid, logging each: an undefined CoderProvisionerKey security scheme and an organization path parameter on two idpsync paths that have no such segment. Operations with x-apidocgen.skip stay hidden, as today (384 of 483 operations are documented).
  • Which versions. OPENAPI_MIN_LINE = "2.24", checked with a new isLineAtLeast helper in @coder/docs-manifest: main and every line or tag from 2.24 up render the new reference, 2.23 and older keep Markdown, and DOCS_OPENAPI=0 turns it off everywhere. A dry run of the converter on every published line found 2.24–2.38 and main convert 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 declare basePath: /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-sources and the reference output in @coder/docs-build, so apps/offlinedocs no longer imports from apps/docs and the offline-docs builder kit still depends only on published packages.
  • Pages through the normal sync. The transform rewrites the version's DocSource before syncDocSource: one .md per operation at reference/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 _openapi frontmatter field, which the sync passes through and fails on in any other shape. The .md-only invariant holds: nothing is emitted as MDX.
  • Rendering. A renderBody hook on createVersionedDocs and createDocsPage swaps 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 behind next/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.
  • Code samples. Each operation page carries four samples, built on the server from the spec and handed to fumadocs-openapi as x-codeSamples: curl, JavaScript (fetch), Python (requests) and Go (net/http, standard library only). Every sample reads the deployment URL and token from CODER_URL and CODER_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 pass sh -n, shellcheck, node --check, py_compile and gofmt. Operations without security send 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 its renderAPIExampleUsageTabs hook, straight from the server-built text, so nothing resolves the reader's stored server URL.
  • Playground removed from the build. Security decided there is no API playground on coder.com: readers would paste production credentials, and Send cannot reach a deployment from the docs origin anyway (Findings). playground: { enabled: false } only stops it rendering, though. fumadocs-openapi 12.5.4 imported the playground client statically in ui/operation/index.js and always mounted PlaygroundAuthProvider in utils/create-page.js, which on mount read a pending OAuth flow from sessionStorage and 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's resolveAlias matches 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/docs and apps/offlinedocs opt 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, and playground:check in CI (both exports, and the offline-docs kit's smoke build) fails on any of six marker strings found only in that code.
  • A bad stored server URL can't break a page. fumadocs-openapi reads the server URL it saved in localStorage on 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.
  • fumadocs-openapi 12.6.1. The bump follows build(deps): upgrade Fumadocs to 16.19.0 for fumadocs-openapi #370's Fumadocs 16.19. The direct shiki (4.6.0) and lucide-react (1.73.0) pins follow what 12.6.1 resolves, so the lockfile still holds one copy of each; @scalar/json-magic is 0.18.0 for the same reason and a second copy, 0.16.1, stays because @fumadocs/json-schema 0.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 exports PlaygroundAuthProvider, so its stub drops it; the stub check failed the build on exactly that, as designed.
  • Sidebar badges. fumadocs-openapi's sidebar mechanism shows each operation's method badge from the stub's _openapi.method. Outside reference/api, each tag folder is collapsed to its index page, so non-API pages don't carry 381 extra links in their payload.
  • Landing page. The engine adds two sections to reference/api/ below coder/coder's intro: "Set up your environment", which shows how to set CODER_URL and CODER_SESSION_TOKEN from 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-ui Cards, 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's reference/api/index.md in the long run; it is generated here so this PR doesn't depend on a content change.
  • Example column and tabs. fumadocs-openapi pins the example column at 400px, where a typical sample needed 550–970px, so through its renderOperationLayout hook 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 the a11y:keyboard runner 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.
  • Schemas page. The 682 rows are server-rendered in collapsed groups by package (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 old schemas#<anchor> link still redirects, including when a filter is set.
  • URLs. The operation slug is GitHub's slug of the summary, which is exactly today's anchor: all 384 reference/api/<tag>#<anchor> links map to reference/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 redirects schemas#<anchor> there.
  • Accessibility. fumadocs-openapi's method badges and links use -600/-400 shades below 4.5:1 (7:1 under More contrast), so brand.css recolors 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.
  • Security. The converter fails closed, naming the JSON pointer, on any $ref that 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.json is read through a new readContainedFile in @coder/docs-sources with 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 or unsafe-eval.
  • Preview. docs-pr-preview.yml builds apps/offlinedocs from a sparse docs/ checkout, so this branch adds coderd/apidoc to that sparse checkout and wires the same reference into apps/offlinedocs. publish-version.yml and historical-sync.yml add coderd/apidoc to their sparse checkouts the same way.

Findings

Page weight. Production build of the real corpus, HTML raw / gz:

Page Before After
install 166.7 / 30.1 KiB, first-load JS 249.6 KiB gz 168.1 / 30.3 KiB, first-load JS 254.8 KiB gz
API landing page, reference/api/ the Markdown intro 931 / 74.9 KiB (the card markup is about 189 KB raw; React's hydration data is about 64% of the page)
Update template settings by ID (largest endpoint) inside the templates page 444.0 / 51.4 KiB
templates (tag page) 2,497 / 126.6 KiB 338.3 / 42.8 KiB
schemas 15,125 / 600.3 KiB 823 / 87.5 KiB, with the filter and groups (741 / 78.5 KiB without)

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-Token header without Access-Control-Allow-Origin, and even CODER_DANGEROUS_ALLOW_ALL_CORS allows 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/files takes 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/coder main on every push; once a docs-preview reviewer approves its deploy, it comments the URL here and links it from the docs preview status. Then, in Firefox and Chrome:

  1. Open <preview>/reference/api/. Expected: coder/coder's intro, then "Set up your environment" with two export lines, 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.
  2. Click the "Get user by name" card. Expected: the endpoint page, with no "Try in Playground" button, and on the right a note that the samples read CODER_URL and CODER_SESSION_TOKEN (linking back to the setup section), then tabs for cURL, JavaScript, Python and Go.
  3. Click each tab. Expected: each sample calls /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.
  4. Optional, in a terminal where the Coder CLI is logged in: run the two export lines from step 1, copy the cURL sample, replace {user} with me, and run it. Expected: your user as JSON.
  5. Look at the sidebar under REST API. Expected: each endpoint has a colored GET, POST, PUT, PATCH or DELETE badge.
  6. Open <preview>/reference/api/templates/#update-template-settings-by-id. Expected: the page moves on to the update-template-settings-by-id page.
  7. Open <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 type workspace in the filter. Expected: only matching rows remain, their groups open, and the count reads "N of 682 schemas".
  8. Switch to dark, then to More contrast in the display settings, on the landing page and on step 2's page. Expected: the badges and links stay readable.
  9. Optional: in the browser console run localStorage.setItem("coder-api-server-url", " http://localhost:3142.") and reload step 2's page. Expected: the page renders normally.
  10. Optional, on step 2's page: open DevTools and search all loaded sources for 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 preview status; it needs a Vercel login, and it always shows this PR's latest deploy. Append each path to it.

What to check Production Preview
Landing page with setup and cards https://coder.com/docs/reference/api/ <preview>/reference/api/
An endpoint page (whoami) https://coder.com/docs/reference/api/users/#get-user-by-name <preview>/reference/api/users/get-user-by-name/
Largest endpoint page https://coder.com/docs/reference/api/templates/#update-template-settings-by-id <preview>/reference/api/templates/update-template-settings-by-id/
Tag page https://coder.com/docs/reference/api/templates/ <preview>/reference/api/templates/
Schemas https://coder.com/docs/reference/api/schemas/ <preview>/reference/api/schemas/
A non-API page https://coder.com/docs/install/ <preview>/install/

Testing

After merging main once 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 in a11y-keyboard.mjs. The heading # link rule on main used weight 600, so it now uses 500 to match brand.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 and contrast:check pass. 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. headingIds now 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 through safeHeadingId, so a Swagger tag named __next_f cannot 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 main again (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 passes playground:check (both exports), csp:check, first-load:check and parity:urls. CI is the check for the axe pass, a11y:keyboard, the e2e suites and actionlint.

After the earlier refresh onto main and 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 lint was clean and typecheck passed in all 19 tasks. A strict sync of coder/coder main at d721122 passes: 387 operation pages, the same as the 387 documented operations in its swagger.json, with 883 pages and 330 images in all. On the fixture build, playground:check and parity:urls pass (no unapproved mismatches). CI on the pushed commit passes build & check, including the axe pass, the single-version and stitch e2e, actionlint and code 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), the basePath fold, the schemas filter and groups, the _openapi frontmatter 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 lint and every typecheck are clean. The axe pass runs 88 scans with no new violations, the a11y:keyboard runner 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 the apps/docs export 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:keyboard and the offline-docs kit dry run all passed again. Earlier on this branch: csp:check, first-load:check, parity:urls, a11y:keyboard and the e2e suites passed, and all generated curl commands passed shellcheck.

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.

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
@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
coder-docs-router Ready Ready Preview Nov 24, 2026 8:05pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
coder-docs Skipped Skipped Nov 24, 2026 8:05pm UTC

Request Review

@linear-code

linear-code Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
DOCS-1431 Spike: render the REST API reference with fumadocs-openapi (per-endpoint pages, try-it panel)

One-night spike to see whether fumadocs-openapi can replace the generated Markdown API reference (docs/reference/api/*.md in coder/coder) with something lighter and more useful. This is a throwaway branch with a preview for Nick to try; it isn't meant to merge.

Why

  • schemas.md is 1.2 MB of Markdown and becomes a 15 MB page (326 K brotli). The API pages are the largest single build cost: removing them saves about 2.7 GiB of build peak, and splitting only schemas.md saves about 1.1 GiB.
  • The CLI reference is already one page per subcommand. The API should read the same way: one page per endpoint, grouped by tag, with request and response types inline.

Scope

  • Convert coder/coder's coderd/apidoc/swagger.json (Swagger 2.0) to OpenAPI 3 when syncing.
  • Render the mainline version with fumadocs-openapi: one page per operation, grouped by tag, and types as expandable trees.
  • The try-it panel builds the request and a curl command. Sending requests from the browser to a Coder deployment depends on CORS and on users entering tokens into the page, which needs Security review, so note what works and don't ship it.
  • Measure:
    • page weight (HTML, first-load JS on API pages compared with other pages);
    • build peak memory compared with today;
    • the axe pass;
    • CSP compliance (no 'unsafe-eval', no new script origins).
  • What happens to links to the current reference/api/<tag> pages and schemas#… anchors.

Outcome

Go 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

Problem

coder/docs-engine#273 renders the REST API reference straight from coderd/apidoc/swagger.json, one page per endpoint.
The demo showed how little text most pages have: a summary, bare parameter names, and schema fields with no explanation.

The raw annotation counts understate the gap.
There are 487 @Summary lines in coderd/ and enterprise/coderd/ (483 routes, plus 4 matches in the swagger test helper) and 93 @Description lines, but descriptions span several lines each, so only 24 of 483 operations have one.
Of the 384 operations the reference publishes, 21 have a description.
The other 99 are hidden with @x-apidocgen {"skip": true} and are out of scope here.

swagger.json, coderd/apidoc/docs.go, and docs/reference/api/*.md are generated by make gen (scripts/apidocgen), so every fix goes in the Go source.

Where each piece of text comes from

Reference text Source in coder/coder Has text today
Operation description // @Description lines on the handler in coderd/ or enterprise/coderd/ 21 of 384 published operations
Parameter description The quoted string in // @Param swaggo requires one, so none is empty, but 381 of 584 are three words or fewer
Schema field description The Go doc comment above the codersdk struct field, copied verbatim 526 of 2,434 fields on published codersdk schemas
Schema description // @Description above the type; swaggo ignores plain Go doc comments on types 3 of 615 codersdk types
Tag description @tag.name and @tag.description in coderd/coderd.go 2 of 28 tags

Field comments also land in site/src/api/typesGenerated.ts and the Go SDK docs, so each PR regenerates those too.

Audit by tag

Computed from coderd/apidoc/swagger.json on main at edd2e07041 (2026-10-28), published operations only.
"Thin" means a parameter description of three words or fewer, such as Page limit, After ID, or Organization ID.
Each codersdk schema is counted once, under the first PR in the plan order below whose published endpoints return it, directly or nested, so the field column is the work that PR owns and the column sums to the total.

Tag Published ops No @Description Params Thin params codersdk fields with no comment Main codersdk files
Users 34 34 42 17 106 of 128 users.go, apikey.go
Authorization 7 7 7 5 17 of 25 users.go, scopes_catalog.go, authorization.go
Organizations 7 7 13 7 39 of 41 provisionerdaemons.go, organizations.go
Members 11 11 22 17 40 of 49 organizations.go, roles.go
Builds 12 11 25 21 156 of 206 workspacebuilds.go, workspaceagents.go
Workspaces 23 21 45 31 80 of 98 workspaces.go
Templates 38 36 68 61 167 of 222 templates.go, templateversions.go, parameters.go
Enterprise 105 99 170 106 332 of 436 oauth2.go, groups.go, templates.go
Chats 51 46 70 48 377 of 478 chats.go
Agents 23 23 36 27 18 of 38 workspaceagents.go
Notifications 13 13 14 2 35 of 35 notifications.go, inboxnotification.go
General 11 11 2 1 253 of 357 deployment.go
Secrets 6 6 12 6 20 of 21 usersecrets.go
AI Gateway 5 1 10 1 73 of 88 aibridge.go
AI Providers 5 5 5 0 31 of 32 aiproviders.go
Debug 5 5 2 1 0 of 0
Git 5 5 4 4 20 of 25 externalauth.go
Insights 5 5 13 10 53 of 56 insights.go
TemplateBuilder 5 5 4 3 48 of 51 templatebuilder.go
PortSharing 3 3 5 3 12 of 12 workspaceagentportshare.go
Applications 2 2 1 1 0 of 1
Files 2 1 3 1 1 of 1 files.go
Prebuilds 2 2 1 1 1 of 1 prebuilds.go
Audit 1 1 3 3 23 of 25 audit.go
InitScript 1 1 2 2 0 of 0
Provisioning 1 1 5 2 0 of 0
WorkspaceProxies 1 1 0 0 6 of 8 workspaceproxy.go
Total 384 363 584 381 1,908 of 2,434

All 11 MCP operations are skipped, so MCP has no row.
Another 283 undocumented fields sit on schemas that only skipped operations return, and 154 of 261 fields on non-codersdk schemas (agentsdk, healthsdk, serpent, and others) have no description; both are out of scope unless a PR's endpoints return them.

Other findings:

  • The organization path parameter reads Organization ID on 48 routes, but httpmw.ExtractOrganizationParam also accepts a name or default (coderd/httpmw/organizationparam.go:72).
    The same parameter has three wordings across 57 routes.
  • The user path parameter has four wordings across 54 routes (User ID, name, or me, User ID, username, or me, Username, UUID, or me, User ID); httpmw.ExtractUserParam accepts an ID, a username, or me.
  • Field comments open with the Go identifier, so the reference shows DeletingAt indicates the time at which… under deleting_at.
  • 235 of General's 253 undocumented fields sit under codersdk.DeploymentValues.
    Their descriptions already exist as serpent.Option descriptions in codersdk/deployment.go, and GET /api/v2/deployment/config returns them at runtime in options, so copying them into field comments would create a second copy that drifts.

First wave: most-used endpoints

There's no usage telemetry behind this list.
It's the calls behind the core CLI workflows, plus the two endpoints the rest of the docs link to most (Get users and Update template settings by ID, four links each).

Endpoint Called by Gaps
POST /api/v2/users/login coder login with a password No description; all 3 request and response fields
GET /api/v2/users/{user} coder login, coder whoami No description; User 13 of 15 fields
GET /api/v2/users coder users list No description; q, limit, offset, after_id are thin
POST /api/v2/users coder users create No description; CreateUserRequest 4 of 9 fields
POST /api/v2/users/{user}/keys/tokens coder tokens create No description; CreateTokenRequest 4 of 5 fields
GET /api/v2/organizations coder organizations list No description; Organization 8 of 9 fields
GET /api/v2/organizations/{organization} coder organizations show No description; organization parameter
GET /api/v2/organizations/{organization}/templates/{templatename} coder templates push, edit, pull No description; Template 30 of 39 fields
POST /api/v2/organizations/{organization}/templateversions coder templates push No description; TemplateVersion 14 of 14 fields
PATCH /api/v2/templates/{template}/versions coder templates push, versions promote No description
PATCH /api/v2/templates/{template} coder templates edit No description; UpdateTemplateMeta 14 of 26 fields
POST /api/v2/users/{user}/workspaces coder create Has a description; CreateWorkspaceRequest 5 of 9 fields
GET /api/v2/workspaces coder list No description; limit, offset are thin
GET /api/v2/users/{user}/workspace/{workspacename} start, stop, ssh, show, and others No description; Workspace 26 of 32 fields
POST /api/v2/workspaces/{workspace}/builds coder start, stop, restart, delete No description; WorkspaceBuild 23 of 24 fields
GET /api/v2/workspacebuilds/{workspacebuild}/logs coder logs, build output in the CLI No description; before, after, follow are thin

These all fall in the first seven PRs of the plan, which together cover 132 operations, 159 thin parameters, and 605 fields.

Style guide

coder/coder's docs style guide and content guidelines apply.
These rules cover what's specific to annotations.

Operations (@Description)

  • Write one or two sentences in second person, present tense, active voice: what the call does, then when to use it.
  • Make the first sentence stand on its own, because the API landing page in docs-engine#273 shows it on each endpoint's card.
  • Don't restate the summary, which is already the page title.
  • When the call needs more than a member's permissions, add a sentence that names the permission and the built-in roles that have it, using role names from coderd/rbac/roles.go (Owner, User Admin, Template Admin, Auditor, Organization Admin, and so on).
    Check the claim against the handler's api.Authorize calls or the dbauthz query it runs.
  • When a list call filters by permission instead of failing, say so, for example "Returns only the workspaces you can read."
  • Add "Requires a Premium license." only when the route sits behind RequireFeatureMW or an entitlement check in the handler.
    Not every Enterprise-tagged route does: POST /api/v2/licenses is how you add the license.
  • Say when a route upgrades to a WebSocket or streams server-sent events, and what each message carries.
  • For deprecated routes, keep @Deprecated and name the replacement by its full path.
  • Write full API paths (/api/v2/workspaces), and put exact field names, parameter names, and enum values in backticks.

Examples, checked against the handlers:

  • GET /api/v2/workspaces: "Returns the workspaces you can read, filtered by the q search query. Use it to find workspaces by owner, template, or status, for example owner:me status:running."
  • POST /api/v2/workspaces/{workspace}/builds: "Starts, stops, or deletes a workspace by queuing a build with the given transition. Use it to change a workspace's state, or set template_version_id to move the workspace to another template version."
  • POST /api/v2/users: "Creates a user account, or a service account for automation when service_account is true. Requires permission to create users, which the Owner and User Admin roles have."

Parameters (@Param)

  • Say what the value selects, which forms it accepts, and its default and limits, taken from the code.
  • Use one wording per parameter everywhere it appears:
    • user: "User ID, username, or me for the authenticated user."
    • organization, on routes that use ExtractOrganizationParam: "Organization ID, name, or default for the default organization."
    • limit, offset, and after_id: one shared wording each.
  • For a q search parameter, list the accepted keys, as GET /api/v2/workspaces already does.

Schema fields (Go comments in codersdk)

  • Describe the value, and don't open with the Go field name, because the reference shows the comment under the JSON name.
  • Refer to other fields by their JSON names, in backticks.
  • Give units, formats, and what null or an omitted value means.
  • Example, Workspace.deleting_at.
    Today: "DeletingAt indicates the time at which the workspace will be permanently deleted. A workspace is eligible for deletion if it is dormant (a non-nil dormant_at value) and a value has been specified for time_til_dormant_autodelete on its template."
    Proposed: "When the workspace is permanently deleted. Set only while the workspace is dormant and its template sets time_til_dormant_autodelete_ms."
  • Add a type-level @Description only when a rule spans several fields, as on CreateWorkspaceRequest.
  • Don't copy serpent.Option descriptions into DeploymentValues field comments.

Mechanics

  • Never edit swagger.json, docs.go, or docs/reference/api/*.md by hand; run make gen and commit the regenerated files with the source change.
  • Keep the Go function comment above the swagger block, which TestEndpointsDocumented enforces.
  • Don't use em dashes or en dashes, and don't put Linear IDs or internal URLs in committed text.

Plan: one PR per tag

Each PR changes comments and annotations only, with no behavior change, so the swagger.json diff should touch only description keys.
The first seven PRs cover the first wave.

# 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 spans coderd/, 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, and go 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

  1. Field comments: OK to stop opening them with the Go identifier?
    Go doesn't require that for struct fields, but most existing codersdk comments do it.
  2. Splits: OK to split Enterprise into eight PRs and Chats into two, as above?
  3. Ratchet: after the first wave, should VerifySwaggerDefinitions require @Description on 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.
  4. 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 codersdk schema has a comment, except DeploymentValues, which options already 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.

Review in Linear

…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
@vercel
vercel Bot temporarily deployed to Preview – coder-docs October 28, 2026 10:19 Inactive
@vercel
vercel Bot temporarily deployed to Preview – coder-docs-router October 28, 2026 10:19 Inactive
…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
@vercel
vercel Bot temporarily deployed to Preview – coder-docs October 28, 2026 11:03 Inactive
@vercel
vercel Bot temporarily deployed to Preview – coder-docs-router October 28, 2026 11:03 Inactive
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 Jesswinters left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-user and /reference/api/workspaces/list-workspaces in the light, more-light and mobile-light modes, with "5 WCAG rule violations, 0 allowlisted". The failing elements are spans inside div[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 light bg-fd-card with the code figure set to bg-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:
    .coder-api-page figure.shiki.bg-transparent:not(.not-fumadocs-codeblock *) {
      background-color: var(--docs-code-bg);
    }
    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.

P2: a webpack build of the app breaks on node:path

  • Cause: packages/docs-config/src/openapi-data.ts imports node:path, and it is now exported from the @coder/docs-config root. That's the first node: import there, and docs-ui's client docs-context imports that root, so the import ends up in browser code.
  • Evidence: next build --webpack in apps/offlinedocs fails with UnhandledSchemeError: Reading from "node:path", with the import trace openapi-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 and playground:check stays clean.
  • Why it matters: Turbopack is unaffected. But withoutOpenApiPlayground explicitly supports webpack and the offline-docs kit is published, and no CI job builds with webpack.
  • Fix: move openApiDataDir/openApiDataFile to a server-only subpath export, or drop node:path from 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 existing codeSpan() 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.tsx pruneDocument: 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 Review red here and on bec26bb, 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:check with 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.js matches but has no stub, so the build fails loudly if anything imports it.
  • $ref checks: they run before swagger2openapi, after conversion, and before the renderer bundles. In-document refs under a $id set to a URL or a file path triggered no fetch and no file read in the bundler. I intercepted fetch to 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.hasOwn lookup 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. readContainedFile rejects absolute paths, .., symlinks on the path, non-regular files and oversized files, and re-checks containment after resolving the path.
  • Publishing: rendersOpenApi selects main and lines and tags from 2.24 up and leaves 2.23 and older on Markdown. DOCS_OPENAPI=0 turns it off. With DOCS_PUBLISH=1, a 2.24+ version missing swagger.json fails the publish. publish-version.yml, historical-sync.yml and docs-pr-preview.yml all sparse-check-out coderd/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"] {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/docs-theme/src/brand.css Outdated
align-items: center;
min-height: 2.5rem;
cursor: pointer;
font-weight: 600;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)}) |`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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("=")))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@nickvigilante
nickvigilante marked this pull request as ready for review November 23, 2026 23:36
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
@nickvigilante

nickvigilante commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

Jess's third review is addressed in 5eceeac, with a reply in each inline thread. pruneDocument now decodes JSON Pointer escapes (~1 to /, then ~0 to ~) in each reference segment, so a component whose name holds / or ~ is kept; the new test fails on the old code (8d10c2d).

A follow-up suggestion, not part of this PR: the webpack failure from the node:path import went unseen because no CI job builds with webpack, though withoutOpenApiPlayground and the published offline-docs kit support it. A fixture next build --webpack of apps/offlinedocs plus playground:check would keep it from coming back, as its own job in the build & check needs list. I left it out here because it changes the deploy boundary and the size of this PR.

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 Jesswinters left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-transparent now gets --docs-code-bg, and brand.test.mjs pins the rule. The axe accessibility pass is green at this head.
  • P2 (node:path in the docs-config root): openapi-data.ts uses string joins, and the new client-entry.test.ts fails on any node: import in the package root. I confirmed next build --webpack of apps/offlinedocs now succeeds, and playground:check on that webpack output says "no API playground code".
  • The P3s:
    • font-weight is 500, and brand.test.mjs fails 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.
    • pruneDocument decodes ~1 before ~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 Review is 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 main and lines 2.24–2.39 on the docs site, 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 Jesswinters left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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): headingIds now runs scanMarkdownNesting and throws past MAX_MARKDOWN_NESTING_DEPTH before fromMarkdown. The constant moved to docs-transforms, so sync and the landing-page rewrite share one cap. The only caller outside transforms is openapi-reference.ts:457, and I found no other fromMarkdown/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.ts and transform.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_f becomes user-content-__next_f, the same protection ordinary headings get. The test also covers a real tag that already reads user-content-__next_f: that one gets -1 instead 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 Review is 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-spike will show whether anything else is open; I can't see it without a Vercel login.
  • headingIds' error reports nesting.line in the comment-stripped content. If stripHtmlComments doesn't keep line numbers, the line could be off for a page with multi-line comments. That's cosmetic.
  • Unchanged from before: republish main and lines 2.24–2.39 after merging, and re-run URL parity.

This review was generated by Coder Agents on behalf of @Jesswinters.

@nickvigilante
nickvigilante merged commit 7168f17 into main Nov 24, 2026
36 of 39 checks passed
@nickvigilante
nickvigilante deleted the vigilante/docs-1431-openapi-spike branch November 24, 2026 20:40
ethanndickson added a commit to coder/coder that referenced this pull request Nov 25, 2026
`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`.

This branch is waiting to be deployed

1 active (outdated), 2 inactive (1 outdated), and 1 waiting deployments
docs-preview — 7912137b Waiting Nov 24, 2026 by nickvigilante via preview / deploy preview #121
Preview — 7912137b Deployed Nov 24, 2026 by vercel[bot]
Preview – coder-docs-router — df5e1068 Deployed Oct 29, 2026 by vercel[bot]
Preview – coder-docs — df5e1068 Deployed Oct 29, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants