Skip to content

API Explorer: serve pages at /docs/api/<key> instead of /docs/api/doc/<key> - #4951

Merged
reakaleek merged 8 commits into
mainfrom
drop-api-doc-segment
Nov 19, 2026
Merged

reakaleek merged 8 commits into
mainfrom
drop-api-doc-segment

Conversation

@reakaleek

@reakaleek reakaleek commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Why

  • The API Explorer replaces bump.sh. Its pages should drop the bump.sh-era /doc segment before the cutover (elastic/docs-eng-team#725), so readers see one URL change, not two.
  • Old /doc links must keep working for readers and authors.

Closes elastic/docs-eng-team#1211

What

  • API pages, navigation, the version switcher, links.json roots, search documents and llms.txt use /docs/api/<key>/....
  • Links to a host that still proxies bump.sh keep the /doc form. This covers www.elastic.co from isolated builds, and any assembler environment without the assembler-api-explorer flag (prod today). Prod output does not change.
  • /doc links stay valid. The link check accepts them in content and in OpenAPI descriptions. Older links.json files with api/doc/... roots still resolve.
  • A /doc content link gets a new hint, ApiLinkLegacyPrefix, which names the page's URL after the cutover. You can suppress it like the other hints.

Notes

  • Direction change from the issue: ApiUrlBuilder.ProductRoot does not read the flag. A build with the flag off renders no API pages, so a flag branch there would never run. The flag decides only how links to prod are written: IUriEnvironmentResolver.LegacyApiUrls, applied once in CrossLinkResolver. All bump.sh-era URL knowledge lives in ApiLegacyRedirects, which is already slated for deletion.
  • Deploy order: /docs/api/doc/* URLs redirect only at the edge, through the CloudFront function from elastic/docs-eng-team#1213. docs-builder serve has no such redirect. Staging, edge and preview need Bump eslint from 9.25.1 to 9.26.0 in /src/Elastic.Markdown #1213. Enable Bump eslint from 9.25.1 to 9.26.0 in /src/Elastic.Markdown #1213 on those environments before or with this deploy. At the cutover (Initial v0 of docs-assembler repos build-all command. #725), flip prod's assembler-api-explorer flag and IsolatedBuildEnvironmentUriResolver.LegacyApiUrls together. A test fails if those two disagree.
  • Search: the next indexing run on each environment writes API documents under the new URLs.
  • Scripted rewrite: the codemod below does the mechanical part. Run on main, it rewrites 169 files. Running it on this branch changes nothing. The files it excludes keep the legacy form on purpose, and I edited them by hand: the legacy helpers in ApiLegacyRedirects, ApiLinkCheck, FloatingLinkSection, the two URI resolvers, the legacy-input tests and the docs about legacy links. The frontend parsers api-tree.ts and api-navigation.ts were also edited by hand.
Codemod
#!/usr/bin/env bash
# Rewrites the API Explorer's /api/doc/<key> paths to /api/<key>. The excluded files keep the legacy form on purpose:
# the legacy helpers and redirect table, the link check and its hint, links to prod, legacy-input tests and docs about
# legacy links. A run on the PR head changes nothing.
set -uo pipefail
keep=(
  ':!src/Elastic.Documentation/Diagnostics/ApiLinkMatcher.cs'
  ':!src/Elastic.Documentation/Diagnostics/HintType.cs'
  ':!src/Elastic.Documentation/Links/ApiLegacyRedirects.cs'
  ':!src/Elastic.Documentation/Links/FloatingLinkSection.cs'
  ':!src/Elastic.Documentation.Links/CrossLinks/ApiLinkCheck.cs'
  ':!src/Elastic.Documentation.Links/CrossLinks/IUriEnvironmentResolver.cs'
  ':!src/services/Elastic.Documentation.Assembler/Links/PublishEnvironmentUriResolver.cs'
  ':!tests/Elastic.Documentation.Tests/Diagnostics/ApiLinkMatcherTests.cs'
  ':!tests/Elastic.Documentation.Tests/Diagnostics/ApiLegacyRedirectsTests.cs'
  ':!tests/Elastic.Markdown.Tests/CrossLinks/ApiPageStatusTests.cs'
  ':!tests/Elastic.Markdown.Tests/CrossLinks/FloatingLinkTests.cs'
  ':!tests/Elastic.Markdown.Tests/CrossLinks/LinksJsonForwardCompatibilityTests.cs'
  ':!tests/Elastic.Markdown.Tests/Inline/ApiLinkTests.cs'
  ':!tests/Navigation.Tests/Assembler/PublishEnvironmentSitePathTests.cs'
  ':!tests/Elastic.Documentation.Build.Tests/.snapshots/CrossLinks/**'
  ':!tests/Elastic.ApiExplorer.Tests/TestData/**'
  ':!docs/syntax/links.md' ':!docs/syntax/link-card.md' ':!docs/syntax/vector-sizing-calculator.md'
  ':!docs/documentation/isolated/configure/index.md'
)
rewrite() { local pattern=$1 perl=$2; git grep -lz -F -e "$pattern" -- src tests tests-integration docs "${keep[@]}" | xargs -0 -r perl -pi -e "$perl"; }

rewrite 'api/doc' 's#api/doc/#api/#g; s#/api/doc\b#/api#g'
# Paths joined from segments: Path.Join(root, "api", "doc", ...), Path.Join(apiRoot, "doc", ...), slug "doc/elasticsearch".
rewrite '"api", "doc", ' 's#"api", "doc", #"api", #g'
rewrite 'apiRoot, "doc", ' 's#apiRoot, "doc", #apiRoot, #g'
rewrite '"doc/elasticsearch' 's#"doc/elasticsearch#"elasticsearch#g'
# URL-encoded paths in inline snapshots, and escaped regexes such as /\/docs\/api\/doc\/.../.
rewrite 'api%2Fdoc%2F' 's#api%2Fdoc%2F#api%2F#g'
rewrite 'api\/doc\/' 's#api\\/doc\\/#api\\/#g'

Verify

mise run test
mise run site:test
mise run serve
# http://localhost:3000/api/elasticsearch/ renders, and its links use /api/elasticsearch/...

🤖 Generated with Claude Code

…<key>

The API Explorer replaces bump.sh, so its pages drop the bump.sh-era `/doc` segment before the cutover. Readers then see one URL change. Links to a host that still proxies bump.sh keep the `/doc` form: www.elastic.co, and any environment without the `assembler-api-explorer` flag. `/doc` links in content and in older link indexes keep working, and the link check hints at their URL after the cutover.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@reakaleek
reakaleek requested a review from a team as a code owner November 19, 2026 09:23
@reakaleek
reakaleek requested a review from akira28 November 19, 2026 09:23
reakaleek and others added 4 commits November 19, 2026 11:14
…w by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…iew by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… differ (per review by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
reakaleek and others added 3 commits November 19, 2026 13:40
The CloudFront function redirects /docs/api/doc/* (elastic/docs-eng-team#1213), so docs-builder serve does not need its own redirect.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@reakaleek
reakaleek merged commit 5304a21 into main Nov 19, 2026
44 checks passed
@reakaleek
reakaleek deleted the drop-api-doc-segment branch November 19, 2026 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant