Skip to content

Warn when hard-coded API links point at missing pages - #4653

Merged
akira28 merged 19 commits into
mainfrom
feature/request-link-checking-related
Nov 9, 2026
Merged

akira28 merged 19 commits into
mainfrom
feature/request-link-checking-related

Conversation

@akira28

@akira28 akira28 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

A hard-coded https://www.elastic.co/docs/api/doc/... link, a redirect to one, or a link between API pages in an OpenAPI description now produces a hint when the page does not exist in the API pages of the link index.

Affects: Links & redirects, Authoring, Configuration

Prompt summary: Implement link checking for the API docs from elastic/docs-eng-team#997. Links into the auto-generated API reference can disappear without notice, for example when an endpoint is discontinued, and nothing validated them. After #4731 landed, check hard-coded API links through the cross-link resolver it added instead of comparing them with a set of generated URLs.

Why

#4731 lets authors cross-link to API pages and fails the build when one is missing, but a hard-coded API URL, a redirects.yml target and a link inside an OpenAPI description are still never checked. API pages come from specs we do not control, so an endpoint can disappear and these links break with no signal.

What

Asking the resolver

ICrossLinkResolver.CheckApiPage answers Exists, Missing or Unknown for a site path. CrossLinkResolver finds the api/{key} section among the fetched link references and calls the new FloatingLinkSection.ContainsSitePath, which matches the longest version root first. A resolver with no section for that API answers Unknown, so nothing is flagged for it. ApiLinkCheck.GetHint turns a link into a hint only for a known missing page.

Where links are read

The check runs where each kind of link is already parsed: inline links, bare URLs in the autolink parser, DirectiveLinkValidator (hero actions, cards, intros), redirects.yml targets (reported against that file), and HtmlWriter.RenderApiDescription for the links between API pages in OpenAPI descriptions, which parse without link validation. A shared description is hinted once per broken link, not once per page that renders it. Links inside % comments are skipped, and so is the changelog pipeline, whose text comes from PR titles that authors cannot fix. ApiLinkMatcher normalizes a URL by dropping the query and fragment, collapsing repeated slashes and lowercasing it. A link under another path prefix, such as a PR preview, is converted to the production URL first.

A hint, not a warning

Every check emits the hint ApiLinkMissingPage. The content-repo smoke tests build with --strict, which fails on any warning, and docs-content and elasticsearch both link to API pages that no longer exist, so warnings turned their CI red. A hint does not fail --strict, shows in CI as a notice, and a docset can silence it under suppress: in docset.yml, like AutolinkElasticCoDocs.

Old bump.sh URLs

ApiLegacyRedirects holds the redirects the edge serves from docs-infra's api-root-redirects.json, moved here from ApiSitemapParityTests, which now uses it. A link to an old root is checked at the page the edge redirects it to, so a link that works today is not flagged and one whose target is gone still is. A root with no pages at all, observability-serverless, always hints. Spec downloads such as kibana.yaml are files, not pages, and are not checked.

Out of scope: #anchor checking, links from product source code, <...> autolinks and raw HTML anchors (no source file contains one), and an API that no docset publishes a section for yet.

Verify

mise run test
dotnet test --project tests/Elastic.Markdown.Tests --treenode-filter "/*/*/*Api*/*"

A staging assembler build (assembler build -c local --environment staging) reports 76 hints across 25 distinct URLs, for example kibana/group/endpoint-detection-engine-rules-api.

Closes elastic/docs-eng-team#997

🤖 Generated with Claude Code

akira28 and others added 2 commits November 2, 2026 17:26
Links from narrative docs and redirects into /docs/api/doc/ were never
checked, so a removed endpoint broke them silently. The assembler now
records those links, compares them with the pages the API Explorer
generated, warns per broken link, and writes api-link-report.json.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The redirect check recorded API targets against docset.yml, so a warning
pointed at the wrong file. ConfigurationFile now exposes the redirects
file and a test covers the recorded location.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@akira28 akira28 added the feature label Nov 2, 2026
…a BOM

An assembler run found 52 links written as .../elasticsearch//operation/...
that the validator reported as broken. Normalizing repeated slashes treats
them like the single-slash form. The report also began with a UTF-8 byte
order mark, which strict JSON parsers reject.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

@akira28
akira28 marked this pull request as ready for review November 3, 2026 09:54
@akira28
akira28 requested a review from a team as a code owner November 3, 2026 09:54
@akira28
akira28 requested a review from technige November 3, 2026 09:54
akira28 and others added 2 commits November 3, 2026 11:43
The three parse-time hooks missed autolinks and recorded link cards twice.
An ApiLinkExporter now reuses the document each page already parsed and
the OutboundLinkExtractor from the search indexer, which now also returns
link positions. Redirect targets are still recorded separately.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…prefix

The exporter route missed API children pages and the hero, card-group and
what's-new fields. Links are recorded again at the inline, autolink and
directive parse points, which every page and directive passes through.
A PR preview serves pages under another path prefix, so the generated
URLs are now recorded under /docs. Each URL is reported once per file.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
akira28 and others added 2 commits November 3, 2026 12:26
About 70 reported links used the old serverless and elastic-cloud-serverless
roots, which the edge redirects. The validator now follows the same redirect
table and checks the target page, so a link that works today is not flagged
but one whose target is gone still is. The table moves out of
ApiSitemapParityTests, which now uses it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Markdig parses <https://...> links itself, so they never reached the API
link hooks. A recorder in front of its autolink parser now sees them
without consuming input. The bare-URL and angle-bracket paths skip
% comment lines, as the inline link parser already does.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Markdig builds an AutolinkInline for <https://...>, not a LinkInline, so
the generic test base failed its own non-null check.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
akira28 and others added 4 commits November 4, 2026 17:32
API descriptions parse without link validation, so the links between API
pages that come from the OpenAPI specs were never checked. HtmlWriter now
records them, using the outbound link extractor, and spec download files
count as generated pages. A run on the staging checkouts finds 10 broken
description links across 5 targets.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…lated' into feature/request-link-checking-related
Comment thread src/Elastic.Markdown/HtmlWriter.cs Outdated
Comment on lines +80 to +89
// Descriptions parse without link validation, so the links they hold between API pages are recorded here for the API link check.
private void RecordApiLinks(MarkdownDocument parsed, IFileInfo source)
{
var context = DocumentationSet.Context;
foreach (var url in OutboundLinkExtractor.Extract(parsed) ?? [])
{
if (ApiLinkMatcher.TryCanonicalize(url, context.UrlPathPrefix, out var canonical))
context.Collector.EmitApiLink(new ApiLinkReference(canonical, source.FullName, 1, 1, canonical.Length));
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P2 (Medium)

RenderApiDescription runs on every page that shows a shared description, such as a schema, parameter or response description. Each call passes a different virtual description.md path (one per page URL), so the (Url, File) dedupe in ApiLinkValidator keeps every copy. One broken link in a shared spec description then produces a warning on every operation page that renders it, which can be hundreds of near-identical warnings, and it inflates checked in the report. Each warning also points at line 1 of a file in the output directory that doesn't exist. Dedupe description links by URL plus spec or product root, or record them once per description text, rather than once per rendering page.

Generated by Libra. Specialist: libra-complexity. React with 👍 or 👎 to give feedback on this comment.

Comment thread src/Elastic.Markdown/HtmlWriter.cs Outdated
Comment on lines +84 to +87
foreach (var url in OutboundLinkExtractor.Extract(parsed) ?? [])
{
if (ApiLinkMatcher.TryCanonicalize(url, context.UrlPathPrefix, out var canonical))
context.Collector.EmitApiLink(new ApiLinkReference(canonical, source.FullName, 1, 1, canonical.Length));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P2 (Medium)

Include raw HTML anchor targets when recording description links. ApiDescriptionPipeline supports <a href="..."> links, but OutboundLinkExtractor only collects Markdown link nodes and directive targets, so an HTML link to a missing API page never reaches the validator and produces neither a warning nor a report entry.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this. No <a href="…/api/doc/…"> appears in the Markdown of the cloned content repos or in the Kibana and Elasticsearch spec sources, where the API links are Markdown links. The description check reads Markdown nodes through OutboundLinkExtractor, and HTML anchors would need a separate scan. I'll add one if a spec starts using them.

akira28 and others added 2 commits November 6, 2026 11:03
Main now publishes API pages in links.json and resolves cross-links to
them, so this branch asks the resolver whether an API page exists instead
of comparing against a set of generated URLs. The post-build validator,
the report and the collector plumbing are gone; each place that reads a
link warns directly. Old bump.sh URLs are checked at the page the edge
redirects them to.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@akira28 akira28 changed the title Warn when links to the API docs point at missing pages Warn when hard-coded API links point at missing pages Nov 6, 2026
Comment on lines 96 to 98
if (ApiLinkCheck.GetWarning(context.CrossLinkResolver, trimmed, context.Build.UrlPathPrefix) is { } warning)
block.EmitWarning(warning);
return url;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P2 (Medium)

Angle-bracket autolinks in directive prose never reach this warning check. For example, a hero :description: containing <https://www.elastic.co/docs/api/doc/kibana/operation/operation-missing> renders as a clickable link, but ResolveMarkdownLinks visits only LinkInline nodes, not Markdig's AutolinkInline nodes. The document's new angle-bracket checker cannot catch it either because directive options are rendered separately with the default pipeline. Validate autolink targets in these fields as well.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moot now: the angle-bracket checker is removed (see the reply on AutoLinkInlineParser.cs), and <...> autolinks are documented as not checked.

…ne roots

A shared description rendered on every page that shows it, so each broken
link now warns once. Bare URLs in changelog entries come from PR text and
are no longer checked. A link to a root with no pages warns, because the
link index never holds a section for it. The angle-bracket checker is
removed: no source file contains such a link. Redirect warnings report
against the docset file, like the existing redirect errors.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Comment on lines 32 to +33
public void Setup(MarkdownPipelineBuilder pipeline) =>
pipeline.InlineParsers.InsertBefore<LinkInlineParser>(new AutoLinkInlineParser());
pipeline.InlineParsers.InsertBefore<LinkInlineParser>(new AutoLinkInlineParser(checkApiLinks));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P2 (Medium)

Removing the angle-bracket checker leaves <https://www.elastic.co/docs/api/doc/kibana/operation/operation-missing> unchecked in ordinary Markdown. Markdig consumes this syntax with its built-in AutolinkInlineParser, so neither the bare-URL parser nor DiagnosticLinkInlineParser calls CheckApiLink. Keep an angle-autolink validation hook, gated by checkApiLinks, and retain the missing-page regression test so this supported link form produces the promised warning.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this. Across the Markdown files of the cloned content repos I found 1,867 inline links, 45 bare URLs and none written as <https://…/api/doc/…>, so a hook for it would have no user today. Markdig parses that syntax in its own AutolinkInlineParser, so checking it needs an extra parser in front of it. docs/syntax/links.md now says <...> autolinks are not checked. I'll add the hook if one shows up.

akira28 and others added 2 commits November 6, 2026 11:34
A redirect warning pointed at docset.yml, which does not contain the link.
ConfigurationFile exposes the redirects file again and the warning uses it.
The docs no longer claim that <...> autolinks are checked.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The smoke tests build docs-content and elasticsearch with --strict, and
every warning fails that build. Those repos link to API pages that no
longer exist, so the warnings turned their CI red. The check now emits a
hint, ApiLinkMissingPage, which does not fail --strict and can be silenced
in docset.yml like the other hints.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@akira28
akira28 merged commit 6f51ffb into main Nov 9, 2026
36 checks passed
@akira28
akira28 deleted the feature/request-link-checking-related branch November 9, 2026 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants