## Problem `apps/docs` ordered its build, dev and codegen steps with pnpm `pre`/`post` hooks and `&&` chains. Turbo couldn't see those steps, so it couldn't cache or parallelize them, and running the build through turbo ran the codegen twice. Part of [FE-4948](https://linear.app/supabase/issue/FE-4948/migrate-the-pnpm-scripts-to-use-turbo). ## Solution The ordering now lives in `apps/docs/turbo.jsonc` as `dependsOn`, and every pre/post hook is gone. The new `maybe-turbo` workspace bin runs a script through `turbo run` unless it's already inside turbo, so `pnpm build`, `pnpm dev`, `pnpm codegen:references` and the other entry points keep running their prerequisites. Turbo is bumped to 2.11.10 for its `jit` input mode. Tasks downstream of the uncached remote fetches use it to hash the gitignored files those fetches write after they finish, so a cache hit can't restore output built from older content. Strict-mode env vars are declared. Other changes: - The R2 upload moves from `postbuild` to the `vercel.json` build command, so it still runs when the build is a cache hit. - `codegen:references:new:ensure` re-downloads when any JavaScript TypeDoc dump is missing or empty. - The guides manifest is now sorted, so its output is deterministic. - A new `turbo-scripts` agent skill (listed in `AGENTS.md`) documents these conventions for every app. Its audit script, `node .agents/skills/turbo-scripts/scripts/audit.mjs apps/<name>`, flags scripts that need `maybe-turbo`, leftover `pre`/`post` hooks, script chains, and wrapped scripts without a turbo task. ## Review instructions 1. Read `packages/maybe-turbo/README.md`, `apps/docs/turbo.jsonc` and `.agents/skills/turbo-scripts/SKILL.md`. 2. From `apps/docs`, set `GH_TOKEN=$(gh auth token)` for the federated fetch and run `pnpm run build:markdown` a few times. Once warm, every task except `build:federated-content` and `codegen:references:new:ensure` should hit the cache. 3. Run `pnpm build` from `apps/docs` and check that the docs Vercel preview deploys and renders normally. ## Checklist Check all before review: - [ ] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
5.7 KiB
Management API reference generation
How /docs/reference/api/* is built from the live Management API OpenAPI
spec. Verify against apps/docs/spec/Makefile and
features/docs/Reference.generated.script.ts before acting — paths drift.
Pipeline
flowchart LR
live["api.supabase.com<br/>/api/v1-json + v2-json"]
raw["spec/api_v{1,2}_openapi.json"]
redocly["Redocly bundle<br/>(no --dereferenced)"]
bundled["spec/transforms/<br/>api_v*_openapi_deparsed.json"]
sections["common-api-sections.json"]
codegen["codegen:references:legacy"]
gen["features/docs/generated/<br/>api.latest.*.json"]
page["ApiReferencePage →<br/>ApiEndpointSection"]
md["public/markdown/reference/api.md"]
live --> raw --> redocly --> bundled
bundled --> sections
bundled --> codegen
sections --> codegen
codegen --> gen --> page
gen --> md
- Download —
make download.api.v1inapps/docs/spec/curls the live OpenAPI intoapi_v1_openapi.json/api_v2_openapi.json. - Bundle —
make dereference.api.v1runs Redocly CLI (@redocly/cli)bundleintotransforms/*_deparsed.json. Management API deliberately omits--dereferenced(circular$refinAPIErrorObject.issues).$refsare resolved later in codegen with a cycle guard. - Nav sections —
sections/generateMgmtApiSections.ctswalks operations/tags intocommon-api-sections.json. - Codegen —
codegen:references:legacy(Reference.generated.script.ts) merges v1+v2, resolves refs, writesapi.latest.endpointsById.json,sections.json,flat.json,bySlug.jsonunderfeatures/docs/generated/. - Runtime —
/reference/api/[operation]viaApiReferencePage→SectionSwitch→ApiEndpointSection(custom React, not MDX). One endpoint per page (DOCS-1268). Hand-written intro MDX lives underdocs/ref/api/. - Agents —
generate-reference-markdown.tsexports the same data topublic/markdown/reference/api.md.
Legacy EJS (generator/api.ts + ApiTemplate.ts) is not the live path.
Redocly today (bundle / lint)
| Job | Where | Notes |
|---|---|---|
| Bundle | make dereference.api.v1 (and sibling targets for auth/storage/analytics) |
Invoked via npx --package=@redocly/cli redocly bundle |
| Lint | make validate.analytics.v0 only |
redocly lint --extends=minimal. Management API has no lint target |
Redocly is the OpenAPI toolchain (bundle/lint), not the page renderer.
Rendering: keep the custom path
Pages render via custom React (ApiEndpointSection), not Scalar / Redoc /
Stoplight Elements. Reasons (see also adding-features.md
and known-issues.md):
- Two pipelines — HTML + markdown export + GraphQL search share one
IApiEndPoint/ generated-JSON shape. A third-party viewer forks that. - Custom extensions —
x-oauth-scope,x-allowed-plans,x-fga-permissionsneed first-class rendering. - Modular pages — DOCS-1268 already split the monolithic API page; embedding a full-spec viewer would reverse that.
- Surface — new dep + theming + parity work fights docs-app direction (reduce surface, don't add parallel renderers).
Prefer improving ApiEndpointSection / schema helpers, or deepening
Redocly lint on download/transform. Do not propose swapping the renderer
for an OpenAPI UI kit without addressing markdown/search/x-* parity.
Closest CLI substitutes if Redocly were unavailable: @apidevtools/swagger-parser
or swagger-cli for bundle; Spectral for lint. Switching buys little while
the custom cycle-safe resolve remains required.
Key files
| Path | Role |
|---|---|
apps/docs/spec/Makefile |
download / Redocly bundle / section generate |
apps/docs/spec/sections/generateMgmtApiSections.cts |
OpenAPI → common-api-sections.json |
apps/docs/features/docs/Reference.generated.script.ts |
merge, resolve refs, write api.latest.* |
apps/docs/features/docs/Reference.api.utils.ts |
IApiEndPoint + schema display helpers |
apps/docs/features/docs/Reference.apiPage.tsx |
route → one operation page |
apps/docs/features/docs/Reference.sections.tsx |
ApiEndpointSection UI |
apps/docs/internals/generate-reference-markdown.ts |
agent markdown export |
Scoped personal access token permission tables
The "Personal Access Tokens" guide's permission and MCP tables are generated
from the Management API specs, MCP permission map, and the same shared catalog
Studio uses. Regenerate content/_partials/access-control/scoped_pat_*.mdx with
make -C apps/docs/spec generate.partials.access-control. Docs Tests runs this
on relevant pull requests and fails if the partials drift; the weekly Management
API update also runs it after refreshing the live inputs.
Related
build-pipeline.md— wherecodegen:referencessits in the turbo graph.app-map.md— reference vs guides routing.known-issues.md— reference pages avoid standard MDX; length / modularization direction.llm-agent-surface.md— markdown export consumption.