Repository navigation
feat(api): Export API reference data as @sentry/api/docs - #150
Merged
Merged
Conversation
sentry-junior
Bot
requested review from
BYK,
MathurAditya724 and
betegon
as code owners
November 13, 2026 14:26
BYK
requested changes
Nov 13, 2026
Add a docs generator next to the operations catalog. It projects the dereferenced spec onto what an API reference page shows: tags, full parameters, the request body's first content type, responses with schemas and examples, security and servers. It ships as the ./docs export with types, plus extractDocs() to build the same data from an unreleased spec. As in the client and the operation catalog since 2.0.0, paths are relative to the API base path, which the export carries as API_BASE_PATH, and server overrides keep only their origin. Tests pin the shape with a fixture and check the published export against the spec it was built from, so the two can't drift. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
BYK
force-pushed
the
feat/api-docs-export
branch
from
November 13, 2026 14:32
811d00e to
db4e4c1
Compare
BYK
reviewed
Nov 13, 2026
…e strings generate-docs now builds docs.ts from ts.factory nodes and writes it through a new writeSource helper that prints with the TypeScript printer. A local oxlint plugin adds sentry-api/no-typescript-source-strings, which reports .ts files written from strings, templates, concatenation or .join(), and string patches through replaceOnce, in build.mjs, scripts/ and lib/. CI runs it as pnpm lint. The generators that predate the rule are listed in .oxlintrc.json until they move to the printer.
API_BASE_PATH comes from the spec's server URL, so naming its current value would go stale if the server changes it.
BYK
approved these changes
Nov 13, 2026
BYK
added a commit
that referenced
this pull request
Nov 13, 2026
Main has been red since the spec sync from getsentry/sentry#131065 landed (36d0d11). That sync made spec paths relative to the server URL's `/api/0`. Two tests still look up or compare full `/api/0` paths, so Build fails and no `@sentry/api` release goes out until this lands. - `test/descriptions.test.ts` (from #142): `spec.paths["/api/0/organizations/{organization_id_or_slug}/dashboards/"]` → `spec.paths["/organizations/{organization_id_or_slug}/dashboards/"]` - `test/docs.test.ts` (from #150, written against the old spec), comparing the export's paths with the spec's: `` `${operation.method} ${API_BASE_PATH}${operation.path}` `` → `` `${operation.method} ${operation.path}` `` No other test reads `spec.paths` by a full `/api/0` key. The remaining `/api/0` strings in tests are request URLs, which are still correct. Checks: `pnpm build`, `pnpm typecheck`, `pnpm test` (681 passed) and `check-script-modes.sh` pass. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A640c5343d03e547097aa9b8a711daaf5 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A640c5343d03e547097aa9b8a711daaf5) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A640c5343d03e547097aa9b8a711daaf5/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #149. Ported from getsentry/sentry#130538, per @BYK's request there: get the docs aligned here first, then move
@sentry/apiinto getsentry/sentry.This adds the data sentry-docs needs to build the API reference from the
@sentry/apiversion it pins, so it no longer has to readopenapi-derefed.jsonfrom a pinned commit of this repository. The sentry-docs adapter is getsentry/sentry-docs#20679.Changes from the sentry version
2.0.0 (#148) made every path relative to the API base path and trimmed server URLs to their origin. The export now follows the same contract:
paths are relative, such as/organizations/, the same as@sentry/api/operations;API_BASE_PATH(/api/0) and asapiBasePathinextractDocs()output, so a page builds the full path as${API_BASE_PATH}${operation.path};serversare origins.extractDocs()appliessplitApiBasePathto a copy of the spec it gets, so the published data and a preview of a local spec have the same shape. It accepts both the current spec and one that declares the base path inservers.sentry-docs#20679 needs a follow-up for this: its adapter has to prepend
API_BASE_PATHto paths, like sentry-docs#20787 does for 2.0.0. I'll push that once this shape is settled.What it adds
scripts/generate-docs.mjs, next to theoperationsgenerator. It runslib/docs-catalog.mjsextractDocs(spec)on the originalopenapi-derefed.jsonand emitssrc/docs.ts. That file holds the data as a JSON string literal, so tsc doesn't infer a type for 3.7 MB of data. It ships as@sentry/api/docs(dist/docs.jsplus.d.ts).lib/docs-types.ts):apiBasePath/API_BASE_PATH.tags: name, description,sidebarName(x-sidebar-name) anddisplayDescription(x-display-description).operations, in spec order:operationId, method and relative path, with summary and description copied as written. Also tags,deprecated,experimental(x-sentry-experimental), server origins, security requirements, and parameters (path-level merged with operation overrides) within,required, description,experimentaland schema. The request body comes from its first content type (content type,required, schema, example), and every response has its status, description, content type, schema andexample/examples.extractDocsis exported too, so sentry-docs'OPENAPI_LOCAL_PATHpreview of an unreleased local spec goes through the same projection as the published data.lib/http-methods.mjsholds the HTTP method set that both catalogs use.The export's shape is now a semver contract
sentry-docs, and anything else that imports
@sentry/api/docs, depends on these field names and types. Removing or renaming a field, or changing its type, is a major release. Adding fields is a minor release. The README says so.Size
Measured with
npm pack --dry-runfrom clean builds of #149 and this branch, using the spec in this repository:Almost all of it is
dist/docs.js(3,840,561 B). It's a separate entry point, so@sentry/apiand@sentry/api/clientusers like toolkit don't load it unless they import./docs. They only pay for the download.Tests
test/docs.test.ts:/api/0inserversand an operation server override under it, so the test also covers the relative paths,apiBasePathand origin-only servers. It also covers path-level parameter overrides, experimental flags, multiple content types, responses without content, named examples and security.@sentry/api/docswithopenapi-derefed.json:extractDocs(spec), andAPI_BASE_PATHis/api/0;API_BASE_PATHplus each relative path equal to the spec's path;test/package.test.ts: the packed-tarball smoke test imports@sentry/api/docs.pnpm build,pnpm typecheckandpnpm testpass locally (54 files, 679 tests).No UI change here. The sentry-docs PR carries the API reference screenshots.
Merge order
#149, this PR, the normal release of an
@sentry/apiversion with./docs, then getsentry/sentry-docs#20679 with itsAPI_BASE_PATHfollow-up. That PR's dependency bump is its last step.Co-Authored-By: BYK 126780+BYK@users.noreply.github.com
--
View Session [Sentry]