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._
19 KiB
Generated
title, description, icon_path
| title | description | icon_path |
|---|---|---|
| Workspace related data | Reference for the `include_related` query parameter, which selects the related data that workspace API responses return. | ./images/icons/api.svg |
This reference is for developers who read workspaces through the Coder Representational State Transfer (REST) API.
It lists the related data that the include_related query parameter selects and the response fields that each selection returns.
The following endpoints accept include_related:
GET /api/v2/workspaces/{workspace}GET /api/v2/users/{user}/workspace/{workspacename}
For the full request and response schema of each endpoint, refer to the Workspaces API reference.
In the Go SDK, pass a wsrelated.Config as the IncludeRelated field of codersdk.WorkspaceOptions.
Select related data
Select only the related data you read, because loading less related data makes the request cheaper.
The value of include_related is a comma-separated list of paths, such as template,latest_build.resources.agents.
Each path is one of the following:
latest_buildlatest_build.joblatest_build.job.queue_positionlatest_build.resourceslatest_build.resources.agentslatest_build.resources.agents.appslatest_build.resources.agents.apps.statuseslatest_build.resources.agents.log_sourceslatest_build.resources.agents.scriptslatest_build.resources.metadatalatest_build.template_versiontemplate
The parameter follows these rules:
- Omit
include_relatedto return all related data. - Pass an empty value,
include_related=, to return only the fields that are always returned. - Selecting a path also selects its ancestors.
For example,
latest_build.jobalso selectslatest_build. - End a path with
.*to select it and every path below it, or pass*to select everything.
An unknown path, an empty entry such as template,,latest_build, or a * before the end of a path returns 400 Bad Request.
Coder checks that you can read the related data you select.
If you can't read part of it, the whole request fails.
GET /api/v2/workspaces/{workspace} returns 403 Forbidden, and GET /api/v2/users/{user}/workspace/{workspacename} returns 404 Not Found.
You might avoid the error by selecting less related data.
The following request returns the workspace with its template data and its latest build, including the build's resources and agents:
curl "https://coder.example.com/api/v2/workspaces/<workspace-id>?include_related=template,latest_build.resources.agents" \
-H "Coder-Session-Token: <your-token>"
Fields that aren't selected
A field that needs related data you didn't select doesn't hold a meaningful value, so don't read it.
Most of these fields are returned with zero values, such as null, an empty string, 0, false, or a zero ID.
Fields that Coder computes from related data, such as health, outdated, and latest_build.status, can hold values computed from the missing data.
For example, without latest_build.resources.agents, health.healthy is true even when an agent is unhealthy.
Response fields
The following table lists each response field and the include_related paths that return it.
A field that holds an object or array returns everything in it.
A field that lists more than one path needs all of them.
These endpoints never populate a field marked Not returned.
| Response field | include_related |
|---|---|
allow_renames |
template |
automatic_updates |
Always returned |
autostart_schedule |
Always returned |
created_at |
Always returned |
deleting_at |
Always returned |
dormant_at |
Always returned |
favorite |
Always returned |
health |
latest_build.resources.agents |
id |
Always returned |
is_prebuild |
Always returned |
last_used_at |
Always returned |
latest_app_status |
latest_build.resources.agents.apps.statuses |
name |
Always returned |
next_start_at |
Always returned |
organization_id |
Always returned |
organization_name |
Always returned |
outdated |
template and latest_build |
owner_avatar_url |
Always returned |
owner_id |
Always returned |
owner_name |
Always returned |
shared_with |
Always returned |
template_active_version_id |
template |
template_allow_user_cancel_workspace_jobs |
template |
template_display_name |
Always returned |
template_icon |
Always returned |
template_id |
Always returned |
template_name |
Always returned |
template_require_active_version |
template |
template_use_classic_parameter_flow |
template |
ttl_ms |
template |
updated_at |
Always returned |
latest_build.build_number |
latest_build |
latest_build.created_at |
latest_build |
latest_build.daily_cost |
latest_build |
latest_build.deadline |
latest_build |
latest_build.has_external_agent |
latest_build |
latest_build.id |
latest_build |
latest_build.initiator_id |
latest_build |
latest_build.initiator_name |
latest_build |
latest_build.matched_provisioners |
latest_build.job |
latest_build.max_deadline |
latest_build |
latest_build.reason |
latest_build |
latest_build.status |
latest_build.job |
latest_build.template_version_id |
latest_build |
latest_build.template_version_name |
latest_build.template_version |
latest_build.template_version_preset_id |
latest_build |
latest_build.transition |
latest_build |
latest_build.updated_at |
latest_build |
latest_build.workspace_id |
latest_build |
latest_build.workspace_name |
latest_build |
latest_build.workspace_owner_avatar_url |
latest_build |
latest_build.workspace_owner_id |
latest_build |
latest_build.workspace_owner_name |
latest_build |
latest_build.job.available_workers |
Not returned |
latest_build.job.canceled_at |
latest_build.job |
latest_build.job.completed_at |
latest_build.job |
latest_build.job.created_at |
latest_build.job |
latest_build.job.error |
latest_build.job |
latest_build.job.error_code |
latest_build.job |
latest_build.job.file_id |
latest_build.job |
latest_build.job.id |
latest_build.job |
latest_build.job.initiator_id |
latest_build.job |
latest_build.job.input |
latest_build.job |
latest_build.job.logs_overflowed |
latest_build.job |
latest_build.job.metadata |
Not returned |
latest_build.job.organization_id |
latest_build.job |
latest_build.job.queue_position |
latest_build.job.queue_position |
latest_build.job.queue_size |
latest_build.job.queue_position |
latest_build.job.started_at |
latest_build.job |
latest_build.job.status |
latest_build.job |
latest_build.job.tags |
latest_build.job |
latest_build.job.type |
latest_build.job |
latest_build.job.worker_id |
latest_build.job |
latest_build.job.worker_name |
Not returned |
latest_build.resources[].created_at |
latest_build.resources |
latest_build.resources[].daily_cost |
latest_build.resources |
latest_build.resources[].hide |
latest_build.resources |
latest_build.resources[].icon |
latest_build.resources |
latest_build.resources[].id |
latest_build.resources |
latest_build.resources[].job_id |
latest_build.resources |
latest_build.resources[].metadata |
latest_build.resources.metadata |
latest_build.resources[].name |
latest_build.resources |
latest_build.resources[].type |
latest_build.resources |
latest_build.resources[].workspace_transition |
latest_build.resources |
latest_build.resources[].agents[].api_version |
latest_build.resources.agents |
latest_build.resources[].agents[].architecture |
latest_build.resources.agents |
latest_build.resources[].agents[].connection_timeout_seconds |
latest_build.resources.agents |
latest_build.resources[].agents[].created_at |
latest_build.resources.agents |
latest_build.resources[].agents[].directory |
latest_build.resources.agents |
latest_build.resources[].agents[].disconnected_at |
latest_build.resources.agents |
latest_build.resources[].agents[].display_apps |
latest_build.resources.agents |
latest_build.resources[].agents[].environment_variables |
latest_build.resources.agents |
latest_build.resources[].agents[].expanded_directory |
latest_build.resources.agents |
latest_build.resources[].agents[].first_connected_at |
latest_build.resources.agents |
latest_build.resources[].agents[].health |
latest_build.resources.agents |
latest_build.resources[].agents[].id |
latest_build.resources.agents |
latest_build.resources[].agents[].instance_id |
latest_build.resources.agents |
latest_build.resources[].agents[].last_connected_at |
latest_build.resources.agents |
latest_build.resources[].agents[].latency |
latest_build.resources.agents |
latest_build.resources[].agents[].lifecycle_state |
latest_build.resources.agents |
latest_build.resources[].agents[].log_sources |
latest_build.resources.agents.log_sources |
latest_build.resources[].agents[].logs_length |
latest_build.resources.agents |
latest_build.resources[].agents[].logs_overflowed |
latest_build.resources.agents |
latest_build.resources[].agents[].metadata |
Not returned |
latest_build.resources[].agents[].name |
latest_build.resources.agents |
latest_build.resources[].agents[].operating_system |
latest_build.resources.agents |
latest_build.resources[].agents[].parent_id |
latest_build.resources.agents |
latest_build.resources[].agents[].ready_at |
latest_build.resources.agents |
latest_build.resources[].agents[].resource_id |
latest_build.resources.agents |
latest_build.resources[].agents[].scripts |
latest_build.resources.agents.scripts |
latest_build.resources[].agents[].started_at |
latest_build.resources.agents |
latest_build.resources[].agents[].startup_script_behavior |
latest_build.resources.agents.scripts |
latest_build.resources[].agents[].status |
latest_build.resources.agents |
latest_build.resources[].agents[].subsystems |
latest_build.resources.agents |
latest_build.resources[].agents[].troubleshooting_url |
latest_build.resources.agents |
latest_build.resources[].agents[].updated_at |
latest_build.resources.agents |
latest_build.resources[].agents[].version |
latest_build.resources.agents |
latest_build.resources[].agents[].apps[].command |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].display_name |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].external |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].group |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].health |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].healthcheck |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].hidden |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].icon |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].id |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].open_in |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].sharing_level |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].slug |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].statuses |
latest_build.resources.agents.apps.statuses |
latest_build.resources[].agents[].apps[].subdomain |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].subdomain_name |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].tooltip |
latest_build.resources.agents.apps |
latest_build.resources[].agents[].apps[].url |
latest_build.resources.agents.apps |