Files
coder/docs/reference
Nick Vigilante 9030742c3e docs: generate a standalone reference page for workspace include_related (#32618)
Adds `scripts/wsrelateddocgen`, a standalone generator that renders a
new Reference page,
[`docs/reference/workspace-related-data.md`](https://github.com/coder/coder/blob/nickvigilante/docs-1860-generate-a-standalone-reference-page/docs/reference/workspace-related-data.md),
from the `wsrelated` struct tags on `codersdk.Workspace` (#32437). The
page explains the `include_related` query parameter, lists the valid
paths, and maps every workspace response field to the paths that return
it. It's wired into `make gen`, so CI fails when the tags and the page
drift apart.

This carries over the content from #32449 as agreed with @spikecurtis.
The table gets its own page instead of going into a Swagger description,
and it doesn't depend on `scripts/apidocgen`, which the FumaDocs OpenAPI
plugin is going to replace. This PR doesn't touch `docs/reference/api/`,
`scripts/apidocgen`, or the Swagger annotations. A follow-up PR will
link the `include_related` parameter description to this page once the
page is live.

The table is row-for-row identical to the one #32449 generates. Changes
from that draft:

- The page lists the 12 valid `include_related` paths, generated from
the same tags, so readers don't have to scan the table for them.
- The generator validates tags with `wsrelated.Parse` instead of adding
a `wsrelated.Paths()` export, so there are no `codersdk` changes.
- Links from the page to the Workspaces API reference are page-level
only, so they keep working when the API reference's anchors change.

Refs #32449, DOCS-1860

**Questions for @spikecurtis (resolved)**

1. The four **Not returned** rows (`latest_build.job.available_workers`,
`.metadata`, `.worker_name`, and
`latest_build.resources[].agents[].metadata`): confirmed. Those fields
come back only when you query the job or agent directly.
2. Permission errors: the page now says that Coder checks read access to
the related data you select and fails the whole request (`403` by ID,
`404` by name), and that selecting less data might avoid the error. Per
your suggestion, it doesn't single out `template`, which is the only
related data with a permission check today (`coderd/workspaces.go:120`,
`:368`, `:2888`).

<details>
<summary>Placement decision, verification, and doc-check
self-check</summary>

### Placement: Reference, not Workspaces

- The reader is an integrator calling the REST API or Go SDK. The
Workspaces section's manifest scope is "guides for Coder end users on
accessing, managing, and personalizing their workspaces", which is a
different audience (`docs/.style/style-guide/audience-and-scope.md`).
- The page is reference material for one API surface, which matches the
existing generated `Reference > API key scopes` page. It sits right
after that page in the sidebar and follows the same `scopesdocgen`
pattern: route metadata from `docs/manifest/`,
`docgenenv.GeneratedHeader`, a Makefile rule with markdownlint and the
table formatter, a `.gitattributes` entry, and a CI `docs-gen` filter
entry.
- It stays out of `docs/reference/api/`. That directory and its
`rest-api.json` sidebar fragment belong to the Swagger generator being
replaced.

### Verification

- `go test ./scripts/wsrelateddocgen/`: passes. Negative controls:
removing the "Not returned" rows, changing the multi-path join, dropping
rows for fields inside arrays, skipping tag validation, and skipping the
multi-path split or the dedupe each make the matching test fail.
- `go test ./coderd/ -run
'TestWorkspaceWSRelatedTags$|TestWorkspaceIncludeRelated$|TestWorkspaceByOwnerAndNameIncludeRelated$'`:
passes. These existing tests pin the behavior the page describes:
omitting the parameter returns everything, paths narrow the response, an
invalid path returns `400`, and every tag yields a populated field.
- `make docs/reference/workspace-related-data.md docs/manifest.json`:
regenerating with `-B` produces identical output.
- `make lint/emdash lint/docs-html lint/docs-manifest
lint/docs-gen-filter`, markdownlint, and Vale on the page: clean.
- `golangci-lint run` with `.golangci.yaml` and
`.golangci.new-code.yaml` on the new package: 0 issues.
- Not run: the full `make gen` and `make lint`, and a live request
against a deployment. The curl example is checked against the handler
source and the tests above. CI runs `go test` on Linux, macOS, and
Windows. The generator only uses `filepath` for file paths, and its
tests don't read files.

### doc-check (author self-check)

Fixed before opening: a Vale `AbbreviationFirstUse` warning for REST, a
"whose" used for a thing (`word-choice.md#whose-for-people-not-things`),
an extra comma before "and", an incomplete list of empty-entry errors,
and the missing list of valid paths.

Not applied:

- I didn't add an explanation of each path. There's no source for those
descriptions, and the field table already shows what each path returns.
- For the permission paragraph, I didn't narrow the statement to
`template`. Self-check flagged the general wording because the other
related data loads with system permissions, but that data is
workspace-scoped: anyone who can read the workspace can read its builds,
resources, and agents (`coderd/database/dbauthz/dbauthz.go:4479`), so
the statement holds in every reachable case.

</details>

---

_Generated by Coder Agents on behalf of @nickvigilante._
2026-12-03 16:13:49 +00:00
..