Repository navigation
Conversation
|
Not feedback directly on your changes, but playing around with this rendered content makes it plainly obvious that we are severely lacking in attribute and top-level resource descriptions. Looks good though. |
fd6b98a to
060145b
Compare
661da62 to
dcdba1b
Compare
dcdba1b to
bdc58fe
Compare
| - <code title="delete /accounts/{account_id}/widgets/{widget_id}">client.Widgets.<a href="https://pkg.go.dev/x#WidgetService.Delete">Delete</a>(ctx, widgetID) error</code> | ||
| `; | ||
|
|
||
| const RESOURCE_GO = `package widget |
There was a problem hiding this comment.
just a thought for later, but it'd be nice to be able to have this stuff generated from forge for the sake of the docs
| import { lstat, readdir, readFile, realpath, stat } from 'node:fs/promises'; | ||
| import path from 'node:path'; | ||
|
|
||
| const DEFAULT_MAX_BYTES = 4 * 1024 * 1024; |
There was a problem hiding this comment.
where'd the estimates for this default come from? just making sure we don't actually need more
dimitropoulos
left a comment
There was a problem hiding this comment.
great work - my only general feedback is it would be nice to put this somewhere separate (separate package, even) to keep it as far away from the rest of the site, since really we should be deleting it once we have firstclass (i.e. not stainless associated) terraform support in forge
Summary
Adds Terraform documentation to API operation pages. Each operation shows the Terraform resources and data sources that call it, with their attributes, an HCL example and the import command.
The data comes from the released Cloudflare Terraform provider instead of Stainless' internal SDK JSON. Every input is public and pinned to a version. The generator is offline and read-only, and a scheduled workflow keeps the data in sync.
How it works
packages/docs-site/scripts/generate-terraform-docs.tsreads local checkouts ofcloudflare/terraform-provider-cloudflare(at a release tag) and of thecloudflare-gomodules itsgo.modrequires. From those checkouts it takes:docs/{resources,data-sources}/*.md: tfplugindocs output, the same content the Terraform Registry showsexamples/internal/services/*client calls, resolved through cloudflare-goapi.mdinternal/version.goand.git/HEADin each checkoutThe output,
src/generated/terraform-docs.json(format 2), stores each declaration once and lists the linked declarations and roles for each SDK endpoint. It also records the provider and SDK versions and commit SHAs. At build time,src/terraform-extension.tsmatches those endpoints to OpenAPI operations by method + path, with path parameter names ignored. Account, zone and combined account-or-zone paths match each other, so it doesn't depend onoperationId. The build warns, instead of failing, about declarations that match no operation.Security
The generator reads third-party repositories, so it treats their contents as untrusted data:
child_process,http,fetch(, dynamicimport(), etc.scripts/source-tree.ts): it refuses symbolic links,..and absolute paths, paths that end up outside the checkout, and oversized files.file:line. An SDK call that can't be resolved also fails the run.go.mod. The output is validated against the same zod schema the site uses to read it.Sync workflow
.github/workflows/sync-terraform-docs.ymlruns daily at 06:17 UTC and can be started by hand:generatehas read-only permissions, no secrets and no saved git credentials.pull-requestnever sees third-party sources.bot/sync-terraform-docsand opens or updates a PR withgh.gh pr merge --match-head-commit.Third-party actions are pinned to commit SHAs, and workflow inputs reach shell scripts only through
envand are validated. The job does nothing until a new provider version is published.UI
sensitive/deprecatedmarkers.terraform importcommand.Coverage (provider v5.27.0, cloudflare-go v6.10.0 / v7.12.0)
create.cloudflare_snippets(its resource makes no API calls). Not documented by the provider:cloudflare_rate_limits(list data source).Validation
api.mdand service parsing, the tfplugindocs parser (includingfile:lineerrors), version checks, source-tree confinement (symlink and path-escape attempts), and the offline guard.pnpm --filter docs-site check(0 errors),oxlintandactionlint.--checkreproduces the committed file byte for byte from v5.27.0 sources.DOCS_SYNC_TOKENsecret (a GitHub App or fine-grained token): PRs opened withGITHUB_TOKENdon't trigger CI, so they would never be merged automatically.Screenshots
From the first iteration. The layout is unchanged, but the labels were updated afterwards: "Computed" is now "Read-only", and the "forces replacement" badge is gone.