Repository navigation
Warn when hard-coded API links point at missing pages - #4653
Conversation
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>
…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>
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4653/ Sample changed pages: |
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>
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>
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
| // 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)); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| 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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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>
| if (ApiLinkCheck.GetWarning(context.CrossLinkResolver, trimmed, context.Build.UrlPathPrefix) is { } warning) | ||
| block.EmitWarning(warning); | ||
| return url; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
| public void Setup(MarkdownPipelineBuilder pipeline) => | ||
| pipeline.InlineParsers.InsertBefore<LinkInlineParser>(new AutoLinkInlineParser()); | ||
| pipeline.InlineParsers.InsertBefore<LinkInlineParser>(new AutoLinkInlineParser(checkApiLinks)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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>
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.ymltarget 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.CheckApiPageanswersExists,MissingorUnknownfor a site path.CrossLinkResolverfinds theapi/{key}section among the fetched link references and calls the newFloatingLinkSection.ContainsSitePath, which matches the longest version root first. A resolver with no section for that API answersUnknown, so nothing is flagged for it.ApiLinkCheck.GetHintturns 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.ymltargets (reported against that file), andHtmlWriter.RenderApiDescriptionfor 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.ApiLinkMatchernormalizes 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 undersuppress:indocset.yml, likeAutolinkElasticCoDocs.Old bump.sh URLs
ApiLegacyRedirectsholds the redirects the edge serves from docs-infra'sapi-root-redirects.json, moved here fromApiSitemapParityTests, 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 askibana.yamlare files, not pages, and are not checked.Out of scope:
#anchorchecking, 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
A staging assembler build (
assembler build -c local --environment staging) reports 76 hints across 25 distinct URLs, for examplekibana/group/endpoint-detection-engine-rules-api.Closes elastic/docs-eng-team#997
🤖 Generated with Claude Code